still having OO knightmares

BlitzMax Forums/BlitzMax Beginners Area/still having OO knightmares

Pete Carter(Posted 2009) [#1]
I have a type i call "soldier" and i have 20 or so instances of that type on screen. my game requires the player to be able to click the mouse on a soldier and then be able to control that one soldier, then be able to click on another to deselect the first.

hope thats clear.

What the best way of doing this?

thanks Pete


EOF(Posted 2009) [#2]
I would do it like this:
Type Soldier
  Field x,y,blah ..
End Type

Global ucSoldier:Soldier    '   current "user-controlled" Soldier

...

' update all soldiers
For s:Soldier=Eachin SoliderList
    If UserClickedSolder(s) Then ucSoldier=s
    ' Update soldiers
    If s<>ucSoldier
        CPU_ControlsThisSoldier
    Else
        USER_ControlsThisSoldier
    EndIf
Next

Essentially, a pointer which indicates which soldier the player is currently controlling


InvisibleKid(Posted 2009) [#3]
Jim posted when i was coding but its done and figured i'd post anyway.

very crude and basic example but i hope it helps




Pete Carter(Posted 2009) [#4]
Thankyou both. Your detailed posts are very helpful.

very crude and basic example

but it answers my question very well


InvisibleKid(Posted 2009) [#5]
your welcome

a side note:
after rereading my posted code

Method CheckMouseCollision(id)

should be
Method CheckMouseCollision()


and

If MouseDown(1) Then s.CheckMouseCollision(s.id)

should be
If MouseDown(1) Then s.CheckMouseCollision()


i was gonna do more with it, but at the last second i decided not to over complicate what should just be a basic example and forgot to change the method/method call (fixed now). all though as is it doesn't affect anything, but its just not needed.

anyway glad it helped 8-)


Pete Carter(Posted 2009) [#6]
Thanks again