Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/entity.py
diff options
context:
space:
mode:
Diffstat (limited to 'entity.py')
-rwxr-xr-xentity.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/entity.py b/entity.py
new file mode 100755
index 0000000..5b95a61
--- /dev/null
+++ b/entity.py
@@ -0,0 +1,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))