News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Drawing a Checker Board

Started by kevin, July 08, 2007, 07:36:12 AM

Previous topic - Next topic

kevin

 This example draws a checker board styled effect to the screen.   The example is more a demonstration of using a 2D typed array to represent the checker board however than a flashy effect.

PlayBASIC Code: [Select]
  Type Tiles
Xpos ; X coord of tile
Ypos ; Y coord of tile
Colour ; Colour of this Tile
EndType


; Dimension an 2D Typed array called Board
Dim Board(10,10) as Tiles


; Dimension colours array
DIm Colours(2)

; Fill the colours array with the two board colours
Colours(0)=rgb(200,100,40)
Colours(1)=rgb(10,50,240)


; Init two variables that will store the tile width/height of each tile
TileWidth =48
TileHeight =32




; Fill the board array with each Tiles information (Xpos,Ypos and colour of this tile)
For Ylp=0 to 10
For Xlp=0 to 10
;
Board(xlp,ylp).Xpos =Xlp*TileWIdth
Board(xlp,ylp).Ypos =Ylp*TileHeight

; Choose the index of the tiles colour
ColourIndex=(Xlp+(Ylp and 1)) and 1

;Store the colour of tile
Board(xlp,ylp).Colour =Colours(colourIndex)


next
next



; Start the programs main loop
Do
; Clear the Screen to black (rgb(0,0,0)= black)
Cls rgb(0,0,0)


; Draw the Board array to the Screen
Lockbuffer
For Ylp=0 to 10
For Xlp=0 to 10
; Get the Screen coords of this tile
Xpos=Board(xlp,ylp).Xpos
Ypos=Board(xlp,ylp).Ypos

;Store the colour of tile
Col=Board(xlp,ylp).Colour
Col2=RgbFade(col,50)
; Draw shaded Box to represent this tile on the screen
ShadeBox Xpos,Ypos,Xpos+TileWidth,Ypos+TileHeight,Col,Col2,Col,Col
next
next
unlockbuffer



Print "checkers anyone ?"
Print Fps()


Sync
loop