File: enemy_zatak.c

package info (click to toggle)
ketm 0.0.6-17sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,356 kB
  • ctags: 875
  • sloc: ansic: 7,303; sh: 410; makefile: 185
file content (101 lines) | stat: -rw-r--r-- 1,743 bytes parent folder | download | duplicates (3)
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
#include "enemy.h"

extern double fps_factor;
extern SPRITE *player;

typedef struct {
	ENEMY_BASE b;
	double angle;
	double speed;
	int state;
	double wait;
	int level;
} ZATAK_DATA;

void enemy_zatak_add(int lv)
{
	int i;
	SPRITE *s;
	ZATAK_DATA *data;

	for(i=0;i<12;i++) {
		s=sprite_add_file("rwingx.bmp",37,PR_ENEMY);
		s->type=SP_EN_ZATAK;
		s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
		s->mover=enemy_zatak_move;
		s->anim_speed=0;
		s->aktframe=0;
		data=mmalloc(sizeof(ZATAK_DATA));
		s->data=data;
		data->b.score=25;
		data->b.health=1;
		data->state=0;
		data->wait=0;
		data->speed=2.0*(((double)rand()/RAND_MAX)*2);
		if(i<6) {
			data->angle=10;
			s->x=-s->w;
			s->y=50;
		} else {
			data->angle=170;
			s->x=WIDTH;
			s->y=50;
		}
		data->level=lv;
	}
}


void enemy_zatak_move(SPRITE *s)
{
	ZATAK_DATA *d=(ZATAK_DATA *)s->data;

	d->wait+=fps_factor;
	switch(d->state) {
		case 0:
			if(d->wait>=40) {
				d->state=1;
			}
			break;
		case 1:
			d->speed-=(0.02*fps_factor);
			if(d->speed<=0) {
				d->speed=0;
				d->state=2;
			}
			break;
		case 2:
			if(d->angle<90) {
				d->angle+=3*fps_factor;
				if(d->angle>=89) {
					d->angle=90;
					d->state=3;
					if(d->level)
						enemy_laser_create(s,5+d->level);
				}
			} else {
				d->angle-=3*fps_factor;
				if(d->angle<=91) {
					d->angle=90;
					d->state=3;
					if(d->level)
						enemy_laser_create(s,5+d->level);
				}
			}
			break;
		case 3:
			d->speed+=0.3;
			if(d->speed>=(6+d->level)) {
				d->speed=6+d->level;
				d->state=4;
			}
			break;
		case 4:
			if(s->y<0)
				s->type=-1;
			break;
	}
	s->x+=cos(degtorad(d->angle))*d->speed*fps_factor;
	s->y+=sin(degtorad(d->angle))*d->speed*fps_factor;
	s->aktframe=(((int)d->angle+270)%360)/10;
}