File: enemy_rwingx.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 (98 lines) | stat: -rw-r--r-- 1,867 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
#include "enemy.h"

extern double fps_factor;
extern SPRITE *player;

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

void enemy_rwingx_add(int lv)
{
	int i;
	SPRITE *s;
	RWINGX_DATA *data;

	for(i=0;i<8;i++) {
		s=sprite_add_file("rwingx.bmp",37,PR_ENEMY);
		s->type=SP_EN_RWINGX;
		s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
		s->mover=enemy_rwingx_move;
		s->anim_speed=0;
		data=mmalloc(sizeof(RWINGX_DATA));
		s->data=data;
		data->b.score=25*(1+lv);
		data->b.health=1+lv;
		data->angle=270;
		data->speed=0.5;
		data->state=0;
		data->wait=20;
		data->level=lv;
		s->x=(WIDTH/8)*i-20;
		s->y=-50;
	}
}


void enemy_rwingx_move(SPRITE *s)
{
	RWINGX_DATA *d=(RWINGX_DATA *)s->data;

	switch(d->state) {
		case 0: /* sleep(d->wait) ticks */
			if(d->wait>0) {
				d->wait-=fps_factor;
			} else {
				/* langsam nach unten */
				d->state=1;
				d->angle=90;
				d->speed=1;
				d->wait=100;
			}
			break;
		case 1: /* move (d->wait) ticks */
			if(d->wait>0) {
				d->wait-=fps_factor;
			} else {
				d->state=2;
				d->wait=60;
				d->speed=0;
			}
			break;
		case 2: /* sleep(d->wait) ticks */
			if(d->wait>0) {
				d->wait-=fps_factor;
			} else {
				/* schnell richtung player */
				d->state=3;
				d->angle=radtodeg(atan2(player->y-s->y,player->x-s->x));
				d->speed=4+d->level;
				d->wait=50;
			}
			break;
		case 3: /* move (d->wait) ticks */
			if(s->y>=HEIGHT-150) {
				if(d->level)
					enemy_bullet_create(s,3+d->level);
				
				d->state=4;
				d->angle+=180;
				d->angle%=360;
				d->speed=6+d->level;
			}
			break;
		case 4:
			if((s->x<-s->w) || (s->x>WIDTH) || (s->y<-s->h) || (s->y>HEIGHT))
				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=((d->angle+270)%360)/10;
}