Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pgzrun
- import os
- import random
- alien = Actor('alien')
- alien.topright = 0, 10
- WIDTH = 500
- HEIGHT = 500
- score = 0
- direction = 0
- def draw():
- screen.clear()
- alien.draw()
- screen.draw.text("Skóre: "+str(score),(10,10),color="white")
- def update():
- global direction
- if direction == 0:
- alien.left += 2
- if alien.left > WIDTH:
- pick_direction()
- set_alien_to_proper_start()
- if direction == 1:
- alien.left -= 2
- if alien.right < 0:
- pick_direction()
- set_alien_to_proper_start()
- if direction == 2:
- alien.top += 2
- if alien.top > HEIGHT:
- pick_direction()
- set_alien_to_proper_start()
- if direction == 3:
- alien.top -= 2
- if alien.bottom < 0:
- pick_direction()
- set_alien_to_proper_start()
- def pick_direction():
- global direction
- direction = random.randint(0,3)
- def set_alien_to_proper_start():
- global direction
- if direction == 0:
- alien.right = 0
- alien.top = random.randint(1,HEIGHT - alien.height)
- if direction == 1:
- alien.left = WIDTH
- alien.top = random.randint(1,HEIGHT - alien.height)
- if direction == 2:
- alien.bottom = 0
- alien.left = random.randint(1,WIDTH - alien.width)
- if direction == 3:
- alien.top = HEIGHT
- alien.left = random.randint(1,WIDTH - alien.width)
- def on_mouse_down(pos):
- if alien.collidepoint(pos):
- set_alien_hurt()
- apply_score()
- else:
- miss()
- def set_alien_hurt():
- alien.image = 'alien_hurt'
- sounds.eep.play()
- clock.schedule_unique(set_alien_normal, 1.0)
- def set_alien_normal():
- alien.image = 'alien'
- def miss():
- global score
- score -= 1 if score!=0 else 0
- def apply_score():
- global score
- score += 1
- pgzrun.go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement