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

extern SPRITE *player;
extern double fps_factor;

typedef struct {
	ENEMY_BASE b;
	int state;
	int tx;
	int ty;
	double speed;
	int level;
} BADGUY_DATA;

void enemy_badguy_add(int lv)
{
	int i;
	SPRITE *s;
	BADGUY_DATA *data;

	for(i=0;i<10;i++) {
		s=sprite_add_file("badguy.bmp",9,PR_ENEMY);
		s->type=SP_EN_BADGUY;
		s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
		s->mover=enemy_badguy_move;
		s->anim_speed=3;
		s->aktframe=0;
		switch(rand()%5) {
			case 0: s->x=rand()%20; break;
			case 1: s->x=WIDTH-rand()%20; break;
			case 2: s->x=310+rand()%20; break;
			case 3: s->x=150+rand()%20; break;
			case 4: s->x=450+rand()%20; break;
		}
		s->y=rand()%20-50;
		data=mmalloc(sizeof(BADGUY_DATA));
		s->data=data;
		data->b.score=5*(lv+1);
		data->b.health=1;
		data->state=0;
		data->tx=player->x;
		data->ty=player->y;
		data->speed=fps_factor*((double)(rand()%200)/100)*(3+lv);
		data->level=lv;

	}
}

void enemy_badguy_move(SPRITE *s)
{
	double angle;
	BADGUY_DATA *d=(BADGUY_DATA *)s->data;
	
	switch(d->state) {
		case 0:
			if((s->x >= player->x)||(s->y>400)) {
				d->state=1;
				s->anim_speed=-3;
				d->tx=-100;
				d->ty=player->y;
				if(d->level>0)
					enemy_bullet_create(s,1+d->level);
				d->speed=6*fps_factor;
			}
			
		case 1:
			if(s->x <= -s->w) {
				s->type=-1;
			}
	}

	angle=atan2(d->ty-s->y,d->tx-s->x);
	s->x+=cos(angle)*d->speed;
	s->y+=sin(angle)*d->speed;
}