from processing import *
lives = 5
score = 0
width = 300
height = 300
monster_x = 40
monster_y = 60
monster_width = 50
monster_height = 50
speed_x = 5
speed_y = 3
move_x = 4
move_y = 6
player_x = 100
player_y = 100
game_over = False
def setup():
global monster
global player
size(width, height)
monster = loadImage("monster.png")
player = loadImage("player.png")
textSize(20)
def draw():
global monster_x
global monster_y
global monster2_x
global monster2_x
global move_x
global move_y
global speed_x
global speed_y
global game_over
background(20,10,50)
image(player, player_x, player_y)
if lives <= 0:
game_over = True
if not game_over:
text("Score: {}".format(score), 10, 25)
text("Lives: {}".format(lives), 10, 45)
monster_x = monster_x + speed_x
monster_y = monster_y + speed_y
if monster_x < 0 or monster_x + monster_width > width:
speed_x = -speed_x
if monster_y < 0 or monster_y + monster_height > height:
speed_y = -speed_y
image(monster, monster_x, monster_y)
else:
textSize(40)
text("Game Over!", 40, 160)
def sprite_clicked(x, y):
in_x = monster_x <= x <= monster_x + monster_width
in_y = monster_y <= y <= monster_y + monster_height
if in_x and in_y:
return True
else:
return False
def keyPressed():
global player_x
global player_y
old_x = player_x
old_y = player_y
if keyboard.keyCode == RIGHT:
player_x = player_x + 5
if keyboard.keyCode == LEFT:
player_x = player_x - 5
if keyboard.keyCode == DOWN:
player_y = player_y + 5
if keyboard.keyCode == UP:
player_y = player_y - 5
player_y = player_y + 5
if player_x < 0 or player_x + 60 > width:
player_x = old_x
if player_y < 0 or player_y + 60 > height:
player_y = old_y
def check_collision_with_walls():
global player_x
global player_y
global lives
global apple_eaten
global cheese_eaten
top_left = check_colour_at_point(player_x, player_y)
top_right = check_colour_at_point(player_x + 40, player_y)
bottom_left = check_colour_at_point(player_x, player_y + 40)
bottom_right = check_colour_at_point(player_x + 40, player_y + 40)
points = [top_left, top_right, bottom_left, bottom_right]
if (0, 0, 0) in points:
player_x = 52
player_y = 52
lives = lives - 1
def mouseClicked():
global score
global lives
if sprite_clicked(mouse.x, mouse.y):
score = score + 10
else:
lives = lives - 1
run()
هذه هي البرمجة وشكرا تعبتك معي