Does anybody know how to make sprites interact with a background.
I need it to get my background to scroll with the character sprite, so when the sprite gets to the middle of the screen the background will then scroll left, but once you have gone this way you can't go back.
If you don't understand this, think Mario.
Also in the background i have gaps in the floor. I need to make it so that you can walk along the floor but when you come to a gap you drop through.
Here is the code i have so far:
newgame:
` Initialize the program
hide mouse
sync rate 0
sync on
cls
`Loads the background image
load image "level.bmp",50,1
load bitmap "protoman.png", 1
` Grab running Protoman images
get image 1,30,379,56,406,1
get image 2,61,379,87,406,1
get image 3,92,379,118,406,1
get image 4,128,379,154,406,1
` Grab jumping Protoman image
get image 7,32,425,59,458,1
BackX=0:BackY=0 :` Background x and y coordinates
BackSpeed=1 :` Background scroll speed (pixels to decrease from BackX)
cls
` Change to main view screen (because of loading bitmap)
set current bitmap 0
` Set the current image number and OldDirection
CImage=1
OldDirection=1
` Set the starting x and y of the character
x=30:y=520
` Set the timers for movement, animation, and jumping
tim=timer()
Imagetim=timer()
timjump=timer()
` DO this LOOP forever (no exit)
do
` Place the background image
paste image 50,BackX,BackY
` Show where BackX is (rem or delete this once you see what it's doing)
text 100,0,"BackX = "+str$(BackX)
` Draw the sprite
sprite 1,x,y,CImage
` Go Left
if leftkey() and timer()>tim+10
` Check if the sprite needs to be mirrored
if OldDirection=1 then mirror sprite 1:OldDirection=2
dec x
` Check if its time to change the image for animation (and not during a jump)
if timer()>Imagetim+150 and Jump=0
inc CImage
` Check if the image is within range of frames 5 and 6
if CImage>=5 then CImage=1
` Reset animation timer
Imagetim=timer()
endif
` Reset movement timer
tim=timer()
endif
` Go Right
if rightkey() and timer()>tim+10
` Check if the sprite needs to be mirrored
if OldDirection=2 then mirror sprite 1:OldDirection=1
inc x
` Check if its time to change the image for animation (and not during a jump)
if timer()>Imagetim+150 and Jump=0
inc CImage
` Check if the image is within range of frames 5 and 6
if CImage>=5 then CImage=1
` Reset animation timer
Imagetim=timer()
endif
` Reset movement timer
tim=timer()
endif
` Jump (only allow when not jumping already)
if spacekey() and timer()>timjump+5 and Jump=0
` Save the old sprite image number
OldImage=sprite image(1)
` Set current image to jump image
CImage=7
` Set jump variable (used to check if jump is active or not)
Jump=1
` Save starting y
OldY=sprite y(1)
` Calculate how high the jump will go
JumpCeiling=OldY-20
` Reset jump timer
timjump=timer()
endif
` Check if Protoman is falling from a jump
if Jump=2 and timer()>timjump+5
` Increase current y coordinate
inc y
` Check if the starting y has been reached and stop jump (change to 0)
if y=>OldY then Jump=0:CImage=OldImage :` Change image to oldimage
` Reset jump timer
timjump=timer()
endif
` Check if Protoman is jumping
if Jump=1 and timer()>timjump+5
` Decrease current y coordinate
dec y
` Check if the Jump Ceiling has been reached (change to 2)
if y<=JumpCeiling then Jump=2
` Reset jump timer
timjump=timer()
endif
sync
loop
Any help will be greatly appreciated.