Page 1 of 1
Tic Tac Toe [WIP] - First Game
Posted: Fri Jan 15, 2021 3:15 pm
by MorbusKobold
Tic Tac Toe - Version 1.2
I've messing around with Love Lua for some Time now, and just wanted to get some Feedback on my Coding Style (Hobby Programmer all self taught).
Here is my first Submission to the Community. It's a simple 2D Clone of TicTacToe, nothing to complicated.
All Libraries are written from Scratch.
collision.lua used this website:
https://2dengine.com/?p=intersections , i've added some stuff and functions.
Bord.lua, Patterns.lua and
Helper.lua aren't used and were used in older Versions.
No AI yet and the Options Menu isnt functioning.
Have fun.
First Post.
Morbus Kobold.
Re: Tic Tac Toe [WIP] - First Game
Posted: Fri Jan 15, 2021 11:36 pm
by darkfrei
How to start the game with mouse only?
Re: Tic Tac Toe [WIP] - First Game
Posted: Fri Jan 15, 2021 11:43 pm
by sphyrth
For a self-taught programmer, that as very clean and readable code. You seem to be fluent in any language you study.
My suggestions will sacrifice some of that cleanness for better coding practices.
#1 - There some parts that should make use of
love.update. Take
menu.update() for an example.
Code: Select all
function love.update()
if game.state == "menu" then
menu.update()
end
end
...
function love.draw()
...
if game.state == "menu" then
menu.draw()
elseif game.state == "game" then
...
end
...
end
#2 - I'm having trouble suggesting something about your usage of
sxBackground, and
syBackground. I know what they're for, but I'm too lazy to think of a solution that uses
local variables and at the same time
not doing it in love.draw().
#3 - I've only recently adjusted from using only dots(.) to semi-colons(:) for tables that use themselves in their functions.
For example, turn this:
Code: Select all
function menu.update()
if menu.entry < 1 then
menu.entry = 1
elseif menu.entry > #menu.entries then
menu.entry = #menu.entries
end
...
end
Into something like this:
Code: Select all
function menu:update() -- or menu.update(self), but you'll call it as menu:update() anyway
if self.entry < 1 then
self.entry = 1
elseif self.entry > #self.entries then
self.entry = #self.entries
end
...
end
Re: Tic Tac Toe [WIP] - First Game
Posted: Sat Jan 16, 2021 11:55 am
by darkfrei
sphyrth wrote: ↑Fri Jan 15, 2021 11:43 pm
#3 - I've only recently adjusted from using only dots(.) to semi-colons(:) for tables that use themselves in their functions.
How to copy such objects with functions without metatables?
Re: Tic Tac Toe [WIP] - First Game
Posted: Mon Jan 18, 2021 6:00 pm
by sphyrth
darkfrei wrote: ↑Sat Jan 16, 2021 11:55 am
How to copy such objects with functions without metatables?
I'm not really a good source for an answer to this, but I currently use normal tables.
Code: Select all
function newObj()
local object = {}
object.sample_var2 = 'blah'
function object:sampleFunction()
--
end
return object
end
Now, I just call that function.
Code: Select all
object1 = newObj()
object2 = newObj()
objectN = newObj()