Ok, in Blitz Basic, the language I have been using for awhile (I've now decided to move to more "real" programming) I used these neat things called types all the time. They were very handy for all manner of things, but especially dynamically spawned entities like bullets and such in a game.
Which, of course, would C++ asCode:Type monster Field x#,y# Field speed# Field facing# End Type
It seems obvious that types are structs, and they behave pretty much the same way. That's all good with me so far, but I do have a problem. In Blitz you could, for example, do this:Code:struct monster { int x; int y; int speed; int facing; };
which would throw another monster on the pile so to speak. It would have no discernable name, so you would simply use a loop, like this, to process the whole set:Code:Function create_monster(x,y,facing,speed) m.monster=New monster m\x=x m\y=y m\facing=facing m\speed=speed End Function
Now, before you correct me, I am well aware of the syntax differance in functions, as well as the . instead of the \ for values within structs, but I was keeping it in Blitz Basic code for consistancy. Now, is there a c++ equivalent to the generic creation, that is the m.monster = NEW monster and the Delete m.monster and the next looping that sorts through the whole stack of the suckers?Code:Function update_monsters() For m.monster= Each monster //some code in here would move each monster according //speed and facing and update their respective coords //as it cycled through each "monster" If collide(m\x,m\y) > 0 Then Delete m.monster //this would delete the current monster if the condition was met Endif Next End function
This was probably the coolest little trick in Blitz and it made all kinds of things that would have been horribly twisted very easy to code, by facilitating the dynamic creation and deletion of various entities as needed. Please tell me how I can do something similar in C++. I am using Bloodshed Dev if it matters.



LinkBack URL
About LinkBacks


