File: entity_player.cpp

package info (click to toggle)
epiphany 0.7.0%2B0-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,532 kB
  • sloc: cpp: 6,404; ansic: 141; makefile: 78; sh: 7
file content (200 lines) | stat: -rw-r--r-- 3,558 bytes parent folder | download | duplicates (7)
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
/***************************************************************************
                          entity_player.cpp  -  description
                             -------------------
    begin                : Thu Sep 20 2001
    copyright            : (C) 2001 by Giuseppe D'Aqu
    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 "sprite.h"
#include "entity.h"
#include "entity_manager.h"

#include "entity_all.h"


Entity_Player::Entity_Player(Level* level, Uint32 x, Uint32 y)
{
	
	m_type=PLAYER;
	
	current_level=level;
	

	
	if((x<current_level->get_size_x())&&(x>=0))
		m_position_x=x;
	else
		m_position_x=0;
		
	if((y<current_level->get_size_y())&&(y>=0))
		m_position_y=y;
	else
		m_position_y=0;
	
	Surface_Manager* surf_man = Surface_Manager::instance();
	m_sprite=Sprite(surf_man->get_surface(Surface_Manager::SRF_PLAYER));
	m_sprite.set_state(SP_STOP);
	m_score=0;
		
	m_exists=true;
		
	m_is_exited=false;
		
	m_is_alive=true;
	
	m_is_snapping=false;
	
	m_direction=STOP;
	
}

void Entity_Player::set_direction(Direction d)
{
	m_direction=d;
}

void Entity_Player::set_snap(bool snap)
{
	m_is_snapping=snap;

}

void Entity_Player::inc_score(int score)
{
	m_score+=score;
}

void Entity_Player::check_and_do()
{
	if(m_just_checked==true)
	{
	//	m_just_moved=false;
		
		return;
	}
	if(m_is_exited)	
	{
		kill();
		return;
	}
	
	//adesso controlla che di lato ci sia una casella vuota
	//oppure un oggetto passabile
	if(m_direction==STOP)
	{
		m_sprite.set_state(SP_STOP);
	}
	
	if(current_level->player_push(m_position_x, m_position_y, m_direction))
	{
		if(!m_is_snapping)
			move(m_direction);
	}
	else
	{
		m_sprite.set_state(SP_STOP);
	}

/*	Entity* neigh_entity;	
	
	Entity_Handle neigh_entity_id=current_level->get_entity(m_position_x,m_position_y, m_direction);
	if(neigh_entity_id!=0)
	{
		neigh_entity=Entity_Manager::instance()->get_entity(neigh_entity_id);
		if(neigh_entity->pass_on_me(m_direction))
		{
			if(!m_is_snapping)
				move(m_direction);
		}
		else
		{
			m_sprite.set_state(SP_STOP);
		}

	}
	else
	{
		if(!m_is_snapping)
		{
			Sample_Manager::instance()->play(SFX_PLAYER_MOVE);
			move(m_direction);
		}
	}
*/		
	m_direction=STOP;

	m_just_checked=true;
	
	m_is_snapping=false;
	

}


bool Entity_Player::pass_on_me(Direction d)
{
	return false;
}

bool Entity_Player::is_alive()
{
	
	return m_is_alive;
	
}

Uint32 Entity_Player::get_score()
{

	return m_score;
	
}

void Entity_Player::win()
{
	m_is_exited=true;

	DEBOUT("Winner!\n");
}

bool Entity_Player::is_exited()
{
	return m_is_exited;
	
}

bool Entity_Player::hit_from_up(Entity_Handle ntt)
{
	current_level->explode(m_position_x,m_position_y);

	kill();
	return false;
}

bool Entity_Player::explode()
{
	kill();
	return true;
}

void Entity_Player::kill()
{
	m_exists=false;
	m_is_alive=false;
	if(!m_is_exited)
	{
		Sample_Manager::instance()->play(SFX_GAME_GAMEOVER);
	}
//	set_position(0,0);

}