Page 25 of 37
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 6:56 am
by Jasoco
Nah. It's working perfectly the way I have it now. I just need to clean up the code and fix some collisions that used to depend on an actor's Y being the top-left corner (It's now the bottom-left to simulate standing at ground level and help sorting correctly) and I can have a working demo. I also want to do some tweaking to the demo maps first too. Maybe tomorrow night I'll have a demo for you all.
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 7:39 am
by Robin
Jasoco wrote:Maybe tomorrow night I'll have a demo for you all.
Yay!
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 10:14 am
by Jasoco
Is there any way to sort by two key=value pairs? Like could I sort by Y then by X?
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 10:17 am
by bartbes
Sure, if you make your comparison function smart enough.
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 11:56 am
by kikito
Jasoco wrote:Is there any way to sort by two key=value pairs? Like could I sort by Y then by X?
reference:
http://www.lua.org/pil/19.3.html
I'm going to assume that your table is called "elements " and it has a list of tables, each with attributes called ".x" and ".y". Also, take into account that I'm using Y just like LÖVE sorts it ("Up" items first). Adapt as needed:
Code: Select all
-- sorts by Y, then by X
function sortByPosition(elem1, elem2)
if(elem1.y > elem2.y) then return true end
if(elem1.x > elem2.x) then return true end
return false
end
...
-- assuming that your table is called "elements"
table.sort(elements, sortByPosition)
Here's a tighter sortByPosition function (does the same as above)
Code: Select all
function sortByPosition(elem1, elem2)
return elem1.y > elem2.y and true or elem1.x > elem2.x and true or false
end
I haven't tested this code, bugs might be lurking.
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 1:24 pm
by Robin
kikito wrote:Code: Select all
function sortByPosition(elem1, elem2)
return elem1.y > elem2.y and true or elem1.x > elem2.x and true or false
end
Not quite. If you read the
reference, you'll see that the sort function is supposed to do <, not >.
Your code would cause the table to be sorted in reverse, and all things on bottom to be drawn first.
EDIT: also, you complicated things
This:
Code: Select all
function sortByPosition(elem1, elem2)
return elem1.y < elem2.y and true or elem1.x < elem2.x and true or false
end
is equivalent to
Code: Select all
function sortByPosition(elem1, elem2)
return elem1.y < elem2.y or elem1.x < elem2.x
end
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 5:13 pm
by kikito
Good point. Thanks.
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 5:37 pm
by Robin
Wait, wait, wait. We were both wrong. Let's examine what happens here:
Code: Select all
s = sortByPosition --shortcut
s({y = 1, x = 4}, {y = 2, x = 3}) --> true, good
s({y = 2, x = 4}, {y = 2, x = 3}) --> false, good
s({y = 3, x = 2}, {y = 2, x = 3}) --> true, *wrong*
You'd need something like:
Code: Select all
return elem1.y == elem2.y and elem1.x < elem2.x or elem1.y < elem2.y
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 7:32 pm
by Jasoco
I have successfully integrated the Map Editor into the game itself! When the demo comes out, you will be able to access it by pressing E during the logo sequence. Right now it only edits map 1. But I plan on adding in a map list that you can choose from by the end of the day. If I don't, I'll let you know when I put the demo up. I will probably put the demo up bugs and all however it is right before I go to bed or by midnight Eastern or something. I dunno. Unless I make great progress in the next couple hours.
Back to work!
Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)
Posted: Sun Jun 27, 2010 7:41 pm
by nevon
It would be a lot easier and a lot more awesome if you would just put it up on some public VCS like (in order of preference
) Github, Gitorious, Sourceforge or whatever.