array of game elements

BlitzMax Forums/BlitzMax Programming/array of game elements

zambani(Posted 2008) [#1]
How do I put all of my game elemets of various types in an array or Tlist so I can loop through them and update them? It seems that Tlist only works with a single type.


tonyg(Posted 2008) [#2]
It seems that Tlist only works with a single type.


That's not true. You must be doing something wrong so post your code.


johnnyfreak(Posted 2008) [#3]
you can use subclasses.

make a superclass gameElements and extend from it the other types.
then fill the list with gameElements elements (with cast operator).


zambani(Posted 2008) [#4]
OK, this is what I'm trying to do. Hopefully you guys will understand

1) I have a type objImage which is there just render images
2) I then extend that type to objPhy. This new type is the basis of all object that I want to be affected by my simple physics/collision effects. Every time objPhy is created, it's added to a Tlist called phyList.
3)Finally I extend that type to the various game element types such as objStructure, objShip,objPod and so on.
4)Now what I do in my main loop is it iterate through physList and update the positions of all of the images based on my physics rules.

The problem is this. Since collisions are only detected in the physObj, I'm trying to pass that collision "event" back to the appropriate game element type that extended it and get access to all of its methods not just the ones common to objPhy type.
Hopfully you guys understand what I'm trying to do.


tonyg(Posted 2008) [#5]
Personally I would have objphy as a field of objimage with an objspec field which has a basespec extended into objship etc. I could then run the collisions against objimage in my renderlist and, if present, use the objphy field to run any physics.
<edit> actually, depending on how different they are I might simply extend for objship etc.


Paposo(Posted 2008) [#6]
Please, put your code or a resumed code