I'm working on programming a "snakes" game in Blitzmax.
This is basic idea;
1. The snake can move on tile objects which represents a big chessboard. The tiles are added to a TList. Each tile itself is a Type ("class") with some properties X,Y, tilenumber etc etc.
2. When the worm moves, the tile on which it is located gets a flag set.
3. This flagged tile is (temporarily) flagged as occupied.
4. My code loops throught the Tlist-"Chessboard" calling an update on each tile, like this:
the code here was typed at work from my head in MS-Word, not in the compiler. it can contain (spelling) mistakes.
The above attempts to;
1. fill a tlist chessboard containing tiles.
2. aloow the player to move onto a tile.
3. Flag the tile as occupied.
4. Loop through all tiles in chessboard, updating it.
Problem:
the clsTile.Update doesnt do anything. The tile isnt rendered. The reference obtained from the Tlist (probably) dont update the object it obtained. Is that true? How can i modify a object in Tlist by reference?
This is basic idea;
1. The snake can move on tile objects which represents a big chessboard. The tiles are added to a TList. Each tile itself is a Type ("class") with some properties X,Y, tilenumber etc etc.
2. When the worm moves, the tile on which it is located gets a flag set.
3. This flagged tile is (temporarily) flagged as occupied.
4. My code loops throught the Tlist-"Chessboard" calling an update on each tile, like this:
the code here was typed at work from my head in MS-Word, not in the compiler. it can contain (spelling) mistakes.
Type MySnakesGame Method manage() Graphics(800,600,0); '//...add about 480 tiles (32x30 pixels) on 800x600 display.. local chessboardList:TList = new TList; for Local count1:int = 0 to 470 Local chessTile:clsTile = new clsTile; chessTile.X = 30; '//ofcoz increments.. chessTile.Y = 30; '// same here chessTile.TileCounter = count1; chessTile.tiledOcuppiedBy = enumNobody; chessboardList.Addlast(chessTile); Next While not keyhit(key_escape) cls(); '//player moves, flag the tile as occupied '//handle keybord input, new X/Y is at 'tilenumber'. Local objOccupiedTile1:clsTile = clsTile(ChessboardList.ValueAtIndex(tilenumber)); objOccupiedTile1.tiledOcuppiedBy = enumPlayer; '//this is suppeds to call-by-ref, or not? '// the display will be filling up, visually showing where your player was. For Local objTile1:clsTile = EachIn ChessboardList:TList objTile1.Update(); Next flip(); Wend EndMethod '// here sumthing strange happens, call by value? Call-by-reference? endType type clsTile field myImage:TImage; Field x:int; Field y:int; '//stupid constructur emulated. call this in your code.. Blitzmax forum exmaple ;). function Create:clsTile() local objTile3:clsTile = new clsTile objTile3.MyImage = loadImage("snakehead1.png"); return objTile3; endfunction method update() If(Self.tiledOcuppiedBy = enumPlayer) DrawImage(Self.MyImage, self.x, self.y); EndIf endmethod end type
The above attempts to;
1. fill a tlist chessboard containing tiles.
2. aloow the player to move onto a tile.
3. Flag the tile as occupied.
4. Loop through all tiles in chessboard, updating it.
Problem:
the clsTile.Update doesnt do anything. The tile isnt rendered. The reference obtained from the Tlist (probably) dont update the object it obtained. Is that true? How can i modify a object in Tlist by reference?