[Newbie] Flying In A Blue Dream

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
hsztheater
Prole
Posts: 5
Joined: Wed Jul 18, 2012 2:17 pm

[Newbie] Flying In A Blue Dream

Post by hsztheater »

Hello :awesome:
I'm new in programming and in the löve community. A couple of months ago, my friend and I decided to create our own "indie games studio" called MarbleWare (nothing serious though, just a hobby for the moment). So far, we've had a lot of ideas, scenarios and stuff for a couple of games but we realized that most of our ideas were way too ambitious for 2 guys without any experience.

What I'm going to present now is the current (and only) game we're working on. We thought it was simple enough to be actually doable, even for us, and we're hoping to learn a lot throughout the process of making this game.

Let me introduce... Flying In A Blue Dream :cool:

This is a very simple game, while in a (blue) dream you are (flying) playing the famous guitarist Joe Satriani and you have to collect all the floating music notes.
Here's a short description of what the "final product" will look like:

Once you launch the .love file, a kind of simple, slightly animated logo introducing our studio will appear. We also want to have a menu with the basic things, play, exit, and maybe an option menu to switch the game into fullscreen and whatnot. Once you click on the play button, a simple cutscene appears, Joe Satriani goes to bed and start dreaming. That is when you take control of him and can actually play, collecting the notes on the "flying in a blue dream" original song (we might have a copyright infringement problem here but let's pretend it's fine). On the bottom of the screen, a "dream time" bar will slowly decrease. It'll actually be a stylized countdown until the song (and the game) is over. You might have a score system like " X notes / Y notes". End of the game.

As you can see, it's pretty simple and we'd really love to go until the end of this project. My friend is doing the art and I'm coding. As I said, I'm new to any kind of programing but I'm learning quite fast. I may however have a lot of questions that I hope you guys will help me with :crazy:

Here's what we've got so far http://cl.ly/1Y2C3Y1W1J2L, the audio track is a midi file converted to wav and then converted to mp3, the quality is really bad but I guess it's illegal to publish the game with the real track by Joe Satriani so you'll have to deal with it :(
I'd be glad if you guys could review my code and tell me what's wrong, what can be optimized and so on. Btw, I used tables but I still don't really understand their use.. :? I'll need to read more about them.

To do list:

A better and random clouds system so that they appear at different times and at different Y positions.
The animated logo
The menu
The cutscene
The score system
The notes system
Pretty much everything actually, haha!

My main concern is about the floating music notes thing, I have no idea what the best way is to achieve what I want... Maybe a scrolling layer?

I'm planning on using this thread as a kind of "dev log" where I'll write things that I learned and where I'll ask for your help, I hope you're cool with that ?
Also, english is not my main language so do tell me if you don't understand something!
raen79
Citizen
Posts: 55
Joined: Sat Jul 21, 2012 11:58 pm

Re: [Newbie] Flying In A Blue Dream

Post by raen79 »

What you have got so far looks pretty cool. I am looking forward to your game coming out ;)
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: [Newbie] Flying In A Blue Dream

Post by Santos »

Welcome! :awesome:

You may find creating functions makes your code more understandable. For example instead of:

Code: Select all

function love.update(dt)
	cloud.x = cloud.x - 64*dt
	if cloud.x <= 0 - 512 then
		cloud.x = 800
	end

	-- etc.
end
You could do:

Code: Select all

function love.update(dt)
	moveCloud(dt)

	-- etc.
end

function moveCloud(dt)
	cloud.x = cloud.x - 64*dt
	if cloud.x <= 0 - 512 then
		cloud.x = 800
	end
end
Using functions like this, love.load, love.update and love.draw could look something like this if you wanted them to:

Code: Select all

function love.load()
	loadMusic()
	loadHero()
	loadBackground()
	loadCloud()
end

function love.update(dt)
	moveCloud(dt)
	moveHero(dt)
end

function love.draw()
	drawBackground()
	drawHero()
	drawClouds()
	drawInformation()
end
Now, on to tables! ^^

There are basically two types of tables: array-like tables, and dictionary-like tables. (Don't worry about remembering these names because I maaay have made them up. Also tables can be both. End of disclaimer. :D)

Array-like tables, or lists, or something:

These can be thought of as lists of things. For example, say you wanted to store the color of clouds:

Code: Select all

cloudColor = {255,255,255,150}
love.graphics.setColor can take a table as an argument:

Code: Select all

love.graphics.setColor(cloudColor)
The way to access each element of the table is like this: cloudColor[*insert position here!*]. For example...

Code: Select all

print(cloudColor[1])   -- Prints 255
print(cloudColor[2])   -- Also prints 255
print(cloudColor[3])   -- Prints 255, again :D
print(cloudColor[4])   -- Prints 150
print(cloudColor[5])   -- Doesn't exist, prints "nil"
They can also be modified:

Code: Select all

cloudColor[1] = 10
cloudColor[2] = 10
love.graphics.setColor(cloudColor)   -- Now the clouds are blue!
For another example:

Code: Select all

levelNames = {
    "The first level",
    "The second level!",
    "Oh snaps it's the third level"
}

currentLevel = 3

love.graphics.setCaption(levelNames[currentLevel])
love.graphics.setCaption will set the window title to "Oh snaps it's the third level".

To add more level names, you could do this if you know the exact "index" of the table you want to use:

Code: Select all

levelNames[4] = "Hey, it's the fourth level!"
levelNames[5] = "BOSS STAGE :O"
Or you could use table.insert to add it to the end of the table (this will have the same effect as the above code):

Code: Select all

table.insert(levelNames, "Hey, it's the fourth level!")
table.insert(levelNames, "BOSS STAGE :O")
You can "loop through" tables like this:

Code: Select all

-- Prints all the level names.

for index, value in ipairs(levelNames) do
    love.graphics.print(value, 10, 20 * index)
end
In this example, index is the current position of the table, and value is what is actually at that position. Once it gets to the end of the loop, it continues with the next element of the table.

What this example is doing is printing the name of level (as stored in value), and printing it an an x position of 10 and a y position of 20 multiplied by the index number: "The first level" will be printed at a y position of 20, "The second level!" will be printed at a y position of 40, etc.

"index" and "value" can be any names you want. It's common to use an _ for variables which won't be used.

Code: Select all

-- Prints all the level names at random y positions.

for _, levelName in ipairs(levelNames) do
    love.graphics.print(levelName, 10, math.random(1, 400))
end
To get the number of elements in a table, you can use #tableName, for example:

Code: Select all

print(#cloudColor)   -- Prints 4
Tables like this can also be useful for collections of things, like clouds and notes in this game, or bricks in Breakout, or aliens in Space Invaders.

Dictionary-like tables, or objects, or, uh, something:

These are useful for "things", like the clouds in this game:

Code: Select all

cloud = {}
cloud.img = love.graphics.newImage("Res/Img/cloud.png")
cloud.x = 800
function cloud.draw()
    love.graphics.draw(cloud.img, cloud.x, 0)
end

function love.draw()
    cloud.draw()
    love.graphics.print("Cloud x position: " .. cloud.x)
end
Instead of being indexed by numbers, they are often indexed by strings.

They can be looped over using pairs:

Code: Select all

something = {x = 10, y = 20}

for key, value in pairs(something) do
   print("key: " .. key .. ", value: " .. value)
end

-- Prints:
-- key: x, value: 10
-- key: y, value: 20
Different ways of doing the same thing:

Code: Select all

something = {}
something.x = 10
something.y = 20
is the same as...

Code: Select all

something = {}
something["x"] = 10
something["y"] = 20
is the same as...

Code: Select all

something = {
    x = 10,
    y = 20
}
is the same as...

Code: Select all

something = {
    ["x"] = 10,
    ["y"] = 20
}
Also:

Code: Select all

cloudColor = {
    255,
    255,
    255,
    150
}
is the same as...

Code: Select all

cloudColor = {
    [1] = 255,
    [2] = 255,
    [3] = 255,
    [4] = 150
}
is the same as...

Code: Select all

cloudColor = {}
cloudColor[1] = 255
cloudColor[2] = 255
cloudColor[3] = 255
cloudColor[4] = 150
love-tile-tutorial has more information about tables and loops, as does the Tables Tutorial on lua-users wiki.

For an example of how all this fits together (with moving clouds at random times and y positions! :ultraglee:) you might want to check out this post.

Hope this helps! :)
hsztheater
Prole
Posts: 5
Joined: Wed Jul 18, 2012 2:17 pm

Re: [Newbie] Flying In A Blue Dream

Post by hsztheater »

Thank you both for your messages!

Wow Santos, you really took the time to write a long and comprehensive lessons on the tables, I really appreciate that, it helps me a lot even though it's still a bit unclear for me on some parts! I'll need to read it again.

Thank you also for the post about the clouds system, I'll try to implement it on the game!

By the way, I have another question and I didn't find any answer on the forums. Have you noticed than when you move the character up and down, a kind of white pixels border appears on him.. Is it something graphic related? My first idea was to ask my friend to do the sprites again but with smoother outlines (now it's only plain black). I hope it'll solve the problem!
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: [Newbie] Flying In A Blue Dream

Post by Santos »

You're welcome! ^^

I think the border is due to drawing the image at locations which aren't whole numbers.

math.floor is a Lua function which returns a number without any decimal places, rounded down. For example math.floor(1.23) and math.floor(1.9) both return 1, and math.floor(-123.4) returns -124.

Try this:

Code: Select all

love.graphics.draw(heros, math.floor(hero.x), math.floor(hero.y))
If you have any questions about tables, let us know! :)

You may find using command line Lua useful for testing things out quickly. (Check out Lua for Windows if you use Windows.)
hsztheater
Prole
Posts: 5
Joined: Wed Jul 18, 2012 2:17 pm

Re: [Newbie] Flying In A Blue Dream

Post by hsztheater »

Added math.floor and... IT WORKS :awesome: Thank you, I learned something valuable and now the game is fixed!
I'll release a 0.2a probably later today that will include the outlines fix, a better cloud system (but I still have to fully understand the code, there's no point copy/pasting the code) and a better organization of my code with the use of functions!
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: [Newbie] Flying In A Blue Dream

Post by OmarShehata »

I'm curious on why you've decided to make your first game downloadable with Lua.

Not only would making it as something like a flash game enable you to make the game a lot faster, but it would also help you get the hang of making games in general. But mostly the reason I would suggest making it as a flash game is because, as a downloadable game, if you have no marketing your game will most likely only reach a few hundred people, maybe a couple thousand if you're lucky, and that's if you offer it for free. Whereas as a flash game, even a simple game could get millions of views, and that comes with a lot of feedback which is essential to a game developer. And web games are generally easier to monetize than downloadable games due to the fierce competition of the latter market and the higher player expectations.

Overall I feel web games would be an easier stepping stone into the game industry. Just thought I'd drop my 2 cents, but good luck with your game and indie endeavor!
hsztheater
Prole
Posts: 5
Joined: Wed Jul 18, 2012 2:17 pm

Re: [Newbie] Flying In A Blue Dream

Post by hsztheater »

Well, to be honest, when we first talked about making a game, we wanted to use UDK and we were foolish enough to think that we'd release the next Silent Hill on Steam a month or two after that. The reality was way different as you can imagine haha, we had a kickass scenario, kickass graphics and music but I got quite disapointed the first time I launched UDK.

Then I bought game maker but I quickly stopped using it as well, it was not really intuitive for me. I then tried construct but I thought it was quite dumb to use that kind of software to make a game, I really wanted to get a bit into programing as well, not the hardcore C language but something that would maybe be a bit easier, LUA with Löve sounded like the best option.

We're not planning on releasing our first game to the mass, it's just going to be our first shot, a couple of friends will play it and that's all, it's a kind of "training project".
A friend who is doing a game designer cursus at school told me the same yesterday, that I should start with Stencyl or something like that.

However, I don't really understand why making a flash game would be faster and help me get the hang of making games in general, is there no programmation at all in flash? Can you elaborate a bit? Thanks for your advices anyway, we want at least to do that first game with Löve and then maybe we'll port in in flash or something!
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: [Newbie] Flying In A Blue Dream

Post by OmarShehata »

hsztheater wrote:A friend who is doing a game designer cursus at school told me the same yesterday, that I should start with Stencyl or something like that.

However, I don't really understand why making a flash game would be faster and help me get the hang of making games in general, is there no programmation at all in flash? Can you elaborate a bit? Thanks for your advices anyway, we want at least to do that first game with Löve and then maybe we'll port in in flash or something!
Quite the contrary. Something like stencyl pretty much has no programming as far as I'm aware, but with flash, you'll be programming pretty much the same way you would be with Lua or anything else. The only difference is that the flash framework is just a lot more streamlined for rapid game development. So something like depth sorting for example, you'll have to make your own system with Lua. Whereas in flash there already is a system in place, but you could still make your own system if you like. Such that when you use another language, you'd have understood how a depth system works, and would be ready to make your own.

This is just one example where Flash makes development easier. Flash also makes the process of creating art/animation and using it a *lot* easier as it allows you to easily work with vector art made in the flash IDE.

If you're doing this game just for learning purposes then I do commend you on your choice. The lower level you start, the harder the learning curve will be but the more you'll understand about game development.
hsztheater
Prole
Posts: 5
Joined: Wed Jul 18, 2012 2:17 pm

Re: [Newbie] Flying In A Blue Dream

Post by hsztheater »

Well well, thank you for your advices then, they will be taken into consideration.
I don't think I'll give up with Löve just now but I'll definitely start to learn about Flash as well.
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests