Hello guys,
I want to learn the right way to create GO scripts. So if it is possible, see the code bellow and give hints to improve it. Thank you!!!
info about my project:
Window: 540x435
Ball Objetc: 128x128
Mission: Do the ball move through the canvas from left to right and stop moving when de right edge of ball “touch” the right edge of canvas.
My Game object script. (it is working. but im sure that can be improved) thank you guys!
local speed;
local WorldWidth = tonumber(sys.get_config("display.width")) -- is it the best way to access end store this info?
function init(self)
msg.post(".", "acquire_input_focus")
self.speed = 6
self.myWidth = 128 -- is it the best way to access end store this info?
self.myHeight = 128 -- is it the best way to access end store this info?
end
local function goToRight(self)
local p = go.get_position()
p.x = p.x + self.speed
local worldRightLimit = WorldWidth - self.myWidth/2
if p.x <= worldRightLimit then
go.set_position(p)
end
end
function update(self, dt)
goToRight(self) -- is it the best way to do this movement? Or is there native functions?
end