from processing import * import random x = [50,100,150,200,250,300,350,400,450,500,550,600,650,700] y = [0,150,200,300,350,450,500,550] player_x = 250 player_y = 150 strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) width = 800 height = 600 score = 0 lives = 5 strawberry_width = 50 strawberry_height = 50 player_width = 50 player_height = 50 def setup(): global q global w global s global player global strawberry global strawberry_x global strawberry_y size(800,600) s = loadImage("ocean.jpg") player = loadImage("player.png") strawberry = loadImage("strawberry.png") q = loadImage("forest.jpg") def draw(): background(190,270,290) global score global strawberry_x global strawberry_y global s image(player, player_x, player_y) fill(0,400,0) text("Score: {}".format(score), 10, 25) text("Lives: {}".format(lives), 10, 45) image(strawberry,strawberry_x,strawberry_y) if score == 0: fill(300,100,150) rect(250,50,290,50) fill(0,250,300) textSize(20) text("Collect the strawberries !",250,90) if score == 2: fill(250,150,210) rect(200,50,330,50) fill(0,250,300) textSize(20) text("Do not touch the lines!",200,90) if score >= 4: fill(330,400,7) rect(0,110,140,40) rect(200,110,200,40) rect(450,110,350,40) fill(78,150,158) rect(0,250,300,40) rect(350,250,100,40) rect(500,250,290,40) fill(300,200,250) rect(0,400,140,40) rect(200,400,200,40) rect(450,400,350,40) if lives <= 0: image(s,0,0) textSize(90) fill(300,0,50) text("Game Over",165,220) if score >= 40: image(q,0,0) textSize(90) fill(0,300,50) text("you win",200,200) def keyPressed(): global player_x global player_y global score global strawberry_x global strawberry_y global lives if keyboard.keyCode == RIGHT: player_x = player_x + 50 if keyboard.keyCode == LEFT: player_x = player_x - 50 if keyboard.keyCode == UP: player_y = player_y - 50 if keyboard.keyCode == DOWN: player_y = player_y + 50 if score == 1: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 3: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 4: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 6: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 8: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 10: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 12: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 14: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 16: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 18: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 20: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 22: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 24: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 26: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 28: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 30: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 32: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 34: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 36: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 36: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if score == 38: strawberry_x =(random.choice(x)) strawberry_y =(random.choice(y)) score = score +1 if player_x < 0 or player_x > width: player_x = 0 player_y = 0 if player_y < 0 or player_y > height: player_x = 0 player_y = 0 if player_x == strawberry_x and player_y == strawberry_y : score = score +1 if score >= 4: if 0<=player_x<=140 and player_y == 100 : lives = lives - 1 if 200 <=player_x<=390 and player_y == 100 : lives = lives - 1 if 450<=player_x<=800 and player_y == 100 : lives = lives - 1 if 0 <= player_x <= 290 and player_y ==250: lives = lives - 1 if 350<=player_x <= 400 and player_y ==250: lives = lives - 1 if 500<=player_x <= 750 and player_y ==250: lives = lives - 1 if 0<=player_x<=130 and player_y ==400: lives = lives - 1 if 200<=player_x<=390 and player_y ==400: lives = lives - 1 if 450 <=player_x<=800 and player_y ==400: lives = lives - 1 run()