Author Topic: question about map editor  (Read 8801 times)

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re-creating physics
« Reply #15 on: 2005-09-27, 05:34:23 AM »
If you want to re-create the physics of GameDev sprites in C++ code, rather than re-using GameDev at runtime, you could look at Sprite.cls.  The main function that handles sprite movement is called Sub Advance().  Inside there, you will see that one of the first things it does is:
DY = DY + CSng(.Template.GravPow - 10) / 10

That increases the Y velocity of the sprite (DY) based on the gravity on the sprite's template.  The gravity is a number between 0 and 20, so after subtracting 10, then it is a number between -10 and +10.  This function does a lot of tests and calculations.  It's too many to describe here, but almost everything that a sprite does starts here.  One of the main functions that this function depends on is ReactToSolid.  You will see that function in the same file.  It controls how a sprite reacts to solid areas of the map.

Even though there is a lot of code, you may be interested only in a very small part of it.  For example, if you only want to handle 8-state sprites controlled by the player, without supporting platforms, you would only need to be concerned with these lines from Sub Advance:
Code: [Select]
  With rDef
      DY = DY + CSng(.Template.GravPow - 10) / 10
   
      If .Template.StateType = CONTROL_INPUT Then
          bAccel = ProcessAction(Prj.GamePlayer.CtlActions)
          ReactToSolid
      End If
      Dis = X
      CurVel = Y
      X = X + DX
      Y = Y + DY
   
      CurState = CurState Mod 8
      If Abs(DX) < Abs(DY / 2) Then ' Vertical movement only
          If DY < 0 Then
              CurState = 0 ' Up
          ElseIf DY > 0 Then
              CurState = 4 ' Down
          End If
      ElseIf Abs(DY) < Abs(DX / 2) Then ' Horizontal movement only
          If DX < 0 Then
              CurState = 6 ' Left
          ElseIf DX > 0 Then
              CurState = 2 ' Right
          End If
      Else ' Horizontal and vertical movement
          If DX < 0 Then
              If DY < 0 Then
                  CurState = 7 ' Up left
              ElseIf DY > 0 Then
                  CurState = 5 ' Down left
              End If
          ElseIf DX > 0 Then
              If DY < 0 Then
                  CurState = 1 ' Up right
              ElseIf DY > 0 Then
                  CurState = 3 ' Down right
              End If
          End If
      End If
      If bAccel And .Template.Flags And FLAG_ACCELSTATES Then CurState = CurState + 8
   
      If Abs(Int(X) - Int(Dis)) >= Abs(Int(Y) - Int(CurVel)) Then
          Dis = Abs(Int(X) - Int(Dis))
      Else
          Dis = Abs(Int(Y) - Int(CurVel))
      End If
      AdvanceFrame Dis
   
      If (.Template.Inertia < 100) Then
          If (byAccelDir And 1) = 0 Then
              DX = DX * .Template.Inertia / 100
          End If
          If .Template.GravPow = 10 Then
              If (byAccelDir And 2) = 0 Then
                  DY = DY * .Template.Inertia / 100
              End If
              If Abs(DY) < 0.05 Then DY = 0
          End If
          If Abs(DX) < 0.05 Then DX = 0
      End If
   
   End With

arcus

  • Visitor
  • *
  • Posts: 8
    • View Profile
question about map editor
« Reply #16 on: 2005-09-28, 11:08:59 PM »
Thank you very much for your reply.
I have a question for SGDK. E.g., in the map there is a slope, and the sprite walk on the slope. How to adjust the pose and angle according to the slope not the plane. It is quite ugly that the sprite is always in same pose whenever on plane or slope. Is there any solution in SGDK to solve this problem?


Thanks a lot
Frank

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Diagonal states
« Reply #17 on: 2005-09-29, 05:31:34 AM »
SGDK provides 8-state sprites that can have different appearances for travelling in the 8 primary directions of a gamepad.  This should help solve the problem by providing unique states specifically for when the sprite is moving diagonally.