Generic OO Blitz Game Engine Core...

Miscellaneous Forums/General Discussion/Generic OO Blitz Game Engine Core...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ok... i just whipped up a small demo showing the concepts i just finished talking about immediately above...

a single .exe about 800k... get it here--> http://home.att.net/~mikey102/OOPBlitzDemo.zip

the code for the program is here...
Include "../samples/OBGameEngine.bb"
Include "../samples/ActorClass.bb"


Global myActor.tObject
Global AnotherActor.tObject
Global wait



Function TheGame(this.tObject)

  ;----------------------------------  initialization
  ;
  If theGame\status=0
   myActor.tObject=CreateObject("ACTOR","media/crewmen/crewman1.x")
   PositionObject(myActor,-120,2,120) 
   anotherActor.tObject=CreateObject("ACTOR","media/crewmen/crewman1.x")
   PositionObject(anotherActor,120,2,120)
   theGame\status=1
   myFont=LoadFont("Arial",21,True,True)
   SetFont myFont
  EndIf 
 
  ;---------------------------------------------------------------------------- always 
  ;  


  ;-------------------------------------------- user is awake start the clock, bump the status 
  ;  
  If KeyDown(200) Or KeyDown(208) Or KeyDown(203) Or KeyDown(205) 
     If wait=0 Then wait=MilliSecs()
     theGame\status=2
  EndIf

  ;-------------------------------------------- now its ok for user to set control object 
  ; 
  If theGame\status=2
    If KeyDown(25) 
      setControlObject(theGame\Player,myActor)
      adjustView(theGame\View,0,46,6)
    EndIf
  EndIf

  ;-------------------------------------------- set notices per condition detected 
  ; 
  If GetControlObject(theGame\Player)=Null 
   notice$="       The Player object currently has no Control Object associated with it, and uses its default move method"
   notice1$="                         Use The Arrow Keys To Move And Turn The Player Object Around Now"
   

  ;----------------------- wait a lil while for this one to pop up 
  ;
   If MilliSecs()>wait+1600 And wait>0
       notice2$="             This is the default behavior for the Player, as it is not yet associated with any other object"
       notice3$="   Since the View is Attached to the Player, it follows it around allowing a 'fly by' functionality by default"
       notice4$="    Press the P key now to set the Control Object for the Player to the Actor object standing on the left"
    EndIf
  Else
    notice$="               The Actor Object on the left is now set as the Control Object for the Player"  
   notice1$="              The W,A,S,D keys now control the movement of the player via SetControlObject() " 
   notice2$="       When the player now moves, he is using the Control Object's (Actor) walk method to move around"
   notice3$="         This allows the Player to control a multitude of object types, inheriting their methods"
   notice4$="          Right now the Actor subclass only moves, but walk animations and more can be added..."
  EndIf

  ;-------------------------------------------- the notices  
  ; 
  Text 20,40,notice$ 
  Text 20,80,notice1$ 
  Text 20,180,notice2$ 
  Text 20,220,notice3$ 
  Text 20,260,notice4$   


  ;-------------------------------------------- user is quitting app
  ; 
  If KeyDown(3) Then FreeFont myFont


End Function


the Actor 'subClass' code is here...
;------------------------------------------------------------------------------------------------------
;
;						Actor Class Globals Declarations 
;
;------------------------------------------------------------------------------------------------------

Global walkingSound,walkingSoundChannel


;------------------------------------------------------------------------------------------------------
;
;						Actor Class Implementation
;
;------------------------------------------------------------------------------------------------------


Function UpdateActors(this.tObject)

      ;----------------------------------- one time initialization
      ;
      If this\status=0
        ScaleMesh this\hEntity,20,20,20
		walkingSound=LoadSound("media/sounds/footstep.wav")
        this\status=1        
      EndIf

     ;------------------------------------------------------------------- always
     ;
   
     If GetControlObject(theGame\Player) = this

     ;---------------------------------------------  walking method
     ;
      If KeyDown(17) 
        MoveEntity this\hEntity,0,0,3
        If ChannelPlaying(walkingSoundChannel)=0 Then walkingSoundChannel=PlaySound(walkingSound)
		ChannelPitch(walkingSoundChannel,35000)
      End If
      If KeyDown(31) 
        MoveEntity this\hEntity,0,0,-3
       If ChannelPlaying(walkingSoundChannel)=0 Then WalkingSoundChannel=PlaySound(walkingSound)
	   ChannelPitch(walkingSoundChannel,35000)
      End If   
 
     ;---------------------------------------------  turning method
     ;
      If KeyDown(30) 
        TurnEntity this\hEntity,0,3,0
      End If   
      If KeyDown(32) 
        TurnEntity this\hEntity,0,-3,0
      End If  
     EndIf


End Function


i had to 'register' the Actor with the Engine by adding this
	Case "ACTOR"
	      UpdateActors(obj)
to the select clauses which allow the engine to process the different objects (this spot is clearly designated by a label in the ide lables list)...

... that's all there is to it.

this allows me to work in a modular, object oriented mindset, concetrating just on the functionality i need at the moment...

define an Actor in ActorClass.bb... add it to the game in MyGame.bb... then code the new object as i want it to behave in the game at the same spot...

if i want to have more Actors, i simply instantiate a new object of the same subclass... what could be simpler, more easy, and more organized...

--Mike