Achilles Posted December 22, 2008 Share Posted December 22, 2008 I have realized that there are many games that could utilize a nice simple set of functions for a grid of labels. So I made this... It has lots of room for expansion and I haven't checked it much. I have included an example script that shows what you can do with it so far.Download here: Grid.zipComments/suggestions/ideas/criticism welcome. I'll probably make a simple snake game soon. Some ideas I had concerning expansion and possible uses:Be able to use pictures OR labels, not just labelsTetrisAdvanced snake gamePac man like gameTic Tac ToeConnect 4Any others? My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Andreik Posted December 22, 2008 Share Posted December 22, 2008 It would be very easy to write a game like Snake (inspired by your example). When the words fail... music speaks. Link to comment Share on other sites More sharing options...
mvendak Posted January 14, 2009 Share Posted January 14, 2009 (edited) Nice UDF! I modified the grid create function to use pictures (as you suggested, it was easy to do). Its now part of a concept to make a rouge-like adventure game in Autoit:CODE#include <GUIConstantsEx.au3>Global $xGrid[1][1] ; an array containing all the control ID's for each item, Ichigo's grid udfGlobal $dungeonFloor[200][200] ;$dungeonFloor values may actually represent something other than floor (walls/black space/door), it would be more accurate the call it first layer (the only layer at this point)Global $dungeonExplored[200][200] ;squares already seen are rememberd by the character, so theres a picture there according to the squares "floor" type (floor/wall/etc)Global $dungeonMob[200][200] ;to be implementedGlobal $dungeonItems[200][200][20] ;to be implementedGlobal $charpos[2] ;main chars xyGlobal $images[100] ;collection of image paths used, 0 is black, 1 is default floor, 2 is default wall, 3 is our hero; needs to be split up to diffrent arrays for different types (floor/character/monster);FileInstalls here$maingui = GUICreate('game',640,320)$images[0]= @ScriptDir&"\black.bmp"$images[1]= @ScriptDir&"\floor.bmp"$images[2]= @ScriptDir&"\wall.bmp"$images[3]= @ScriptDir&"\door.bmp"$images[10]= @ScriptDir&"\hero.bmp"$charpos[0] = Random(1,10,1)$charpos[1] = Random(1,10,1)_CreateLevel_Memory(40,20)_CreateLevel_Gui(20, 40, 16, $maingui)$charControl = GUICtrlCreatePic($images[10],16*$charpos[0],16*$charpos[1],16,16)GUISetState(@SW_SHOW) HotKeySet("w","Test1")HotKeySet("s","Test2")HotKeySet("a","Test3")HotKeySet("d","Test4") while 1 Sleep(300) WEndFunc _CreateLevel_Gui($x, $y, $size, $gui) ;visualization of the "dungeon" as a grid of pictures. Based on the Grid UDF made by Ichigo If $x < 0 or $y < 0 or $size < 0 then Return -1 ReDim $xGrid[$x][$y] $bX = $x $bY = $y GUISwitch($gui) For $x = 0 to $bX - 1 For $y = 0 to $bY - 1 if $dungeonExplored[$x][$y] = 0 then $xGrid[$x][$y] = GUICtrlCreatePic($images[0], $y * $size, $x * $size, $size, $size) ;most of the place is black... Else $temp = $dungeonFloor[$x][$y] $xGrid[$x][$y] = GUICtrlCreatePic($images[$temp], $y * $size, $x * $size, $size, $size) ;however, a few blocks are already "seen" by the mainchar at startup EndIf Next Next Return 1EndFuncFunc _CreateLevel_Memory($sizex, $sizey) ;creating the floor and a little house/fort/whatever for the character to start in. Some algorith to generate a level goes herefor $x=0 to $sizex for $y=0 to $sizey if $dungeonFloor[$y][$x] = "" Then ;this is needed so the default squre type wont override rooms/corridors created before (not implemented yet) $dungeonFloor[$y][$x] = 1 ;set everything to 1, walkable floor. $dungeonExplored[$y][$x] = 0 ;nothing is explored yet EndIf NextNext_CreateRoom($charpos[0] - 1 ,$charpos[1] - 1, 4, 12, 3) ;bigger room, the character starts in this one_CreateRoom($charpos[0] + 2 ,$charpos[1] - 1, 4, 4, 4) ;smaller rooms, with doors to the left, overlapping one wall with oneanother_CreateRoom($charpos[0] + 5 ,$charpos[1] - 1, 4, 4, 4)_CreateRoom($charpos[0] + 2 ,$charpos[1] + 5, 4, 4, 4)_CreateRoom($charpos[0] + 5 ,$charpos[1] + 5, 4, 4, 4)For $x = -1 to 1 for $y = -1 to 1 $dungeonExplored[$charpos[1] + $y][$charpos[0] + $x] = 1 ;the squares next to the character start as explored NextNext EndFuncFunc _CreateRoom($startx, $starty, $sizex , $sizey, $melyikfal = "") ;creates a square room. last variable is the side of the room to have its door on$sizex -= 1 ;room dimensions corretion, so _CreateRoom(10, 10, 4 , 4) is a 4x4 room rather then a 5x5$sizey -= 1$x = $startxfor $y=$starty to $sizey + $starty ;top wall $dungeonFloor[$y][$x] = 2 $dungeonExplored[$y][$x] = 0Nextfor $x = $startx + 1 to $sizex + $startx ; everything else, walls on the starting and ending position $y=$starty $dungeonFloor[$y][$x] = 2 $dungeonExplored[$y][$x] = 0 for $y=$starty + 1 to $sizey + $starty $dungeonFloor[$y][$x] = 1 $dungeonExplored[$y][$x] = 0 Next $y=$sizey + $starty $dungeonFloor[$y][$x] = 2 $dungeonExplored[$y][$x] = 0Next$x = $startx + $sizexfor $y=$starty to $sizey + $starty ;bottom wall $dungeonFloor[$y][$x] = 2 $dungeonExplored[$y][$x] = 0NextIf $melyikfal = "" then $melyikfal = Random(1,4,1) ;after the room is created one door is created. numbers are clockwise 1:top 2:right etcSwitch $melyikfal Case 1 ;if top wall $hol = Random(1,$sizex -1,1) $dungeonFloor[$starty][$startx+ $hol] = 3 Case 2 ;if right wall $hol = Random(1,$sizey-1,1) $dungeonFloor[$starty+ $hol][$startx + $sizex] = 3 Case 3 ;if bottom wall $hol = Random(1,$sizex -1,1) $dungeonFloor[$starty + $sizey][$startx+ $hol] = 3 Case 4 ;if left wall $hol = Random(1,$sizey-1,1) $dungeonFloor[$starty+ $hol][$startx] = 3EndSwitchEndFuncFunc _MoveCharacter($direction) ;Character tries to go in a certain direction. To do: split up to more functions, so other objects (monsters?) may access those functions $temp = $xGrid[$charpos[1]][$charpos[0]] ;point where he tries to move from Switch $direction Case "up" If $charpos[1] <> 0 AND $dungeonFloor[$charpos[1] - 1][$charpos[0]] = 1 Then ;floor there (first part to avoid errors at the edges of the map) $charpos[1] -= 1 ;walk on that floor ElseIf $charpos[1] <> 0 AND $dungeonFloor[$charpos[1] - 1][$charpos[0]] = 3 Then ;door there $siker = _OpenDoor($charpos[1] - 1,$charpos[0]) ;try to smash it return $siker ; successfull or not Else return 0 EndIf Case "down" If $charpos[1] <> UBound($xGrid,1) -1 AND $dungeonFloor[$charpos[1] + 1][$charpos[0]] = 1 Then $charpos[1] += 1 ElseIF $charpos[1] <> UBound($xGrid,1) -1 AND $dungeonFloor[$charpos[1] + 1][$charpos[0]] = 3 Then $siker = _OpenDoor($charpos[1] + 1,$charpos[0]) Else return 0 EndIf Case "left" If $charpos[0] <> 0 And $dungeonFloor[$charpos[1]][$charpos[0] - 1] = 1 Then $charpos[0] -= 1 ElseIf $charpos[0] <> 0 And $dungeonFloor[$charpos[1]][$charpos[0] - 1] = 3 Then $siker = _OpenDoor($charpos[1],$charpos[0] - 1) return $siker Else return 0 EndIf Case "right" If $charpos[0] <> UBound($xGrid,2) -1 AND $dungeonFloor[$charpos[1]][$charpos[0] + 1] = 1 Then $charpos[0] += 1 ElseIf $charpos[0] <> UBound($xGrid,2) -1 AND $dungeonFloor[$charpos[1]][$charpos[0] + 1] = 3 Then $siker = _OpenDoor($charpos[1],$charpos[0] + 1) Return $siker Else return 0 EndIf EndSwitchGUICtrlSetState($temp,$GUI_SHOW) ;the square you stood on was hidden, now its visible again as you moved away from itFor $y = -1 to 1 ;render your new surroundings: set those squres to explored, and show their picture accoring to "floor" value for $x = -1 to 1 If $x = 0 and $y = 0 then ContinueLoop ;no need to set this one anyway If $charpos[1] + $y >= 0 And $charpos[0] + $x >=0 AND $charpos[1] + $y <= UBound($xGrid,1) -1 AND $charpos[0] + $x <= UBound($xGrid,2) - 1 Then ;errors avoided $img_n = $dungeonFloor[$charpos[1] + $y][$charpos[0] + $x] GUICtrlSetImage($xGrid[$charpos[1] + $y][$charpos[0] + $x], $images[$img_n]) $dungeonExplored[$charpos[0] + $x][$charpos[1] + $y]=1 EndIf NextNextGUICtrlSetState($xGrid[$charpos[1]][$charpos[0]],$GUI_HIDE) ;hide the square you step onGUICtrlSetPos($charControl,16*$charpos[0],16*$charpos[1]) ; move the picture of the main charGUICtrlSetState ($charControl ,$GUI_ONTOP) ;not sure if this is needed...return 1EndFuncFunc _OpenDoor($bX,$bY)$kocka = Random(0,100,1) ;d100 dice to get success of door "opening" (right now: smashing)Switch $kocka Case 1 to 75 ; 3 out of 4, you fail return 0 case 76 to 100 ;you smash the door $dungeonFloor[$bX][$bY] = 1 ;the door there is now a floor GUICtrlSetImage($xGrid[$bX][$bY], $images[1]) ;and its image updates return 2 EndSwitchEndFuncFunc Test1() _MoveCharacter("up")EndFuncFunc Test2() _MoveCharacter("down")EndFuncFunc Test3() _MoveCharacter("left")EndFuncFunc Test4() _MoveCharacter("right") EndFunc So this is it. You cant do much yet, just smash the doors of the starting fort and then explore the outsides = lots of floor type squares. The 16x16 images I painted:http://img502.imageshack.us/img502/2978/blacklv1.bmphttp://img516.imageshack.us/img516/3462/doorxp7.bmphttp://img164.imageshack.us/img164/2861/floorgu2.bmphttp://img102.imageshack.us/img102/2757/herozp2.bmpDownload to the script folder if you dont feel like painting your own. (Sorry, im a newb and the forum wont accept these within IMG tags, "bad format") Edited January 14, 2009 by mvendak Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now