yo, I need help w/ adding mobile support
this is my "main" file:
init = function() Camx = 0 Camy = 0
player = new player()
audio.playMusic( "bgm", 50, )
end
update = function() player.update()
Camx = Camx + (player.x - Camx) * 0.1 Camy = Camy + (player.y - Camy) * 0.1 end
draw = function() screen.clear() screen.setTranslation(-Camx, -Camy)
screen.drawMap( "world",0, 0,500,196 ) screen.drawMap( "desert",-500, 196,500,196 ) screen.drawMap( "world_2",500, 0,500,196 ) screen.drawMap( "world_3",500, -195.6,500,196 ) screen.drawMap( "world_4",0, -195.6,500,196 ) screen.drawMap( "world_5",0, 196,500,196 ) screen.drawMap( "world_6",500, 196,500,196 ) screen.drawMap( "desert",-500, 0,500,196 ) screen.drawMap( "desert",-500, -196,500,196 ) screen.drawMap( "desert",-500, -392,500,196 ) screen.drawMap( "desert_2",-1000, 0,500,196 ) screen.drawMap( "desert_2",-1500, 0,500,196 ) screen.drawMap( "desert_2",-1000, -196,500,196 ) screen.drawMap( "desert_2",-1500, -196,500,196 ) screen.drawMap( "desert_2",-1500, -392,500,196 ) screen.drawMap( "desert_3",-1000, -392,500,196 ) screen.drawMap( "desert_2",-1000, -588,500,196 ) screen.drawMap( "desert_2",-1500, -588,500,196 )
player.draw()
screen.setTranslation(0,0) end
and this is my "player" file:
player = class constructor = function() this.x = 0 this.y = 0
this.width = 10
this.height = 10
this.image = "j311idle"
this.username = "Player"
this.vx = 0
this.vy = 0
this.acceleration = 0.2
this.deacceleration = 0.08
this.maxspeed = 0.5
this.dashSpeed = 5
this.dashTime = 0
this.dashCooldown = 0
this.dashDuration = 6
this.dashCooldownMax = 20
this.invincible = 0
this.lastDirX = 0
this.lastDirY = 1
this.t1x = 0 this.t1y = 0 this.t1life = 0
this.t2x = 0 this.t2y = 0 this.t2life = 0
this.t3x = 0 this.t3y = 0 this.t3life = 0
this.t4x = 0 this.t4y = 0 this.t4life = 0
this.trailMaxLife = 6
end
updateTrail = function() this.t4x = this.t3x this.t4y = this.t3y this.t4life = this.t3life this.t3x = this.t2x this.t3y = this.t2y this.t3life = this.t2life this.t2x = this.t1x this.t2y = this.t1y this.t2life = this.t1life
this.t1x = this.x
this.t1y = this.y
this.t1life = this.trailMaxLife
end
getInputX = function() return (keyboard.RIGHT - keyboard.LEFT) + (gamepad.RIGHT - gamepad.LEFT) end
getInputY = function() return (keyboard.UP - keyboard.DOWN) + (gamepad.UP - gamepad.DOWN) end
isDashPressed = function() return keyboard.SHIFT or gamepad.X end
update = function() if this.dashCooldown > 0 then this.dashCooldown -= 1 end if this.invincible > 0 then this.invincible -= 1 end
local ix = this.getInputX()
local iy = this.getInputY()
if ix != 0 or iy != 0 then
this.lastDirX = ix
this.lastDirY = iy
end
if this.isDashPressed() and this.dashCooldown <= 0 then
this.dashTime = this.dashDuration
this.dashCooldown = this.dashCooldownMax
this.invincible = this.dashDuration
this.vx = this.lastDirX * this.dashSpeed
this.vy = this.lastDirY * this.dashSpeed
end
if this.dashTime > 0 then
this.dashTime -= 1
this.updateTrail()
this.invincible = this.dashTime
else
if ix != 0 then this.vx += this.acceleration * ix
else this.vx *= (1 - this.deacceleration) end
if iy != 0 then this.vy += this.acceleration * iy
else this.vy *= (1 - this.deacceleration) end
if this.vx > this.maxspeed then this.vx = this.maxspeed end
if this.vx < -this.maxspeed then this.vx = -this.maxspeed end
if this.vy > this.maxspeed then this.vy = this.maxspeed end
if this.vy < -this.maxspeed then this.vy = -this.maxspeed end
end
this.x += this.vx
this.y += this.vy
if this.t1life > 0 then this.t1life -= 1 end
if this.t2life > 0 then this.t2life -= 1 end
if this.t3life > 0 then this.t3life -= 1 end
if this.t4life > 0 then this.t4life -= 1 end
this.anim()
end
anim = function() local ix = this.getInputX() local iy = this.getInputY()
local moving = (ix != 0 or iy != 0)
if this.dashTime > 0 then
if this.lastDirX > 0 then this.image = "j311right"
elsif this.lastDirX < 0 then this.image = "j311left"
elsif this.lastDirY > 0 then this.image = "j311top"
else this.image = "j311down"
end
return
end
if not moving then
this.image = "j311idle"
return
end
if ix > 0 then this.image = "j311right"
elsif ix < 0 then this.image = "j311left"
elsif iy > 0 then this.image = "j311top"
elsif iy < 0 then this.image = "j311down"
end
end
draw = function() if this.t4life > 0 then screen.drawSprite(this.image, this.t4x, this.t4y, this.width0.6, this.height0.6) end if this.t3life > 0 then screen.drawSprite(this.image, this.t3x, this.t3y, this.width0.7, this.height0.7) end if this.t2life > 0 then screen.drawSprite(this.image, this.t2x, this.t2y, this.width0.8, this.height0.8) end if this.t1life > 0 then screen.drawSprite(this.image, this.t1x, this.t1y, this.width0.9, this.height0.9) end
screen.drawText(this.username, this.x, this.y - this.height, "", "#ffffff")
screen.drawText(this.username, this.x, this.y - this.height, "center")
if this.invincible > 0 then
if this.invincible % 2 == 0 then
screen.drawSprite(this.image, this.x, this.y, this.width, this.height)
end
else
screen.drawSprite(this.image, this.x, this.y, this.width, this.height)
end
end end
how do I add mobile support???
