My Adventure Game Engine - Making Way For Adventure Engine 2

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
hertzcastle
Party member
Posts: 100
Joined: Sun Jan 04, 2009 4:51 pm
Location: brighton, uk

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by hertzcastle »

looks amazing! keep it up!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Robin »

Jasoco wrote:Well, here's how it goes. I have a Scenery Object defined in the Library:

Code: Select all

sceneryLibrary["Flower 1"] = {i = worldTiles, q = gr.newQuad(0, 128, 16, 16, worldTiles:getWidth(), worldTiles:getHeight()), ani = false }
And I would place it in the map by using adding Scenery to the current world space:
If you remove the space, you could use:

Code: Select all

sceneryLibrary.Flower1 = {i = worldTiles, q = gr.newQuad(0, 128, 16, 16, worldTiles:getWidth(), worldTiles:getHeight()), ani = false }
Wouldn't make much difference in other places, though.
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Jasoco »

TechnoCat wrote:That transparent gray circle-gradient background on the menu is so sexy. It looks so very pleasant to look at. Also, consider making the target icon green arrow smaller. Or maybe even just a small green triangle.
It's even sexier on the plain white background of the title/intro screen. Looks really nice. And using a plain clean font with greys and black makes it look more... sophisticated? I dunno.

Yeah. The arrow is a bit big. Once I get "depth sorting" in place I will do tweaking there. I want to be able to walk behind scenery then in front of it, which will require me to throw everything into a single table then sort it by Y every frame. Now that I know I can give table entries names like that I should be able to do it much easier. As long as sort and pairs() are fast enough once I get into levels with many objects.

When I say objects, I mean everything that needs to have depth. The player, enemies, projectiles, scenery, switches, everything. I'd be able to give the Player a name object["player"] and still be able to move it even if it gets sorted. Right? These tables can still be sorted, right? If they can't, then it's all in vain.

Code: Select all

object["player"].y = player.y
object["enemy_1"].y = enemy[1].y
Etc...

sort(objects)

function sort(T)
  table.sort(T, 
    function(a, b)
      return a.y < b.y
    end
  ) 
end
Every frame. The jist of it. I'll probably make it so it only sorts when something moves up or down since that's the only time it's needed. But it should go pretty fast.

When I get home, I will do some tests. I hope to have a prototype and new demo sometime this weekend. Once I can get sorting, the whole engine will reach the next level. I also ported the Map Editor I made to 0.6.2, and am fixing some bugs. Eventually I will either include it with my demo, or build it in. I already have a secret Edit mode in place in the current version where you press E at the logo screen to go into the editor. I need to make the editor have the ability to place Scenery. Right now it's still Tiles. With the editor built in, I'll only need one copy of the images and resources instead of one per .love project. It will be soooo much better and easier to edit this thing with it built-in. And hopefully I'll make it possible to switch between the editor and the game so I can make a preview mode and testing ground.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by bartbes »

If you do use that snippet above, please, please take the anonymous function out and make it a local function outside of sort, what you're doing now creates a function every time you sort, which is wasteful and probably decreases performance.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Robin »

It doesn't create a new function each time, but it does create a new closure each time.

@Jasoco, if you're going to refer to object["player"], you might as well use object.player. As I have said before, it has its own short cut bytecode. And it's even a bit faster!
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Jasoco »

Sorting doesn't want to work for me. Any ideas? It refuses to reorder the table rows if I use unique names. Anyone have an example sort function that would work with this:

tableName.item1 = { x = ?, y = 45 }
tableName.item2 = { x = ?, y = 83 }
tableName.item3 = { x = ?, y = 99 }
tableName.item4 = { x = ?, y = 1 }
tableName.item5 = { x = ?, y = 55 }
tableName.item6 = { x = ?, y = 32 }

And would rearrange them so that they're ordered by Y? With the highest being last?
If done correctly, the above would end up in this order when iterated over in a for loop:

tableName.item4
tableName.item6
tableName.item1
tableName.item5
tableName.item2
tableName.item3

This is what I need. But I can't get it to work. Can it be done?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Robin »

Well, sorting obviously only works with numeric keys. If you don't want to use numeric keys, I'd suggest the following approach:

Code: Select all

sortedTable = {}
for key in pairs(tableName) do
    sortedTable[#sortedTable+1] = key
end

function sort_func(a, b)
    return tableName[a].y < tableName[b].y
end

table.sort(sortedTable, sort_func)
Then you use sortedTable for the draw order.

EDIT: you could probably also use values instead of keys (which makes the drawing code different as well, but you know that):

Code: Select all

sortedTable = {}
for _,value in pairs(tableName) do
    sortedTable[#sortedTable+1] = value
end

function sort_func(a, b)
    return a.y < b.y
end

table.sort(sortedTable, sort_func)
Help us help you: attach a .love.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Jasoco »

Is there really no way to do it without having to create a new table from all my "objects" every frame then sorting that? Because that's what I was trying to avoid. But if it's not possible, I guess I end up having to create a table of "Stuff that needs to be drawn" each time. It was really all in the interest of speed.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Jasoco »

I kind of have a prototype in place. Sorting works and all that fun, except that it now slowed my framerate by about 10-15 FPS. I'm hoping that's just an optimization thing but damn. Edit: Turns out my FPS is better than I thought and that it only dropped when I turned on the debug text. (Which runs through a lot of for loops to display text for debugging purposes.) So that's awesome!

Guess I have to play around.
Screen shot 2010-06-26 at 11.04.25 PM.jpg
Screen shot 2010-06-26 at 11.04.25 PM.jpg (63.73 KiB) Viewed 2919 times
As you can see in this horribly compressed prototype screenshot, the squares (Objects) are sorted by Y. Red is scenery, blue is people, green is enemy. If I dump everything into this table, then handle all the drawing depending on what the new object is supposed to be, I could have something really cool... If speed decides to work in my favor. I'm hoping if I remove all the old legacy drawing code it will speed up a bit because there's a lot of for pairs loops to go through right now.

Still sad I couldn't sort a key'd table by one of its other keys like above. Bah. TNTBasic at least had a "sprite" system where drawables were all objects with Z-indexes. That was probably the one thing that dead language had going for it. (The only thing mind you. I'm glad it's dead. Löve is so much faster.)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My Adventure Game Engine (NEW DEMO ON PAGE 20! 6/17/10)

Post by Robin »

Jasoco wrote:Is there really no way to do it without having to create a new table from all my "objects" every frame then sorting that? Because that's what I was trying to avoid. But if it's not possible, I guess I end up having to create a table of "Stuff that needs to be drawn" each time.
Not really. If you really prefer using string keys, you can have the "drawing table" being persistent, only adding and removing references when something like that changes, and sorting it every frame.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 79 guests