Organizing aliens in a shmup

BlitzMax Forums/BlitzMax Beginners Area/Organizing aliens in a shmup

NickFalk(Posted 2007) [#1]
My random dabblings in Max are slowly turning into an old fashioned space-shooter. The star field is up and running as is the player-sprite. I've put together a trial-shooting mechanism as well as a few trial-aliens. Everything works and I am quite comfortable that I'll be able to pull the functionality things off. I am however interested in any thoughts you may have about the organisation of aliens/levels etc.

At the moment I have a Talien type and plan to make several different aliens based on this type (different movement-patterns, graphics etc). My trial-alien is organised as an Array based on one such type. This does work OK, but makes a lot of the code hard to read - trialalien[counter].move is OK, but imagine what it looks like when checking for collisions.

I was therefore thinking that it might be a better idea to actually include the array-bit inside the original Talien-type. It will be a bit awkward I guess, but might make things easier for me further down the line.

I'm also thinking to make the "levels" simply by having a counter initiating certain alien-attacks at a given time.

In general I'm interested in how anyone else have implemented stuff like this...


MikeT(Posted 2007) [#2]
you could add the aliens to a list then loop through that


Who was John Galt?(Posted 2007) [#3]
For this type of stuff lists really are easier than arrays. You can have a list of aliens that is global within your type. Your alien creation and deletion functions then just add and remove aliens from this list.

I usually have an Update_All() function in each type that loops through the list and updates all my aliens. This keeps your program's main loop easier.

Try it. Believe me its simpler and cleaner than all this array stuff.


sswift(Posted 2007) [#4]
Type Alien

   Global List:TList = CreateList()
   
   Field _Link:TLink

   Function Create()
      Local A:Alien
      A = New Alien
      A._Link = List.AddLast(A)
   End Function

   Function UpdateAll()
      Local A:Alien

      For A = EachIn List
         A.Update()
      Next
   End Function

   Method Update()
   End Method
   
   Method Free()
      _Link.Remove()
      _Link = Null
   End Method

End Type


Just Alien.Create() to create an alien, call Alien.UpdateAll() in your main loop, and that will call the Update() function for each alien, inside which you can access the fields of the type. And when the alien is destroyed just call Free() or Self.Free() in its update function, or with the pointer to it if freeing it from somewhere else.


Who was John Galt?(Posted 2007) [#5]
I think you have a typo there, Swift. Where you have 'Alien' it should read 'AlienSpaceBeetle'.


sswift(Posted 2007) [#6]
:-)