Page 1 of 2

Simple Tetris Clone for LOVE

Posted: Mon Dec 12, 2011 1:42 am
by _ex_
Hi guys,
I ported my clone http://code.google.com/p/simple-tetris-clone/ to LOVE

Image

I just learned Lua so the source code it's just a mess of global objects and functions (Game and Platform)
Any help refactoring it? I'm missing the encapsulation and data hiding support of other programming languages :x
If you can review in pedantic mode I would love to hear about your observations.
I'm aiming for a simple code base but in the Lua spirit.

UPDATE: Added the awesome music theme Jarno gently composed for me.

Thanks!

Re: Simple Tetris Clone for LOVE

Posted: Mon Dec 12, 2011 4:38 am
by ivan
Looks pretty cool, good work.
Your code is very clear, seems like you know what you're doing.
Since you're going with an event system for the input you can do away with the large if-then code:

Code: Select all

keys = {}
keys["left"] = Game.Event.MOVE_LEFT
keys["right"] = Game.Event.MOVE_RIGHT
...

function Platform:onKeyDown(key)
  if keys[key] then
    Game:onEventStart ( keys[key] )
  end
end
You can then move the keys table to a seperate config file.

Are you moving to Lua from C/C++?
I think with a bit of OO programming a lot of those if-then statements could be avoided.
Other than that the game and code are pretty good.
I do have a couple of minor gripes:
I think you should be allowed to rotate the pieces counter-clockwise (for example with the down arrow)
Visually the game looks good but there's too much text I think.
The button instructions could be removed altogether, and instead of numeric stats perhaps you could have progress bars like in Tengen Tetris on the NES.

Re: Simple Tetris Clone for LOVE

Posted: Mon Dec 12, 2011 5:02 am
by _ex_
hey Ivan, thanks for the feedback, much appreciated
ivan wrote: I think you should be allowed to rotate the pieces counter-clockwise (for example with the down arrow)
Visually the game looks good but there's too much text I think.
The button instructions could be removed altogether, and instead of numeric stats perhaps you could have progress bars like in Tengen Tetris on the NES.
The game support CCW rotations, but that event is not mapped to any key.
I think this little game is more like a demo, the cool things (sound, music, effects) are left as an exercise to the astute reader :D
I'm not moving to Lua, but I needed a bit of no trivial code in Lua for learning purposes :joker: .

Re: Simple Tetris Clone for LOVE

Posted: Tue Dec 13, 2011 6:18 pm
by negester
_ex_ wrote: I'm missing the encapsulation and data hiding support of other programming languages
You do these in Lua via proxy tables. Private items, read-only items, counting accesses to an item, etc.

It's an advanced topic, and I'm not even going to try explaining it. You're obviously an experienced programmer who presumably likes to dive in at the deep end, so visit http://www.lua.org/pil/13.4.html It's somewhere in the subsections.

Re: Simple Tetris Clone for LOVE

Posted: Tue Dec 13, 2011 8:15 pm
by josefnpat
This is a very nice clone! Mind adding a quick fullscreen, and/or a way to scale the game?

Also, I love the "love" colors :)

Re: Simple Tetris Clone for LOVE

Posted: Tue Dec 13, 2011 11:27 pm
by _ex_
josefnpat wrote:This is a very nice clone! Mind adding a quick fullscreen, and/or a way to scale the game?
Also, I love the "love" colors :)
Thanks! I just started using the engine, so I don't know how LOVE supports the full-screen scaling with different resolutions and aspect ratios, Does it support automatic black stripes when the aspect ratio is different?. Need to play more with this.

Re: Simple Tetris Clone for LOVE

Posted: Wed Dec 14, 2011 12:31 am
by Robin
_ex_ wrote:I don't know how LOVE supports the full-screen scaling with different resolutions and aspect ratios,
Yep.
_ex_ wrote:Does it support automatic black stripes when the aspect ratio is different?
Nope.

Re: Simple Tetris Clone for LOVE

Posted: Wed Dec 14, 2011 3:08 am
by slime
_ex_ wrote:Does it support automatic black stripes when the aspect ratio is different?
I believe that's up to the video driver, not any game or framework or engine.

Re: Simple Tetris Clone for LOVE

Posted: Sun Jan 01, 2012 2:24 am
by _ex_
Added the awesome music theme Jarno gently composed for me.

Re: Simple Tetris Clone for LOVE

Posted: Sun Jan 01, 2012 5:23 am
by MarekkPie
Sweet clone. I like the visual drop shadow as well. One thing I'd suggest it some audio indication that you've made a tetris.