I am trying to develop a 2D platformer, and I can't make any collision happen between the player and the platform
SET IMAGE COLORKEY 255, 255, 255, `Gets rid of white background
SYNC ON
SYNC RATE 30 `Set up the sync
REM ****** Variable stuff ********
PlayerID = 1 `Player's ID Number
Brick = 8 `Brick number
BG = 10 `Background number
Gravity# = 6 `Tells the gravity
Jumping = 0 `Tells if Mario is jumping or not
JumpSpeed = 4 `Tells how fast mario is jumping
PlayerX = 25 `Player's X Coordinate
PlayerY = 0 `Player's Y Coordinate
Falling = 0 `Tells if Mario is falling
Anim = 0 ` Shows which animation Mario should be at
fRight = 1 `Checks if Mario is facing right or not
Frame = 0
imgnum = 1 `Shows which sprite should be drawn
BrickSprite = 7 `ALlows BrickSprite to be drawn
REM ******************************************
REM ************* Load the images **************
LOAD IMAGE "Mountain.bmp", BG
LOAD IMAGE "Brick.bmp", Brick
LOAD IMAGE "Mstanding_l.bmp", 1
LOAD IMAGE "Mstanding_l.bmp", 2
LOAD IMAGE "MWalking_l.bmp", 3
LOAD IMAGE "MWalking_l.bmp", 4
LOAD IMAGE "MJumping.bmp", 5
LOAD IMAGE "MJumping.bmp", 6
REM *********** The game's main loop *****************
DO
Anim = 0
PASTE IMAGE BG, 0, 0 `Makes the background
SPRITE BrickSprite, 999, 999, Brick `Bricks becomes sprites
GOSUB LoadBricks
IF Jumping = 0 `If there is no jumping
Old_Y = PlayerY `Makes sure Mario is on the ground
ENDIF
SPRITE PlayerID, PlayerX, PlayerY, imgnum `Brings out the player
JumpMax = Old_Y - 80 `How high the player can jump
GOSUB PlayerInput `Get player input
GOSUB PlayerAnim `Change the animation
GOSUB Gravity `Get the gravity
GOSUB Collision `Check collision
RESTORE `This makes the array appear
SYNC `Update the game
LOOP
REM ****** Load the Bricks ******************
LoadBricks:
DIM LevelArray(10, 10) `Loads the Level array, 0s mean nothing while 1s mean bricks
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 0, 0, 0, 0, 0, 1, 1, 1, 1, 1
DATA 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
DATA 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
FOR j = 1 TO 10
FOR i = 1 TO 10
READ LevelArray(i, j) `Loads the array
NEXT i
NEXT j
REM Paste the bricks
Width = SPRITE WIDTH(BrickSprite) `Determines brick width
Height = SPRITE HEIGHT(BrickSprite) `Determines brick height
FOR i = 1 TO 10
FOR j = 1 TO 10
IF LevelArray(i, j) = 1 `Array with a value of 1 indicates that a brick should be there
`One with a 0 should contain nothing
`Paste the brick on the screen
PASTE SPRITE BrickSprite, (Width * i) - Width, Height * j
ENDIF
NEXT j
NEXT i
RETURN
REM *************** End the Load Brick GOSUB *****************
REM **************** Read the player's input ****************
PlayerInput:
REM Walking Right
IF RIGHTKEY() = 1
IF CONTROLKEY() = 1
REM Running Right
PlayerX = PlayerX + 3
ENDIF
PlayerX = PlayerX + 1
IF fRight = 0
MIRROR SPRITE PlayerID `Reverses Mario
fRight = 1
ENDIF
Anim = 1
ENDIF
REM Walking Left
IF LEFTKEY() = 1
IF CONTROLKEY() = 1
REM Running Right
PlayerX = PlayerX - 3
ENDIF
PlayerX = PlayerX - 2
IF fRight = 1
MIRROR SPRITE PlayerID `Reverses Mario
fRight = 0
ENDIF
Anim = 1
ENDIF
REM Player jumps
IF SPACEKEY() = 1 AND Jumping = 0 AND Falling = 0 `If none of these are happening
Jumping = 1 `The player may jump
ENDIF
REM Limit Player
IF PlayerX <= 0 `Player can't go outside
PlayerX = 0
ENDIF
RETURN
REM **************** Get the gravity *********
Gravity:
IF Falling = 1 `If falling is true...
PlayerY = PlayerY + Gravity# `Add the gravity
imgnum = 6 `Gives Mario his falling image
ENDIF
IF Jumping = 1 `If jumping is true...
imgnum = 5 `Change sprite
PlayerY = PlayerY - (JumpSpeed*3) `Make the player go up
ENDIF
IF PlayerY <= JumpMax `If the player reaches maximum
Falling = 1 `Sets falling to true
Jumping = 3
ENDIF
RETURN
REM ********** Animate Mario ******************
PlayerAnim:
IF Anim = 1
imgnum = 2 + (Frame/2)
Frame = Frame + 1
IF Frame >= 3 THEN Frame = 0
ELSE
imgnum = 2
ENDIF
RETURN
REM ********* Test Collision *************
Collision:
IF SPRITE COLLISION (PlayerID, BrickSprite) = 1 `Checks if there is a collision
Falling = 0
Jumping = 0
PlayerY = PlayerY - SPRITE HEIGHT(BrickSprite) `Stops the player from falling
ENDIF
IF Falling = 0 AND SPRITE COLLISION (PlayerID, 0) = 0 `If there is no collision
Falling = 1
ENDIF
RETURN
Whenever I start the program, Mario just falls though, And I want him to stop on the brick.