Move infinitively in a direction.

FloridaGamesFloridaGames Member Posts: 328
edited March 2012 in Working with GS (Mac)
someone, I can't recall who, posted this template on the forums a while back and I always kept it. It is giving me some problems though. I want it so when you press left,right,up, or down instead of moving over 1, it moves over until it hits a wall.
Heres the project: http://dl.dropbox.com/u/66596212/Collision_With_Tables.zip .
As always, any help would be very appreciated.

Best Answer

  • tatiangtatiang Posts: 11,949
    edited March 2012 Accepted Answer
    Loops are a bit unwieldy in GameSalad, but generally I have two timers, one inside the other. The outer one is a "for" timer (e.g. for 2 seconds) and the inner one is an "every" timer (e.g. every 0.1 seconds) with a change attribute behavior at the end to increase the column or row number. I took a screenshot of one such rule (it only uses a single timer, though):

    image

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

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2012
    It's a great template posted by @UtopianGames here: http://forums.gamesalad.com/discussion/38411/free-tables-template-from-dba. If you look at the move left rule -- for example -- it is changing the cellvalue to the cellvalue in the table column to the left of the current location. Then, if that value is not a wall (is false), it changes self.position.x to self.position.x minus the width of the actor. That effectively moves it over one square to the left. To move it until it hits a wall, you would create a loop that checks the next square to the left and continues to do this but increases an attribute that stars at 0 (e.g. game.MoveLeftCount) by one if the square to the left is empty (table cell value is false). If you come across a true value, stop the loop (or just let it complete but don't keep counting) and move the player by changing self.position.x to self.position.x minus self.width*game.MoveLeftCount.

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

  • FloridaGamesFloridaGames Member Posts: 328
    Thanks so much! How would I create a loop, I tried " Every .01 second: if tablecellvalue is false change attribute left count +1" The tablecellvalue is indeed false, I tested w/a display text behavior, but it wouldn't increase the leftcount attribute.
Sign In or Register to comment.