A downloadable game

Falling Object Game V1

Project Description

A simple falling ball catching game, without using OOB. Use mouse to control the catcher. When current score is higher, the speed of falling balls is higher and become more difficult to reach higher score. 

Assignment Rubrics

  • 2 points - the falling object must move programmatically (ie. not controlled by the player)
  • 2 points - the catching object must move based on player input (mouse, keyboard, etc.)
  • 4 points - collision detection between the two objects (distance or rectangular, depending on visuals)
  • 2 points - the falling object respawns to a random location when caught or falls off the screen
  • Extra Credit (1 point) - display a score
  • Extra Credit (1 point) - display the high score (involves a fail state)
  • Extra Credit (2 points) - add acceleration or more interesting velocities to either object

My Code

#Falling Object Game V1(PesudoVer)
gravConst = 0.03
gravInitConst = gravConst #make this equal to gravConst
gravDifficuty = 0.003
score = 0 
highScore = 0
resetGame = True
winGame = False
mousePos = PVector(0, 0)
ballPos = PVector(0, 0)
ballSpd = 3
ballInitSpd = ballSpd #make this equal to ballSpd
ballRad = 12  #It's not Rad! It's Diameter!!!
catcherRect = [0, 0, 100, 30, 0, 0, 10, 10] # xpos, ypos, width, height, corner-rounding stuff, cheating by change the width to 2000
catcherHeight = 700
tolerance = 30 #Give player some tolerance on Y axis, also reducing tunneling effect, set to 9999 if you are really stronk (or cheating)
def calculate():
    global resetGame, winGame, ballSpd, mousePos
    checkBtmCollision()
    checkWinCollision()
    if winGame or resetGame:
        print("Should have reset Game NOW!")
    else:
        ballSpd += gravConst
        tempVolVect = PVector(0, ballSpd)
        #print(ballPos.x, ballPos.y)
        ballPos.add(tempVolVect)
    mousePos = PVector(mouseX, mouseY)
def checkBtmCollision():
    global resetGame
    #print("CheckBTMCollision called")
    
    if (ballPos.y + ballRad) > 800:
        print(ballPos.x)
        
        resetGame = True
    
def checkWinCollision():
    global resetGame, winGame
    
    #print("CheckWinCollision called")
    
    #calculate Y-axis collision first, should between a range of tolerance
    upperBound = catcherHeight - (catcherRect[3] / 2)
    lowerBound = upperBound + tolerance
    ballLowerBound = ballPos.y + ballRad
    
    #print(lowerBound, upperBound, ballLowerBound)
    
    #then calculate X-axis collision
    leftBound = (mousePos.x - (catcherRect[2] / 2)) - (ballRad * (2 / 3))
    rightBound = (mousePos.x + (catcherRect[2] / 2)) + (ballRad * (2 / 3))
    
    if ((ballLowerBound < lowerBound) and (ballLowerBound > upperBound)):
        print("X checked!")
        if((leftBound < ballPos.x) and (rightBound > ballPos.x)):
            print("Y Checked!")
            resetGame = True
            winGame = True
            
            print("check Win Collision worked")
    
    
def showBall():
    global ballPos, ballSpd
    stroke(50,255,50)
    fill(255)
    circle(ballPos.x, ballPos.y, ballRad * 2)
def showCatcher():
    global catcherRect
    stroke(50,255,50)
    fill(255)
    rectMode(CENTER)
    rect(mousePos.x, catcherHeight, catcherRect[2], catcherRect[3], catcherRect[4], catcherRect[5], catcherRect[6], catcherRect[7])
    
def showScoreBoard():
    textSize(30)
    fill(122, 255, 211)
    scoreText = ("Your Score is: %i" % (score))
    #print(scoreText)
    highestScoreText = ("Highest Score: %i" % (highScore))
    #print(highestScoreText)
    text(scoreText, 0, 30)
    fill(238, 255, 112)
    text(highestScoreText, 0, 60)
    
    
def setup():
    size(600, 800)
    stroke(50,255,50)
    frameRate(60) #framebased physics, yay
    
def draw():
    global score, highScore, resetGame, winGame, ballPos, ballSpd, gravConst
    background(0)
    if resetGame:
        ballPos = PVector(random(20,580), 0)
        resetGame = False
        if winGame:
            score += 1
            winGame = False
            gravConst += gravDifficuty #Gotta go fast! <Intense Music Playing>
        else:
            #TODO highScore stuff
            if score > highScore:
                highScore = score
            score = 0
            gravConst = gravInitConst #reset difficulity
            ballSpd = ballInitSpd #reset ball speed
    #print(gravConst)
    calculate()
    showBall()
    showCatcher()
    showScoreBoard()

Screenshot


Simple Painter App Gameplay

Download

Download
application.windows64.zip 42 MB

Install instructions

  • Java 8 required. 
  • Or use processing IDE (python mode) to run it

Leave a comment

Log in with itch.io to leave a comment.