Perhaps a basic tutorial on making a basic 2D side-scrolling platform game? Have been trying to work it out, but have not had much success.
Here's what I managed to do so far:
Rem * Title : Basic Platform Game
Rem * Author : Steve Paul Thomas
Rem * Date : November 2008
sync on
sync rate 30
rem Create an offscreen bitmap
create bitmap 1,640,480
set current bitmap 1
rem Fill it with near black
cls rgb(60,60,60)
rem Return drawing operations to the screen
set current bitmap 0
copy bitmap 1,0
sync
rem Temporary boxes to make it medialess
rem Player
ink rgb(255,255,255),0
box 0,0,32,32
get image 1,0,0,32,32
cls 0
rem Land
ink rgb(0,128,0),0
box 0,0,32,32
get image 2,0,0,32,32
cls 0
rem load image "man.bmp",1
rem load image "platform.bmp",2
rem load sound "bounce.wav",1
playerx = 96
playery = 416
rem The player sprite
player_spr = 301
rem Set our hero to be standing still
speed# = 0.0
rem Set vertical speed to zero
vspeed# = 0.0
rem Set the maximum distance he can move per cycle
maxspeed# = 5.0
rem Set the inital direction
direction$ = "left"
rem This will be used in the jumping to work out
rem how many pixels to subtract off of the players
rem current y
targety = 0
rem Set vertical direction
vdir$ = "down"
rem How high can he jump in pixels?
jumpheight = 64
rem Boolean Integer that says whether player is jumping is - true or false
rem where 0 is false and 1 is true
jumping = 0
rem Boolean Integer that says whether player is on the ground - true or false
onground = 1
rem )))))))))) I N I T I A L I S A T I O N ((((((((((((((((((((((((((
rem Set the program up !
gosub _setup_land
rem Initialise player sprite to prevent bob not found errors
sprite player_spr,playerx,playery,1
rem ))))))))) E N D O F I N I T I A L I S A T I O N (((((((((((((((
rem ))))))))))) M A I N P R O G R A M L O O P ((((((((((((((((((((((
do
cls 0
copy bitmap 1,0
rem Player pressed left key
if leftkey()=1 or joystick left()=1 then gosub _pressed_left
rem Player pressed right key
if rightkey()=1 or joystick right()=1 then gosub _pressed_right
if returnkey()=1 then playerx = 128 : playery = 448 : onground = 1 : jumping = 0
rem Player pressed the jump button
if spacekey()=1 or joystick fire a()=1 then gosub jump
if controlkey()=1 then vdir$ = "down" : onground = 0 : jumping = 1
rem Has the player jumped? If so, then stuff in this sub will
rem activate and keeping running until the jump is over
gosub _jump_handling
rem Keep player inside screen, also keep him moving if
rem his speed his above zero, reduce speed slightly each
rem cycle
gosub _maintain_move_and_pos
rem Test if our hero touched any blocks
gosub _collision_testing
rem Record current x position
oldplayerx = playerx
oldplayery = playery
rem Draw our hero at the correct place
sprite player_spr,playerx,playery,1
rem Keep the speed in sensible limits
if speed# < 0.0 then speed# = 0.0
if speed# > maxspeed# then speed# = maxspeed#
ink rgb(255,255,255),0
set cursor 0,10
print "Speed: ";speed#
print "Vertical Speed: ";vspeed#
print "Player X:";playerx
print "Old Player X: ";oldplayerx
print "Player Y: ";playery
print "Old Player Y:";oldplayery
print
print "On Ground: ";onground
print "Jumping: ";jumping
print "Screen FPS: ";screen fps()
rem Redraw the screen
sync
loop
rem ))))))))))) E N D M A I N P R O G R A M L O O P (((((((((((((((((((
rem Emergency program end
end
` ))))))))))))))))))))))))) S U B R O U T I N E S ((((((((((((((((((((((((
_pressed_left:
rem If user had previously pressed right then reset speed
if direction$ = "right" then speed# = 1.0
rem If speed is less than the maximum speed then increase it
if speed# < maxspeed# then inc speed#,0.25
rem Player left by speed value
dec playerx,speed#
direction$ = "left"
return
_pressed_right:
rem If user had previously pressed right then reset speed
if direction$ = "left" then speed# = 1.0
rem If speed is less than the maximum speed then increase it
if speed# < maxspeed# then inc speed#,0.25
rem Player right by speed value
inc playerx,speed#
direction$ = "right"
return
rem If the player moves left or right
_maintain_move_and_pos:
rem Player is not using left and right keys
if leftkey()=0 and rightkey()=0 and joystick left()=0 and joystick right()=0
rem If speed is still greater than 0 then
rem we need to slow it down
if speed# > 0.0
dec speed#,0.15
rem For ice try this:
`dec speed#,0.05
endif
if direction$ = "left" and speed# > 0.0 then dec playerx,speed#
if direction$ = "right" and speed# > 0.0 then inc playerx,speed#
endif
rem make sure sprite is contained on screen
if playerx < 0 then playerx = 0
if playerx > 608 then playerx = 608
return
_setup_land:
sprite 1,0,448,2
sprite 2,32,448,2
sprite 3,64,448,2
sprite 4,96,448,2
sprite 5,192,448,2
sprite 6,160,384,2
sprite 7,224,416,2
sprite 8,64,416,2
return
_collision_testing:
rem For all the block sprites
for i = 1 to 8
rem If player is just to the left of block or in the middle and touching it
if (sprite x(player_spr) >= sprite x(i)-32) and (sprite x(player_spr) <= sprite x(i)+16) and sprite collision(player_spr,i)>0
rem If player y is within same height as block side
if sprite y(player_spr) >= sprite y(i) and sprite y(player_spr) <= sprite y(i)+32
rem Push the player back
playerx = oldplayerx-1
speed# = 0.0
endif
endif
rem If player is just to the right of block or in the middle and touching it
if (sprite x(player_spr) <= sprite x(i)+32) and (sprite x(player_spr) > sprite x(i)+17) and sprite collision(player_spr,i)>0
rem If player y is within same height as block side
if sprite y(player_spr) >= sprite y(i) and sprite y(player_spr) <= sprite y(i)+32
rem Push the player forward
playerx = oldplayerx+1
speed# = 0.0
endif
endif
rem If player y is sitting on top of platform or just beneath it
if sprite collision(player_spr,i)> 0 and (sprite y(player_spr) >= sprite y(i)-32 and sprite y(player_spr) <= sprite y(i))
rem If player is standing in between left limit of platform and right limit
if (sprite x(player_spr) >= sprite x(i)-32 and sprite x(player_spr) <= sprite x(i)+32)
rem If player y is in the block then correct it before drawing
if (sprite y(player_spr) > sprite y(i)-32 and sprite y(player_spr) <= sprite y(i)-16) then playery = sprite y(i)-32
rem Player is on the ground and is no longer jumping
onground = 1
jumping = 0
vspeed# = 0
endif
endif
remstart
all of this code is rubbish and does not work :(
rem If player hits bottom of platform
if sprite collision(player_spr,i)>0 and (sprite y(player_spr) >= sprite y(i) and sprite y(player_spr) <= sprite y(i)+30)
if (sprite x(player_spr) >= sprite x(i)-32 or sprite x(player_spr) <= sprite x(i)+32)
playery = oldplayery+1
endif
endif
if (sprite collision(player_spr,i)=0) and (sprite x(player_spr) < sprite x(i)-32 or sprite x(player_spr) > sprite x(i)+32) then falling = 1
remend
next i
return
rem If the player presses the spacebar
jump:
rem If on the ground and not jumping then allow jump
if onground = 1 and jumping = 0
onground = 0
falling = 0
jumping = 1
rem Work out the peak of his jump
targety = (playery - jumpheight)
rem Set his vertical direction to up
vdir$ = "up"
rem Set jumping speed
vspeed# = 4
endif
return
rem If the player is jumping and not reached the target y
rem yet
_jump_handling:
rem If hero is below the jump target height then make him go up
if jumping = 1 and onground = 0
if playery > targety and vdir$ = "up"
dec playery,vspeed#
endif
endif
rem If hero reaches target height, then he needs to fall
rem so set to falling mode
if playery <= targety and vdir$ = "up" and onground = 0
vdir$ = "down"
vspeed# = 3
endif
rem If hero is falling down and still hasnt hit the floor
rem yet then, increase his drop some more
if vdir$ = "down" and onground = 0 and jumping = 1
inc playery,vspeed#
if vspeed# < 10.0 then inc vspeed#
endif
rem If hero has touched ground then enable onground and disable jumping
rem to ignore falling code
if playery >= 448
vspeed# = 0
onground = 1
jumping = 0
playery = 448
endif
return
` )))))))))))))))))) E N D O F S U B R O U T I N E S (((((((((((((((((((
I was just trying to get the basics working, but got totally lost.
I don't Adam and believe it!