Advertisement
Guest User

Game_lõputo

a guest
May 12th, 2013
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. import pygame, math, random, sys, time
  2. pygame.mixer.init(44100, -16, 2, 1024)
  3. pygame.init()
  4. screen = pygame.display.set_mode([800, 600])
  5. screen.fill([0, 0, 0])
  6.  
  7. sound_fire = pygame.mixer.Sound('laser.ogg')
  8. #bang = pygame.mixer.Sound('explosion.ogg')
  9. #song = pygame.mixer.music.load('whiteandnerdy.mp3')
  10.  
  11. ship = pygame.image.load('spaceship.png')
  12. ship_frame = ship.get_rect()
  13. alien = pygame.image.load('alien.png')
  14. alien_frame = alien.get_rect()
  15. bullet = pygame.image.load('bullet.png')
  16. bullet_frame = bullet.get_rect()
  17.  
  18. #pygame.mixer.music.play()
  19.  
  20.  
  21.  
  22. ship_x, ship_y, ship_step = 400, 500, 2
  23. place_score = (5, 5)
  24. bullet_step = 1
  25. badguy_delay = 500
  26.  
  27. epoint = random.randint(200, 400)
  28. badguy_x = epoint
  29. badguy_y = 0
  30.  
  31.  
  32. running = True
  33.  
  34. #moving the ship
  35. delay = 1
  36. interval = 1
  37. pygame.key.set_repeat(delay, interval)
  38. shot=False
  39. monster = False
  40. def bulletshot():
  41. global bullet_x, bullet_y, shot
  42. bullet_x = ship_x + 26
  43. bullet_y = ship_y-20
  44. pygame.draw.rect(screen, [0, 0, 0], [bullet_x, bullet_y, 30, 25], 0)
  45. bullet_y=bullet_y - 1
  46. screen.blit(bullet, (bullet_x, bullet_y))
  47. if bullet_y < -10:
  48. pygame.draw.rect(screen, [0, 0, 0], [bullet_x, bullet_y, 30, 25], 0)
  49. shot = False
  50.  
  51. def badguy():
  52. midpoint = random.randint(200, 400)
  53. alaius = random.randint(100, 300)
  54. global monster, badguy_x, badguy_y
  55. pygame.draw.rect(screen, [0, 0, 0], [badguy_x, badguy_y, 42, 42], 0)
  56. badguy_y+=0.1
  57. badguy_x=(alaius*(math.sin(0.1*badguy_y))+ midpoint)
  58. screen.blit(alien, (badguy_x, badguy_y))
  59. if badguy_y > 458:
  60. pygame.draw.rect(screen, [0, 0, 0], [badguy_x, badguy_y, 42, 42], 0)
  61. monster = False
  62.  
  63. #def gameover():
  64.  
  65.  
  66. while running:
  67. pygame.draw.line(screen, [0, 0, 205], (0, 500), (800, 500), 1)
  68. screen.blit(ship, (ship_x, ship_y))
  69. for i in pygame.event.get():
  70. if i.type == pygame.QUIT:
  71. running = False
  72. if i.type == pygame.KEYDOWN:
  73. if i.key == pygame.K_LEFT:
  74. ship_x = ship_x - ship_step
  75. elif i.key == pygame.K_RIGHT:
  76. ship_x = ship_x + ship_step
  77. elif i.key == pygame.K_SPACE:
  78. shot = True
  79. sound_fire.play()
  80. if ship_x<-20:
  81. ship_x=-20
  82. if ship_x>750:
  83. ship_x=750
  84. if shot:
  85. bulletshot()
  86. if monster:
  87. badguy()
  88. if not monster:
  89. monster = True
  90. pygame.display.flip()
  91. pygame.time.delay(1)
  92.  
  93.  
  94.  
  95. pygame.quit ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement