Page 1 of 1

Basic platformer WIP - Demo

Posted: Thu Jan 16, 2014 2:15 am
by Wesleyyy
Heya,

After experimenting with LÖVE for a while, using Lua knowledge I learned via Roblox, I am now creating a basic platformer. I'm considering following Game Architecture & Design in college next year and so far, I'm liking it.

I tried using ATL and a collision system I found somewhere to build the basics, but I didn't understand either of them. After a few hours of thinking, I build the tile and movement from scratch myself and implementing collision didn't cause too much trouble. I don't have any plans for now, I'm just creating whatever I think fits in the game.

Image

There's only 1 short level I made in Tiled a while ago. The blue pole marks the end of the level. If you can touch it, you win.

** Known bugs:
- When walking to the right, walls don't properly stop you. Instead, they bumb you back and forth.
- Triggers (Jumping springs) only detect the bottom-left pixel.
- When you collect a coin, a sound plays. If you collect another while the sound still plays, you won't hear another sound.
(If there's anyone who would like to help me with the collision/sound, I really appreciate it!)

All feedback and help is much appreciated!

I think I'm in love with LÖVE now :3

Re: Basic platformer WIP - Demo

Posted: Thu Jan 16, 2014 3:16 am
by davisdude
Very nice looking game so far! And welcome to the community! :)

I have some comments on the code:
Starting on line 314 of main.lua, and ending on line 621, you have:

Code: Select all

if MapTile[y][x] == number then
     ...
end
if MapTile[y][x] == number then
     ...
end
I'm pretty sure this slows down the game speed a lot. Instead, use else-if statements! :)

Code: Select all

if MapTile[y][x] == number1 then
     ...
elseif MapTile[y][x] == number2 then
     ...
elseif...
You get the idea.

On line 630 of main.lua:

Code: Select all

if MapEntity[n].visible == true then
can also be

Code: Select all

if MapEntity[n].visible then
It's also a good habit to define arguments in the local space instead of globally (read why here if you want).
And I would highly recommend making a separate player.lua and enemy.lua, etc. files, simply for code cleanliness and manageability. Close to 1,000 lines of code is not something that is easy to edit...

Other than that, the code is very well written, so far as I can tell! :D

The game is also rather playable, considering it is the first!

Re: Basic platformer WIP - Demo

Posted: Thu Jan 16, 2014 4:17 am
by Wesleyyy
davisdude wrote:Very nice looking game so far! And welcome to the community! :)
I have some comments on the code:

...

Other than that, the code is very well written, so far as I can tell! :D
The game is also rather playable, considering it is the first!
Hey, thank you very much!

Would moving the

Code: Select all

if MapTile[y][x] == number1 then
     ...
elseif MapTile[y][x] == number2 then
     ...
elseif...  etc
loop and/or the love.graphics.newQuad() list to a seperate draw.lua file make the game any slower?

Re: Basic platformer WIP - Demo

Posted: Thu Jan 16, 2014 5:12 am
by Karai17
Looking good so far!

Moving them to a new file will not cause any slow down, no.

To fix the "moving right into a wall" bug, before you move the player forward, check to see if his new position will be colliding with the wall. If it is, don't move.

Code: Select all

player:move(x,y)
    local pos = {
        x = player.x + x,
        y = player.y + y
    }

    if not checkCollision(pos) then
        player.x = pos.x
        player.y = pos.y
    end
end