File: enemy_gametext.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 (63 lines) | stat: -rw-r--r-- 1,067 bytes parent folder | download | duplicates (6)
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
#include "enemy.h"

extern double fps_factor;

/* not a real enemy - just a line of text */

typedef struct {
	int state;
	double speed;
	double destx;
	double desty;
	double wait;
} GAMETEXT_DATA;

void enemy_gametext_add(char *text, int ypos)
{
	SDL_Surface *sur;
	SPRITE *s;
	GAMETEXT_DATA *g;


	sur=font_render(text,FONT04);
	s=sprite_add(sur,1,PR_BONUS,1);
	s->flags|=SP_FLAG_FREESURFACE|SP_FLAG_VISIBLE;
	s->type=SP_ETC;
	s->x=WIDTH;
	s->y=ypos;
	s->mover=enemy_gametext_mover;
	g=mmalloc(sizeof(GAMETEXT_DATA));
	s->data=g;
	g->destx=(WIDTH/2)-sur->w/2;
	g->desty=ypos;
	g->speed=5;
	g->wait=0;
	g->state=0;
}

void enemy_gametext_mover(SPRITE *s)
{
	GAMETEXT_DATA *g=(GAMETEXT_DATA *)s->data;
	SDL_Surface *sur;

	switch(g->state) {
	case 0:
		s->x-=g->speed*fps_factor;
		if(s->x<=g->destx) {
			g->wait=50;
			g->state=1;
		}
		break;
	case 1:
		g->wait-=fps_factor;
		if(g->wait<=0) {
			g->state=2;
		}
		break;
	case 2:
		sur=sprite_getcurrimg(s);
		parsys_add(sur,s->w,1,s->x,s->y,20,0,0,100,LINESPLIT,NULL);
		SDL_FreeSurface(sur);
		s->type=-1;
	}
}