SHARE
TWEET

Untitled

a guest Apr 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pgzrun
  2. import os
  3. import random
  4.  
  5. alien = Actor('alien')
  6. alien.topright = 0, 10
  7.  
  8. WIDTH = 500
  9. HEIGHT = 500
  10.  
  11. score = 0
  12. direction = 0
  13.  
  14. def draw():
  15.     screen.clear()
  16.     alien.draw()
  17.     screen.draw.text("Sk√≥re: "+str(score),(10,10),color="white")
  18.  
  19. def update():
  20.     global direction
  21.     if direction == 0:
  22.         alien.left += 2
  23.         if alien.left > WIDTH:
  24.             pick_direction()
  25.             set_alien_to_proper_start()
  26.     if direction == 1:
  27.         alien.left -= 2
  28.         if alien.right < 0:
  29.             pick_direction()
  30.             set_alien_to_proper_start()
  31.     if direction == 2:
  32.         alien.top += 2
  33.         if alien.top > HEIGHT:
  34.             pick_direction()
  35.             set_alien_to_proper_start()
  36.     if direction == 3:
  37.         alien.top -= 2
  38.         if alien.bottom < 0:
  39.             pick_direction()
  40.             set_alien_to_proper_start()
  41.            
  42. def pick_direction():
  43.     global direction
  44.     direction = random.randint(0,3)
  45.  
  46. def set_alien_to_proper_start():
  47.     global direction
  48.     if direction == 0:
  49.         alien.right = 0
  50.         alien.top = random.randint(1,HEIGHT - alien.height)
  51.     if direction == 1:
  52.         alien.left = WIDTH
  53.         alien.top = random.randint(1,HEIGHT - alien.height)
  54.     if direction == 2:
  55.         alien.bottom = 0
  56.         alien.left = random.randint(1,WIDTH - alien.width)
  57.     if direction == 3:
  58.         alien.top = HEIGHT
  59.         alien.left = random.randint(1,WIDTH - alien.width)
  60.  
  61.        
  62. def on_mouse_down(pos):
  63.     if alien.collidepoint(pos):
  64.         set_alien_hurt()
  65.         apply_score()
  66.     else:
  67.         miss()
  68.  
  69. def set_alien_hurt():
  70.     alien.image = 'alien_hurt'
  71.     sounds.eep.play()
  72.     clock.schedule_unique(set_alien_normal, 1.0)
  73.  
  74. def set_alien_normal():
  75.     alien.image = 'alien'
  76.  
  77. def miss():
  78.     global score
  79.     score -= 1 if score!=0 else 0
  80.  
  81. def apply_score():
  82.     global score
  83.     score += 1
  84.  
  85. pgzrun.go()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top