Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Jeff's Platform Game Engine v2
PowerPoint Import Xtra (FREE)
Drag and Switch
Generic behavior to emulate a Keystroke
Generic behavior to copy a file
cXtraEditBox
Library dmm_cdext - Audio CD Controller
Marks button, 4 picts with rollover, rolloff
simINET Xtra
Force Characters
 

 

 

Behavior Spaceship Move by keypress

Added on 7/24/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: KurtKoenig (website)

Move A sprite on KeyPressed

Download PC Source    Download Mac Source
--Move A sprite on KeyPressed
--by Kurt Koenig * Belgium          7/2000
--------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------

property ThisOne, Booster,Angle,TheLoch,TheLocv,pRight, pOrig,¬
        pBottom, Boostermember, ForwKey, RevKey, TurnLeft, Turnright


on getPropertyDescriptionlist
  desclist = [:]
  
  addprop desclist, #ForwKey, [#comment : "which key to move the ship forwards" ,¬
#format : #string , default : ""]
  addprop desclist, #RevKey, [#comment : "which key to move the ship backwards" ,¬
#format : #string , default : ""]
  addprop desclist, #TurnRight, [#comment : "which key to turn to the rightside" ,¬
#format : #string , default : ""]
  addprop desclist, #TurnLeft, [#comment : "which key to turn to the leftside" , ¬
#format : #string , default : ""]
  addprop desclist, #Boostermember, [#comment : "Enter a member for accelerating ship", ¬
#format : #member, #default : ""]
  
  return desclist
  
end

on getbehaviordescription
  return ¬
"You can use this behavior on a sprite (for  example:"&RETURN&"¬
spaceship,Car,Airplane,and assign four keys to "&RETURN&"¬
steer it.(backwards,forwards, turnleft,turnright)"
  
end getbehaviordescription


on getbehaviortooltip
  return¬
"Use this behavior on a sprite, which one then"&RETURN&"¬
will be moveable with the keys you define"
  
end getbehaviortooltip

on beginsprite me
  pOrig = the member of sprite the currentspritenum
  pStage = the rect of the stage
  pRight = pStage[3] - pStage[1]
  pBottom = pStage[4] - pStage [2]
  ThisOne = me . spriteNum
  Booster = float(0)
  TheLoch = sprite(ThisOne).loch
  TheLocv = sprite(ThisOne).locv
  Angle = 0
  
end

on MyPos me
  myqd = sprite(ThisOne).quad
  myLeft = min(myqd[1][1],myqd[2][1],myqd[3][1],myqd[4][1])
  myRight = max(myqd[1][1],myqd[2][1],myqd[3][1],myqd[4][1])
  myTop = min(myqd[1][2],myqd[2][2],myqd[3][2],myqd[4][2])
  myBtm = max(myqd[1][2],myqd[2][2],myqd[3][2],myqd[4][2])
  case 1 of
    (myRight < 0) : TheLoch = pRight
    (myLeft > pRight) : TheLoch = 0
    (myBtm < 0) : sprite(ThisOne).TheLocv = pBottom
    (myTop > pBottom) : TheLocv = 0
  end case
  
end


on exitFrame me
  (sprite ThisOne). member = porig
  if keypressed(RevKey) then
    if Booster > -3 then
      Booster = Booster - 0.3
    end if
  end if
  if keypressed(ForwKey) then
    sprite (ThisOne) . member =  member Boostermember
    if Booster < 3 then
      Booster = Booster + 1
    end if
  end if
  Booster = Booster * 0.9
  if keypressed (TurnLeft) then
    Angle = Angle -3
  end if
  if keypressed (TurnRight) then
    Angle = Angle + 3
  end if
  pAngle = Angle * pi()/180
  TheLoch = TheLoch +(cos(pAngle)*Booster)
  TheLocv = TheLocv +(sin(pAngle)*Booster)
  Mypos me
  sprite(ThisOne).loch = TheLoch
  sprite(ThisOne).locv = TheLocv
  sprite(ThisOne).rotation = Angle  
end

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail