Discord
Login
Community
DARK THEME

Shooter

hi, im coding a pig in sky shooter, where you have to shoot pigs with your mouse (dont ask why) and i want that you are get points if you press at your mouse and your mouse.x and the distance to the pig.x is smaller or bigger than 3 (or same)

Check for mouse.press in the update function and use abs(a - b) for the distance between a and b:

update = function()
  if mouse.press then
    for pig in pigs // or other iteration code
      if abs(mouse.x - pig.x) <= 3 then
        // destroy pig and gain points
      end
    end
  end
end

but how this works with an y coordinate and an x coordinate

Just check the Y distance as well.

if abs(mouse.x - pig.x) <= 3 and abs(mouse.y - pig.y) <= 3 then
  // destroy pig and gain points
end

Post a reply

Progress

Status

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