[solved] tilemap collision problems

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.
Post Reply
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

[solved] tilemap collision problems

Post by mk8 »

helo, so im trying to make this tetris clone, and everything is working except that the actual gameplay doesnt, the collision detection (atleast i think thats it) is basically making u lose instantly
im linking the .love file, i recommend playing it w/console because i have made some debug,
the collision detection code is tetris.lua at lines 278-295 and the code that locks the pieces in place is in the same file at lines 133-163
thanc in advanc
EDIT: to give a deeper explanation how the code works:
each piece is represented by four squares, each with an x and a y coordinate { {x1,y1}, {x2,y2}, {x3,y3}, {x4,x4} }
however, they are not stored in the piece variable directly - all possible pieces (each rotation is a separate piece) are stored in a table and the piece variable controlled by the player only has 3 components: x and y position and an id, determining which one of the (19) possible pieces & rotations the player controls. there is only one function for checking collisions - you supply it with the position (x and y) and the id of the piece you want to check collisions for, and it should check if any of the squares is either out of bounds, or overlapping with the board (the board is a tilemap with either 0s (no square) or a value from 1 to 3 (the square graphic, all should act the same)), and returns true if it does. the locking-in-place is fairly simple - the game checks if the piece can be moved down (checks with the coordinates x, y + 1) and if it can't, it adds all 4 of its squares into the tilemap (this part works). the problem is, the overlap checking code returns true even if on the very top of the board, when it's all empty (found out through debugging). can anyone help? (btw thak you for your time if you read all this and decide to help you're *awesome*)
Attachments
tetris thing.love
(15.13 KiB) Downloaded 78 times
Last edited by mk8 on Thu Dec 09, 2021 9:05 am, edited 1 time in total.
hippity hoppity ur code is my property (thanc in advanc)
User avatar
pgimeno
Party member
Posts: 3541
Joined: Sun Oct 18, 2015 2:58 pm

Re: tilemap collision problems

Post by pgimeno »

My understanding is that the piece is colliding with itself. You'd need to add it to the board *after* checking collisions.

I've had a lot of problems with your handling of line endings, in this line of retroinput.txt:

Code: Select all

local d_key, d_controls = data[1], data[2]:sub(1, -newline:len()+1)
because when the length is 1, -1 + 1 = 0 and the result is an empty string. That can be just removed because unlike what Lua does, the CR at the end of the line is removed if present.
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

Re: tilemap collision problems

Post by mk8 »

so ive tried to improve it a bit, but it still doesnt work. can anyone help? the collision system is a bit different now, but its very similar (mostly in also not working bruh) to the old one. what i think happens is that the collision checking function somehow always returns true, or the code locks the pieces in either way. im linking the entire .love file, but all the code that doesnt work is in yeetris.lua, main.lua is one hell of a mess but works fine dont touch it alright?, and retroinput.lua has some flaws, but those are not very important rn. thanc for ur time
Attachments
yeetris.love
(14.86 KiB) Downloaded 82 times
hippity hoppity ur code is my property (thanc in advanc)
mk8
Prole
Posts: 34
Joined: Thu Apr 22, 2021 7:11 am

Re: tilemap collision problems

Post by mk8 »

ok so i figured it out, the problem was that the code for getting the playfield to draw was not returning a new table, but messing with the old one instead and instantly locked the pieces no matter what (function tetrs:getPlayfield()). i implemented a simple table copying function and it works fine now, tho thanks pgimeno for ur tips on the input library
hippity hoppity ur code is my property (thanc in advanc)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 19 guests