Hi all!
I’m making my first game with corona, which is a simple game with main menu, main game, and try again screens. The object of the game will be for the character (a flying frog…) to dodge asteroids that are falling at random x coordinates from the top of the screen. the character can be moved left of right depending on which side of the screen is touched.
I haven’t gotten too far in the game, but I just wanted to hopefully get some feedback on if I’m doing everything correctly.
I have all code on the main.lua file. I have functions for the background, character, asteroids, etc. set up at the top. Then I have functions for the mainMenu(), mainGame(), and tryAgain() which will use the functions created beforehand. I will then use events like collision or touches in the mainMenu(), mainGame(), and tryAgain() functions to switch between the 3 game states. Is this the correct way to do it in Corona? I keep hearing about storyboards, but no idea what those are.
Here is what the code looks like, it isn’t nearly complete.
-- hide status bar
display.setStatusBar(display.HiddenStatusBar)
-- start physics and turn off gravity
local physics = require("physics")
physics.start()
physics.setGravity(0,0)
-- set W and H to width and height of device screen
local W = display.contentWidth
local H = display.contentHeight
-- table to hold spawned asteroids
local ast={}
-- asteroid properties
local function asteroids()
local asteroid = display.newImage("Images/ast.png")
asteroid.width = 128
asteroid.height = 128
asteroid.x = W/2
asteroid.y = 0
physics.addBody(asteroid, {0,0,0})
asteroid:setLinearVelocity(0,600)
end
-- asteroid spawner (table.insert)
local function astSpawn()
end
-- frog properties
local function frog()
local frog = display.newImage("Images/Frog6.png")
frog.x = W/2
frog.y = H/1.2
frog.width = 96
frog.height = 128
end
-- background properties
local function background()
local background = display.newImage("Images/Background.png")
background.x = W/2
background.y = H/2
background.width = W
background.height = H
end
-- button properties
local function button()
local button = display.newImage("Images/bluebutton.png")
button.x = W/2
button.y = H/2
local text = display.newText("Play Game",W/2,H/2,nativesystemFont,64)
end
-- main menu screen functions (will have touch event triggering mainGame() to start)
local function mainMenu()
background()
button()
frog()
end
-- main game screen functions (will have collision event triggering tryAgain() to start)
local function mainGame()
background()
frog()
asteroids()
end
-- try again screen functions (will have touch event triggering mainMenu() to start)
local function tryAgain()
end
-- starts the game at mainMenu() screen
mainMenu()
Any feedback would be awesome!