GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

"Tetris"-like tiled puzzle help

Hello guys,
I'm working on a puzzle game, think of tetris, but not exactly like that. The main difference is that I have just squares and not different shapes.
I've been able to spawn the tiles on top of the screen and make them move down and then stop if they collide with the baseline of the grid or with another tile.
I'm not sure how to avoid the tiles overlapping other tiles if I try to move left or right the current tile while falling down. Explaining it seems complicated, so I made a sketch.

In this scheme the yellow tile is the current one the user is controlling, the grey ones are the ones already positioned. As you can see the yellow tile has other tiles on the left and free space on the right. I want the user to be able to move right but not left in this case.

I don't want to use a "collide" because I want tiles to be perfectly locked on the grid and not moving with physics, so I don't want to push tiles. Well, like in Tetris you know.

What could be an easy way to do this?

To sum up the thing I want to achieve: the user is able to control one tile at a time while falling down, they can move left or right (of a fixed amount of pixels, like on a grid) the piece and rotate it (but this is not important now), untile it collide with the ground or another tile underneath. Then it stops and another piece falls down from the top.

thanks for your help

Wonder Maru: casual games for casual people. www.wondermaru.com

Comments

  • Wonder MaruWonder Maru Posts: 98Member, PRO

    a solution I thought is this:

    I create 2 other actors "sensor_left" "sensor_right", the same height as the tile and I spawn them along with the tile, one to its left and one to its right, and move them along with it.
    I create 2 boolean attribute like "left_side_open" and "right_side_open".
    In the sensor actors I put a condition that if that actor collide with a tile the boolean corresponding to that side is false (so there's no open space there).
    Once the tile is positioned I destroy the sensor actors and reset the attributes.

    Makes sense, right?

    Wonder Maru: casual games for casual people. www.wondermaru.com

  • Wonder MaruWonder Maru Posts: 98Member, PRO

    that solution is trickier than I thought. Any other ideas?

    Wonder Maru: casual games for casual people. www.wondermaru.com

  • RThurmanRThurman Posts: 2,820Member, Sous Chef, PRO

    Tetris is basically a grid with squares that light up. The actors (sprites) don't really move.

    It is much easier to make a grid-based Tetris game. Just make a 10x10 table (for example). Then populate your scene with a 10x10 grid of actors. Each actor lights up as its corresponding table cell is activated. (For example, set each actor up with a rule that says when its corresponding table cell has a value of 1, then set the actor's alpha to 1. Otherwise set alpha to 0.

  • Wonder MaruWonder Maru Posts: 98Member, PRO

    I see, but this makes the "movement" very flashy, I'd like to have something less "old school" and smoother :/

    Wonder Maru: casual games for casual people. www.wondermaru.com

  • JapsterJapster Posts: 672Member
    edited October 2016

    @Wonder Maru said:
    I see, but this makes the "movement" very flashy, I'd like to have something less "old school" and smoother :/

    You could always use a push to initiate an interpolate/smoothly move your tile across to the next exact grid position, and only once there (ie. aligned perfectly) poll for a movement again? - That way you can use @RThurman's idea, but just storing the blocked/wall and 'free' squares instead, then keep track of your character's X,Y location within the 'grid', and compare against it in the table, to provide blocked or allowable direction choices, once it reaches a new location in it/on screen?

    I did something similar with a Tetris game I wrote on my C64 decades ago, using sprites... :smiley:

    Basically, your actor is only moving to reflect it's position within the table, kind of like cheating to make a character/grid-based screen... :smile: So you can move it smoothly...

    Failing that, you can move by 1 pixel at a time, anywhere you like, etc, but just keep track or the four corners (Xpos-width/2, Xpos+width/2, same with Ypos, to get 4 corner coordinates) (i.e. divide by pixels per on-screen square) to keep track of which 'grid' location(s) it's currently in.... :) then you know if a move 1 more pixel across, will take it into an 'occupied' square?

    First method's definitely easier though, but the second gives absolute pixel control! :smiley:

  • -Timo--Timo- Posts: 2,313Member

    The falling doesn't look perfectly smooth unfortunately.. and it's still far from perfect but it maybe helps and gives you some ideas.

  • Wonder MaruWonder Maru Posts: 98Member, PRO

    thank you!!! I'll check it out :)

    Wonder Maru: casual games for casual people. www.wondermaru.com

  • KevinCrossKevinCross London, UKPosts: 1,893Member
    edited October 2016

    I have a template I created ages ago which does this. It was a columns game/template so 3 blocks were dropping at once. You might be able to salvage something useful from it. There's a video on the page showing it in action.

    http://www.kevincross.co.uk/?attachment_id=143

  • Wonder MaruWonder Maru Posts: 98Member, PRO

    @KevinCross said:
    I have a template I created ages ago which does this. It was a columns game/template so 3 blocks were dropping at once. You might be able to salvage something useful from it. There's a video on the page showing it in action.

    http://www.kevincross.co.uk/?attachment_id=143

    man, this is awesome! Sorry for the late reply, I've been busy and couldn't work on the project. I'm gonna be back on it tonight. I'll check you project for sure! It seems to be doing almost exactly what I'm looking for!
    so cool!
    Thanks!

    Wonder Maru: casual games for casual people. www.wondermaru.com

Sign In or Register to comment.