1 /***************************************************************************
2                           entity_boulder.cpp  -  description
3                              -------------------
4     begin                : Thu Sep 20 2001
5     copyright            : (C) 2001 by Giuseppe D'Aqu�
6     email                : kumber@tiscalinet.it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License, Version 2, as published by  *
13  *   the Free Software Foundation.                                   *
14  *                                                                         *
15  ***************************************************************************/
16 
17 #include "dephine.h"
18 #include "sprite.h"
19 #include "surface_manager.h"
20 #include "entity.h"
21 #include "entity_boulder.h"
22 #include "entity_player.h"
23 
24 
Entity_Boulder(Level * level,Uint32 x,Uint32 y)25 Entity_Boulder::Entity_Boulder(Level* level, Uint32 x, Uint32 y)
26 {
27 	current_level=level;
28 	m_position_x=x;
29 	m_position_y=y;
30 	m_type=BOULDER;
31 	Surface_Manager* surf_man = Surface_Manager::instance();
32 	m_sprite=Sprite(surf_man->get_surface(Surface_Manager::SRF_BOULDER));
33 	m_sprite.set_state(SP_STOP);
34 	m_is_falling=false;
35 	m_exists=true;
36 
37 
38 }
39 
check_and_do()40 void Entity_Boulder::check_and_do()
41 {
42   bool was_falling=m_is_falling;
43 	Entity_Falling::check_and_do();
44 	if((was_falling==true)&&(m_is_falling==false))
45 	{
46 		Sample_Manager::instance()->play(SFX_BOULDER_FALL);
47 	}
48 }
49 
pass_on_me(Direction d)50 bool Entity_Boulder::pass_on_me(Direction d)
51 {
52 
53 	if(((d==RIGHT)||(d==LEFT))&&(m_is_falling==false))
54 	{
55 		if((current_level->get_entity(get_position_x(), get_position_y(), d))==0)
56 		{
57 			move(d);
58 			m_just_checked=true;
59 				if((current_level->get_entity(get_position_x(), get_position_y(), DOWN))==0)
60 					m_is_falling=true;
61 			return true;
62 		}
63 	}
64 	return false;
65 
66 }
67 
player_pressing_left(Entity_Handle right_entity)68 bool Entity_Boulder::player_pressing_left(Entity_Handle right_entity)
69 {
70 	if((right_entity==0)&&(m_is_falling==false))
71 	{
72 		move(RIGHT);
73 		m_just_checked=true;
74 		m_is_falling=true;
75 		return true;
76 	}
77 	return false;
78 }
79 
player_pressing_right(Entity_Handle left_entity)80 bool Entity_Boulder::player_pressing_right(Entity_Handle left_entity)
81 {
82 	if((left_entity==0)&&(m_is_falling==false))
83 	{
84 		move(LEFT);
85 		m_just_checked=true;
86 		m_is_falling=true;
87 
88 		return true;
89 	}
90 	return false;
91 }
92 
explode()93 bool Entity_Boulder::explode()
94 {
95 	m_exists=false;
96 	return true;
97 }
98