Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/entity.py
blob: 5b95a6192e7ea86d4a15c0532b194d1e96dd87f6 (plain)
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
# -*- coding: utf-8 -*-
# filename: entity.py
#
# Ceibal Rol
# Copyright (C) 2008,2009 Gabriel Balbuena
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Ceibal Jam http://ceibaljam.org

import pygame
from   pygame.locals import *

#direction constants
EAST      = 0
NORTHEAST = 1
NORTH     = 2
NORTHWEST = 3
WEST      = 4
SOUTHWEST = 5
SOUTH     = 6
SOUTHEAST = 7

class Entity(pygame.sprite.Sprite):
	def __init__(self):
		self.id = "id1"

class Player(Entity):
	
	def __init__(self, map):
		pygame.sprite.Sprite.__init__(self)

		self.map = map
		self.image = pygame.image.load('./data/entity/ogre/stopped 0000.png').convert_alpha()

		self.rect = self.image.get_rect()
		self.rect.move_ip(50, 50) # posicion inicial

		self.pos_xi = 0 # posicion x
		self.pos_yi = 0 # posicion y

		self.is_running = True

	def update(self):
		" Realiza el movimiento del Player en el Map "	
		teclas_pulsadas = pygame.key.get_pressed()
		dx = 0
		dy = 0

		if teclas_pulsadas[K_UP]:
			dy = -1

		elif teclas_pulsadas[K_DOWN]:
			dy = 1

		if teclas_pulsadas[K_LEFT]:
			dx = -1

		elif teclas_pulsadas[K_RIGHT]:
			dx = 1

		if not self.map.is_walkable(self.rect.x + dx, self.rect.y):
			dx = 0

		if not self.map.is_walkable(self.rect.x, self.rect.y + dy):
			dy = 0

		self.rect.move_ip(dx, dy)   # cambia la posicion del Player
		self.map.mirar_a(self.rect) # centra la atencion de la camara en el

	def _print(self, screen):
		x = self.rect.x - self.map.camara_x - self.pos_xi
		y = self.rect.y - self.map.camara_y - self.pos_yi
		screen.blit(self.image, (x, y))