Making a Game

Hello, I have a few questions about making a game with corona sdk. How would you add for example in angry birds, when you begin the app, there is a button that says play, how would you do that and make it transition to the level screen? Also, how would you add levels and level screens to your game? Sorry for my nooby questions.

Thanks [import]uid: 14686 topic_id: 5116 reply_id: 305116[/import]

Hi geothan:

There are all kinds of ways to do things in Corona. As for screen and transitions, Corona has groups that you can use, but it’s not real obvious how to do it.

I would definitely take a look at this:
http://developer.anscamobile.com/code/director-class-10

Ricardo has a very nice example program and even a video.

I don’t know if you’ve seen this yet, but it might also help:
http://developer.anscamobile.com/code/ghosts-vs-monsters

It’s a game very much like Angry Birds. Note, though, that it was created very quickly, and I would NOT set up my levels the way they did. I think there’s been some discussion on that, so you should look for that when you’re ready.

In the meantime, if I were you, while you’re getting up to speed, I would start with a framework based on the director class. Create a very simple game with very simple levels. Once you understand that, then start thinking about more complicated stuff.

Best of luck!
Lococo
[import]uid: 9659 topic_id: 5116 reply_id: 16995[/import]

Hey thanks for replying all the information really makes a difference. Also what is the Menu page called?

Thanks [import]uid: 14686 topic_id: 5116 reply_id: 17157[/import]

Are you referring to the initial page within a game?

You may want to search for modules if that’s the case. Initially they are confusing, but later really helpful. Also, once you get those down there is a plugin called director that will do a lot of that for you. [import]uid: 10903 topic_id: 5116 reply_id: 17167[/import]

alright thanks and I’ve been researching A LOT, but what are some main things you need to create an app. Like I know you need a main.lua. But what are some other things, like the ui.lua, and the config.lua, etc. Are there any others? And is there a thread that tells you all of that?

Thanks btw =D [import]uid: 14686 topic_id: 5116 reply_id: 17170[/import]

ui actually isn’t necessary, for a basic app all you should have are the main.lua and config.lua. When you’re far enough down the road where you need to submit to apple you need different sized icons, and a distribution certificate, but Apple explains most of that.

All of the coding can be done in main file without other modules, but as the app grows using modules becomes a good way to organize. Config is there just to display your app on different devices correctly. [import]uid: 10903 topic_id: 5116 reply_id: 17171[/import]

oh, I though all of them were necessary, but lets say that I want to add a start screen or a level screen to the game would that be done in main.lua? [import]uid: 14686 topic_id: 5116 reply_id: 17173[/import]

If I understand your question, the answer is yes, you’d set that up in main.lua. I would use the director class I mentioned earlier – you can look at his example to see how he structured his sample code.

There are three things I did when I was learning Corona:

(1) Read “Programming in Lua” by Ieuralimschy (I hope I’m spelling that right.)

(2) Read the articles at http://developer.anscamobile.com/resources/docs

(3) Read all the sample code you can get your hands on. Read it and try to understand what those programmers were doing.

All the best!
Lococo
[import]uid: 9659 topic_id: 5116 reply_id: 17174[/import]

Again it depends on the complexity of your app. As things become more complex one way of doing things is to make each scene or screen change a different module. But if you’re app is just two screens, the main and a level then everything could be done in main. [import]uid: 10903 topic_id: 5116 reply_id: 17175[/import]

I would second this “(3) Read all the sample code you can get your hands on. Read it and try to understand what those programmers were doing.” and actually put this at the top of your list. Tinkering with existing code was the best way for me to figure out what worked and what didn’t.

You can start by downloading sample code and just start changing the value of variables and see what happens. [import]uid: 10903 topic_id: 5116 reply_id: 17176[/import]

Alright guys thanks for all the help, this will prob be my last question for now =P . But here is my main.lua that I have been following a tutorial on youtube. In this folder I have the picture of the floor, the background, the main.lua, and the picture of a dog. Here is the main.lua

–> Add physics engine, start up engine, and apply gravity
local physics = require(“physics”)
physics.start()
– Set gravity to act “down” (ie, towards the bottom of the device)
physics.setGravity( 0, 9.8 )

–> Hide status bar using setStatusBar()
display.setStatusBar(display.HiddenStatusBar)

system.activate( “multitouch” )

–> physics.setDrawMode(“hybrid”)

–> Add background image
local background = display.newImage(“space_background.jpg”)

–> Add dog to stage and position
local dog = display.newImage(“dog.png”)
dog.x = display.contentWidth/2
–> Turn dog into physics body
physics.addBody(dog, { bounce = 0.5, radius = 45, friction = 1.0} )

local dog2 = display.newImage(“dog.png”)
dog2.x = dog.x - 105
–> Turn dog2 into physics body
physics.addBody(dog2, {bounce=0.4, radius = 45, friction = 1.0})

local dog3 = display.newImage(“dog.png”)
dog3.x = dog.x + 105
–> Turn dog3 into physics body
physics.addBody(dog3, {bounce=0.5, radius = 45, friction = 1.0})

–> Add floor image and position
local floor = display.newImage(“floor.png”)
floor.y = display.contentHeight - floor.stageHeight/2
–> Turn floor into a physics body
physics.addBody(floor, “static”, { bounce = 0.2})

–Define wall graphics (rectangles)
local leftWall = display.newRect(0, 0, 1, display.contentHeight )
local rightWall = display.newRect(display.contentWidth, 0, 1, display. contentHeight )

– Turn wall graphics into physics bodies
physics.addBody(leftWall, “static”, { bounce = 0.1} )
physics.addBody(rightWall, “static”, { bounce = 0.1} )

– Define our touch event listener.
function moveDog(event)
local dog = event.target
dog:applyLinearImpulse( 0, -0.2, event.x, event.y )
end

– Add the listener to our dog
dog:addEventListener(“touch”, moveDog)
dog2:addEventListener(“touch”, moveDog)
dog3:addEventListener(“touch”, moveDog)
From all of that would it be possible to add the menu screen? And from the ghost vs. monster I see that his main.lua is very short but it includes like import director and I see director:changeScene( “loadmainmenu” ). Btw, I’m starting to read the book, I got from google books =P Thanks for the patients with all of my noby questions.

[import]uid: 14686 topic_id: 5116 reply_id: 17180[/import]

I would put aside your code for a couple of hours and take a VERY CLOSE look at how the director class works. Once you understand that, you should be able to see how to fit your existing code into it.

In general, you’ll have to modify any of your code that creates a display object, and insert the newly created object into the current director group. (Most functions that create a display object let you pass the group as the first parameter, so it’s easy.) If that doesn’t make sense right now, it will once you look at some code that uses director.lua.

You’ll have a main.lua module which will bring up the main menu. You’ll put the main menu code into a module you’ll probably want to call mainmenu.lua. That will have button which will open other modules.

Take a look at the “Ghosts vs Monsters” and “Martian Control” samples. They offer an excellent intro to the kind of thing you’re asking about.
[import]uid: 9659 topic_id: 5116 reply_id: 17186[/import]