Game Maker's Garage Forum

Game Creation => GameMaker => Topic started by: Mystor on March 04, 2008, 02:11:10 PM

Title: GM Grid Systems
Post by: Mystor on March 04, 2008, 02:11:10 PM
This is my idea:

Because of the number of GM Grid Systems that silver has written, I think that we should have a place to put all of the code.

People can post the different Grid System's code (Preferabally along with a Grid Nav example)

Please refrain idle conversation :P

(This is because I can't find the code for grid nav v5 etc...)

Mist
Title: Re: GM Grid Systems
Post by: Silverwind on March 04, 2008, 03:26:51 PM
Wow, I was just planning to do that this morning, you practically used the very words I did! :D Great minds think alike.

I'm gonna update Roguesoft's download link for the Grid Nav Example when I get the V6 example done. I think it's V4 atm. ::)
Title: Re: GM Grid Systems
Post by: Mystor on March 04, 2008, 03:28:26 PM
Actually it is V5, the original V5 that is :p

As in the one without walls and portals, instead using other stuff :-/

The one with movecompleted etc...

Whatever, it is outdated :P

Mist
Title: Re: GM Grid Systems
Post by: Silverwind on March 04, 2008, 03:41:13 PM
Ah, that's slightly better at least. Here's the updated V6 template:
Code: [Select]
PICT CurrentCard
gridlayout$ = ""
area$ = "surface"
northcard = 0
southcard = 0
eastcard = 0
westcard = 0
playerY = gridY * 44
playerY = playerY - 39
playerX = gridX * 44
playerX = playerX - 39
moveY = gridY
moveX = gridX

SPRITE 15 playerX playerY $playersprite$$

'----PLAYER CODE--------------------------------------------------------------------------------
ON KEYDOWN
newtile$ = "empty"
IF keydown$ = "UPARROW" THEN moveY = gridY - 1
IF keydown$ = "DOWNARROW" THEN moveY = gridY + 1
IF keydown$ = "LEFTARROW" THEN moveX = gridX - 1
IF keydown$ = "RIGHTARROW" THEN moveX = gridX + 1
'----GRID CODE-----------------------------------------------------------------------------------
moveXY = 0
moveXY = 7 * moveY
moveXY = moveXY - 7
moveXY = moveXY + moveX
newtile$ = MID$ gridlayout$ moveXY 1
IF newtile$ = "0" THEN newtile$ = "empty"
IF newtile$ = "1" THEN newtile$ = "wall"
IF newtile$ = "2" THEN newtile$ = "portal 1"
'---/GRID CODE-----------------------------------------------------------------------------------
IF moveY < 1 THEN
  gridY = 7
  GOTOCARD northcard
END IF
IF moveY > 7 THEN
  gridY = 1
  GOTOCARD southcard
END IF
IF moveX > 7 THEN
  gridX = 1
  GOTOCARD eastcard
END IF
IF moveX < 1 THEN
  gridX = 7
  GOTOCARD westcard
END IF
IF newtile$ = "portal 1" THEN
  gridY = 0
  gridX = 0
  GOTOCARD 0
END IF
IF newtile$ = "empty" THEN
  IF keydown$ = "UPARROW" THEN playerY = playerY - 44
  IF keydown$ = "DOWNARROW" THEN playerY = playerY + 44
  IF keydown$ = "LEFTARROW" THEN playerX = playerX - 44
  IF keydown$ = "RIGHTARROW" THEN playerX = playerX + 44
  gridY = moveY
  gridX = moveX
END IF
IF newtile$ = "wall" THEN
  moveY = gridY
  moveX = gridX
END IF

SPRITE 15 playerX playerY
END KEYDOWN
'---/PLAYER CODE--------------------------------------------------------------------------------
Title: Re: GM Grid Systems
Post by: Mystor on March 04, 2008, 03:56:48 PM
Ok...

Based off of the current V5 Grid Nav example, I have made somthing work like smart nav.

Code: [Select]
SPRITE 10 playerX playerY player1.gif
CLEAR TEXT
PRINT playerX: $playerX$
PRINT playerY: $playerY$
PRINT
PRINT gridX: $gridX$
PRINT gridY: $gridY$
PRINT
PRINT moveX: $moveX$
PRINT moveY: $moveY$
PRINT
PRINT
PRINT movesuccessful: $movesuccessful$
PRINT keydown$: $keydown$$

ON KEYDOWN

directionkeypressed = 0
movesuccessful = 0
IF keydown$ = "UPARROW" THEN moveY = gridY - 1
IF keydown$ = "DOWNARROW" THEN moveY = gridY + 1
IF keydown$ = "LEFTARROW" THEN moveX = gridX - 1
IF keydown$ = "RIGHTARROW" THEN moveX = gridX + 1
IF keydown$ CONTAINS "ARROW" THEN directionkeypressed = 1
IF moveY < 1 THEN movesuccessful = 1
IF moveY > 7 THEN movesuccessful = 1
IF moveX < 1 THEN movesuccessful = 1
IF moveX > 7 THEN movesuccessful = 1
'----GRID CODE-----------------------------------------------------------------------------------

walls$ = " 54 25 46 17 67 77"
portals$ = ""
mypos = 10 * moveX
mypos = mypos + moveY
mpos$ = STR$ mypos
IF walls$ CONTAINS mpos$ THEN
  movesuccessful = 1
END IF
IF portals$ CONTAINS mpos$ THEN
  '(portal code)
END IF
'---/GRID CODE-----------------------------------------------------------------------------------
IF movesuccessful = 0 THEN
  IF keydown$ = "UPARROW" THEN playerY = playerY - 44
  IF keydown$ = "DOWNARROW" THEN playerY = playerY + 44
  IF keydown$ = "LEFTARROW" THEN playerX = playerX - 44
  IF keydown$ = "RIGHTARROW" THEN playerX = playerX + 44
  gridY = moveY
  gridX = moveX
  SPRITE 10 playerX playerY
END IF
IF movesuccessful = 1 THEN
  moveY = gridY
  moveX = gridX
END IF

CLEAR TEXT
PRINT playerX: $playerX$
PRINT playerY: $playerY$
PRINT
PRINT gridX: $gridX$
PRINT gridY: $gridY$
PRINT
PRINT moveX: $moveX$
PRINT moveY: $moveY$
PRINT
PRINT
PRINT movesuccessful: $movesuccessful$
PRINT keydown$: $keydown$$

END KEYDOWN

BTW, I know that the walls$ string has a space at the beginning, CONTAINS doesn't like the first character :(

Mist
Title: Re: GM Grid Systems
Post by: alias on April 09, 2008, 06:04:41 AM
I made an old grid system, i shall upload it someplace then put the link here...

EDIT:
LINK: http://myfreefilehosting.com/f/dcca1a19be_0.17MB bad link use this one
http://www.filefactory.com/file/6042cb
Title: Re: GM Grid Systems
Post by: Al Staffieri on April 10, 2008, 10:43:33 AM
Quote
I know that the walls$ string has a space at the beginning, CONTAINS doesn't like the first character

It's a problem with STR$.  When you convert a number to a string with STR$ it puts a space in front of the number unless it's a negative number.

x = 10
a$ = STR$ x
' the above makes a$ = " 10"

x = -10
a$ = STR$ x
' the above makes a$ = "-10"
Title: Re: GM Grid Systems
Post by: Mystor on April 10, 2008, 01:55:50 PM
I see!
Cool :)

Mist
Title: Re: GM Grid Systems
Post by: Silverwind on April 30, 2008, 03:26:56 AM
I've updated the V6 template to include TD's awesome upgrade. Now V6 is even more unstoppably unstoppable! :D
Title: Re: GM Grid Systems
Post by: Tireas Dragon on April 30, 2008, 10:22:20 AM
I still don't understand v5  ???  Well since its primitive compared to to the new v6 I guess it doesn't matter   :)