How do i get my character to move in all direction
I'm struggling to find a way to get my character to move around in all directions using WSAD also i'm still very new to this program. i'm trying to make an rpg game
I'm struggling to find a way to get my character to move around in all directions using WSAD also i'm still very new to this program. i'm trying to make an rpg game
https://microstudio.io/Constantine_RetroGamer/rpg/
https://microstudio.dev/i/ItsRPixelG/rpixelg_gemo/
Browse sources in the Explore section (can be searched by the tag >> rpg)
The easiest way to do this is:
In init()
It's best if you create an object type structure that will contain all the necessary fields regarding the player's position.
in the update()
section - you can check the state of key presses.
in the draw()
section you draw the entire game.
Player = class
constructor = function()
this.x = 0
this.y = 0
this.size = 10
end
update = function()
if keyboard.W then
this.y += 1
elsif keyboard.S then
this.y -= 1
elsif keyboard.A then
this.x -= 1
elsif keyboard.D then
this.x += 1
end
end
draw = function()
screen.drawRect( this.x, this.y, this.size, this.size, "orange")
end
end
init = function()
player = new Player()
end
update = function()
player.update()
end
draw = function()
screen.clear()
player.draw()
end