Topic:   Grid Nav?   (Read 20291 times)


0 Members and 2 Guests are viewing this topic.

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Grid Nav?
« on: December 15, 2010, 04:38:24 PM »
I am making a game that uses the grid navigation system, but I can't figure out how to make it so when I go to the edge of the card it goes to a new card. I know it's possible, because I've seen it in GM games, (quest of magic) but I need to know how to use it,
-zoo804
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Grid Nav?
« Reply #1 on: December 15, 2010, 05:22:53 PM »
Hurray! Great to see a new developer. :) This should do the trick, just pop it in a card script:

Code: [Select]
' --- Edit these vars to set the attributes of the grid.
gridMap$ = "0000"
gridSize = 7
tileSize = 44
northCard = [card number here]
southCard = [card number here]
westCard = [card number here]
eastCard = [card number here]

' --- Edit these vars to set the attributes of the player.
playerSprite$ = "player1.gif"
playerGridX = 4
playerGridY = 4
playerMoveSpeed = 16

' --- Determine the player's sprite coordinates based on its grid coordinates.
playerSpriteY = playerGridY * tileSize
playerSpriteY = playerSpriteY - tileSize
playerSpriteY = playerSpriteY + 5
playerSpriteX = playerGridX * tileSize
playerSpriteX = playerSpriteX - tileSize
playerSpriteX = playerSpriteX + 5
SPRITE 1 playerSpriteX playerSpriteY $playerSprite$$

'----------------------------------------------------------------------- -------------------------

ON KEYDOWN
 Â playerNewGridX = playerGridX
 Â playerNewGridY = playerGridY

 Â ' --- Check which direction the player wants to move in.
 Â IF keydown$ = "UPARROW" THEN playerNewGridY =playerGridY - 1
 Â IF keydown$ = "DOWNARROW" THEN playerNewGridY = playerGridY + 1
 Â IF keydown$ = "LEFTARROW" THEN playerNewGridX = playerGridX - 1
 Â IF keydown$ = "RIGHTARROW" THEN playerNewGridX = playerGridX + 1

 Â ' --- Check what kind of tile the player is trying to move onto. (check if it's traversable or not)
 Â playerNewGridXY = 0
 Â playerNewGridXY = gridSize * playerNewGridY
 Â playerNewGridXY = playerNewGridXY - gridSize
 Â playerNewGridXY = playerNewGridXY + playerNewGridX
 Â playerTile$ = MID$ gridMap$ playerNewGridXY 1
 Â IF playerTile$ = "0" THEN playerTile$ = "Empty"
 Â IF playerTile$ = "1" THEN playerTile$ = "Wall"

 Â '--- Check if the player is trying to leave the grid.
 Â IF playerNewGridX < 1 THEN
 Â   playerGridX = gridSize
 Â   GOTOCARD westCard
 Â END IF
 Â IF playerNewGridX > gridSize THEN
 Â   playerGridX = 1
 Â   GOTOCARD eastCard
 Â END IF
 Â IF playerNewGridY < 1 THEN
 Â   playerGridY = gridSize
 Â   GOTOCARD northCard
 Â END IF
 Â IF playerNewGridY > gridSize THEN
 Â   playerGridY = 1
 Â   GOTOCARD southCard
 Â END IF

 Â ' --- If the tile has no obstacles on it, move the player onto the tile.
 Â IF playerTile$ = "Empty" THEN
 Â   playerGridX = playerNewGridX
 Â   playerGridY = playerNewGridY
 Â END IF

 Â ' --- Determine the player's sprite coordinates based on its grid coordinates.
 Â playerSpriteY = playerGridY * tileSize
 Â playerSpriteY = playerSpriteY - tileSize
 Â playerSpriteY = playerSpriteY + 5
 Â playerSpriteX = playerGridX * tileSize
 Â playerSpriteX = playerSpriteX - tileSize
 Â playerSpriteX = playerSpriteX + 5
 Â SPRITEPATH 1 playerSpriteX playerSpriteY playerMoveSpeed
END KEYDOWN

Make sure to set the northCard, southCard, westCard and eastCard values at the beginning of the code. If the player walks off the grid to the left, the game will load whatever card number you assigned westCard, and so on.

If there's anything you don't understand, or if you'd like to add something to the engine, just ask. I love helping with grid navs! :D
« Last Edit: December 15, 2010, 05:28:30 PM by Silverwind »
I survived the spammage of 2007

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: Grid Nav?
« Reply #2 on: December 15, 2010, 07:19:45 PM »
2 in a week?! Huzzah!



Remember to submit a game to the GMG Cup! Winner gets 25$
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.

EqwanoX


  • Administrator

  • GMG Extraordinaire

  • *****


  • Posts: 1180
Re: Grid Nav?
« Reply #3 on: December 16, 2010, 10:10:57 AM »
you should use scrolling maps, then you can have every thing on one card

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Grid Nav?
« Reply #4 on: December 16, 2010, 03:19:33 PM »
Thanks for the help!
BTW sweet logo EqwanoX
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Grid Nav?
« Reply #5 on: December 16, 2010, 04:52:49 PM »
Hey silverwind,
This gives me a syntax error. Is it something I did wrong, or is the code not working properly.
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: Grid Nav?
« Reply #6 on: December 16, 2010, 05:09:43 PM »
That's odd, I must have typed an extra $ or something somewhere. What line does the error occur on? I'm too tired to look at it now, but I'll try to release a new template tomorrow morning with card switching incorporated. :)

EDIT:

Did you set values for northCard, southCard, eastCard and westCard? The values have to be a number, like this:

Code: [Select]
northCard = 5

EDIT AGAIN:

Hey Zoo, you should check out my video tutorials for new developers:
http://alstaffieri.com/gmguide.html
One of them shows you how to make a simple Storm The Castle game, which is a great exercise and gets you used to event based structures, such as ON TIMER.
« Last Edit: December 16, 2010, 05:18:35 PM by Silverwind »
I survived the spammage of 2007

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Grid Nav?
« Reply #7 on: December 16, 2010, 05:28:50 PM »
I just put the card script, but didn't delete my other grid nav stuff in the script. I was supposed to do that right.
-Zoo804
P.S. Watched all your videos 3 months ago. Good job
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Grid Nav?
« Reply #8 on: December 17, 2010, 10:34:35 AM »
3 months? What have you done with GM since then?
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Grid Nav?
« Reply #9 on: December 17, 2010, 07:16:01 PM »
I just joined GMG, but I've had GM for 1 or 2 years now. I don't make much worth putting on the site though. I only know some basic stuff.
-zoo804
Kirby, your pudgy buddy from dream land, is back again on the game boy®!

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: Grid Nav?
« Reply #10 on: December 18, 2010, 12:21:30 PM »
Hey it's great to see more members!
The first thing I made with GM was just a choose-your-adventure game with pictures and buttons. It's kind of what I'm doing now, but with Silver Creator. And more complicated. XD
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Zoo


  • GMG Extraordinaire

  • ***


  • Posts: 1686
    • My Bandcamp
Re: Grid Nav?
« Reply #11 on: February 09, 2011, 09:01:12 PM »
On the topic of the grid navigation template what do you use to put houses in RPGs?
Kirby, your pudgy buddy from dream land, is back again on the game boy®!