PYTHON
Shoot The Fruit
This is Shoot The Fruit game. The original game consist of clicking on a photo that appears on the screen, and then the same image would appear in a different position. I have modified the code so that instead of one image there are 3, and I have also added a different dimension to each image and a count of the score. I have also added a timer for the game to last 30s. and I have finally made the game open in fullscreeen
This is the modified code:
from random import randint
import pgzrun
import pygame
background = Actor("fondocomida1")
apple = Actor("apple")
orange = Actor("orange")
pineapple = Actor("pineapple")
score = 0
time_left = 10
WIDTH = 1350
HEIGHT = 700
game_over = False
def draw():
screen.surface = pygame.display.set_mode((WIDTH, HEIGHT), pygame.FULLSCREEN)
screen.clear()
screen.blit("fondocomida1", (0, 0))
apple.draw()
orange.draw()
pineapple.draw()
screen.draw.text("Score: " + str(score), color="white", topleft=(10, 10))
if game_over:
screen.fill(color="black")
screen.draw.text("Final Score: "+ str(score), topleft=(10, 10), color="white", fontsize=60)
def place_fruits():
apple.x = randint(50,1200)
apple.y = randint(50,600)
orange.x = randint(50,1200)
orange.y = randint(50,600)
pineapple.x = randint(50,1200)
pineapple.y = randint(50,600)
def time_up():
global game_over
game_over = True
def on_mouse_down(pos):
global score
if apple.collidepoint(pos):
print("Good shot!")
place_fruits()
score = score + 1
if orange.collidepoint(pos):
print("No! Oranges no")
place_fruits()
score = score - 1
if pineapple.collidepoint(pos):
print("PARTY! +5")
place_fruits()
score = score + 5
clock.schedule(time_up, 10)
place_fruits
pgzrun.go()