Discord
Login
Community
DARK THEME

Collisoins

Hello! Can anyone help me with collisions for my brick breaker game? The ball keeps moving through the block for some reason. If anyone can help that would be great. Here's the code.

  player = object end
  player.x = 0
  player.y = 0
  player.speed = 4.5
  end
  //pixels per frame
  //ball start postiion
  ball = object
    x = 0
    y = -50
    speed = 4
end

update = function()
  //player movement and collisions
  if keyboard.RIGHT then
    player.x += player.speed
end
 
if keyboard.LEFT then 
  player.x -= player.speed
end
// check collision
if distance(player.x, player.y, ball.x, ball.y) <15 then
  ball.y += ball.speed
end
//ball movement
ball.y -= ball.speed
//keep player on screen
player.x =clamp(player.x, -160,160)
player.y =clamp(player.y, -80,80)
ball.y =clamp(ball.y, -89,89)
end

draw = function()
  screen.clear()
  //sets up screen
  screen.drawMap("map"0,0,475,225)
  //The items and players
  screen.drawSprite("block", player.x, player.y-75, 40,40)
  screen.drawSprite("bluebrick", blue.x-150, blue.y+65,30,30)
  screen.drawSprite("redbrick", red.x-150, red.y-3,30,30)
  screen.drawSprite("orangebrick", orange.x-150 orange.y+14,30,30)
  screen.drawSprite("purplebrick", purple.x-150, purple.y+82,30,30)
  screen.drawSprite("ball", ball.x, ball.y, 20,20)
  screen.drawSprite("yellowbrick", yellow.x-150, yellow.y+31, 30,30)
  screen.drawSprite("greenbrick", green.x-150, green.y+48, 30,30)
end

from what i can see, there is not collision for the ball and the bricks, just ball and player

you can use the collision library to check for collision and have it react based on that

ok

Does anyone know how to use the collision library?

https://microstudio.dev/i/gilles/platformerbasics/

https://microstudio.dev/i/microstudio/collisions/

https://microstudio.dev/i/Duruti/collision_aabb/

https://microstudio.dev/i/Loginus/collision/

https://microstudio.dev/i/Loginus/mapcollision/

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community