❇❇ ╠╣ow to make a grid ❇❇

lukey5227lukey5227 Member Posts: 111
edited July 2012 in Community Tutorials

╠╣ow to make a grid

I've seen a lot of people saying its difficult for them to make just a simple grid. Its actually simpler then you may think! I'll first give a basic grid and then have other suggestions for other scenarios you may encounter. I know it seems long but sometimes I'll over explain certain things so others understand also.

STEPS

1) Create your actor
This is the actor that will move in the grid-like movement.

2) Make two new attributes
These will be integers. A column and row attribute (these attributes should be inside the actor).

3) Make the arrow key rules
IF left arrow key is pressed, col - 1, right is pressed, col + 1, up is pressed, row + 1, down is pressed, row - 1.

4) Constrain the two attributes
To make sure that the attributes you've added don't go overboard, constrain col to max(1,min(Game.Grid-Size,col)) and row to max(1,min(Game.Grid-Size,col)). This means that The lowest possible value is 1 and the highest is the number of squares in your grid there are.

5) Constrain the position
Finally, constrain your actor's X position to (col*Square-Grid-Size) + padding (Square-Grid-Size is the size of the squares in your grid) and Y to row*Square-Grid-Size + padding. These may seem switched but going left and right means switching columns. Going up and down means switching rows. This is why we made the arrow keys do what they're doing now in Step #3. Adding padding is optional although allows you to have free sides. This gives an auto padding of half the square-grid-size. To remove this padding or add fine padding, look at Step #6.

(Optional) 6) Instead of constraining to (col*Square-Grid-Size) + padding, constrain it to ((col - 1)*Square-Grid-Size) + (Square-Grid-Size/2) + padding. Replace col with row for Y placement. This means if col and row are 1, they'll both be put to 0, making the multiplication useless. Half the size of the grid would bring you to the center square. You are now free to add padding as normal!

Good luck on your grid like game!

5227 Tutorials

Comments

  • creativeappscreativeapps Member Posts: 1,770
    Good One Lucas...:)
  • NY415NY415 Member Posts: 25
    I would also suggest putting in an additional rule to stop diagonal movement
    For example UP you can put in a rule so that it will only move up if
    if game.UP > game.LEFT
    if game.UP > game.RIGHT

    I put it as 2 different rules because I couldn't find an OR function
  • Shadow_DevelopmentShadow_Development Rocklin, CA. United StatesMember Posts: 85
    Great tutorial. I love how you explain in further depth than the some of the YouTube tutorials. Keep up the awesome work.
Sign In or Register to comment.