Jump to content
IGNORED

Platforming Code Examples


KevKelley

Recommended Posts

I have been experimenting with different ways to do platforming for fun.  I had tried to make a relatively simple code that allowed for the player sprite to move smoothly, quickly, jump and drop, stop when jumping into a platform, and if approaching steps moves up or down with ease. I also tried to make it generous with clipping edges of a platform so that you don't immediately get stopped in your tracks if you jump and hit the playfield.

 

I came up with one for SuperChip and one for DPC+ that seem to satisfy my goals that would require minimal tweaking for the desired game.

 

Here is the snippet of SuperChip code:

 if joy0down then goto SKIP_LR_CHECK
 if joy0right && player0x<140 then p0x=p0x+0.5 :o{1}=0:k=k+1
 if joy0left && player0x>15 then p0x=p0x-0.5:o{1}=1:k=k+1
 
SKIP_LR_CHECK 
 if !collision(player0,playfield) then goto SKIP_COLLISION_CHECK
 if  e{0} then f=28
 ;if joy0fire && f>0 then p0y=p0y:goto SKIP_COLLISION_CHECK ; allows for jumping through floor 

   p0y=p0y-0.50 
 if  f<19 && f>0 then p0y=p0y+0.50:f=20
SKIP_COLLISION_CHECK 

  if joy0fire  && !e{0} && e{1} && f<1 then  e{0}=1:f=1:k=41
SKIP_UP
  if !joy0fire && f=0  then  e{0}=0
SKIP_UP2

 if f<>0  then f=f+1
 
 if f>0 && f<19 then p0y=p0y-1.0:AUDV0=3:AUDC0=6:AUDF0=player0y:gosub JUMP
 if f>25 && f<30 then p0y=p0y+1.0:AUDV0=3:AUDC0=6:AUDF0=player0y:gosub JUMP 
 if f>=30 then f=0:AUDV0=0:k=0:gosub RUN1
 
 if !e{0} && !e{1} && f=0 then p0y=p0y+1.25:AUDV0=0

 temp1 = (player0x-14)/4: temp2 = ((player0y)/4) 
 
 if pfread(temp1,temp2) then e{1}=1:AUDV0=0 :goto NO_FALL
 e{1}=0
 e{0}=0
 
NO_FALL
 if player0y<1 then e{1}=1:e{0}=0:f=19:AUDV0=0 
 if player0y>80 then player0y=80

 

and here is the DPC+ code:

   temp1 = (player0x-13)/4
   temp2 = (player0y+player0height)/2 ; FLOOR CHECK 
   temp3 = (player0y+1)/2 ; CEILING CHECK 
   temp4 = (player0y+player0height-2)/2

 if joy0left then p0x=p0x-1.06 :k=k+1:REFP0=8; LEFT
 if joy0right then p0x=p0x+1.06 :k=k+1; right

 if joy0fire  && !e{0} && j<1 then  e{0}=1:j=1 :e{2}=1; JUMP 
SKIP_UP
 if !joy0fire && j=0 && var1=0  then  e{0}=0
SKIP_UP2
 if j=0 then goto FALL
 if j<>0  then j=j+1:var1=var1+1
 if j>0 && j<10 then p0y=p0y-3.5:AUDV0=3:AUDC0=6:AUDF0=var1:e{1}=1:goto SKIP_FALL ; UP
 if j>25 && j<45 then p0y=p0y+2.0:AUDV0=3:AUDC0=6:AUDF0=var1:e{1}=0:goto SKIP_FALL ; DOWN
 if j>=47 then j=0:AUDV0=0
   
FALL
 
 if var1>15 then AUDV0=0
 if !pfread(temp1,temp2) then p0y=p0y+2.0:var1=var1+1:j=0:AUDV0=3:AUDC0=12:AUDF0=var1:goto AFTER_BUMP; FALL
 if pfread(temp1,temp2) then AUDV0=0:var1=0:e{2}=0
 if  !e{2} && pfread(temp1,temp4) then p0y=p0y-2.0 ; steps
 goto AFTER_BUMP

SKIP_FALL

 if collision(player0,playfield) then AUDC0=15:AUDF0=22:AUDV0=10
  if e{1} && pfread(temp1,temp3) then j=43; bump head 

AFTER_BUMP

 

I figure I will include the .bas files if anyone wants a look or to use/modify for their own projects. 

 

I would like to add additional examples, like a standard kernel or multisprite version just for fun. These were a nice project to play around with and learn

PLATFORM_2023_11_25_23_SC.bas SS2_2023_12_21.bas

  • Like 3
Link to comment
Share on other sites

2 hours ago, Random Terrain said:

Have you tried any of these?

 

 

Yes! Thank you.  I started looking at how that platforming code worked but I was trying to get something a little different. That one works very well and is very smooth. I was attempting to use less variables (I haven’t compared them) and have more compact code so I can just plug it into any new project I start. 
 

Sometimes with other example programs I tend to get lost so this was an experiment to see if I can get something playable and new. 

  • Like 1
Link to comment
Share on other sites

3 hours ago, Random Terrain said:

Speaking of code, that's old code from something like 12 years ago, so I should probably look at it and see if I can use fewer variables and improve it in other ways. Then put the fixed versions on the bB page.

I find your example programs very clean and organized and easy to understand.

 

When I first tried making a platformer I kind of cheated and just made the sprites move on certain planes. I was playing around with some other code either relying more on collision statements or on pfread statements. I thought these two versions worked nicely. 
 

I did have a hard time trying to get multi sprite platformer working. I thought that would be a nice challenge. I wanted to have a variety of options in the future. 
 

 

  • Like 1
Link to comment
Share on other sites

I’ll have to add the code later (I forgot my tablet at home) but I modified the DPC+ code a little further to allow for platforming to exist on the top and then have an area on the bottom where you can walk around. I have a game idea I was exploring and thought having a combination of gameplay elements might be desired. 
 

This modification also goes to my goal of such a code. A simple platform code that can be altered relatively easily for any game idea. 

  • Like 1
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...