Ok, I have this watered down version of my (unfinished) Engine, minus 50% of it, but its enough to show the problem.
function setup()
GrassBlock = readImage("Planet Cute:Grass Block")
parameter.watch("HeroMoveX")
parameter.watch("HeroMoveY")
HeroMoveX = 53
HeroMoveY = HEIGHT-(70+85.5)
newDpad = Dpad(100,125,2)
end
function draw()
for x=53,WIDTH,102 do
for y=HEIGHT-(36),1,-85 do
sprite(GrassBlock, x, y, 108, 176)
sprite("Planet Cute:Character Boy",HeroMoveX,HeroMoveY)
newDpad:draw()
end
if HeroMoveY < 99.5 then
HeroMoveY = 99.5
end
if HeroMoveX > WIDTH-53 then
HeroMoveX = WIDTH-53
end
if HeroMoveY > 783.5 then
HeroMoveY = 783.5
end
if HeroMoveX <= 53 then
HeroMoveX = 53
end
end
end
function touched(touch)
newDpad:touched(touch)
end
Dpad = class()
function Dpad:init(posX,posY,size)
-- you can accept and set parameters here
self.pos = vec2(posX,posY)
self.size = size
self.sel = ""
end
function Dpad:draw()
-- Codea does not automatically call this method
pushStyle()
if self.sel == "up" then
fill(255, 255, 255, 255)
end
rect(self.pos.x-(self.size*10),self.pos.y,self.size*20,self.size*30)
popStyle()
pushStyle()
if self.sel == "left" then
fill(113, 251, 1, 255)
end
rect(self.pos.x-(self.size*40),self.pos.y-(self.size*20),self.size*30,self.size*20)
popStyle()
pushStyle()
if self.sel == "down" then
fill(113, 251, 1, 255)
end
rect(self.pos.x-(self.size*10),self.pos.y-(self.size*50),self.size*20,self.size*30)
popStyle()
pushStyle()
if self.sel == "right" then
fill(113, 251, 1, 255)
end
rect(self.pos.x+(self.size*10),self.pos.y-(self.size*20),self.size*30,self.size*20)
popStyle()
end
function Dpad:touched(touch)
-- Codea does not automatically call this method
if touch.state == BEGAN then
-- Up Button
if (self.pos.x-(self.size*10)) <= touch.x and touch.x <=(self.pos.x-(self.size*10))+self.size*20 then
if (self.pos.y <= touch.y) and (touch.y <= self.pos.y + self.size*30) then
HeroMoveY = HeroMoveY + 85.5
-- Down Button
elseif self.pos.y-(self.size*50) <= touch.y and self.pos.y-(self.size*50 - self.size*30) >= touch.y then
HeroMoveY = HeroMoveY - 85.5
end
elseif self.pos.y >= touch.y and self.pos.y-(self.size*20) <= touch.y then
-- Left Button
if self.pos.x - (self.size*40) <= touch.x and self.pos.x - (self.size*40 - self.size*30) >= touch.x then
HeroMoveX = HeroMoveX - 102
-- Right Button
elseif self.pos.x + (self.size*10) <= touch.x and self.pos.x +(self.size*40) >= touch.x then
HeroMoveX = HeroMoveX + 102
end
else
end
end
--self.sel = ""
end
function Dpad:getLastPress(touch)
end
My question is, would it be possible to add sprites where my guy could not walk and nit have to do the whole
If HeroMoveX > blah and HeroMoveX < Blah then thing? I just can’t think of a different way without rewriting the engine.