1 /********************************************************************
2   Mega Mario SRC
3     created:	2005/09/18
4 	created:	18:9:2005   10:13
5 	author:		Jens Wellmann (c)
6 *********************************************************************/
7 
8 #include "Global.h"
9 #include <math.h>
10 
cFireCircle(int _x,int _y,int _size)11 cFireCircle::cFireCircle(int _x,int _y,int _size)
12 {
13 	size = _size;
14 	x=_x+10;
15 	y=_y+10;
16 	angle = rand()%360;
17 	counta2 = 1;
18 }
update()19 void cFireCircle::update()
20 {
21 	tmp_rect.x = cam_x-size*20;
22 	tmp_rect.y = cam_y-size*20;
23 	tmp_rect.h = cam_y+HEIGHT+size*40;
24 	tmp_rect.w = cam_x+WIDTH+size*40;
25 
26 	if(!pointCollision(&tmp_rect,x,y))
27 		return;
28 
29 	dir_x = (double)sin(angle *0.017453292519943295)*20.0f;
30 	dir_y = (double)cos(angle *0.017453292519943295)*20.0f;
31 
32 	for(int i=0;i<size;i++)
33 	{
34 		rect.x = x-cam_x + (dir_x*i);
35 		rect.y = y-cam_y + (dir_y*i);
36 		SDL_UpperBlit(FIREBALL[0]->FIREBALLS[(int)counta2],0,screen,&rect);
37 		if(collision(&PLAYER->rect,&rect))
38 			if(!PLAYER->stat)
39 				PLAYER->die();
40 			else
41 				PLAYER->changeStat(0);
42 	}
43 	angle+=2;
44 	if(angle>=360)
45 		angle = 0;
46 
47 	counta2+=0.1f;
48 	if(counta2 >= 3)
49 		counta2 = 0;
50 
51 }
52 
53 #define BULLETSPEED 3
54 SDL_Surface *CANNON_SURFACE[3];
initCANNON()55 void initCANNON()
56 {
57 	CANNON_SURFACE[0] = LoadIMG(DATADIR "gfx/characters/cannon.png");
58 	CANNON_SURFACE[1] = LoadIMG(DATADIR "gfx/characters/cannon_bulletr.png");
59 	CANNON_SURFACE[2] = LoadIMG(DATADIR "gfx/characters/cannon_bulletl.png");
60 }
61 
cCannon(int _x,int _y)62 cCannon::cCannon(int _x,int _y)
63 {
64 	x=_x;
65 	y=_y;
66 	count = 400;
67 	die = 0;
68 
69 }
update()70 void cCannon::update()
71 {
72 
73 	tmp_rect.x = x - cam_x;
74 	tmp_rect.y = y - cam_y;
75 	tmp_rect.w = 40;
76 	tmp_rect.h = 40;
77 
78 	if(!collision(&tmp_rect,&LEVEL->SCREEN_RECT))
79 		updating=0;
80 	else
81 		updating =1;
82 
83 	SDL_UpperBlit(CANNON_SURFACE[0],0,screen,&tmp_rect);
84 
85 
86 	count++;
87 	tmp_rect.x = bullet_x-cam_x;
88 	tmp_rect.y = bullet_y-cam_y;
89 	if(updating&&count >= 400&&!collision(&tmp_rect,&LEVEL->SCREEN_RECT))
90 	{
91 		bullet_x = x;
92 		bullet_y = y+9;
93 		PLAYSOUND1(S_CANNON);
94 		dir = (PLAYER->x < x) ? -BULLETSPEED : BULLETSPEED;
95 		bullet_x += (dir>0)? 30 : -30;
96 		count = rand()%400;
97 	}
98 	bullet_x += dir;
99 
100 	SDL_BlitSurface(CANNON_SURFACE[(dir<0)?2:1],0,screen,&tmp_rect);
101 
102 	if(die)
103 	{
104 		die++;
105 		bullet_y+=4;
106 		if(bullet_y-cam_y>=HEIGHT)
107 		{
108 			die = 0;
109 			bullet_x+=WIDTH;
110 			count = 250;
111 		}
112 
113 	}else
114 	{
115 		if(PLAYER->x+40 >= bullet_x && PLAYER->x <= bullet_x+40)
116 			{
117 				if(PLAYER->y+PLAYER->H >= bullet_y && PLAYER->y+PLAYER->H <= bullet_y+25/2)
118 				{
119 					die = 1;
120 					dir/=3;
121 					PLAYER->y_speed=-10;
122 					PLAYSOUND1(S_STOMP);
123 					SCORE->init(bullet_x,bullet_y,150);
124 					return;
125 				}
126 			}
127 
128 		if(collision(&PLAYER->rect,&tmp_rect))
129 			if(!PLAYER->stat)
130 				PLAYER->die();
131 			else
132 				PLAYER->changeStat(0);
133 
134 	}
135 
136 
137 
138 }
139