File: bonus.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 (115 lines) | stat: -rw-r--r-- 2,206 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
109
110
111
112
113
114
115
#include "bonus.h"

extern double fps_factor;
extern SDL_Surface *screen;

void bonus_add(int x, int y, int type)
{
	SPRITE *s;
	BONUS_DATA *data;

	switch(type) {
	case SP_BONUS_FIREPOWER:
		s=sprite_add_file("bonus_p.bmp",16,PR_BONUS);
		s->anim_speed=3;
		break;
	case SP_BONUS_ADDSPEED:
		s=sprite_add_file("bonus_s.bmp",16,PR_BONUS);
		s->anim_speed=2;
		break;
	case SP_BONUS_BOMB:
		s=sprite_add_file("bonus_f.bmp",16,PR_BONUS);
		s->anim_speed=3;
		break;
	case SP_BONUS_COIN:
		s=sprite_add_file("coin.bmp",20,PR_BONUS);
		s->anim_speed=3;
		break;
	case SP_BONUS_EXTRA:
		s=sprite_add_file("bonus_x.bmp",16,PR_BONUS);
		s->anim_speed=3;
		break;
	case SP_BONUS_HEALTH:
		s=sprite_add_file("bonus_h.bmp",9,PR_BONUS);
		s->anim_speed=2;
		break;
	default:
		CHECKPOINT;
		error(ERR_WARN,"cant add unknown bonus! debug me! please! now!");
		return;
	}
	s->flags|=(SP_FLAG_VISIBLE|SP_FLAG_COLCHECK);
	if(x<600)
		s->x=x+20;
	else
		s->x=x-10;
	s->y=y;
	s->type=type;
	s->mover=bonus_move;
	data=mmalloc(sizeof(BONUS_DATA));
	s->data=data;
	data->speed=rand()%400/100+1;
}

void bonus_move(SPRITE *s)
{
	BONUS_DATA *d=(BONUS_DATA *)s->data;

	s->y+=d->speed*fps_factor;
	if(s->y>480) s->type=-1;
}

void bonus_info_add(int x, int y, char *filename)
{
	SPRITE *c;
	c=sprite_add_file(filename,1,PR_BONUS);
	c->flags=SP_FLAG_VISIBLE;
	c->type=SP_ETC;
	c->x=x;
	c->y=y;
	c->alpha=255;
	c->mover=bonus_info_move;
}

void bonus_info_move(SPRITE *c)
{
	if(c->alpha>=3*fps_factor) {
		c->alpha-=3*fps_factor;
		c->y-=fps_factor;
	} else {
		c->type=-1;
	}
}

void bonus_info_text(int x, int y, char *text, int font)
{
	SDL_Surface *t;
	SPRITE *s;

	t=font_render(text,font);
	s=sprite_add(t,1,PR_BONUS,1);
	s->flags|=SP_FLAG_FREESURFACE|SP_FLAG_VISIBLE;
	s->type=SP_ETC;
	s->x=x;
	s->y=y;
	s->alpha=255;
	s->data=mmalloc(sizeof(BIT_DATA));
	((BIT_DATA *)s->data)->distance=255;
	s->mover=bonus_infotext_move;
}

void bonus_infotext_move(SPRITE *c)
{
	BIT_DATA *b=(BIT_DATA *)c->data;
	// SDL_Surface *s;

	c->y+=fps_factor*2;
	b->distance-=fps_factor*3;
	c->alpha=b->distance;
	if(b->distance<=0) {
		// s=sprite_getcurrimg(c);
		// parsys_add(s,1,1,c->x,c->y,30,0,0,100,PIXELIZE,NULL);
		c->type=-1;
	}
		
}