Discord
Login
Community
DARK THEME

Help me with map collisions please!

Hello! For a couple of days now I've been trying to make some sprite-to-map collisions, but it’s just not been working. Could someone help?

This is my code with none of the changes I've made:

init = function()
  player = object
    y = 0
    x = 0
    velocityy = 0
    velocityx = 0
    state = 'joshidleright'
    w = 50
    h = 50
  end
  lastkeypressed = 'right'
  gravity = 0.5
  hitbox = [playerx, playery + 3, 50, 48]
end

update = function()
  screen.clear(-3)
  if keyboard.LEFT then
    player.velocityx -= 5
    player.state = "joshwalkleft"
    lastkeypressed = 'left'
  end
  if keyboard.RIGHT then
    player.velocityx += 5
    player.state = "joshwalkright"
    lastkeypressed = 'right'
  end
  if keyboard.UP and lastkeypressed == 'left' then
    player.velocityy = 8
    player.state = "joshjumpleft"
  end
  if keyboard.UP and lastkeypressed == 'right' then
    player.velocityy = 8
    player.state = "joshjumpright"
  end
  if keyboard.DOWN then
  end
  if not keyboard.DOWN and not keyboard.UP and not keyboard.LEFT and not keyboard.RIGHT and lastkeypressed == 'left' then
    player.state = 'joshidleleft'
  end
  if not keyboard.DOWN and not keyboard.UP and not keyboard.LEFT and not keyboard.RIGHT and lastkeypressed == 'right' then
    player.state = 'joshidleright'
  end
  player.velocityy -= gravity
  player.y += player.velocityy
  if player.velocityy <= -20 then
    player.velocityy = -20
  end
  if player.y <= -80 then
    player.y = -80
  end
  player.x += player.velocityx
  if not keyboard.LEFT or not keyboard.RIGHT then
    player.velocityx = 0
  end
end

draw = function()
  screen.drawSprite(player.state, player.x, player.y, player.w, player.h)
  screen.setAlpha(0)
  screen.fillRect(hitbox)
  screen.setAlpha(1)
  drawmaps()
end

Here is the link to the chat that might help you. https://microstudio.dev/community/help/map-collisions/2624/

Post a reply

Progress

Status

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