Discord
Login
Community
DARK THEME

how do i make it shoot?

init = function() movement_speed = 2 bullet_speed = 10 end

update = function() if keyboard.LEFT then x -= movement_speed end if keyboard.RIGHT then x += movement_speed end if keyboard.UP then y += movement_speed end if keyboard.DOWN then y -= movement_speed end if mouse.press then shoot = 1 else shoot = 0 end screen.clear("rgb(0,255,0)") end

draw = function() screen.drawSprite("player",x,y,100,100) end

i want this to spawn the "bullet" sprite and make the bullet sprite move forward until touching the wall then when it hits the wall it disappears

You need a couple of things:

  • bullet class with position in the constructor
  • player class with position in the constructor
  • bullets list

You create a new bullet object every time you shoot at the position of the player, put it in your bullets list, and update that list in your update and draw functions (you can create custom functions in your bullet class to do this)

Wall collision is checking if two things overlap with each other. There's tons of tutorials for this online

If you need any specific help, just ask!

Post a reply

Progress

Status

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