Page 2 of 3

Re: crowd sourced game - organizing files and objects

Posted: Wed Mar 14, 2012 3:14 pm
by tsturzl
kikito wrote:
tsturzl wrote:It really seems like what he's doing is actually easier, IMO. Really the concept isn't that hard to grasp...
I was under the impression that he was not yet *doing* anything, but thinking about ways of doing things, and asking questions.
He just posted, right before you what he was currently doing. I'm assuming he's started at least making some prototyping code
Stateful provides a couple tools to deal with this complexity: first, states are stackable (so megaman can be "jumping" and "wood-powered" at the same time), but the code has no "ifs": instead, methods are overriden in certain order.

Second, one state can "inherit" from another, so if two states are "mostly the same except from one bit" the code isn't duplicated; when you change the parent, you don't have to remember changing the child.

Finally, there are callbacks that are automatically called every time a state is entered/exited (or pushed/popped from the state stack). If you need some initialization code to be called every time that megaman changes from one other power to "IcePower", Stateful makes sure that that method is called; you don't have to remember it.

I'm not saying it is the ideal solution, but I'm certain it's worth considering.
Ok, I see where stateful is handy. I just don't think this is the scenario. I'm not sure, but what he seems to want to do is swap parts of different characters. Possibly gradually transforming between the 2. I'm not quite certain. I don't know if stateful is meant for this.

I also think its a good learning experience to do it manually, because then he'll have an understanding of how stateful works, thus being able to use it better.
tsturzl wrote:Using stateful.lua just seems like another library to learn.
I don't know what to make of that phrase. You seem to be implying that using libraries, or learning to use them, is a bad thing.
Not at all. I'm just saying, if its simple to implement why use a library? I suppose if you're building the entire game with stateful it would be useful, but I don't think that'd be a good idea. I think doing things manually is a good way to learn, and will also better suite his needs.

Re: crowd sourced game - organizing files and objects

Posted: Wed Mar 14, 2012 3:16 pm
by tsturzl
teh8bits wrote:I know I'm new here and to Lua in general, but wouldn't it just be easiest to have a few booleans and avoid nested ifs? I know from Java experience it wouldn't be hard to make some cut off boolean so if he gets hit the next tick he would stop firing and start getting hurt.
Better yet just have in the firing animation method if ~= hurting
I was just providing some examples. That would be a good way to do it yes. You can also standardize variables, which is less costly than having a function.

Re: crowd sourced game - organizing files and objects

Posted: Wed Mar 14, 2012 4:53 pm
by teh8bits
What do you mean by standardizing? Like just having all entities that need a variable depicting if they're on the ground have a variable named onGround? (same names throughout?)

Re: crowd sourced game - organizing files and objects

Posted: Wed Mar 14, 2012 10:07 pm
by tsturzl
teh8bits wrote:What do you mean by standardizing? Like just having all entities that need a variable depicting if they're on the ground have a variable named onGround? (same names throughout?)
Basically. Just name the variables the same. This way even objects that aren't related can be referenced as if they were. It helps stream line development later on when you tie it all together.

Re: crowd sourced game - organizing files and objects

Posted: Wed Mar 14, 2012 10:08 pm
by teh8bits
Alright makes sense

Re: crowd sourced game - organizing files and objects

Posted: Fri Mar 16, 2012 4:26 am
by sanjiv
Thanks guys, for all your help

Given the tactic of interchanging tables, will I be able to use sprite-sheets to store images? I know how to draw from them, but I can't seem to figure out a way to store those images as variables. I guess I'd have to simply store their quads in tables? It seems like I'd be clogging up my memory doing this.

@ stateful: I have absolutely no interest in building my own class/object orientation system, but I confess I haven't learned how to use other people's libraries yet. Doing things the simple stupid way for now gives me smaller victories more often, and I think is an important learning process for a beginner like me.

But yeah, things have already gotten hairy.

@ booleans: Are you talking about setting up

Code: Select all

jumping = false
shooting=false

if jumping and shooting then
     jumpAndShoot()
end

Re: crowd sourced game - organizing files and objects

Posted: Fri Mar 16, 2012 8:21 pm
by tsturzl
sanjiv wrote:Thanks guys, for all your help

Given the tactic of interchanging tables, will I be able to use sprite-sheets to store images? I know how to draw from them, but I can't seem to figure out a way to store those images as variables. I guess I'd have to simply store their quads in tables? It seems like I'd be clogging up my memory doing this.

@ stateful: I have absolutely no interest in building my own class/object orientation system, but I confess I haven't learned how to use other people's libraries yet. Doing things the simple stupid way for now gives me smaller victories more often, and I think is an important learning process for a beginner like me.

But yeah, things have already gotten hairy.

@ booleans: Are you talking about setting up

Code: Select all

jumping = false
shooting=false

if jumping and shooting then
     jumpAndShoot()
end
Jumping would be a good one, not sure about shooting. I guess it depends on how you want your gun/blast to be. You might not need a shooting animation. I'd use a jumping boolean to tell weather or not I can jump again, and to stop applying downward acceleration on the player so they don't fall through the ground. Jumping=false when player collides with ground, apply upward acceleration on jumping key press then set jumping=true. Shooting you can just check in the update call for the shooting keypress, or you can set a boolean in the keypressed and keyreleased callback.

Sprite Sheets are stored as quads, I don't believe there is any way to efficiently separate them into different variables/objects. I see what you want to do, and I don't mean to be rude, but that's not the way to go about doing animations. You're on the right track using Quads, however you use a single quad for each animation.

You really want to keep your character objects clean, and not have a bunch of animation code scattered about your character object. There are a few choices:

1. Make an animation object that stores the quad itself, then iterates through bases on the width and height of each frame on the spritesheet. Then give that animation object update and draw functions. This is pretty agonizing...

2. Use the AnAL library found on the wiki, its pretty simple to use.

3. Use kikito's "anim8" library found here: viewtopic.php?f=5&t=8281
Its a lot like AnAL but is more flexible, you can define your own grids for this. Lets say the last 2 frames on your sheet are blank because the animation isn't that long, in AnAL your animation would go invisible at the end and flicker, with anim8 you can define the grid to stop/loop before the last 2 frames. You can also use anim8 to render several animations from the same sheet.

I'd say if you're looking for simplicity and your sprite sheets don't have blank space, go with AnAL. Otherwise anim8. If you really want to get your hands dirty make your own animation object. It isn't that hard but its still a bit of work, not to mention you'll probably get more functionality out of one of the libraries I mentioned.

Re: crowd sourced game - organizing files and objects

Posted: Sat Mar 17, 2012 3:18 am
by sanjiv
so with something like this
Image
where the different sprites may be of different sizes, is anim8 my best choice out of the ones you listed?

On the wiki entry for new quad (https://love2d.org/wiki/love.graphics.newQuad), it suggests that create a specific resource once and store it somewhere it can be reused. How would one do that? I didn't easily come across an answer to this, but it seems like it would be standard knowledge.

Re: crowd sourced game - organizing files and objects

Posted: Sun Mar 18, 2012 3:43 am
by tsturzl
sanjiv wrote:so with something like this
Image
where the different sprites may be of different sizes, is anim8 my best choice out of the ones you listed?

On the wiki entry for new quad (https://love2d.org/wiki/love.graphics.newQuad), it suggests that create a specific resource once and store it somewhere it can be reused. How would one do that? I didn't easily come across an answer to this, but it seems like it would be standard knowledge.
A library such as anim8 or AnAL will do this for you. Otherwise what its saying is don't recall love.graphics.newQuad every update, as it will be super slow. Just call it and save it, probably in your object. However if you are using anim8 or AnAL, you don't need to create a quad, because the library will do that.

anim8 isn't for sprites that are different sizes, its for if you have several animations on one sheet or if you have a couple blank spaces on your sprite sheet at the end.

Have a look here, https://love2d.org/wiki/AnAL

Re: crowd sourced game - organizing files and objects

Posted: Sun Aug 19, 2012 5:12 am
by sanjiv
(New Question: switching between sets of functions, not just sets of variables)
tsturzl wrote:
I agree somewhat with this. However I think its better to just do it objectively with tables, this way you could make an array full on different characters that you could swap between in real time, not to mention its good practice. This way you can keep your players health, x/y coords, image object, and other relative variables inside your player object.
I understand how to store sets of variables in tables, and then switch which variable-sets. But tables can also store functions. How can I switch between function sets?

For example, below I have two 'forms' the player can take. One form lets the player move horizontally, and the other vertically. How can I create a player.move() function that will change depending on which form (A or B) is active?

Code: Select all

player={}
player.x=10 --x
player.y=10 --y
player.s=10 --speed
player.form='A' -- can switch between 'A' and 'B'


formA={}
function formA.move(dt)
     player.x=player.x+player.s*dt
end

formB={}
function formB.move(dt)
     player.y=player.y+player.s*dt
end