Help with collision!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
florodude
Prole
Posts: 20
Joined: Mon Jul 30, 2012 10:16 pm

Help with collision!

Post by florodude »

Here is how I coded my map.

Code: Select all

   Tileset = love.graphics.newImage('tile.bmp')
  
TileW, TileH = 50,50
tilesetW, tilesetH = Tileset:getWidth(), Tileset:getHeight()
  
 grassq = love.graphics.newQuad(0,  0, TileW, TileH, tilesetW, tilesetH)
 BoxQuad = love.graphics.newQuad(32, 0, TileW, TileH, tilesetW, tilesetH)



  local tileString = [[
ssssssssssssssss
ssssssssssssssss
ssssssssssssssss
ssssssssssssssss
ssssssssssssssss
ssssssssssssssss
wwwwwwwwwwwwwwww
wwwwwwwwwwwwwwww
wwwwwwwwwwwwwwww
wwwwwwwwwwwwwwww
wwwwwwwwwwwwwwww
wwwwwwwwwwwwwwww
]]


local quadInfo = {
  { 's', 0,  0 , 0 }, -- sand
  { 'w', 50, 0 , 1},  -- water
  { '#', 10, 0, 0 },  -- tiles
    { 'g', 150, 0 , 0 },  -- grass
}


Quads = {}
for _,info in ipairs(quadInfo) do
  -- info[1] = character, info[2]= x, info[3] = y
  Quads[info[1]] = love.graphics.newQuad(info[2], info[3], TileW, TileH, tilesetW, tilesetH)
end

TileTable = {}

local width = #(tileString:match("[^\n]+"))

for x = 1,width,1 do TileTable[x] = {} end

local rowIndex,columnIndex = 1,1
for row in tileString:gmatch("[^\n]+") do
  assert(#row == width, 'Map is not aligned: width of row ' .. tostring(rowIndex) .. ' should be ' .. tostring(width) .. ', but it is ' .. tostring(#row))
  columnIndex = 1
  for character in row:gmatch(".") do
    TileTable[columnIndex][rowIndex] = character
    columnIndex = columnIndex + 1
  end
  rowIndex=rowIndex+1
end

columntest = 1
rowtest = 1

function drawmap()
  for columnIndex,column in ipairs(TileTable) do
    for rowIndex,char in ipairs(column) do
      local x,y = (columnIndex-columntest)*TileW, (rowIndex-rowtest)*TileH
      love.graphics.drawq(Tileset, Quads[char], x, y)
    end
  end

end

And I want to set it so in the fourth arguement of the QuadInfo table, the value is either 0 or 1 for passable or impassible tile. How would I set this up?
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Help with collision!

Post by substitute541 »

.
.
.
.

Okay sorry for the breadcrumbs but, If you are going to add a new line to the string, you MUST add "\n". And I suggest not using "[[ ]]". Just use double quotes, It's much easier to understand (the first time I looked at your "tileString", I thought it was a table).
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Help with collision!

Post by kikito »

substitute541 wrote:If you are going to add a new line to the string, you MUST add "\n". And I suggest not using "[[ ]]". Just use double quotes, It's much easier to understand (the first time I looked at your "tileString", I thought it was a table).
I don't agree with any of this. Using [[]] for strings is the most common way in Lua to specify strings with lots of carriage returns, and makes \n unnecessary on this context.

substitute541, I suggest you get familiarized with this syntax instead. It's not going to disappear just because you don't know it :)
When I write def I mean function.
florodude
Prole
Posts: 20
Joined: Mon Jul 30, 2012 10:16 pm

Re: Help with collision!

Post by florodude »

Thanks for the suggestions...but any help with the question?
User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: Help with collision!

Post by IndieKid »

Did I understand you right that you want make it check if we need to draw a tile(1-draw, 2-return nothing)?
florodude
Prole
Posts: 20
Joined: Mon Jul 30, 2012 10:16 pm

Re: Help with collision!

Post by florodude »

No, I want the player to not be able to pass through the object.
User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: Help with collision!

Post by IndieKid »

florodude wrote:No, I want the player to not be able to pass through the object.
Can you, please, send me the whole project folder.
florodude
Prole
Posts: 20
Joined: Mon Jul 30, 2012 10:16 pm

Re: Help with collision!

Post by florodude »

User avatar
IndieKid
Citizen
Posts: 80
Joined: Sat Dec 22, 2012 7:05 pm
Contact:

Re: Help with collision!

Post by IndieKid »

You have player connected to pixel-grid and that's bad. Connect him to grid-map, and then check if movement is allowed.
florodude
Prole
Posts: 20
Joined: Mon Jul 30, 2012 10:16 pm

Re: Help with collision!

Post by florodude »

What would be the best way to go about doing that? Set coordinates and have a collision map?

So like...

Collision Map

001
001
111

And if the player is the X..
000
0X0
000

he'd be on like coordinate 2,1? I'm just confused on the best way to do this I guess, thanks for all your help so far by the way, I figured I'd need to implement some sort of grid system.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests