Jump to content
IGNORED

Jumping and Changing Playfields


Itchy_Nipples

Recommended Posts

Hi guys, I just started programming today with Visual bB and I'm getting the hang of it pretty well. (I've programmed before, just nothing like this) and I'm in the middle of making a game, one that I've made before in other IDEs and other platforms, and I'm having some trouble trying to figure out how to make my sprite jump, and how to change playfields.

 

First of all, my game: The idea of the game is that you're controlling a player sprite (a simple square) and you must jump platform to platform in the playfield to get to the goal token (a circle) and once you do, you get a point, and the playfield changes to the next level.

 

The challenge is to not fall, so I would have to implement some sort of action that the sprite is constantly falling and detects collision with the platforms (right?) but how would I have the sprite jump when the fire button is pressed on the joystick? I think I can get the idea down but I can't get it into Visual bB. I also have no idea how I can make the playfield change upon collecting the token (or changing the playfield at all for that matter).

 

Any help given at all would be highly appreciated!

 

I can provide my .bin or .bas if needed but there's no much there besides the basic sprite and having it move back and forth on the screen at the moment.

Link to comment
Share on other sites

I've searched for the topic of Finite States and I couldn't find anything concrete on how to implement one, I did find a page that explained on how I could set one up but I have seemingly lost it... :? :? :? Would you have any examples of how I could use one? It doesn't have to be exactly what I'm looking for, I've just never heard of these and implementing would be even harder if I don't know the syntax of one.

Link to comment
Share on other sites

I think ZackAttack makes it sound simpler than it's likely

to look if you're jumping in to the subject cold (ie with no

knowledge at all of state machines).


For one thing, state will necessarily include stuff like what platform

you're on and whether you've fallen off screen.


But to interpret ZackAttack (and risk trying to put words in his mouth)


You'd have a state variable who's value reflects the current state

and you'll choose which piece of code to run depending on the state variable

(maybe) using on-gosub.



You don't really need to deal with Y movement at all if you are on platform

and you might want to deal with moving up (jumping) and moving down (falling) differently


So if you're in the on platform state you don't worry about what happens

when you're falling or jumping at all.

You will look for stuff that changes state.

if fire is pressed change to jump state.

if X movement moves you off platform change to falling state

(and there will be concomittent stuff that goes with that like Y velocity)



(personally I think falling and jumping are likely to be so similar that

I'd just have it be moving in the Y direction or not but that would depend

on what you want your code to do and how you prefer to deal with it)
Link to comment
Share on other sites

Would there be a more simple way of implementing jumping and falling off of a platform? Something like having the player sprite constantly falling and having collision detection with the playfield? When it collides with the playfield, have it stop falling. The only problem would be getting the jumping working with that way.

 

Are here examples on the forum that show how to create a FSM? I have the logistics down I'd just need to move it from pseudo-code to Visual bB. Is there an example .bas or some other source code that has one so I can see what it looks like and I can get an idea of what I'd need to do?

Edited by Itchy_Nipples
Link to comment
Share on other sites

Don't forget that using collision detection is going to have some issues to work out. Like jumping under a platform and hitting your head on it. You don't want the player getting their head stuck to platforms.

 

Post you bas file and I'll see if I can help you out later.

 

Btw, there's a sub-forum dedicated to batari basic. You'll get more/better responses if you post basic questions there.

Link to comment
Share on other sites


for one thing the sprite has to overlap the platform in order for there to be a collision

for another you don't need to fall at all if you're on the platform so there'd be no point

in falling (and presumably then undoing it if you don't want to fall)


assuming the platform is a simple horizontal surface, you could test the limits

when you move in the x direction something like



if !joyright then left
x = x + 1
if x = right_limit then fall
goto after_x_move

left
if !joyleft then after_x_move
x = x - 1
if x = left_limit then fall

after_x_move
Link to comment
Share on other sites

Don't forget that using collision detection is going to have some issues to work out. Like jumping under a platform and hitting your head on it. You don't want the player getting their head stuck to platforms.

 

Post you bas file and I'll see if I can help you out later.

 

Btw, there's a sub-forum dedicated to batari basic. You'll get more/better responses if you post basic questions there.

 

I've attached my most recent .bas file

default.bas

Edited by Itchy_Nipples
Link to comment
Share on other sites

Here's an easy way...

 

rem Generated 6/12/2015 11:34:52 PM by Visual bB Version 1.0.0.548
rem **********************************
rem *<filename> *
rem *<description> *
rem *<author> *
rem *<contact info> *
rem *<license> *
rem **********************************

set tv ntsc

title

player0x=50 : player0y=50

goto main2

main2

player0y=player0y+1

if collision(player0,playfield) then player0y=player0y-1 : b=0

COLUP0=28
COLUBK=02

playfield:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
................................
................................
................................
...........................XXXXX
......................XXXXXX....
................XXXXXX..........
.........XXXXXXX................
XXXXXXXXX.......................
................................
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

player0:
%00000000
%00000000
%00000000
%00011000
%00011000
%00000000
%00000000
%00000000
end

drawscreen

if joy0right then player0x=player0x+1
if joy0left then player0x=player0x-1
if joy0fire then a=a+1 : b=b+1
if b>12 then a=0
if b>48 then b=0
if a>=1 then player0y=player0y-2
if !joy0fire then a=0

goto main2

 

 

 

Gravity included!!

Link to comment
Share on other sites

For the jumping stuff, this might be helpful:

 

atariage.com/forums/topic/179473-fake-gravity-platformer-test/

 

I need to go back and clean up the code one of these days.

 

youtube.com/watch?v=Hy5_K2oUprY

https://www.youtube.com/watch?v=Hy5_K2oUprY

 

 

You might also want to post batari Basic questions in the batari Basic forum from now on:

 

atariage.com/forums/forum/65-batari-basic/

Link to comment
Share on other sites

Here's the solution that I came up with. It uses collision detection with PF too, which as I already mentioned introduces some issues. Papa's solution would probably run a little faster because it doesn't use any gosubs. The downside to his solution is that it's harder to read and maintain, and it doesn't properly handle when you jump off a ledge and continue to hold the fire button. A nice enhancement to either solution would be to add a lookup table so the player slows at the peak of the jump and then gains speed again as he starts falling.

 rem Generated 6/12/2015 11:34:52 PM by Visual bB Version 1.0.0.548
 rem **********************************
 rem *<filename>                                   *
 rem *<description>                              *
 rem *<author>                                    *
 rem *<contact info>                          *
 rem *<license>                                *
 rem **********************************
 
 ;alias variables a so it's easier to read the code
 ;It's best to alias them all in one place so you can keep track of which variable have been used already
 dim jumpState = a
 dim jumpHeightRemaining = b

 ;define constants for each state, again this will help readability
 const jumping = 0
 const falling = 1
 const standing = 2

 ;How many pixels to jump vertically before you start falling
 const JumpHeight = 20
 const JumpVelocity = 1
 const FallVelocity = 1

 ;initialize state machine to standing.
 jumpState = standing


 player0x = 50
 player0y = 28

main2

 COLUP0=28
 COLUBK=02

 playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 ................................
 ................................
 ................................
 ...........................XXXXX
 ......................XXXXXX....
 ................XXXXXX..........
 .........XXXXXXX................
 XXXXXXXXX.......................
 ................................
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end

 player0:
 %00011000
 %00011000
end

 drawscreen

 ;TODO use var0-var43 to determine if player0 is adjacent to the playfield horizontally
 if joy0right then player0x = player0x + 1
 if joy0left then player0x = player0x - 1
 
 on jumpState gosub OnJump OnFall OnStand

 goto main2

OnJump
 ;Output condition logic
 player0y = player0y - JumpVelocity 
 jumpHeightRemaining = jumpHeightRemaining - JumpVelocity 
 ;Next state conditioning logic
 if !joy0fire || jumpHeightRemaining{7} then jumpState = falling
 return

OnFall
 ;Next state conditioning logic
 ;TODO use var0-var43 to determine if player0 is adjacent to the playfield vertically
 if collision(player0,playfield) then jumpState = standing : return
 ;Output condition logic
 player0y = player0y + FallVelocity
 return

OnStand
 ;Output condition logic
 
 ;Next state conditioning logic
 if joy0fire then gosub StartJump
 if !collision(player0,playfield) then jumpState = falling
 return

StartJump
 jumpHeightRemaining = JumpHeight
 jumpState = jumping
 return
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...