File: enemy_mine.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 (108 lines) | stat: -rw-r--r-- 2,032 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
102
103
104
105
106
107
108
#include "enemy.h"

extern double fps_factor;

typedef struct {
	ENEMY_BASE b;
	int state;
	int tx;
	int ty;
	int delay;
	int level;
} MINE_DATA;

void enemy_mine_add(int lv)
{
	SPRITE *s;
	MINE_DATA *data;

	s=sprite_add_file("12side.bmp",19,PR_ENEMY);
	s->type=SP_EN_MINE;
	s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
	s->mover=enemy_mine_move;
	s->anim_speed=1;
	s->aktframe=0;
	s->x=rand()%(WIDTH+10)-10;
	s->y=-40;
	data=mmalloc(sizeof(MINE_DATA));
	s->data=data;
	data->b.score=30;
	data->b.health=5;
	data->tx=rand()%270+50;
	data->ty=rand()%300+50;
	data->state=0;
	data->level=lv;
}

void enemy_mine_move(SPRITE *s)
{
	MINE_DATA *d=(MINE_DATA *)s->data;
	double angle;

	switch(d->state) {
		case 0: /* move */
			angle=atan2(d->ty-s->y,d->tx-s->x);
			s->x+=cos(angle)*1.5*fps_factor;
			s->y+=sin(angle)*1.5*fps_factor;
			if((s->x >= d->tx-1) && (s->x <= d->tx+1) &&
			   (s->y >= d->ty-1) && (s->y <= d->ty+1)) {
				d->state=1;
				d->delay=50;
			}
			break;
		case 1:
			d->delay-=fps_factor;
			if(d->delay<=0) {
				d->state=2;
				d->delay=30;
				s->anim_speed=0;
			}
			break;
		case 2:
			d->delay-=fps_factor;
			if(d->delay<=0) {
				enemy_supermine_add(s,d->level);
				s->type=-1;
			}
			break;
	}
}

void enemy_supermine_add(SPRITE *c, int lv)
{
	SPRITE *s;
	MINE_DATA *data;
	int i;

	for(i=0;i<8;i++) {
		s=sprite_add_file("12side.bmp",19,PR_ENEMY);
		s->type=SP_EN_MINE;
		s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
		s->mover=enemy_supermine_move;
		s->anim_speed=2;
		s->aktframe=0;
		s->x=c->x;
		s->y=c->y;
		data=mmalloc(sizeof(MINE_DATA));
		s->data=data;
		data->b.score=10*(1+lv);
		data->b.health=1+lv;
		data->state=(360/8)*i;
		data->level=lv;
	}
}

void enemy_supermine_move(SPRITE *s)
{
	MINE_DATA *d=(MINE_DATA *)s->data;

	if(d->level)
		if(rand()%(100-d->level*10)==0)
			enemy_bullet_create(s,3+d->level);

	s->x+=cos(degtorad(d->state))*3*fps_factor;
	s->y+=sin(degtorad(d->state))*3*fps_factor;

	if((s->x<0-s->w)||(s->x>WIDTH)||(s->y<0-s->h)||(s->y>HEIGHT))
		s->type=-1;
}