summaryrefslogtreecommitdiffstats
path: root/draw.h
diff options
context:
space:
mode:
authorDiffieHellman <DiffieHellman@endianness.com>2024-04-30 00:45:48 +1000
committerDiffieHellman <DiffieHellman@endianness.com>2024-04-30 00:52:03 +1000
commit87f05f8d0dff3688da35af625cb2bd66aa0d52d2 (patch)
tree732c882af3fd143f6f4169a4ea1d3db9513ba594 /draw.h
parent976183462c22191a1ef6f91ccd7eae084ffd0a81 (diff)
downloadnyancat-master.tar.gz
nyancat-master.tar.bz2
nyancat-master.zip
Restructed source into indididual object files, cleaned up licensing headers adding correct copyright years, added licenses, added malformed input handling and added bouncing cats featureHEADmaster
new file: LICENSE-AGPLv3 new file: LICENSE-GPLv3 modified: Makefile modified: README deleted: draw.h new file: globals.c modified: globals.h new file: main.c new file: main.h modified: nyan.c new file: nyan.h deleted: res/default/bg00.png deleted: res/default/bg01.png deleted: res/default/bg02.png deleted: res/default/bg03.png deleted: res/default/bg04.png deleted: res/default/fg00.png deleted: res/default/fg01.png deleted: res/default/fg02.png deleted: res/default/fg03.png deleted: res/default/fg04.png
Diffstat (limited to 'draw.h')
-rw-r--r--draw.h158
1 files changed, 0 insertions, 158 deletions
diff --git a/draw.h b/draw.h
deleted file mode 100644
index eb14e42..0000000
--- a/draw.h
+++ /dev/null
@@ -1,158 +0,0 @@
-#ifndef DRAW_H
-#define DRAW_H
-
-void add_sparkle(void)
- {
- sparkle_instance *new = ec_malloc(sizeof(sparkle_instance));
-
- new->loc.x = SCREEN_WIDTH + 80;
- new->loc.y = (rand() % (SCREEN_HEIGHT + sparkle_height)) - sparkle_height;
- new->frame = 0;
- new->frame_mov = 1;
- new->speed = 10 + (rand() % 30);
- new->layer = rand() % 2;
-
- LIST_INSERT_HEAD(&sparkle_list, new, entries);
- }
-
-void add_cat(unsigned int x, unsigned int y)
- {
- cat_instance *new = ec_malloc(sizeof(cat_instance));
-
- new->loc.x = x;
- new->loc.y = y;
-
- LIST_INSERT_HEAD(&cat_list, new, entries);
- }
-
-void add_rainbow(unsigned int x, unsigned int y)
- {
- rainbow_instance *new = ec_malloc(sizeof(rainbow_instance));
-
- new->loc.x = x;
- new->loc.y = y;
- new->sprite = rainbow_sprite;
-
- LIST_INSERT_HEAD(&rainbow_list, new, entries);
- }
-
-void update_rainbows()
- {
- cat_instance *c;
-
- /* rainbows need to be placed according to the cat position (which changes constantly) */
- LIST_FOREACH(c, &cat_list, entries)
- {
- add_rainbow((SCREEN_WIDTH - rainbow_width) / 2 - OFFSET /* Default position in the center */
- - ((SCREEN_WIDTH - cat_width) / 2 - c->loc.x), /* Plus the amount the cat is off the center */
- (SCREEN_HEIGHT - rainbow_height) / 2 /* Default position in the center */
- - ((SCREEN_HEIGHT - cat_height) / 2 - c->loc.y));/* Plus the amount the cat is off the center */
- }
-
-
- rainbow_instance *r, *rtmp;
-
- /* update the position of each rainbow left */
- LIST_FOREACH_SAFE(r, &rainbow_list, entries, rtmp)
- {
- r->loc.x -= rainbow_width;
-
- /* if rainbow is off screen, delete and free() it */
- if ((r->loc.x + rainbow_width) < 0)
- {
- LIST_REMOVE(r, entries);
- free(r);
- }
- }
- }
-
-void update_sparkles()
- {
-
- /* ensure screen has enough sparkles at all times */
- sparkle_spawn_counter += rand() % SCREEN_HEIGHT;
- while (sparkle_spawn_counter >= 1000)
- {
- add_sparkle();
- sparkle_spawn_counter -= 1000;
- }
-
- sparkle_instance *s, *stmp;
- LIST_FOREACH_SAFE(s, &sparkle_list, entries, stmp)
- {
- /* move sparkle left */
- s->loc.x -= s->speed;
- s->frame += s->frame_mov;
-
- /* reset sparkle frame */
- if (s->frame + 1 >= sparkle_count || s->frame < 1){s->frame_mov = 0 - s->frame_mov;}
-
- /* if sparkle offscreen, delete it */
- if ((s->loc.x + sparkle_width) < 0)
- {
- LIST_REMOVE(s, entries);
- free(s);
- }
- }
- }
-
-void handle_sine()
- {
- cat_instance *c;
-
- LIST_FOREACH(c, &cat_list, entries)
- {
- /* sine magic */
- double pos = (SCREEN_HEIGHT - cat_height)/2 * sin((2*PI*444444)*t);
- c->loc.y = ((SCREEN_HEIGHT - cat_height)/2 - pos);
- }
-
- t += 20;
- }
-
-void draw_cats()
- {
- cat_instance* c;
-
- LIST_FOREACH(c, &cat_list, entries)
- {
- /* source sprite dimensions */
- SDL_Rect srcrect = {cat_sprite * cat_width, 0, cat_width, cat_height};
- /* dimensions of destination rectangle */
- SDL_Rect dstrect = {c->loc.x, c->loc.y, cat_width*cat_size, cat_height*cat_size};
-
- SDL_RenderCopy(renderer, cat_texture, &srcrect, &dstrect);
- }
- }
-
-void draw_rainbows()
- {
- rainbow_instance* r;
-
- LIST_FOREACH(r, &rainbow_list, entries)
- {
- /* source sprite dimensions */
- SDL_Rect srcrect = {r->sprite * rainbow_width, 0, rainbow_width, rainbow_height};
- /* dimensions of destination rectangle */
- SDL_Rect dstrect = {r->loc.x, r->loc.y, rainbow_width*cat_size, rainbow_height*cat_size};
-
- SDL_RenderCopy(renderer, rainbow_texture, &srcrect, &dstrect);
- }
- }
-
-void draw_sparkles()
- {
- sparkle_instance* s;
-
- LIST_FOREACH(s, &sparkle_list, entries)
- {
- /* source sprite dimensions */
- SDL_Rect srcrect = {sparkle_sprite * sparkle_width, 0, sparkle_width, sparkle_height};
- /* dimensions of destination rectangle */
- SDL_Rect dstrect = {s->loc.x, s->loc.y, sparkle_width*cat_size, sparkle_height*cat_size};
-
- SDL_RenderCopy(renderer, sparkle_texture, &srcrect, &dstrect);
- }
- }
-
-#endif