NUMBERF/CKER (formerly Numberwang) - math game (not 2048)
Re: NUMBERF/CKER (formerly Numberwang) - math game (not 2048
this is very simple yet one of the most fun games i have ever played. very nicely done
Re: NUMBERF/CKER (formerly Numberwang) - math game (not 2048
Hi unek!
I looked at your code and was quite impressed.
I was wondering about one construct.
You define anim_after() function in merge.
No parameters are passed to the internal function update via the anim_after() function.
You then call anim_after() outside of merge - in love.update().
This works but what parameters are being passed to the local update(x1,y1) function?
Just don't know how this works.
Appreciate an explaination.
I looked at your code and was quite impressed.
I was wondering about one construct.
You define anim_after() function in merge.
Code: Select all
local function merge(x1, y1, x2, y2)
launchAnim(x1, y1, x2, y2, board[y2][x2], board[y1][x1])
board[y1][x1] = board[y1][x1] + board[y2][x2]
board[y2][x2] = 0
anim_after = function()
update(x1, y1)
end
end
You then call anim_after() outside of merge - in love.update().
Code: Select all
if anim_dt - dt < anim_time and anim_dt > anim_time and anim_after then
anim_after()
end
Just don't know how this works.
Appreciate an explaination.
Re: NUMBERF/CKER (formerly Numberwang) - math game (not 2048
When merge is called, its arguments are stored as local variables to the function; defining anim_after in the same function using variables local to the function creates what is called a closure. The local variables x1,y1 are "saved" and bound to anim_after, so every time merge is called it defines anim_after to use whatever x1,y1 merge received.
TL,DR: anim_after uses whatever x1,y1 the "merge" function received last.
EDIT: Look here for some closures explanation from the PIL.
TL,DR: anim_after uses whatever x1,y1 the "merge" function received last.
EDIT: Look here for some closures explanation from the PIL.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: NUMBERF/CKER (formerly Numberwang) - math game (not 2048
edit:
Not as good as Micha's...
Not as good as Micha's...
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: NUMBERF/CKER (formerly Numberwang) - math game (not 2048
Belated thanks to Nixola for explanation of closures.
The highScore function posted by Beelz sure is slick.
Added it to my version of Numberf/cker.
Only required modifying two lines of code.
Posting my slightly modified version of this interesting game - no credit claimed.
The highScore function posted by Beelz sure is slick.
Added it to my version of Numberf/cker.
Only required modifying two lines of code.
Posting my slightly modified version of this interesting game - no credit claimed.
- Attachments
-
- numDiv.love
- Refactored version of number/cker
- (23.13 KiB) Downloaded 136 times
Who is online
Users browsing this forum: No registered users and 1 guest