summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLAMMJohnson <john_anthony@lavabit.com>2011-04-26 20:25:17 +0100
committerLAMMJohnson <john_anthony@lavabit.com>2011-04-26 20:25:17 +0100
commit9a1b1b71f5f3e97bb1cb887dea632b718e2e2227 (patch)
tree487d4a2a24fe12fa1bddca99f12377c4a072bcfb
parent9eaac3f8892faaf3a44b3d9c194ed40ada596c66 (diff)
downloadnyancat-9a1b1b71f5f3e97bb1cb887dea632b718e2e2227.tar.gz
nyancat-9a1b1b71f5f3e97bb1cb887dea632b718e2e2227.tar.bz2
nyancat-9a1b1b71f5f3e97bb1cb887dea632b718e2e2227.zip
Added cat management
-rw-r--r--TODO5
-rw-r--r--nyah.c67
2 files changed, 55 insertions, 17 deletions
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..901f08a
--- /dev/null
+++ b/TODO
@@ -0,0 +1,5 @@
+-- Make screen blanking happen only in the places objects previously were rather than redrawing the whole screen
+-- Add Xinerama support (one cat per monitor)
+-- Add sound
+-- Add command-line args
+-- Add rc file
diff --git a/nyah.c b/nyah.c
index a65a684..fbb5b23 100644
--- a/nyah.c
+++ b/nyah.c
@@ -26,11 +26,13 @@ struct sparkle_instance {
SDL_Surface* cat_img[5];
SDL_Surface* sparkle_img[5];
-sparkle_instance* sparkles_front_start = NULL;
+sparkle_instance* sparkles_list = NULL;
+cat_instance* cat_list = NULL;
Uint8 bgcolor;
void add_sparkle(void);
-void draw_cat(unsigned int frame);
+void add_cat(unsigned int x, unsigned int y);
+void draw_cats(unsigned int frame);
void draw_sparkles(unsigned int layer);
void fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col);
void handleinput(void);
@@ -51,7 +53,7 @@ static int SURF_TYPE = SDL_HWSURFACE;
void
add_sparkle(void) {
- sparkle_instance* s = sparkles_front_start;
+ sparkle_instance* s = sparkles_list;
sparkle_instance* new;
new = malloc(sizeof(sparkle_instance));
@@ -64,8 +66,8 @@ add_sparkle(void) {
new->layer = rand() % 2;
new->next = NULL;
- if (!sparkles_front_start) {
- sparkles_front_start = new;
+ if (!sparkles_list) {
+ sparkles_list = new;
return;
}
@@ -77,28 +79,57 @@ add_sparkle(void) {
}
void
-draw_cat(unsigned int frame) {
+add_cat(unsigned int x, unsigned int y) {
+ cat_instance* c = cat_list;
+ cat_instance* new;
+
+ new = malloc(sizeof(cat_instance));
+
+ new->loc.x = x;
+ new->loc.y = y;
+ new->next = NULL;
+
+ if (!cat_list) {
+ cat_list = new;
+ return;
+ }
+
+ /* Find end of list */
+ while (c->next)
+ c = c->next;
+
+ c->next = new;
+}
+
+void
+draw_cats(unsigned int frame) {
+ cat_instance* c = cat_list;;
SDL_Rect pos;
- pos.x = 40;
- pos.y = 40;
+ while (c) {
- if(frame == 0)
- pos.y -= 5;
+ pos.x = c->loc.x;
+ pos.y = c->loc.y;
+
+ if(frame == 0)
+ pos.y -= 5;
- SDL_BlitSurface( cat_img[frame], NULL, screen, &pos );
+ SDL_BlitSurface( cat_img[frame], NULL, screen, &pos );
+
+ c = c->next;
+ }
}
void
draw_sparkles(unsigned int layer) {
- sparkle_instance* s = sparkles_front_start;
+ sparkle_instance* s = sparkles_list;
SDL_Rect pos;
while (s) {
if (s->layer == layer) {
pos.x = s->loc.x;
pos.y = s->loc.y;
- SDL_BlitSurface( sparkle_img[sparkles_front_start->frame], NULL, screen, &pos );
+ SDL_BlitSurface( sparkle_img[sparkles_list->frame], NULL, screen, &pos );
}
s = s->next;
}
@@ -151,10 +182,10 @@ putpix(SDL_Surface* surf, int x, int y, Uint32 col) {
void
remove_sparkle(sparkle_instance* s) {
- sparkle_instance* s2 = sparkles_front_start;
+ sparkle_instance* s2 = sparkles_list;
if (s2 == s) {
- sparkles_front_start = s->next;
+ sparkles_list = s->next;
free(s);
return;
}
@@ -168,7 +199,7 @@ remove_sparkle(sparkle_instance* s) {
void
update_sparkles(void) {
- sparkle_instance* next, *s = sparkles_front_start;
+ sparkle_instance* next, *s = sparkles_list;
while(s) {
s->loc.x -= s->speed;
@@ -210,6 +241,8 @@ main( int argc, char *argv[] )
load_images();
+ add_cat((SCREEN_WIDTH - cat_img[0]->w) / 2 , (SCREEN_HEIGHT - cat_img[0]->h) / 2);
+
/* clear initial input */
while( SDL_PollEvent( &event ) ) {}
@@ -223,7 +256,7 @@ main( int argc, char *argv[] )
CLEARSCR();
draw_sparkles(0);
- draw_cat(curr_frame);
+ draw_cats(curr_frame);
draw_sparkles(1);
update_sparkles();