summaryrefslogtreecommitdiffstats
path: root/draw.h
blob: ab816173416cffcaa243ca46efd989894b6f3e8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#ifndef DRAW_H
#define DRAW_H

void add_sparkle(void)
	{
	sparkle_instance* new;

	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_add(&new->list, &sparkle_list);
	}

void add_cat(unsigned int x, unsigned int y)
	{
	cat_instance* new;

	new = ec_malloc(sizeof(cat_instance));
	new->loc.x = x;
	new->loc.y = y;
	list_add(&new->list, &cat_list);
	}

void add_rainbow(unsigned int x, unsigned int y)
	{
	rainbow_instance* new;

	new = ec_malloc(sizeof(rainbow_instance));
	new->loc.x = x;
	new->loc.y = y;
	new->sprite = rainbow_sprite;
	list_add(&new->list, &rainbow_list);
	}

void update_rainbows()
	{
	cat_instance *c;

	/* Rainbows need to be placed according to the cat position (which changes constantly) */
	list_for_each_entry(c, &cat_list, list)
		{
		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, *tmpr;

	/* Update the position of each rainbow that exists */
	list_for_each_entry_safe(r, tmpr, &rainbow_list, list)
		{
		r->loc.x -= rainbow_width;

		/* If rainbow if off the screen, delete and free() it */
		if ((r->loc.x + rainbow_width) < 0)
			{
			list_del(&r->list);
			free(r);
			}
		}
	}

void update_sparkles()
	{

	sparkle_spawn_counter += rand() % SCREEN_HEIGHT;
	while (sparkle_spawn_counter >= 1000)
		{
		add_sparkle();
		sparkle_spawn_counter -= 1000;
		}

	sparkle_instance *s, *tmps;
	list_for_each_entry_safe(s, tmps, &sparkle_list, list)
		{
		s->loc.x -= s->speed;
		s->frame += s->frame_mov;

		if (s->frame + 1 >= sparkle_count || s->frame < 1){s->frame_mov = 0 - s->frame_mov;}

		if ((s->loc.x + sparkle_width) < 0)
			{
			list_del(&s->list);
			free(s);
			}
		}
	}

void handle_sine()
	{
	cat_instance *c;

	list_for_each_entry(c, &cat_list, list)
		{
		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_for_each_entry(c, &cat_list, list)
		{
		SDL_Rect srcrect = {cat_sprite * cat_width, 0, cat_width, cat_height};
                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_for_each_entry(r, &rainbow_list, list)
		{
		SDL_Rect srcrect = {r->sprite * rainbow_width, 0, rainbow_width, rainbow_height};
		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_for_each_entry(s, &sparkle_list, list)
		{
		SDL_Rect srcrect = {sparkle_sprite * sparkle_width, 0, sparkle_width, sparkle_height};
                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