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 
9 #include "Global.h"
10 
11 
cEnemy(int _x,int _y)12 cEnemy::cEnemy(int _x,int _y)
13 {
14 	dir = 0;
15 
16 	x= _x;
17 	y= _y;
18 	y_speed = 0;
19 
20 	walkcount = 0;
21 	walkcount2 = 0;
22 	walkadd = 0;
23 	speed = ENEMYSPEED;
24 	dir = speed;
25 	dead = 0;
26 	DEATHcount = 0;
27 	dying = 0;
28 
29 }
30 
31 
update()32 void cEnemy::update()
33 {
34 	if(dead)
35 		return;
36 
37 	if(DEATHcount>0)
38 	{
39 		DEATHcount++;
40 		if(DEATHcount>=2000)
41 			dead=1;
42 	}
43 	else
44 	{
45 		down_touch  = (bool)LEVEL->posValid(x+3,y+3+H) + LEVEL->posValid(x+W-3,y+3+H);
46 		left_touch  = LEVEL->posValid(x-1,y+H/1.25) + LEVEL->posValid(x-1,y+H/4);
47 		right_touch = LEVEL->posValid(x+W+1,y+H/1.25) + LEVEL->posValid(x+W+1,y+H/4);
48 
49 		if(dying)
50 		{
51 			down_touch = 0;
52 			left_touch = 0;
53 			right_touch = 0;
54 			if(rect.y>=HEIGHT)
55 				dead = 1;
56 		}
57 		else if(PLAYER->x+40 >= x && PLAYER->x <= x+W)
58 		{
59 			if(PLAYER->y+PLAYER->H >= y && PLAYER->y+PLAYER->H <= y+H/2)
60 				headbang();
61 		}
62 		if((left_touch+right_touch))
63 			dir*=-1;
64 
65 		if(!down_touch)
66 		{
67 			y += y_speed;
68 			if(y_speed<8)
69 				y_speed+=0.4f;
70 		}
71 		else
72 			y_speed = 0;
73 
74 		x += dir;
75 
76 		//DEFINED IN EVERY SINGLE ENEMY:
77 		add_update();
78 		for(int i=0;i<TURTLEcount;i++)
79 			if(!TURTLE[i]->dead)
80 			{
81 				if(TURTLE[i]->down && TURTLE[i]->rect.x != rect.x && collision(&TURTLE[i]->rect,&this->rect))
82 				{
83 					dir*=-1;
84 					x += dir + dir;
85 				}
86 			}
87 
88 		MakeMyWalk();
89 	}
90 		rect.x = (int)x - cam_x;
91 		rect.y = (int)y - cam_y;
92 
93 
94 	//DEFINED IN EVERY SINGLE ENEMY:
95 	draw();
96 }
97 
die()98 void cEnemy::die()
99 {
100 	dying = 1;
101 	y -= 40;
102 	SCORE->init(x,y,scoring);
103 	PLAYSOUND2(S_KICK);
104 	BLOOD_GENERATOR->newBlood(x,y);
105 }
106 
107 // NOT USED NOW ://///////////////////////////
add_update()108  void cEnemy::add_update(){}
headbang()109  void cEnemy::headbang(){}
draw()110  void cEnemy::draw(){}
111 //////////////////////////////////////////////
112 
playerTouchRight()113 int cEnemy::playerTouchRight()
114 {
115 	if(PLAYER->x+38 >= x && PLAYER->x+38 <= x+(W/2))
116 	{
117 		if(PLAYER->y+PLAYER->H >= y+(H/2) && PLAYER->y<=y+H)
118 			return true;
119 	}
120 	return 0;
121 }
playerTouchLeft()122 int cEnemy::playerTouchLeft()
123 {
124 	if(PLAYER->x >=x+W/2 && PLAYER->x <= x+(W))
125 	{
126 		if(PLAYER->y+PLAYER->H >= y+(H/2) && PLAYER->y<=y+H)
127 			return true;
128 	}
129 	return 0;
130 }
131 
MakeMyWalk()132 void cEnemy::MakeMyWalk()
133 {
134 		walkcount2++;
135 		if(walkcount2 >= 12)
136 		{
137 			walkcount = (walkcount) ? 0 : 1;
138 			walkcount2=0;
139 		}
140 }
141