Limiting movement to 90º increments (IE: 0, 90 , 180, 270) on a grid (among other things)

Jsn95Jsn95 Member Posts: 6
edited November 2012 in Working with GS (Mac)
I'm working on an interesting top down slider puzzle game... My master plan here is to have random objects spawn via a table grid system, I think the grid will be comprised of 16x16 spaces. The player actor is 16x32 (the 16 side is the front / pushing side).

I just installed GS 0.10.1 if that matters

My "pusher"/player actor is unstoppable, so once the scene starts via "tap to start" the player actor does not stop moving. For whatever reason, none of my "press to touch commands" work, so I've currently got "tap to start" set up as on mouse button down (1 time) to start movement, and since touching doesn't work so I've set "turning" the player actor to the left and right key since touching isn't working... I've already got turning set to 90º at a time to either the left or right and that seems to work fine.. So thus far, the player actor moves, and pushes things, although not quite how I want it to on an iphone, becuase the "touch doesn't work".

So anyway, now that you get the gist of what I'm doing here... keeping in mind that my random spawn grid of pushable/non-pushable actors is 16x16... Can I limit movement of the player actor to spaces in the grid while still being unstoppable, but rotating it's 16x32 body when commanded to turn into the nearest 16x16 space in the grid?

Or am I over my head here?

Comments

  • famekraftsfamekrafts Member, BASIC Posts: 834
    Show us your code so we can understand why it's not workin. Take a screenshot and give us link.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    If you want to constrain the actor to grid squares, you would use this:

    Change Attribute self.position.X to ceil(self.position.X/game.gridSize)*game.gridSize.

    The formula takes the X value and divides it by the grid size to figure out which grid square it is nearest and then rounds the value up and multiplies by the grid size to convert grid square # to X position.

    You would use this when Touch is Released or when no movement keys are being pressed.

    What I did in addition to this was to check mod(self.position.Y,game.gridSize) and if it was > game.gridSize/2, I used "ceil" (ceiling) in my formula; otherwise, I used "floor".

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.