aboutsummaryrefslogtreecommitdiff
path: root/src/enemies/podoboo.c
blob: 1dfc30b2617cbf778feb7077366241fee44a3f8d (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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "podoboo.h"
#include "../PHL.h"
#include "../hero.h"
#include "../game.h"
#include "../effect.h"
#include <stdlib.h>
#include <math.h>

void podobooStep(Podoboo* p);
void podobooDraw(Podoboo* p);

void createPodoboo(int x, int y, int offset, int height)
{
	int i;
	for (i = 0; i < MAX_ENEMIES; i++) {
		if (enemies[i] == NULL) {
			Enemy* e = malloc(sizeof *e);
			Podoboo* p = malloc(sizeof *p);
			
			p->id = i;
			
			p->x = x;
			p->y = p->ystart = y;
			
			p->hp = 2;
			p->blink = 0;			
			
			p->yoffset = p->rot = 0;
			
			p->vsp = 0;
			p->grav = 0.13;
			
			p->jumpheight = -5;
			/*
			if (height == 1) {
				p->jumpheight = -5.4;
			}
			*/
			if (height == 1) {
				p->jumpheight = -7;
			}
			
			p->imageIndex = 0;			
			
			p->timer = 30 * offset;
			p->state = 0;
			
			e->data = p;
			e->enemyStep = podobooStep;
			e->enemyDraw = podobooDraw;
			e->type = 15;
			
			enemies[i] = e;
			i = MAX_ENEMIES;
		}
	}
}

void podobooStep(Podoboo* p)
{
	//Blinking
	{
		if (p->blink > 0) {
			p->blink -= 1;
		}
	}
	
	p->timer -= 1;
	
	//Patterns
	{
		//Float in lava
		if (p->state == 0)
		{
			//Animate
			p->imageIndex += 0.1;
			if (p->imageIndex >= 2) {
				p->imageIndex -= 2;
			}
		
			//Bob movement
			p->rot += 5;
			if (p->rot >= 360) {
				p->rot -= 360;
			}
			p->y = p->ystart + (5 * sin(p->rot * 3.14159 / 180));
			
			//Jump
			if (p->timer <= 0) {
				p->state = 1;
				createLavaSplash(p->x + 20, p->y);
				
				p->y = p->ystart;
				p->vsp = p->jumpheight;
			}
		}
		//In air
		else if (p->state == 1)
		{
			//Animate
			p->imageIndex += 0.25;
			if (p->imageIndex >= 3) {
				p->imageIndex -= 3;
			}
		
			//Movement
			p->y += p->vsp;
			p->vsp += p->grav;
			
			//Land in lava again
			if (p->vsp > 0 && p->y >= p->ystart) {
				createLavaSplash(p->x + 20, p->y);
				p->y = p->ystart;
				p->state = 0;
				p->vsp = 0;
				p->timer = 60;
			}
		}
		
	}
	
	//Create Mask
	Mask mask;
	{
		mask.unused = mask.circle = 0;
		mask.w = mask.h = 30;
		mask.x = p->x + 5;
		mask.y = p->y + 5;
	}
	
	//Collide with hero
	{
		if (checkCollision(mask, getHeroMask())) {
			heroHit(15, mask.x + (mask.w / 2));
		}
	}
	
	//Weapon collision
	{
		int i;
		for (i = 0; i < MAX_WEAPONS; i++) {
			if (weapons[i] != NULL) {
				if (weapons[i]->cooldown == 0) {
					if (checkCollision(mask, weapons[i]->weaponMask)) {
						weaponHit(weapons[i]);
						p->hp -= 1;
						p->blink = 15;
						
						//Death
						if (p->hp <= 0) {
							createEffect(2, p->x - 12, p->y - 12);
							spawnCollectable(p->x + 20, p->y);
							enemyDestroy(p->id);
						}
						
						i = MAX_WEAPONS;
					}
				}
			}	
		}
	}

}

void podobooDraw(Podoboo* p)
{
	if (p->blink % 2 == 0) {
		int thisImage = p->imageIndex;
		
		if (p->state == 1) {
			thisImage += 2;
		}
		
		PHL_DrawSurfacePart(p->x, p->y, 280 + (40 * thisImage), 520, 40, 40, images[imgEnemies]);
	}
}