Trouble with collisions

  • Hey there guys!

    I'm developing a tetris like game for mobile. I had a hadache getting the movement mechanics to work, since I'm a newbie, and because I wanted to move the blocks with swipe controls on the mobile. In the end, I came up with this function.

    It may be a little messy, but it worked perfectly. I'm using 16x16 tiles, so this is why there is so many /16 and *16. Is to always keep the blocks inside the 16px grid. The "touchDistanceForFrames1to5" is to compensate the distance between the touch and the block (so the block won't simply teleport to the touch's X location).

    Now to the problem: I can't make the blocks collide to the laterals of the game area (I've created 2 very tall retangles for the collisions, one to the left and other to the right). I got all sorts of problems. I simply couldn't make the blocks stay inside the playable area. I've tried on collision, is overlapping, nothing worked.

    Any tips on how to get this collision working? Or maybe to simplify all this mess with the movements?

    Thankssssss!

  • Now to the problem: I can't make the blocks collide to the laterals of the game area (I've created 2 very tall retangles for the collisions, one to the left and other to the right). I got all sorts of problems. I simply couldn't make the blocks stay inside the playable area. I've tried on collision, is overlapping, nothing worked.

    Any tips on how to get this collision working? Or maybe to simplify all this mess with the movements?

    Thankssssss!

    for the best tetris example/collision i found this a long time ago on the C2 section, it should work on C3 i have a clone of my own based on the mechanics of it, with more advanced features including swiping and holding pieces like tetris blitz. however i postponed it cause i wanted to do the tap choice lane type of thing, but the movement for swiping should be working just fine as you would replace the keyboard input with swipe input or distance from initial touch to the current touch. everything else should be the same.

    i can't share my clone but you can look at the mechanics of the original tutorial and you can figure it out. is pretty easy.

    tetris c2 clone

  • Thanks , I'll check that out! :)

  • Thanks , I'll check that out! :)

    no problem, however the swiping movement for mobile i find it a bit glitchy for tetris type of game, that's why i found the EA tetris blitz version taken that level of wrong input into a simplistic way of doing things, which is predicting each movement or find a place where the pieces can fit and just tap on it. for the regular user on mobile is much more convenient, on pc/keyboard/gamepads/joystics we don't have that issue we can quickly tap the keys and arrange the pieces, but mobile wise we don't have a keyboard to interact with it(unless you get a joystick type of controller for mobiles), from my experience swiping is just not cut for this game.

    but have fun on trying to implement it, i know i had! ^_^

    edited: you might not need to do the swipe, but basically if user keeps the touch on left side of screen u move blocks to left and if they keep pressed on right side of screen the blocks move to right, the collision stop should work the same as the tutorial as they will cancel out your input when they hit the margin blocks. or you can use the touch input on start and some variables to keep track of distance, speed, direction etc. but there are to many things in my opinion.

    swiping itself is a bit of a weird input honestly, and you can "fake it" by using some hidden sprite that u can drag and stuff but its just overcomplicating things for something that shouldn't be that hard to begin with.

    also have you figured out yet, what input would u use to rotate the blocks? ^_^ ..... (are you going with tap?) ....

  • Yeah, I found the swipe really complicated and kinda frustrating too. I thought it would be something very simple to implement (actually I thought there would be some swipe input on Construct). I wanted to use swipe because I think is so more intuitive to use on mobile than tapping the screen...

    For the rotate I used tap. I created 2 variables for touchStart and touchDuration, being touchStart = on any tap start set to time, and touchDuration = on any tap end set to time-touchStart. When the touchDuration is longer than 0.3 it activates the swipe, when is shorter it does the rotation. I did it this way so it wouldn't rotate every time you swiped. It worked pretty much perfectly ^^

    Now I'm actually thinking about using just taps to move the blocks... How would you suggest doing the rotations?

  • Now I'm actually thinking about using just taps to move the blocks... How would you suggest doing the rotations?

    ^_^ ... that's where i was stuck as well, cause there is no screen space for buttons the game area covers almost everything, and my template has even the left side "hold piece" and if i make the gameplay screen smaller i would had to squint my eyes to play which isn't very good.

    but i guess swiping up could be a rotation possibility, tapping to move and swipe down to force down the blocks.

    the problem with your delay of 0.3 to activate swipe is that it works good on low levels right? cause the speed of blocks is slow, but the moment you are like level 10 or 20 or whenever u increase the speed the blocks, the waiting 0.3 to activate movement fails, that's why i think tetris blitz got it perfect as movement for mobile, the game shows you all the available moves of the current piece in play, and u just select one of the possible moves. I stopped my tetris development there, cause im kinda bad at arrays. ^_^

    however if your version has screen space, id just put a rotate button somewhere on the screen. and use the tap to move pieces. but my version doesn't have that luxury ^_^

    on my end i have the keyboard controls as secondary and works good so far, and mobile is in the workings for a couple of months now... im stuck at decision making on it.

    another reason i stopped development on it, is cause tetris company ltd has a monopoly on the gameplay (including every aspect of it patented, and any clone that is out there is going to be sued whenever it gets any revenue that makes some more than a cup of coffee. you can license the game from them, and clone it, but is probably gonna cost to much to be feasible.)

    so im not really sure i want to make a tetris clone anymore for a while now ^_^ and spend my time on marketing it and be then taken down.

  • andreluizgollo

    I have been working on a tetris clone for a while too... I have been trying to copy the way the old iphone Tris game worked (before EA killed it long ago) - it was by far my favorite tetris game. I had it on my phone up until not too long ago when it finally was no longer compatible with iOS. I really liked how smoothly the pieces moved...

    you can drag a piece left or right, up or down, a swiping motion down will drop the piece. a tap rotates the piece.

    it has been difficult to duplicate the feel, but I think I am getting close. What I do is track how far a touch has moved from the initial point, and how many ticks it has been in touch. when the touch ends, if it has moved less than a minimum threshold, and for less than a set number of ticks, it considers that a tap and tries to rotate. If the touch moved more than a certain threshold down, but not horizontally, and for less than 15 ticks, then it considers that a swipe down and drops the piece to the bottom.

    that way there is no delay in moving the piece... you start moving the piece right away, and decide later if it was a tap or swipe.

    you can try my version here: (although it is still really buggy). https://www.rieperts.com/games/tetris/

    one of the problems is that I don't have the piece drift to be aligned to a column when you stop dragging yet. if it can't move it snaps into place before it locks the piece down... I had it rounding off to the nearest column, but if it was less than half way to a column it would snap back and that didn't look right so that is turned off in this version.

    if you drag too long the movement gets weird, and right now, it doesn't limit how long you can drag it upwards, and this version never speeds up...

    I was also testing particles - other interface things that only partially work so it isn't ready for anything other than proof of concept, lol :)

    oh, if you are playing with keyboard and mouse, the pause and restart buttons don't do anything (they do with touch). But you can press "P" to pause, or press space bar to restart...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hey there. I ended up using taps to move the blocks. I used 2 invisible sprites on each side of the screen, and one in the middle for rotating. Also, for forcing the block down, I used swipe. I changed the 0.3 seconds to swipe distance. At least 15px of Y distance from touch start to touch end to be detected as a swipe. It is working pretty good and the game is mostly finished now. I'm not as happy as I was with moving the blocks with swipe, but still, it is very good. I'm preparing to publish it now. It'll be my first game on Google Play. :)

  • Awesome andreluizgollo, ^_^ good luck on the launch!

    AllanR looks good, but i tested it only on desktop, and dragging objects (swipping to move) didn't worked for me.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)