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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
/***************************************************************************
entity_peperon.cpp - description
-------------------
begin : Tue Apr 23 2002
copyright : (C) 2002 by Giuseppe D'Aqui'
email : kumber@tiscalinet.it
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License, Version 2, as published by *
* the Free Software Foundation. *
* *
***************************************************************************/
#include "dephine.h"
#include "entity.h"
#include "entity_monster.h"
#include "entity_manager.h"
#include "entity_tomato.h"
#include "entity_player.h"
Entity_Tomato::Entity_Tomato(Level* level, Uint32 x, Uint32 y, Direction direction)
{
current_level=level;
m_position_x=x;
m_position_y=y;
m_type=PEPERON;
Surface_Manager* surf_man = Surface_Manager::instance();
m_sprite=Sprite(surf_man->get_surface(Surface_Manager::SRF_TOMATO));
m_sprite.set_state(SP_STOP);
m_exists=true;
m_is_exploding=false;
m_direction=direction;
}
void Entity_Tomato::check_and_do()
{
if(m_just_checked==true)
{
// m_just_moved=false;
return;
}
if(m_is_exploding==true)
{
explode_all_around();
return;
}
Entity_Handle up_entity_id=current_level->get_entity(m_position_x, m_position_y, UP);
Entity_Handle right_entity_id=current_level->get_entity(m_position_x, m_position_y, RIGHT);
Entity_Handle down_entity_id=current_level->get_entity(m_position_x, m_position_y, DOWN);
Entity_Handle left_entity_id=current_level->get_entity(m_position_x, m_position_y, LEFT);
if(((up_entity_id!=0)&&(Entity_Manager::instance()->get_entity(up_entity_id)->get_type()==PLAYER))||
((right_entity_id!=0)&&(Entity_Manager::instance()->get_entity(right_entity_id)->get_type()==PLAYER))||
((down_entity_id!=0)&&(Entity_Manager::instance()->get_entity(down_entity_id)->get_type()==PLAYER))||
((left_entity_id!=0)&&(Entity_Manager::instance()->get_entity(left_entity_id)->get_type()==PLAYER)))
{
kill();
current_level->get_player().set_direction(STOP);
return;
}
switch(m_direction)
{
case UP:
if(right_entity_id!=0)
{
if(up_entity_id==0)
{
// move(UP);
}
else
{
m_direction=LEFT;
}
}
else
{
m_direction=RIGHT;
}
break;
case RIGHT:
if(down_entity_id!=0)
{
if(right_entity_id==0)
{
// move(RIGHT);
}
else
{
m_direction=UP;
}
}
else
{
m_direction=DOWN;
}
break;
case DOWN:
if(left_entity_id!=0)
{
if(down_entity_id==0)
{
// move(DOWN);
}
else
{
m_direction=RIGHT;
}
}
else
{
m_direction=LEFT;
}
break;
case LEFT:
if(up_entity_id!=0)
{
if(left_entity_id==0)
{
// move(LEFT);
}
else
{
m_direction=DOWN;
}
}
else
{
m_direction=UP;
}
break;
default:
m_sprite.set_state(SP_STOP);
}
if(current_level->get_entity(m_position_x, m_position_y, m_direction)==0)
{
//if(!(current_level->get_sample(SFX_MONSTER_MOVE)->is_playing()))
//{
Sample_Manager::instance()->play(SFX_MONSTER_MOVE);
//}
move(m_direction);
}
m_just_checked=true;
}
bool Entity_Tomato::hit_from_up(Entity_Handle smasher)
{
if(Entity_Manager::instance()->get_entity(smasher)->get_type()==BOULDER)
{
kill();
}
return false;
}
bool Entity_Tomato::pass_on_me(Direction d)
{
return false;
}
void Entity_Tomato::kill()
{
// m_exists=false;
// Entity::kill();
current_level->explode(m_position_x, m_position_y, SAPPHIRE);
}
void Entity_Tomato::explode_all_around()
{
Entity::kill();
current_level->explode(m_position_x-1,m_position_y-1, EMERALD);
current_level->explode(m_position_x,m_position_y-1, EMERALD);
current_level->explode(m_position_x+1,m_position_y-1, EMERALD);
current_level->explode(m_position_x-1,m_position_y, EMERALD);
// current_level->explode(m_position_x,m_position_y);
current_level->explode(m_position_x+1,m_position_y, EMERALD);
current_level->explode(m_position_x-1,m_position_y+1, EMERALD);
current_level->explode(m_position_x,m_position_y+1, EMERALD);
current_level->explode(m_position_x+1,m_position_y+1, EMERALD);
}
bool Entity_Tomato::explode()
{
//explodes all entities around ;)
if(m_just_checked==true)
{
m_is_exploding=true;
}
else
{
m_is_exploding=true;
m_just_checked=true;
}
// m_exists=false;
// current_level->explode(m_position_x-1,m_position_y-1);
// current_level->explode(m_position_x,m_position_y-1);
// current_level->explode(m_position_x+1,m_position_y-1);
// current_level->explode(m_position_x-1,m_position_y);
// current_level->explode(m_position_x,m_position_y);
// current_level->explode(m_position_x+1,m_position_y);
// current_level->explode(m_position_x-1,m_position_y+1);
// current_level->explode(m_position_x,m_position_y+1);
// current_level->explode(m_position_x+1,m_position_y+1);
return true;
}
|