File: enemy_cube.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,308 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 double fps_factor;

typedef struct {
	ENEMY_BASE b;
	double radius;
	double angle;
	int flag0;
	int flag1;
	int flag2;
	int level;
} CUBE_DATA;

void enemy_cube_add(int lv)
{
	int i;
	SPRITE *s;
	CUBE_DATA *data;

	for(i=0;i<16;i++) {
		s=sprite_add_file("cube.bmp",16,PR_ENEMY);
		s->type=SP_EN_CUBE;
		s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
		s->mover=enemy_cube_move;
		s->anim_speed=1;
		s->aktframe=i%s->frames;
		data=mmalloc(sizeof(CUBE_DATA));
		s->data=data;
		data->b.score=15*(1+lv);
		data->b.health=1+lv;
		data->radius=350;
		data->angle=360/16*i;
		data->flag0=1;
		data->flag1=0;
		data->flag2=0;
		data->level=lv;
	}
}

void enemy_cube_move(SPRITE *s)
{
	CUBE_DATA *d=(CUBE_DATA *)s->data;
	
	d->flag2+=fps_factor;
	if(d->flag2<500) {
		if(!d->flag1) {
			d->radius+=fps_factor;
			if(d->radius>150) d->flag1=1;
		} else {
			d->radius-=fps_factor;
			if(d->radius<=10) d->flag1=0;
		}
		d->angle-=3*fps_factor;
		if(d->angle<0)
			d->angle+=360;


		if(!(rand()%500)) {
			enemy_bullet_create(s,1);
		}

		if(!(rand()%600)) {
			bonus_add(s->x,s->y,SP_BONUS_FIREPOWER);
		}
	} else {
		d->radius+=2*fps_factor;
		if(d->radius>350)
			s->type=-1;
	}

	s->x=(cos(degtorad(d->angle))*d->radius)+WIDTH/2;
	s->y=(sin(degtorad(d->angle))*d->radius)+HEIGHT/2;

}