Discord
Login
Community
DARK THEME

how do I have wall collisions

so I'm trying to make a horror game because this game does not have any (I think) and not even 20 minutes in I notice the problem I cant get the player to colide with the wall it just goes thru it and I don't want to have to put 50 lines of code into a wall just to make it function here is the code I got currently

init = function()
  player = object end
  player.x = 0
  player.y = 0
  player.speed = 2
end

update = function()
  if keyboard.W then
    player.y += player.speed
  elsif keyboard.S then
    player.y -= player.speed
  elsif keyboard.A then
    player.x -= player.speed
  elsif keyboard.D then
    player.x += player.speed
  end
end

draw = function()
  screen.clear("black")
  screen.drawText(player.x + " X", 0 ,50, 20, "white")
  screen.drawSprite("player", player.x, player.y, 25, 25)
  screen.drawSprite("wall_1", 20, 20, 40, 40)
end

how do I make it apply for all walls because its not just gonna be 1 wall block its gonna be way more then that

Post a reply

Progress

Status

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