Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

nctse

1
Posts
1
Topics
A member registered Feb 18, 2017 · View creator page →

Creator of

Recent community posts

TIC-80 community · Created a new topic Camera

I am having difficulties working out how to move my player into different rooms on the map. I also noticed if I called a different room e.g. map (rget(9)) then the memory of collision would still remain as if I was in map(rget(1)) even if the screen was alpha colour. Plus I don't know how to call multiple rooms on the map. Can any one give me any tips about how to move between rooms or use a camera or screen scrolling. I am only new to Lua and TIC-80. I've look at other game code, but can't find any simple functions or tutorials. Here is my code. Thanks


-- title:  Neilo
-- author: Neil
-- desc:   Platformer
-- script: lua

 -- Objects
  solids={[3]=true,[4]=true}
  bads={[5]=true}
  doors={[6]=true}

 -- Player 
  t=0
  p={
    x=120,
    y=72,
    vx=0, -- Velocity X
    vy=0, -- Velocity Y   
  }
  
function init()  
  music(0)
  
end
init()
function TIC()
  -- move left and right
  if btn(2) then
    p.vx = -1
  elseif btn(3) then
    p.vx = 1
  else
    p.vx = 0
  end
 
  -- jump
  if p.vy == 0 and btn(4)
  then
    sfx (1)
    p.vy = -3.0
  end
  
  -- side-collisions
  if solid(p.x + p.vx, p.y + p.vy)
  or solid(p.x + 7 + p.vx, p.y + p.vy)
  or solid(p.x + p.vx, p.y + 7 + p.vy)
  or solid(p.x + 7 + p.vx, p.y + 7 + p.vy)
  then
    p.vx = 0
  end
  
  -- gravity
  if solid(p.x + p.vx, p.y + 8 + p.vy)
  or solid(p.x + 7 + p.vx, p.y + 8 + p.vy)
  then
    p.vy = 0
  else
    p.vy = p.vy + 0.2
  end
  
  -- top-collisions
  if p.vy < 0
  and (solid(p.x+p.vx, p.y + p.vy)
        or solid(p.x + 7 + p.vx, p.y + p.vy)
      )
  then
    p.vy = 0
  end
  
   -- side-collisions with bad
  if bad(p.x + p.vx, p.y + p.vy)
  or bad(p.x + 7 + p.vx, p.y + p.vy)
  or bad(p.x + p.vx, p.y + 7 + p.vy)
  or bad(p.x + 7 + p.vx, p.y + 7 + p.vy)
  then
     p.x=120
     p.y=68
  end
  
   -- side-collisions with door
  if door(p.x + p.vx, p.y + p.vy)
  or door(p.x + 7 + p.vx, p.y + p.vy)
  or door(p.x + p.vx, p.y + 7 + p.vy)
  or door(p.x + 7 + p.vx, p.y + 7 + p.vy)
  then   
     p.x=220
     p.y=10
     end
  
  p.x = p.x + p.vx
  p.y = p.y + p.vy
  
  cls()
 map(rget(1))
  spr(1+(t%60)/30, p.x, p.y)
  t=t+1
end


function solid(x,y)
  -- the // divides and rounds down
  return solids[mget((x)//8, (y)//8)]
end

function bad(x,y)
  -- the // divides and rounds down
  return bads[mget((x)//8, (y)//8)]
end
function door(x,y)
  -- the // divides and rounds down
  return doors[mget((x)//8, (y)//8)]
end


--divide the map into rooms
rooms = {}
 for x = 0,240-30,30 do
  for y = 0,136-17,17 do
   table.insert(rooms, {x,y})
  end
 end


--returns the room by index (1-64)
function rget(i)
 return rooms[i][1],rooms[i][2],30,17
end