Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/#Game.py#
diff options
context:
space:
mode:
Diffstat (limited to '#Game.py#')
-rw-r--r--#Game.py#131
1 files changed, 123 insertions, 8 deletions
diff --git a/#Game.py# b/#Game.py#
index 0b2c4ea..7541cb9 100644
--- a/#Game.py#
+++ b/#Game.py#
@@ -5,17 +5,79 @@ from AnimatedSprite import *
class Game():
def __init__(self):
- pygame.display.init()
- self.screen = pygame.display.set_mode((800,600))
- self.clock = pygame.time.Clock()
+# pygame.display.init()
+# self.screen = pygame.display.set_mode((1200,900))
+# self.clock = pygame.time.Clock()
# load images
- images_main = self.load_sprite_group(50,50,"main.png")
+# images_main = self.load_sprite_group(50,50,"main.png")
# load levels
# setup objects
- self.me = AnimatedSprite(images_main,30)
+# self.me = AnimatedSprite(images_main,30)
# start
- print("initializing...")
+
+ print("initializing game...")
+
+ pygame.display.init()
+ self.screen = pygame.display.set_mode((1200,900))
+ self.clock = pygame.time.Clock()
+
+ print("loading images...")
+
+ self.images = []
+ master_image = pygame.image.load(os.path.join('images',
+ 'xoxi-ninios-sprite-01.png')).convert_alpha()
+ master_width, master_height = master_image.get_size()
+ w = int(master_width/4)
+ h = int(master_height/4)
+ for i in xrange(4):
+ self.images.append(master_image.subsurface((i*w,0,w,h)))
+ for i in xrange(4):
+ self.images.append(master_image.subsurface((i*w,h,w,h)))
+ for i in xrange(4):
+ self.images.append(master_image.subsurface((i*w,2*h,w,h)))
+ for i in xrange(4):
+ self.images.append(master_image.subsurface((i*w,3*h,w,h)))
+
+ self.bg_image = pygame.image.load(os.path.join('images',
+ 'derechos-plaza-fondo.jpg')).convert_alpha()
+
+ sps = [0, 1, 0, 2, 0, 1, 0, 3, 4, 5, 4, 6, 4, 5, 4, 7, 8, 9, 8, 10,
+ 8, 9, 8, 11, 15, 13, 15, 14, 15, 13, 15, 12]
+ nf = [1, 2, 3, 4, 5, 6, 7, 0, 9, 10, 11, 12, 13, 14, 15, 8, 17, 18, 19,
+ 20, 21, 22, 23, 16, 25, 26, 27, 28, 29, 30, 31, 24]
+ dxs = [5, 5, 5, 5, 5, -5, -5, -5, -5, -5]
+ dys = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+
+ self.sp = AnimatedSprite(images, sps, nf, dxs, dys, 50, 400, 10)
+ self.sp2 = AnimatedSprite(images, sps, nf, dxs, dys, 50, 400, 10)
+
+ self.grilla = [[0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],
+ [0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0],
+ [0,0,1,1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,1,1,0,0,0,0],
+ [0,0,1,1,1,1,1,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1],
+ [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1],
+ [0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,1,0,0,1,1],
+ [1,1,1,1,1,0,0,1,1,1,1,0,0,1,1,0,0,1,1,1,0,0,1,1],
+ [0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,0,0,1,1,1,0,0,1,1],
+ [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
+ [0,0,1,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0],
+ [0,0,1,0,0,0,0,1,1,1,1,0,0,1,1,1,1,0,0,1,1,0,0,0],
+ [0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0],
+ [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0,0],
+ [0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1],
+ [1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1],
+ [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
+ [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1],
+ [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1]]
+
+
+ playing = True
+
+ sp.updateMove(0)
+ sp2.updateMove(random.randint(1,4))
+
+
def load_sprite_group(self, w, h, filename):
'''
@@ -52,8 +114,61 @@ class Game():
def main():
- game = Game()
- game.start()
+# game = Game()
+# game.start()
+
+
+
+ while playing:
+ for event in pygame.event.get():
+ if event.type == pygame.QUIT:
+ playing = False
+ elif event.type == pygame.MOUSEBUTTONDOWN:
+ pass
+ elif event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_UP:
+ sp.updateMove(UP)
+ sp.updateFrame(0)
+ if event.key == pygame.K_DOWN:
+ sp.updateMove(DOWN)
+ sp.updateFrame(8)
+ if event.key == pygame.K_LEFT:
+ sp.updateMove(LEFT)
+ sp.updateFrame(16)
+ if event.key == pygame.K_RIGHT:
+ sp.updateMove(RIGHT)
+ sp.updateFrame(24)
+ elif event.type == pygame.KEYUP:
+ if event.key == pygame.K_UP:
+ sp.updateMove(0)
+ sp.updateFrame(0)
+ if event.key == pygame.K_DOWN:
+ sp.updateMove(0)
+ sp.updateFrame(8)
+ if event.key == pygame.K_LEFT:
+ sp.updateMove(0)
+ sp.updateFrame(16)
+ if event.key == pygame.K_RIGHT:
+ sp.updateMove(0)
+ sp.updateFrame(24)
+
+ sp.domove(grilla)
+ sp2.ai(grilla)
+
+ screen.blit(bg_image, (0, 0))
+
+# dibujar_grilla(grilla,screen)
+
+ time_passed = clock.tick(20)
+ sp.update(time_passed)
+ sp2.update(time_passed)
+
+ sp.render(screen)
+ sp2.render(screen)
+
+ pygame.display.flip()
+
+
if __name__ == "__main__":
main()