Foro de elhacker.net

Programación => Scripting => Mensaje iniciado por: BigBear en 1 Enero 2015, 15:46 pm



Título: [Python-Pygame] E.T Must Die 0.3
Publicado por: BigBear en 1 Enero 2015, 15:46 pm
Un simple shooter que hice en Python usando Pygame , el juego consiste en eliminar la amenaza de E.T antes de que escape de nuestro planeta.
Es un juego raro pero me sirvio para estudiar el tema de programacion de juegos en Python xD.

Una imagen :

(http://doddyhackman.webcindario.com/images/shooter_python.jpg)

Un video de como se juega :

4IDdJbHybXM

El codigo :

Código
  1. #!usr/bin/python
  2. #E.T Must Die 0.3
  3. #(C) Doddy Hackman 2015
  4. #Credits : Based on Bush Shootout.py Coded by Nathaniel
  5. #Thanks to Nathaniel
  6.  
  7. import pygame
  8. from pygame.locals import *
  9. import sys,random,time
  10.  
  11. pygame.init()
  12.  
  13. juego = pygame.display.set_mode((860,640))
  14. pygame.display.set_caption("E.T Must Die 0.3")
  15. icono = pygame.image.load("Data/Images/icono.png").convert_alpha()      
  16. pygame.display.set_icon(icono)
  17. pygame.mouse.set_visible(False)
  18.  
  19. letra = pygame.font.Font(None,35)
  20.  
  21. vida = 200
  22. control = False
  23.  
  24. class mira(pygame.sprite.Sprite):
  25. def __init__(self):
  26. pygame.sprite.Sprite.__init__(self)
  27. self.mira = pygame.image.load("Data/Images/mira.png")
  28. self.rect = self.mira.get_rect()
  29. self.rect.x = 860/2
  30. self.rect.y = 640/2
  31. def mover(self):
  32. posicion = pygame.mouse.get_pos()
  33. self.rect.x = posicion[0]
  34. self.rect.y = posicion[1]
  35. juego.blit(self.mira,self.rect)
  36. def lanzar(self):
  37. yeah = pygame.sprite.spritecollide(self,lista,dokill=False)
  38. if yeah:
  39.  
  40. global vida
  41. vida = vida - 10
  42. pygame.mixer.Sound("Data/Sounds/risa2.wav").play()
  43.  
  44. class threat(pygame.sprite.Sprite):
  45. def __init__(self):
  46. pygame.sprite.Sprite.__init__(self)
  47. self.imagen = pygame.image.load("Data/Images/avatar.png")
  48. self.rect = self.imagen.get_rect()
  49. self.tiempo = 15
  50. self.contador = int(self.tiempo)
  51. def mover(self):
  52. self.contador += 1
  53. if self.contador >= self.tiempo:
  54. self.rect.x = random.randrange(20,850)
  55. self.rect.y = random.randrange(30,540)
  56. self.contador = 0
  57. juego.blit(self.imagen,self.rect)
  58.  
  59.  
  60. pygame.mixer.Sound("Data/Sounds/menu.wav").play()
  61. men = pygame.image.load("Data/Images/portada.png")
  62. juego.blit(men,(0,0))
  63. pygame.display.update()
  64. time.sleep(9)
  65.  
  66. pygame.mixer.init()
  67. pygame.mixer.music.load("Data/Sounds/theme.mp3")
  68. pygame.mixer.music.play()
  69.  
  70. mira = mira()
  71. threat = threat()
  72.  
  73. lista = pygame.sprite.Group()
  74. lista.add(threat)
  75.  
  76. cro = pygame.time.Clock()
  77. mil = 0
  78.  
  79. while True:
  80.  
  81.        mil += cro.tick()
  82.        casi = mil/1000
  83.        casi = 30 - casi
  84.  
  85. if casi < 1:
  86. control = True
  87.  
  88. for acatoy in pygame.event.get():
  89.  
  90. if acatoy.type == QUIT:
  91. sys.exit(1)
  92.  
  93. if acatoy.type == MOUSEBUTTONDOWN and acatoy.button == 1:
  94. pygame.mixer.Sound("Data/Sounds/disparo.wav").play()
  95. mira.lanzar()
  96.  
  97. if not control:
  98.  
  99. fondo = pygame.image.load("Data/Images/fondo.jpg")
  100. juego.blit(fondo,(0,0))
  101. juego.blit(letra.render("Remaining Time : "+str(casi),True,(255,0,0)),(20,10))
  102. juego.blit(letra.render("Threat "+str(vida),True,(255,0,0)),(700,10))
  103. mira.mover()
  104. threat.mover()
  105.  
  106. if vida == 0:
  107. over = pygame.image.load("Data/Images/ganaste.png")
  108. juego.blit(over,(0,0))
  109. pygame.display.update()
  110. time.sleep(10)
  111. sys.exit(1)
  112.  
  113. else:
  114. over = pygame.image.load("Data/Images/perdiste.png")
  115. juego.blit(over,(0,0))
  116. pygame.display.update()
  117. pygame.mixer.Sound("Data/Sounds/risa.wav").play()
  118. time.sleep(10)
  119. sys.exit(1)
  120.  
  121. pygame.time.delay(15)
  122. pygame.display.flip()
  123.  
  124. #The End ?
  125.  


Si quieren bajar el juego lo pueden hacer de aca (https://sourceforge.net/p/etmustdie/).