Wall Problem

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.

Why not adding some physics objects associated to the sprites ? This what i did in my Ants program and it works fine.

Physics in Codea is not my strong suit, Have any small demos?

And I have looked at ants, but I cant pick out the physics in it

As i said the Ants program (the 5th one in http://jmv38.comze.com/CODEAbis/server.php)

‘pick out’? What do out mean? You cant just pick out and paste a part of the program that does it, you have to integrate it into your program.

Sorry, wasnt clear, I couldn’t see the physics in relation to the world, sorry for the confusion

first you define the world object, like edges:
edge[1] = physics.body(EDGE,vec2(d,d),vec2(WIDTH-d,d))
then you define a shape for your objects: i have defined a circle for each ant:

    self.body = physics.body(CIRCLE,3*caller.sizeFactor/0.7)
    local body = self.body
    body.info = self
    body.type = DYNAMIC
    body.fixedRotation = true    
    body.position = caller.v0
    local angle = rad(rnd(360))
    body.angle = angle
    self.linearVelocity = vec2(cos(angle),sin(angle))*self.speed
    body.linearVelocity = self.linearVelocity

then my ants will bump in worl objects

Just wondering:
body.fixedrotation means it rotates on a fixed point?
What does caller.v0 mean?

@CodeaNoob - if you have a tile based map, you can have a table which tells you what is in each tile, and it is easy to check if you can go in a square or not

If your hero is walking about freely, then you will need to either use physics or else write a simple collision detection routine. For example, if all the objects that he can’t walk through are listed in a table called Objects, and they all have an x,y,w,h property, then you can have a very simple function that loops through them and checks for collisions. So even though it is doing “if HeroMoveX> or …”, it is only in one place, and only a few lines of code.

After all, this is all the physics is doing anyway! Doing it yourself will put less strain on FPS because physics creates a lot more work for the processor.