A HUGE THANK YOU IN ADVANCE FOR THE HELP!! C++ Class- INTRO TO DATA STRUCTURES -
ID: 3576722 • Letter: A
Question
A HUGE THANK YOU IN ADVANCE FOR THE HELP!!
C++ Class- INTRO TO DATA STRUCTURES - USING CORONA SDK!!
This will be another lua game. We will be using the Corona simulator. The original game was written by Gary Sims for Android Authority
Here are the rules for the game as it is.
You start out with no points, the goal is to get to 500 points. If your score gets below zero, you lose.
There are three kinds of balloons.
-Red: If you click on it, 100 points are added to your score, and a little “Boom” appears. If you miss it, one point is taken from your score.
-Green: if you click on it, 10 points are added to your score, nothing appears. If you miss it, one point is taken from your score.
-Black: If you click it, your score it cut in half, a little “Ouch!” appears, but if you miss it, nothing is taken from your score.
This is how I would like you to revise the game…
The basic rules remain the same. You start out with no points, the goal is to get to 500 points. If your score gets below zero, you lose.
Red: don’t change it. Green: Have the “Boom” appear when it is clicked. (Keep it the same otherwise.)
Black: Keep it the same.
Yellow: Yes, yellow, that’s the main change. Add a yellow balloon (the image file “yellow.png”, is included.)
Around half of the time, when you click on the yellow balloon, it will add 10 points to your score, some of the time it will take away 10 points. If you miss it, one point will be taken away. Have the “boom” appear when the points are added, and “Ouch!” when they are taken away.
There are at least two ways to go about this, you could use a random number generator, or you can make two different kinds of yellow balloons. Here is what you will get, a zip file, game 2.zip. It is in the course files folder.
HERE IS THE CODE I HAVE. THANK YOU
-- Start the physics engine
local physics = require( "physics" )
physics.start()
-- Calculate half the screen width and height
halfW = display.contentWidth*0.5
halfH = display.contentHeight*0.5
-- Set the background
local bkg = display.newImage( "sky.png", halfW, halfH )
-- Score
score =0
scoreText = display.newText(score, halfW, 10)
-- Called when the balloon is tapped by the player
-- Increase score by 10
local function balloonTouched(event)
if ( event.phase == "began" ) then
Runtime:removeEventListener( "enterFrame", event.self )
event.target:removeSelf()
--adds to score if game still in play
if (score >=0) then
if (score < 500) then
score = score + 10
end
end
scoreText.text = score
end
if (score < 0)
then scoreText.text = "You Lose!"
end
if (score > 499)
then scoreText.text= "You Win!"
end
end
-- Called when the bomb is tapped by the player
-- Half the score as a penalty
local function bombTouched(event)
if ( event.phase == "began" ) then
Runtime:removeEventListener( "enterFrame", event.self )
local blast = display.newImage( "ouch.png",event.x,event.y)
physics.addBody( blast )
event.target:removeSelf()
--divides score if game still in play
if (score >=0) then
if (score < 500) then
score = math.floor(score * 0.5)
scoreText.text = score
end
end
end
end
local function superTouched(event)
if ( event.phase == "began" ) then
Runtime:removeEventListener( "enterFrame", event.self )
local blast = display.newImage( "boom.png",event.x,event.y)
physics.addBody( blast )
event.target:removeSelf()
--adds to score if game is still going.
if (score >=0) then
if (score < 500) then
score = score + 100
end
end
scoreText.text = score
end
if (score < 0)
then scoreText.text = "You Lose!"
end
if (score > 499)
then scoreText.text= "You Win!"
end
end
-- Delete objects which has fallen off the bottom of the screen
local function offscreen(self, event)
if(self.y == nil) then
return
end
if(self.y > display.contentHeight + 50) then
Runtime:removeEventListener( "enterFrame", self )
self:removeSelf()
--takes away from score if game is still going
if (score >=0) then
if (score < 500) then
score = score - 1
end
end
scoreText.text = score
if (score < 0)
then scoreText.text = "You Lose!"
end
if (score > 499)
then scoreText.text= "You Win!"
end
end
end
-- Delete objects which has fallen off the bottom of the screen
local function offscreenbomb(self, event)
if(self.y == nil) then
return
end
if(self.y > display.contentHeight + 50) then
Runtime:removeEventListener( "enterFrame", self )
self:removeSelf()
end
end
-- Add a new falling balloon or bomb
local function addNewBalloonOrBomb()
-- You can find red_ballon.png and bomb.png in the GitHub repo
if (score >= 0) then
if (score < 500) then
local startX = math.random(display.contentWidth*0.1,display.contentWidth*0.9)
if(math.random(1,5)==1) then
-- BOMB!
local bomb = display.newImage( "bomb2.png", startX, -300)
physics.addBody( bomb )
bomb.enterFrame = offscreenbomb
Runtime:addEventListener( "enterFrame", bomb )
bomb:addEventListener( "touch", bombTouched )
else
if(math.random(1,5)==2) then
-- super!
local super = display.newImage( "super2.png", startX, -300)
physics.addBody( super )
super.enterFrame = offscreen
Runtime:addEventListener( "enterFrame", super )
super:addEventListener( "touch", superTouched )
else
-- Balloon
local balloon = display.newImage( "green_balloon.png", startX, -300)
physics.addBody( balloon )
balloon.enterFrame = offscreen
Runtime:addEventListener( "enterFrame", balloon )
balloon:addEventListener( "touch", balloonTouched )
end
end
end
end
end
-- Add a new balloon or bomb now
--addNewBalloonOrBomb()
-- Keep adding a new balloon or bomb every 0.5 seconds
if (score >= 0) then
if (score < 500) then
timer.performWithDelay ( 500, addNewBalloonOrBomb, -1)
end
end
Explanation / Answer
Solution:
See the updated code below
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- hide the status bar
display.setStatusBar( display.HiddenStatusBar )
-- include the Corona "composer" module
--local composer = require "composer"
-- load menu screen
--composer.gotoScene( "menu" )
-- Start the physics engine
local physics = require("physics")
physics.start()
-- Calculate half the screen width and height
halfW = display.contentWidth*0.5
halfH = display.contentHeight*0.5
-- Set the background
local bkg = display.newImage("sky.png", halfW, halfH)
-- Score
score =0
scoreText = display.newText(score, halfW, 10)
-- Called when the balloon is tapped by the player
-- Increase score by 10
local function balloonTouched(event)
if (event.phase == "began") then
Runtime:removeEventListener("enterFrame", event.self )
event.target:removeSelf()
--adds to score if game still in play
if (score >=0) then
if (score < 500) then
score = score + 10
end
end
scoreText.text = score
end
if (score < 0)
then scoreText.text = "You Lose!"
end
if (score > 499) then
scoreText.text= "You Win!"
end
end
-- Called when the bomb is tapped by the player
-- Half the score as a penalty
local function bombTouched(event)
if (event.phase == "began") then
Runtime:removeEventListener("enterFrame", event.self )
local blast = display.newImage("ouch.png",event.x,event.y)
physics.addBody( blast )
event.target:removeSelf()
--divides score if game still in play
if (score >=0) then
if (score < 500) then
score = math.floor(score * 0.5)
scoreText.text = score
end
end
end
end
local function superTouched(event)
if (event.phase == "began") then
Runtime:removeEventListener("enterFrame", event.self )
local blast = display.newImage("boom.png",event.x,event.y)
physics:addBody(blast)
event.target:removeSelf()
--adds to score if game is still going.
if (score >=0) then
if (score < 500) then
score = score + 100
end
end
scoreText.text = score
end
if (score < 0) then
scoreText.text = "You Lose!"
end
if (score > 499) then
scoreText.text= "You Win!"
end
end
-- Delete objects which has fallen off the bottom of the screen
local function offscreen(self, event)
if (self.y == nil) then
return
end
if (self.y > display.contentHeight + 50) then
Runtime:removeEventListener("enterFrame", self)
self:removeSelf()
--takes away from score if game is still going
if (score >=0) then
if (score < 500) then
score = score - 1
end
scoreText.text = score
if (score < 0) then
scoreText.text = "You Lose!"
end
if (score > 499) then
scoreText.text= "You Win!"
end
end
end
end
-- Delete objects which has fallen off the bottom of the screen
local function offscreenbomb(self, event)
if (self.y == nil) then
return
end
if (self.y > display.contentHeight + 50) then
Runtime:removeEventListener("enterFrame", self)
self:removeSelf()
end
end
-- Add a new falling balloon or bomb
local function addNewBalloonOrBomb()
-- You can find red_ballon.png and bomb.png in the GitHub repo
if (score >= 0) then
if (score < 500) then
local startX = math.random(display.contentWidth*0.1,display.contentWidth*0.9)
if(math.random(1,5)==1) then
-- BOMB!
local bomb = display.newImage("bomb2.png", startX, -300)
physics:addBody(bomb)
bomb.enterFrame = offscreenbomb
Runtime:addEventListener("enterFrame", bomb)
bomb:addEventListener("touch", bombTouched)
else if(math.random(1,5)==2) then
-- super!
local super = display.newImage("super2.png", startX, -300)
physics:addBody(super)
super.enterFrame = offscreen
Runtime:addEventListener("enterFrame", super)
super:addEventListener("touch", superTouched)
else
-- Balloon
local balloon = display.newImage("green_balloon.png", startX, -300)
physics:addBody(balloon)
balloon.enterFrame = offscreen
Runtime:addEventListener("enterFrame", balloon)
balloon:addEventListener("touch", balloonTouched)
end
end
end
end
end
-- Add a new balloon or bomb now
--addNewBalloonOrBomb()
-- Keep adding a new balloon or bomb every 0.5 seconds
if (score >= 0) then
if (score < 500) then
timer.performWithDelay (500, addNewBalloonOrBomb, -1)
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.