Help with coding approach

Hi, I’d like a little help arranging the logical layout of the code for a game.

The Concept:
Every time you click a button a plastic army man is spawned. You can spawn as many army men as you like. The user also has control over the intensity of a burning fire and can pick up spawned army men and drop them into the fire and they will eventually melt. The intensity of the fire is user controlled through a slider control. If the fire is “High” intensity then it takes 1 second for the army man to melt, if the fire is “Medium” intensity it takes 2 and if the fire is “low” then it takes 3 seconds. A melted army man becomes a blob of plastic which can be picked up and moved.

How would you keep track of it all?

I’m thinking the logical layout would be

  1. Create a table to track spawned army men and also give them a health value

Armyman[i].health = 3

  1. Once in the fire create some sort of loop that has a timer which subtracts one value from armyman[i].health until it reaches zero. Have the value of armyman[i].health return to 3 if it is removed from the fire before it reaches 0.

  2. If armyman.health = 0, then create a melted blob in its place and delete armyman[i]

Is this the best approach?
[import]uid: 78150 topic_id: 15511 reply_id: 315511[/import]

@ggortva,

  1. Have 4/5 images as you want to display the various stages of melting for the army men.
  2. have a state for each spawned armyMan (like you have with .health )
  3. Everytime you change the state, change the graphic (easy if you use sprites, you just need to change the frame number)
  4. Also have another variable .isInFire which will determine if the armyMan needs to melt or not
  5. and another called .fireIntensity
  6. Have a function onEnterFrame for each of the ArmyMan, if it isInFire then based on the fireIntensity, decrease the health and change the graphic.

Hope it is easy to understand.

If you were not working on this project, I would have loved to make a tutorial out of the concept you just asked for. It has TUTORIAL written all over it…

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15511 reply_id: 57332[/import]

JayantV, thanks for the reply. I used one of your tutorials on tables and it was really helpful. I have no objections to you making a tutorial out of this =)
Would one table be sufficient to track all of this?
[import]uid: 78150 topic_id: 15511 reply_id: 57622[/import]

Thanks for that, here’s a bit more on that with some more details on how you can approach it here

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15511 reply_id: 57625[/import]

That perfect thanks!

Say you wanted to change the physical properties of an object once it goes through the fire (i.e. make it lighter), could this be done without recreating the objects? [import]uid: 78150 topic_id: 15511 reply_id: 57637[/import]

@ggortva,
wait a second, hope you are not trying to change this into a physics object that will start to float… :wink:

Ok, how would that help? How does weight matter? Where are you going to use it? I mean let’s say it was the Tin Soldier and the Sugar Plum Fairy, the Tin soldier will not become lighter. So I am kind of confused.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15511 reply_id: 57692[/import]

My question isnt relevant to the above example (which I really hope you make a tutorial out of :wink: ) I was just thinking of other uses for the above approach, lets say a sponge that you dunk into a bucket of water. At first the dry sponge would be very light and a little bit bouncy. However once you dunked it into a bucket of water, it would heavy and would plop rather than bounce.

So I guess my question is, could you change the physics properies of an object on the fly? or would the object have to be recreated? [import]uid: 78150 topic_id: 15511 reply_id: 57765[/import]

Aaaah, see… if you had started a new thread, it would have made more sense.

NEways, you want to make a physics thingie out of it… :frowning:

I do not think you can change the physics property of an object on the fly. However there are different ways to manage what you want. Once you dunk the sponge into the bucket, you can create a new sponge with the new properties.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15511 reply_id: 57770[/import]

follow this link for the tutorial! http://howto.oz-apps.com/ [import]uid: 51459 topic_id: 15511 reply_id: 61455[/import]