Sign in to follow this  
Wellimp

[Question] Movement and Scrolling Map Algorithm/Code

Recommended Posts

Hello Everyone, This is My First Post. Im Learning BlitzBasic And C++/SDL. But im trying to Find Out a tutorial About it. Im trying to make a 2D Platform game "Mario-Like". I Could Make a mario sprite Moving Forward, and Backward but i can make a Good Jump Neither a Map Scrolling (No AutoScrolling). and second things is how to make when "mario" Jump to a [?] Box and that box move a bit to up. My Code Example Moving Forward, BackWard Mario_front = "MarioFront.png" Mario_Flipped = Mario_Front Fliped to Left if BackArrow is Pressed using Mario_Flipped Mario_PositionX = Mario_PositionX - 2 end if if UpArrow is pressed Using Mario_Front Mario_PositionX = Mario_PositionX + 2 end if But i really don't know how make a good Jump. Thanks ^____^

Share this post


Link to post
Share on other sites
The easiest way to implement a jump is to create an array with how many pixels your character moves per frame and increase that as he gets higher and remove as he gets lower

e.g.



jumpArray = { -1, -2, -3, 0, 3, 2, 1 }

mainloop
{
if isJumping
{
++curJumpFrame
player.y += jumpArray[curJumpFrame]
}


Of course, you'll need to cater for if the player has landed on a platform or finished his jump and stop it when necessary

Share this post


Link to post
Share on other sites
That's good way, But Im trying and it's better know but i got some problem.. Mario Is Diggin Instead Jumping. what is wrong. Look Im doing da but in blitz
Dim Jump(7) ; (-2,-4,-8,0,8,4,2)

If Player_Jumping = True Then ; if i press Jump Button

If Jump_pos = 7 Then Jump_pos = 1

Jump_pos = Jump_pos+1

Player_POSY = Player_POSY + Jump(Jump_pos)

DrawImage player_jump, Player_POSX, Player_POSY, player_jump_frame

End If

Thanks

Share this post


Link to post
Share on other sites
i think you have to move up and then down (jump).

so probably your problem lies in the jump array.
just try switching the sign and it might work correct.

Dim Jump(7) ; (2,4,8,0,-8,-4,-2)

Share this post


Link to post
Share on other sites
I Understand what you are saying guys, the problem is when i try to put into a Blitz Basic Code... Im Doing Something Wrong.

Im gonna put a sample of what im trying.



Const SCR_W = 640
Const SCR_H = 480

;AutoMidHandle True

Graphics SCR_W,SCR_H,16,2

SetBuffer BackBuffer()
Global Player,Player2,Player_Millisecs, player_frame, Player_POSX#=10, Player_POSY# = SCR_H-131, Player_Moving, Player_Jumping, Jump_pos = 0
Global Escape_Key = 1
Global LEFT_KEY = 203, RIGHT_KEY = 205, UP_KEY = 200, JUMP_KEY = 57, HIGH_JUMP = 200
Dim Jump(7)

Player = LoadAnimImage("Mario_Jump2.png",18,28,0,2)

MaskImage Player,0,0,0

ScaleImage Player, 2.5,2.5

Jump(0) = -4
Jump(1) = -8
Jump(2) = -16
Jump(3) = 0
Jump(4) = 16
Jump(5) = 8
Jump(6) = 4


While Not KeyHit(Escape_Key)

Cls
Player_Moving = False

If KeyDown (RIGHT_KEY) = True Then

Player_POSX = Player_POSX + 2
Player_Moving = True
End If

If KeyDown (LEFT_KEY) = True Then

Player_POSX = Player_POSX - 2
Player_Moving = True
End If

If KeyDown(JUMP_KEY) = True Then
If Jump_pos = 6 Then Jump_pos = 0
Jump_pos = Jump_pos + 1
Player_POSY = Player_POSY + Jump(Jump_pos)
Player_Jumping = True
End If

DrawImage Player, Player_POSX, Player_POSY, player_frame

If Player_Moving = True Then

Player_Animation()

End If

Flip

Wend

End

Function Player_Animation()
If MilliSecs() > player_MilliSecs + 100 Then
player_millisecs = MilliSecs() ;reset player_millisecs
player_frame = (player_frame +1) Mod 2
End If
End Function



Share this post


Link to post
Share on other sites
Hi Wellimp,
First, welcome to the site :-)

Perhaps this site can help you - it deals with tile based games, and things like jumping.

Tile Based Games

It is written using Flash, but it should still help - it enabled me to start writting a 2d platform game using Delphi/Pascal :-)

cheers,
Paul


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this