How to Program a boardgame with Free BlitzMax, code included NOW Hex&chit

Started by gameleaper, September 28, 2015, 10:28:14 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gameleaper

'just paste this code into blitzmax folder together with the 2 PNGs attached and run
'you must provide 2 files for this program to work troops.png 20 pixels high 40 across 2 chits
'a 1024x768 backdrop

Graphics 1024,768,32,60
Global chit = LoadAnimImage(".\troops.PNG",20,20,0,2,flags=ALPHABITS  ) '2 twenty by twenty chits
Global backdrop = LoadImage(".\backdrop.PNG"  ) 'plain backdrop

Global gameboard[10,10,20] '10 x 10 grid gameboard with 20 items of info per location
Global x1 = 0
Global y1 = 0
'try setting the gameboard as shown below
gameboard[1,1,1] = 1
gameboard[1,3,1] = 1


While Not KeyHit(KEY_ESCAPE) 'hit escape to exit

Cls 'clear screen before redrawing each loop through

DrawImage(backdrop ,0,0) 'draw backdrop

'use a for next loop to draw chits
For x= 0 To 9
For y = 0 To 9
If gameboard[x,y,1] = 1 Then DrawImage(chit,x*20,y*20,frame=1) 'frame is chit number
Next
Next

' devise x and y by 20 pixels, this is because the chits are 20 pixels
'the idea is to find where the mouse pointer is
x1 = MouseX() /20
y1 = MouseY() /20

'this sets gameboard on off by left or right clicking
If x1 < 10 And x1 > -1 And y1 < 10 And y1 > -1
If MouseDown(1) 'Left click set on
gameboard[x1,y1,1] = 1
EndIf
If MouseDown(2) 'right click set off
gameboard[x1,y1,1] = 0
EndIf
EndIf



Flip 'this flips the board onto the screen

Wend

End

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Paste in above not this bit of text! The code is as simple as I could make a demo on how to program a boardgame, its how I start a program! I thought Id repost this code in its own thread so people will see it rather than not seen thread

gameleaper

'this is a hexgrid, with 40x40 size
'you must provide 2 files for this program to work troops.png 40 pixels high 80 across 2 chits
'a 1024x768 backdrop

Graphics 1024,768,32,60
Global chit = LoadAnimImage(".\HexGame\troops.PNG",40,40,0,2,flags=ALPHABITS  ) '2 forty by forty chits
Global backdrop = LoadImage(".\HexGame\backdrop.PNG"  ) 'plain backdrop

Global gameboard[40,40,40] '40 x 40 grid gameboard with 40 items of info per location
Global x1 = 0
Global y1 = 0
Global shift = 0

Global sa = 0
Global ba = 0

'try setting the gameboard as shown below
gameboard[1,1,1] = 1
gameboard[1,3,1] = 1


While Not KeyHit(KEY_ESCAPE) 'hit escape to exit

Cls 'clear screen before redrawing each loop through


DrawImage(backdrop ,0,0) 'draw backdrop

drawhexgrid() 'call the function to draw hexgrid







x1 = MouseX() /40
y1 = MouseY() /40

'this adjusts the code for a hexgrid rather than squares
shift = 0 'initialise shift
If x1 = 0 Or x1 = 2 Or x1 = 4 Or x1 = 6 Or x1 = 8 Or x1 = 10 Or x1 = 12 Or x1 = 14 Or x1 = 16 Or x1 = 18 Or x1 = 20 Or x1 = 22 Or x1 = 24 Or x1 = 26 Then shift = 1
If shift = 1
y1 = (MouseY()-20) /40 '-20 because the +20 we added in the display loop and the mousey
EndIf

'use a for next loop to draw chits
For x= 0 To 26
For y = 0 To 16

shift = 0 'initialise shift
If x = 0 Or x = 2 Or x = 4 Or x = 6 Or x = 8 Or x = 10 Or x = 12 Or x = 14 Or x = 16 Or x = 18 Or x = 20 Or x = 22 Or x = 24 Or x = 26 Then shift = 1 'check to see if we are on a shifted down hex
If gameboard[x,y,1] = 1 And shift = 0 Then DrawImage(chit,x*40,y*40,frame=1) 'frame is chit number 1 or 2
If gameboard[x,y,1] = 1 And shift = 1 Then DrawImage(chit,x*40,(y*40)+20,frame=1) 'frame is chit number 1 or 2, adds 10 to Y(down)

Next
Next

' devise x and y by 20 pixels, this is because the chits are 20 pixels
'the idea is to find where the mouse pointer is




'this sets gameboard on off by left or right clicking
If x1 < 25 And x1 > 0 And y1 < 16 And y1 > -1 'x has 25 across, y has 16 down
If MouseDown(1) 'Left click set on
gameboard[x1,y1,1] = 1
EndIf
If MouseDown(2) 'right click set off
gameboard[x1,y1,1] = 0
EndIf
EndIf



Flip 'this flips the board onto the screen

Wend



End

Function drawhexgrid()

' the loops draw 6 hexsides and repeat through the loops

a = 80
b = 0
c = 80
d = 0

For a2 = 0 To 15
For a1 = 0 To 26 Step 2
DrawLine(5+a,20+b,35+c,20+d)
DrawLine(35+a,20+b,45+c,40+d)
DrawLine(45+a,40+b,35+c,60+d)
DrawLine(35+a,60+b,5+c,60+d)
DrawLine(5+a,60+b,-5+c,40+d)
DrawLine(-5+a,40+b,5+c,20+d)
a=a+80
c=c+80
Next
a = 80
c = 80
b = b+40
d = d+40
Next

a = 40
b = -20
c = 40
d = -20

For a2 = 0 To 15
For a1 = 0 To 23 Step 2
DrawLine(5+a,20+b,35+c,20+d)
DrawLine(35+a,20+b,45+c,40+d)
DrawLine(45+a,40+b,35+c,60+d)
DrawLine(35+a,60+b,5+c,60+d)
DrawLine(5+a,60+b,-5+c,40+d)
DrawLine(-5+a,40+b,5+c,20+d)
a=a+80
c=c+80
Next
a = 40
c = 40
b = b+40
d = d+40
Next





End Function

End



gameleaper

That's a full HexGame framework especialy for you GJK, all I ask guys is you give me any freebies you make from it.

notice the troops chits has been changed in size from 20x20 to 40x40 so use the new file attached

gameleaper

Ive given away secrets here, so study well, its a short program that you start all projects with.

bayonetbrant

The key to surviving this site is to not say something which ends up as someone's tag line - Steelgrave

"their citizens (all of them counted as such) glorified their mythology of 'rights'...and lost track of their duties. No nation, so constituted, can endure." Robert Heinlein, Starship Troopers

bbmike

Awesome! Thanks for doing that gameleaper. You've just made me install BlitzMax on my computer.  :D
"My life is spent in one long effort to escape from the commonplace of existence."
-Sherlock Holmes

"You know, just once I'd like to meet an alien menace that wasn't immune to bullets."
-Brigadier Lethbridge-Stewart

"There's a horror movie called Alien? That's really offensive. No wonder everyone keeps invading you!"
-The Doctor

"Before Man goes to the stars he should learn how to live on Earth."
-Clifford D. Simak

gameleaper

glad to help,hope you can some game going bb, put the 2 graphic files in a "HexGame" named folder(forgot I put them in a folder

GJK

I've copied your secrets and put them in to a Word doc and saved them in my BlitzMax folder so that I can refer back to it in the future.  This week and weekend are pretty full with planned activities but the following week I plan to really study this.  There's a number of solitaire games that are just itching to have a computer ai put to them to automate all the chart lookup's.  Thanks for sharing!
Clip your freaking corners!
----------------------
Blood Bowl on VASSAL - Ask me about it! http://garykrockover.com/BB/
----------------------
"Fat, drunk, and stupid is no way to go through life, son."

-Dean Vernon Wormer

GJK

Clip your freaking corners!
----------------------
Blood Bowl on VASSAL - Ask me about it! http://garykrockover.com/BB/
----------------------
"Fat, drunk, and stupid is no way to go through life, son."

-Dean Vernon Wormer

gameleaper

Now that BlitzMax is free, I thought I would follow and do a giveaway to you, GJK don't feel like you have to use the code I just thought you would like to see how I do it. don't try deciphering it, its Done just change things like the number of chits it has etc...

OJsDad

Thanks GameLeaper.  Unfortunately, when I run, all I get is a black screen.  I just upgraded to Windows 10, so that may be the issue. 
'Here at NASA we all pee the same color.'  Al Harrison from the movie Hidden Figures.