“”"
This is my program Hit.it. The player is the ball and the aim of the game is to hit the dogs coming from the sky. If the player hits more than 10 dogs, they win. If not, they lose.
“”"
add_library(“sound”)
ellX = 350 #initial dog position
ellY = 0
count = 0 #count score
ball = 0
countdown = 5 #beginning countdown
moveDown = True #dog starts moving down
def setup():
global sf, x, bgImage, y, speed, acceleration, countdown
countdown = 5
x, y = -50, -50
speed = 2
acceleration = 0.4
size(800, 600)
frameRate(1)
sf = SoundFile(this,“backgroundmusic.mp3”)
sf.play()
bgImage = loadImage(“backgroundimage.jpeg”)
dog = loadImage(“dog.png”)
def mouseReleased():
global x, y, speed
x = mouseX
y = mouseY
speed = 1
def draw():
global bgImage, x, y, speed, dog, count, moveDown, ellX, ellY, ball, countdown
image(bgImage, 0, 0, width, height)
stroke(0, 255, 0)
image(dog, ellX, ellY, 130, 50) #initial position of dog
text("Score:", count, 450, 50)
textSize(18)
text("Welcome to Hit.it! Hit 15 or more dogs and you will win!", width/8, height/8)
text("Get ready to play once the timer runs out!", width/6, height/6)
textSize(50)
text(countdown, height/2, width/2)
if countdown > 0:
countdown = countdown - 1
else:
noLoop()
y = y + speed
speed = speed + acceleration
if y > height:
speed = speed * -1
y = height
if moveDown == True:
ellY = ellY + 4 #dogs always moves down at speed of 4
if ellY <= 650:
moveDown = True #how far down it moved
if ellY> 650:
ellY = 0
ellX = random (30, 570) #random placement
moveDown = True
count = count + 1
if ball < y + 50 and y > ellY - 50 and ball < x + 50 and ball > x - 50: #what happens when the ball hits the dog
ellY = 0
ellX = random(30, 570)
moveDown = True
count= count + 1
if count < 10:
text("You lost!")
else:
text("Congratulations, you won!")