Strategy Game Style Movement

Does anyone now how to select one avatar and move it with swipe controls… Then select a different avatar and move it with the same swipe controls? I’m guessing i need to put the swipe controls in a class. But I have no idea how to differentiate between which avatar to control at a given time. Please help. Code below. Thx. @.@

--# Main
-- Move

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    sx=50.5
    sy=85.5
    w=101
    h=171
    dx=101
    dy=85.5
end

function draw()
    background(0, 0, 0, 255)
    
    sprite("Documents:TileSetTest",WIDTH/2,HEIGHT/2)
    
    sprite("Planet Cute:Character Horn Girl",151.5,256.5,w,h)
    
    sprite("Planet Cute:Character Pink Girl",sx,sy,w,h)   
end    

function touched(touch)
    local id = touch.id
    local state = touch.state
    local x = touch.x
    local y = touch.y
    if state == BEGAN then
        swipeId = id  -- Preserve the id
        swipeX = x    -- Preserve the position
        swipeY = y    -- Preserve the position
        return
    end
    if state == ENDED and id == swipeId then
        swipeId = nil
        if math.abs(x - swipeX) < 100 then -- Within tolerance?
            if swipeY - y > 100 then       -- Long enough?
                print("Swipe down")
                sy = sy - dy
            end
            if y - swipeY > 100 then       -- Long enough?
                print("Swipe up")
                sy = sy + dy
            end
        end
        if math.abs(y - swipeY) < 100 then
            if swipeX - x > 100 then
                print("Swipe Left")
                sx = sx - dx
            end
            if x - swipeX > 100 then
                print ("Swipe Right")
                sx = sx + dx
            end
        end
    end
end

Maybe a tapCount would be part of the answer? But how to implement a double tap without messing up the swipe code?

Put the two avatars in a table having there x and y values and then select an avatar when someone touches it and then control the x and y of the avatar. I think I might not be clear so here’s the code.


--# Main
-- Move

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    avatars={vec2(101,170), --Horn Girl
            vec2(50.5,85.5)--Pink Girl
            }
    SA=1 --Selected Avatar right now Horn Girl since 1
    w=101
    h=171
    dx=101
    dy=85.5
end

function draw()
    background(0, 0, 0, 255)

    sprite("Documents:TileSetTest",WIDTH/2,HEIGHT/2)

    sprite("Planet Cute:Character Horn Girl",avatars[1].x,avatars[1].y,w,h)

    sprite("Planet Cute:Character Pink Girl",avatars[2].x,avatars[2].y,w,h)
end    

function touched(touch)
    local id = touch.id
    local state = touch.state
    local x = touch.x
    local y = touch.y
    if state == BEGAN then
        swipeId = id  -- Preserve the id
        swipeX = x    -- Preserve the position
        swipeY = y    -- Preserve the position
        return
    end
    if state == ENDED and id == swipeId then
        swipeId = nil
        if math.abs(x - swipeX) < 100 then -- Within tolerance?
            if swipeY - y > 100 then       -- Long enough?
                print("Swipe down")
                avatars[SA].y = avatars[SA].y - dy
            end
            if y - swipeY > 100 then       -- Long enough?
                print("Swipe up")
                avatars[SA].y = avatars[SA].y + dy
            end
        end
        if math.abs(y - swipeY) < 100 then
            if swipeX - x > 100 then
                print("Swipe Left")
                avatars[SA].x = avatars[SA].x - dx
            end
            if x - swipeX > 100 then
                print ("Swipe Right")
                avatars[SA].x = avatars[SA].x + dx
            end
        end
    end
    
    if state==ENDED then --Select an Avatar
        for k,v in pairs(avatars) do
            if x>v.x-30 and x<v.x+30 and y>v.y-30 and y<v.y+30 then
                SA=k
            end
        end
    end
end

@Saurabh, thank you soooo much!!! Nothing short of elegant!!! What I would have tried would have been so messy and probably wouldn’t have worked anyway. I’m going to post an updated version for other newbies to play with.


--# Main

--# Main
-- Move

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    SA=1 --Selected Avatar right now (Horn Girl since 1)
    sw=50.5
    sh=85.5
    w=101
    h=171
    dx=101
    dy=85.5
    
    avatars={vec2(sw, sh+h), -- Horn Girl
            vec2(sw, sh), -- Pink Girl
            vec2(sw+w*2, sh), -- Cat Girl
            vec2(sw+w*3, sh+h*4), -- Princess Girl
            vec2(sw+w*9, sh+h*3) -- Boy
            }
end

function draw()
    background(0, 0, 0, 255)

    sprite("Documents:TileSetTest",WIDTH/2,HEIGHT/2)

    sprite("Planet Cute:Character Horn Girl",avatars[1].x,avatars[1].y,w,h)

    sprite("Planet Cute:Character Pink Girl",avatars[2].x,avatars[2].y,w,h)
    
    sprite("Planet Cute:Character Cat Girl",avatars[3].x,avatars[3].y,w,h)
    
    sprite("Planet Cute:Character Princess Girl",avatars[4].x,avatars[4].y,w,h)
    
    sprite("Planet Cute:Character Boy",avatars[5].x,avatars[5].y,w,h)
end    

function touched(touch)
    local id = touch.id
    local state = touch.state
    local x = touch.x
    local y = touch.y
    if state == BEGAN then
        swipeId = id  -- Preserve the id
        swipeX = x    -- Preserve the position
        swipeY = y    -- Preserve the position
        return
    end
    if state == ENDED and id == swipeId then
        swipeId = nil
        if math.abs(x - swipeX) < 100 then -- Within tolerance?
            if swipeY - y > 100 then       -- Long enough?
                print("Swipe down")
                avatars[SA].y = avatars[SA].y - dy
            end
            if y - swipeY > 100 then       -- Long enough?
                print("Swipe up")
                avatars[SA].y = avatars[SA].y + dy
            end
        end
        if math.abs(y - swipeY) < 100 then
            if swipeX - x > 100 then
                print("Swipe Left")
                avatars[SA].x = avatars[SA].x - dx
            end
            if x - swipeX > 100 then
                print ("Swipe Right")
                avatars[SA].x = avatars[SA].x + dx
            end
        end
    end

    if state==ENDED then --Select an Avatar
        for k,v in pairs(avatars) do
            if x>v.x-30 and x<v.x+30 and y>v.y-30 and y<v.y+30 then
                SA=k
            end
        end
    end
end


Ok, I figured out how to keep all my avatars from going off the edges of the screen. And even figured out how to put the code into a function. Woot! Yeah, I know, not very impressive, but I’m thrilled anyway. However, I have yet more agonizingly noob questions for anybody with the time or inclination.

  1. My program worked the same when I put the screen edges code in the draw function as when I put it into its own function screenEdges(). So are functions mostly for organization? Or do they help chunks of code interfering with other chunks?

  2. Could I use the table and loop that Saurabh generously provided to prevent my selected avatar “SA” from occupying the same x,y coordinates as the other avatars? (So far my grid is defined by limiting the movement of avatars to only the center of each tile (dx=101, dy=85.5).) So my idea is to use x,y coordinates instead of rectangles or physics objects to keep everybody on separate tiles…

  3. @Saurabh What do k and v mean in the for loop? Also, it seems like the associated table keeps updating the x and y values since I can select an avatar even after it moves from its starting point. Is that right? I’ve done the lua tuts for tables and loops by ignatz, but they don’t seem natural to me yet…

Thanks everyone!! Code below


--# Main

--# Main
-- Move

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    SA=1 --Selected Avatar right now (Horn Girl since 1)
    sw=50.5
    sh=85.5
    w=101
    h=171
    dx=101
    dy=85.5
    
    avatars={vec2(sw, sh+h), -- Horn Girl
            vec2(sw, sh), -- Pink Girl
            vec2(sw+w*2, sh), -- Cat Girl
            vec2(sw+w*3, sh+h*4), -- Princess Girl
            vec2(sw+w*9, sh+h*3) -- Boy
            }
end

function draw()
    background(0, 0, 0, 255)

    sprite("Documents:TileSetTest",WIDTH/2,HEIGHT/2)

    sprite("Planet Cute:Character Horn Girl",avatars[1].x,avatars[1].y,w,h)

    sprite("Planet Cute:Character Pink Girl",avatars[2].x,avatars[2].y,w,h)
    
    sprite("Planet Cute:Character Cat Girl",avatars[3].x,avatars[3].y,w,h)
    
    sprite("Planet Cute:Character Princess Girl",avatars[4].x,avatars[4].y,w,h)
    
    sprite("Planet Cute:Character Boy",avatars[5].x,avatars[5].y,w,h)
    
    screenEdges()       
end    

function touched(touch)
    local id = touch.id
    local state = touch.state
    local x = touch.x
    local y = touch.y
    if state == BEGAN then
        swipeId = id  -- Preserve the id
        swipeX = x    -- Preserve the position
        swipeY = y    -- Preserve the position
        return
    end
    if state == ENDED and id == swipeId then
        swipeId = nil
        if math.abs(x - swipeX) < 100 then -- Within tolerance?
            if swipeY - y > 100 then       -- Long enough?
                print("Swipe down")
                avatars[SA].y = avatars[SA].y - dy
            end
            if y - swipeY > 100 then       -- Long enough?
                print("Swipe up")
                avatars[SA].y = avatars[SA].y + dy
            end
        end
        if math.abs(y - swipeY) < 100 then
            if swipeX - x > 100 then
                print("Swipe Left")
                avatars[SA].x = avatars[SA].x - dx
            end
            if x - swipeX > 100 then
                print ("Swipe Right")
                avatars[SA].x = avatars[SA].x + dx
            end
        end
    end

    if state==ENDED then --Select an Avatar
        for k,v in pairs(avatars) do -- Iterate through avatars table in pairs
            if x>v.x-30 and x<v.x+30 and y>v.y-30 and y<v.y+30 then -- Defines tap select area
                SA=k -- What does k,v stand for?
            end
        end
    end
end

function screenEdges()
        -- Tells currently selected avatar (SA) to go back to edge of screen when it passes the invisible edges set at w, h, WIDTH, and HEIGHT.
    if avatars[SA].x < w then avatars[SA].x = sw end
    if avatars[SA].x > WIDTH then avatars[SA].x = sw * 19 end
    if avatars[SA].y < h then avatars[SA].y = sh end
    if avatars[SA].y > HEIGHT then avatars[SA].y = sh * 9 end
end


@Kempoman - functions should give the same result as inline (everything in one function) code, but they are there for several reasons.

  • Avoid duplication - to prevent having to write the same code repeatedly
  • Debugging - to break the code into logical chunks that can be checked separately, making it much easier to find errors
  • Organisation - to make code readable
    and more

@Kempoman - the k,v in the for loop are

k = an id number for each item in the table. Often, you won’t need to bother with this, but if you want to delete an item, you will need it.

v = the item that is stored in the table. You have put vec2 variables in there, so v will be a vec2 (with properties v.x and v.y) and the for loop will cycle through all your avatars.

@Kempoman - to avoid collisions, you could use several approaches, but the logical place to do it is when you’re moving an avatar, in the touch function. You can go in four different directions, so you need to check each of them, and if an avatar is already there, cancel the movement.

So one way you could do it is to write a function MoveAvatar that takes three parameters, the current avatar index number; the change in x position; and the change in y position (only one of the x and y will change, of course). It would set a new vec2 for the avatar.

So if your movement is down, you currently say

avatars[SA].y=avatars[SA].y-dy

instead you would say

MoveAvatar(SA,0,-dy)

if you swiped right, you would say

MoveAvatar(SA,dx,0)

and now you should see how useful functions are in making your code simpler.

What would MoveAvatar do?

A simple approach is just to cycle through the avatars and check the x,y positions don’t conflict, eg

function MoveAvatar(id,dx,dy)
    local newX, newY = avatars[id].x+dx,avatars[id].y+dy --temporary new positions
    for k,v in pairs(avatars)
        if v.x==newX and v.y==newY then --if true, we have a clash
            return end  --don't move, we have a clash
        end
    end
    --if we got this far, there are no clashes, make the move
    avatars[id].x,avatars[id].y=avatars[id].x+dx,avatars[id].y+dy
end

Ignatz, you are amazing!!! I… think… I… Understand!! This is so cool. To me all of you seem like wizards. :slight_smile:

That’s what I thought a few months ago, so you’ll soon be a wizard if you just keep learning

At the moment, your avatar locations are x,y screen coordinates.

I think you’ll do better by creating a virtual grid (ie 2D table) on the screen, starting at [1][1] at bottom left, and going to [r][c] at top left, where r=rows and c=columns.

This enables you to hold a map of the screen in memory, and instead of moving your avatars to pixel locations, you move them to squares on your map, eg [3][4]. Then when you’re drawing, you can easily convert those map locations into pixels.

This map based approach is really useful if you want to put objects on your map, because you could use a table to store the objects in each cell of the map.

So I suggest separating the mapping and screen drawing functions, because it will be much easier to manage and to extend your code.

As a former UI designer always keep you data separate from your drawing routines. You can make the migration to 3d or just a different display scheme easily.

I use grid[x][y] for the map and store a dataObject in that location, and I have a table with dataObjects for any non-map things (like the player, enemies, doors…). You can then check grid[x][y].tileType and key off the value. This will let you have flexibility if you want to have a tileType that allows passage for a certain type of tileType. For example, 1=player, 2=enemy, 3=stopEnemy,4=food

Here is what I use:

mapData = class()

function mapData:init(id,pos,tileType,isShown,blocksLOS,stateObstacle)
  --  print("mapData")
    -- you can accept and set parameters here
    self.id = id -- the id number of the rectangle created in the grid[][]
    self.pos = pos  -- the position to be multiplied  *also the begin vec2 of the astar search
    self.tileType = tileType  -- the id number now it is mesily made by hand
    -- later it will be the map format from tiled editor.
    self.isShown = isShown   -- to display the correct texture map coordinate
    self.isDrawn = 1 -- flag to draw tile on screen
    self.isPointOfInterest = vec2(0,0) -- the vec2 location the the endpoint of the astar search
    self.giveDamage = 0
    self.takeDamage = 0
    self.blocksLOS = blockLOS
    self.isEnemy = 0
    self.health = 0
    self.isOnFire = 0
    self.name = "default"
    self.state = tileType
--    self.timer = newTimerClass to be created later
end

Hope this helps

Thank you Ignatz and Thwapp. I’ve been making a lot of progress with your help. I will post my results when I have reached some of my goals. Hopefully soon. :slight_smile:

I took your advice Ignatz and started switching from pixels to tables and I like it so far.

Ok, so I’ve learned a little about tables thanks to you wizards. Unfortunately, I couldn’t figure out how to make the avatars and bugs move within the table, which would solve a lot of overlapping problems.

So here’s my idea for the game if you are interested. Bug boy wants to save his friend cat girl from the evil bugs in level 1. His power is super strength so he can pick up objects like trees, bushes, and later on boulders. Here’s the twist: when thrown, each of these objects pushes a bug in a different compass direction and there are a limited number of each object. The bugs are too strong to defeat directly, so bug boy has a plan to push the two opposite bugs together (this makes them fight each other and explode).

To prototype this level, I was hoping someone could help me figure out how to:

  1. Move avatars within a table.
  2. Pick up and carry objects.
  3. Throw objects so that they push a bug in a given direction one tile.
  4. Make objects and bugs disappear.
  5. Open a door only when carrying a key.

Btw, in future levels, bug boy will be joined by cat girl who will have different powers --which will be needed to solve greater challenges. She might have the ability to grow a limited number of extra trees. Later, when other friends are rescued, they will join the team with their own unique powers, like turning water into ice, etc…

I’m pretty sure i could have put all my sprites in a table with a table right? For 1,maxnum something do I = Id end I’m not sure. However, I thought it would be hard to remember which number was which sprite…

Hope you guys don’t mind helping me out again. I really appreciate it :). Code below.


--# Main

-- Final

displayMode(FULLSCREEN)
supportedOrientations(CurrentOrientation)

moveSprites = {}
layer1 = 1
layer2 = 2
layer3 = 3

function setup()
    SA=1 --Selected Avatar right now (Horn Girl since 1)
    sw=50 --Starting point
    sh=121
    w=101 --Width of sprite
    h=171
    dx=101 --Change in x
    dy=85.5
    
    avatars={vec2(sw, sh+h), -- Horn Girl
            vec2(sw+w*8, sh), -- Pink Girl
            vec2(sw+w*2, sh), -- Cat Girl
            vec2(sw+w*3, sh+h*3), -- Princess Girl
            vec2(sw+w*9, sh+h) -- Boy
            }
    
    makeSprites()
    
end

function makeSprites()
    for i = 1, 8 do --rows
        for j = 1, 11 do  --columns
            if layers[layer1][i][j] > 0 then
                table.insert(moveSprites,moveSprite((j*100-50),HEIGHT-(i*86-50),layers[layer1][i][j]))
            end
        end
    end

     for i = 1,8 do
        for j = 1,11 do
            if layers[layer2][i][j] > 0 then
               table.insert(moveSprites,moveSprite((j*100-50),HEIGHT-(i*86-36),layers[layer2][i][j]))
            end
        end
    end
    
    for i = 1,8 do
        for j = 1,11 do
            if layers[layer3][i][j] > 0 then
               table.insert(moveSprites,moveSprite((j*100-50),HEIGHT-(i*86-36),layers[layer3][i][j]))
            end
        end
    end
end

function draw()
    background(6, 223, 252, 255)
    
    sprite("Documents:Level1Map",WIDTH/2,HEIGHT/2) -- Contains Grass, water, dirt, sky.
    
    for i = 1, table.maxn(moveSprites, i) do -- Get largest possible numerical index.
        moveSprites[i]:draw()
    end

    -- sprite("Planet Cute:Character Horn Girl",avatars[1].x,avatars[1].y,w,h)

    -- sprite("Planet Cute:Character Pink Girl",avatars[2].x,avatars[2].y,w,h)
    
    -- sprite("Planet Cute:Character Cat Girl",avatars[3].x,avatars[3].y,w,h)
    
    -- sprite("Planet Cute:Character Princess Girl",avatars[4].x,avatars[4].y,w,h)
    
    sprite("Planet Cute:Character Boy",avatars[5].x,avatars[5].y,w,h)
    
    screenEdges()   
end

function touched(touch)
    local id = touch.id
    local state = touch.state
    local x = touch.x
    local y = touch.y
    if state == BEGAN then
        swipeId = id  -- Preserve the id
        swipeX = x    -- Preserve the position
        swipeY = y    -- Preserve the position
        return
    end
    if state == ENDED and id == swipeId then
        swipeId = nil
        if math.abs(x - swipeX) < 100 then -- Within tolerance?
            if swipeY - y > 100 then       -- Long enough?
                print("Swipe down")
                moveAvatar(SA,0,-dy)
            end
            if y - swipeY > 100 then       -- Long enough?
                print("Swipe up")
                moveAvatar(SA,0,dy)
            end
        end
        if math.abs(y - swipeY) < 100 then
            if swipeX - x > 100 then
                print("Swipe Left")
                moveAvatar(SA,-dx,0)
            end
            if x - swipeX > 100 then
                print ("Swipe Right")
                moveAvatar(SA,dx,0)
            end
        end
    end

    if state==ENDED then --Select an Avatar
        for k,v in pairs(avatars) do -- Iterate through avatars table in pairs
            if x>v.x-30 and x<v.x+30 and y>v.y-30 and y<v.y+30 then -- Defines tap select area
                SA=k -- What does k,v stand for?
            end
        end
    end
end

function screenEdges()
        -- Tells currently selected avatar (SA) to go back to edge of screen when it passes the invisible edges set at w, h, WIDTH, and HEIGHT.
    if avatars[SA].x < w then avatars[SA].x = sw 
    elseif avatars[SA].x > WIDTH then avatars[SA].x = sw * 19 end
    if avatars[SA].y < h then avatars[SA].y = sh
    elseif avatars[SA].y > HEIGHT then avatars[SA].y = sh * 6 end
end

function moveAvatar(id,dx,dy)
    local newX, newY = avatars[id].x+dx, avatars[id].y+dy -- Temporary new positions.
    for k,v in pairs(avatars) do
        if v.x==newX and v.y==newY then -- If true, we have a clash.
            return -- Don't move, we have a clash.
        end
    end
    -- if we got this far, there are no clashes, make the move.
    avatars[id].x,avatars[id].y=avatars[id].x+dx,avatars[id].y+dy
end

--# MoveSprite
moveSprite = class()

function moveSprite:init(x,y,i)
    -- you can accept and set parameters here
    self.pos = vec2(x,y)
    self.size = vec2(101,171)
    self.i = i
end

function moveSprite:draw()
    -- Codea does not automatically call this method
    if self.i == 1 then
        sprite("Planet Cute:Door Tall Open", self.pos.x, self.pos.y)
    elseif self.i == 2 then
        sprite("Planet Cute:Character Boy", self.pos.x, self.pos.y)
    elseif self.i == 3 then
        sprite("Planet Cute:Character Cat Girl", self.pos.x, self.pos.y)
    elseif self.i == 4 then
        sprite("Planet Cute:Character Horn Girl", self.pos.x, self.pos.y)
    elseif self.i == 5 then
        sprite("Planet Cute:Character Pink Girl", self.pos.x, self.pos.y)
    elseif self.i == 6 then
        sprite("Planet Cute:Character Princess Girl", self.pos.x, self.pos.y)
    elseif self.i == 7 then
        sprite("Planet Cute:Enemy Bug", self.pos.x, self.pos.y)
    elseif self.i == 8 then
        sprite("Planet Cute:Gem Blue", self.pos.x, self.pos.y)
    elseif self.i == 9 then
        sprite("Planet Cute:Gem Green", self.pos.x, self.pos.y)
    elseif self.i == 10 then
        sprite("Planet Cute:Gem Orange", self.pos.x, self.pos.y)
    elseif self.i == 11 then
        sprite("Planet Cute:Brown Block", self.pos.x, self.pos.y)
    elseif self.i == 12 then
        sprite("Planet Cute:Chest Open", self.pos.x, self.pos.y)
    elseif self.i == 13 then
        sprite("Planet Cute:Chest Lid", self.pos.x, self.pos.y)
    elseif self.i == 14 then
        sprite("Planet Cute:Chest Closed", self.pos.x, self.pos.y)
    elseif self.i == 15 then
        sprite("Planet Cute:Heart", self.pos.x, self.pos.y)
    elseif self.i == 16 then
        sprite("Planet Cute:Key", self.pos.x, self.pos.y)
    elseif self.i == 17 then
        sprite("Planet Cute:Plain Block", self.pos.x, self.pos.y)
    elseif self.i == 18 then
        sprite("Planet Cute:Rock", self.pos.x, self.pos.y)
    elseif self.i == 19 then
        sprite("Planet Cute:Star", self.pos.x, self.pos.y)
    elseif self.i == 20 then
        sprite("Planet Cute:Stone Block Tall", self.pos.x, self.pos.y)
    elseif self.i == 21 then
        sprite("Planet Cute:Tree Short", self.pos.x, self.pos.y)
    elseif self.i == 22 then
        sprite("Planet Cute:Tree Tall", self.pos.x, self.pos.y)
    elseif self.i == 23 then
        sprite("Planet Cute:Tree Ugly", self.pos.x, self.pos.y)
    elseif self.i == 24 then
        sprite("Planet Cute:Wall Block Tall", self.pos.x, self.pos.y)
    elseif self.i == 25 then
        sprite("Planet Cute:Window Tall", self.pos.x, self.pos.y)
    elseif self.i == 26 then
        sprite("Planet Cute:Door Tall Closed", self.pos.x, self.pos.y)
    elseif self.i == 27 then
        sprite("Planet Cute:Selector", self.pos.x, self.pos.y)
    elseif self.i == 28 then
        pushStyle()
        tint(0, 97, 250, 255)
        sprite("Planet Cute:Enemy Bug", self.pos.x, self.pos.y)
        popStyle()
    end
end

function moveSprite:touched(touch)
    -- Codea does not automatically call this method
end

--# Layers
layers = {

-- Open door layer
{
{0,0,0,0,0,0,0,0,0,0,0}, 
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
},

-- Contains walls, doors, trees, shrubs, keys,... bugs,... and avatars? How do I get them to move?
{
{24,24,24,21,21,0,0,21,0,0,0}, 
{24,3,24,0,0,28,0,0,0,0,0},
{24,0,24,0,21,0,0,21,0,0,0},
{24,26,24,0,0,0,0,0,0,0,0},
{21,0,21,0,0,0,23,23,0,2,0},
{0,0,0,0,0,0,23,0,0,22,21},
{22,22,0,0,0,0,0,0,0,0,22},
{16,7,0,0,0,0,23,0,0,0,0},
},

{
{0,0,0,0,0,0,0,0,0,0,0}, 
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0}, 
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
},

{
{0,0,0,0,0,0,0,0,0,0,0}, 
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
},

{
{0,0,0,0,0,0,0,0,0,0,0}, 
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0},
},

}


@Kempoman - we all learn by doing, you’re going the right way and will soon be teaching us stuff :)>-

Your questions. Here are my suggestions

1 Move avatars within a table
2 Pick up and carry objects

Store more stuff in the avators table, like so

avatars={}
avatar[1]={img="Planet Cute:Character Horn Girl",x=1,y=1,inventory={}}
avatar[2]={img="Planet Cute:Character Pink Girl",x=1,y=1,inventory={}}
--etc

Now we have stored the image name, x and y position, and a table listing the objects they are carrying, which you can add to, or delete from, as you wish, eg

table.insert(avatar[1].inventory,"small key")

4 Make objects and bugs disappear.

Objects and bugs can be stored in tables, and removed when you want to get rid of them

5 Open a door only when carrying a key.

Check if the character has a key in their inventory

.
Also - you have a long list of character names and repetitive code in moveSprite:Draw()

Better is something like this

in the init function:

moveSprite.chars={"Door Tall Open", "Character Boy", 
            "Character Cat Girl", etc....}

and in the draw function, just one line replaces all the code (except maybe number 28, where you draw extra stuff)

sprite("Planet Cute:"..moveSprite.chars[self.i], self.pos.x, self.pos.y)

Thanks for understanding where I’m at @Ignatz! I should be able to go quite a ways before i get stuck again thanks to you! One tiny silly question: Are the two dots in
sprite("Planet Cute: "…moveSprite etc
significant?

Btw, my son really likes math. He is six and starting algebra. I got into catos hike and then codea because I wanted him to apply his math skills so he wouldn’t forget math or get bored with it. So he is even more motivated to get to the point where I can start teaching him codea so he can make his own games. Which means i need to hurry up and learn it! :stuck_out_tongue:

If you are ever in Las Vegas and need anything, let me know!