|
Post by bplus on Feb 16, 2024 15:18:07 GMT
And I mean little! sw = 800: sh = 600 Screen _NewImage(sw, sh, 32) x = sw / 2: y = sh / 2 Do Cls kh& = _KeyHit x = x + -5 * (kh& = 19200) * (x > 0) + 5 * (kh& = 19712) * (x < sw) y = y + -5 * (kh& = 18432) * (y > 0) + 5 * (kh& = 20480) * (y < sh) Line (x - 50, y - 50)-Step(100, 100), _RGB(255, 255, 0), BF _Limit 300 ' 10 is too choppy 30 OK? 300! doesn't seem 10 X's faster than 30 _Display Loop Until kh& = 27 System Comments: line 1: sw and sh are short for screen width and screen height. We are setting up a call to custom size our Screen with _NewImage(sw, sh, 32). With old QB stuff we were stuck with a few screen choices, 12, 13 probably better ones for graphics, and had absolutely No Control over screen size, yuck!!! line 2: makes that call and the 32 there is specifying 32 bit color which gives us millions of color options through the _RGB32(red, green, blue, alphaOptional) color specification function. You can also use &Hrrggbbaa specifing colors hexidecimally. line 3: x = .... and y = .... x, y are used for locating our yellow rectangle the subject or "hero" of game you the player control with arrow keypresses. Line 3 gets us started smack in middle of screen. line 4: we enter our main loop line 5: we clear off the screen from last loop to rebuild anew line 6: we poll the keyboard for any key presses and store into kh&. _KeyHit is better than old Inkey$ system because we have numbers rather than one or 2 chars (= ascii byte codes) to analyse. Now we get to the heavy duty calculation! Lines 7 and 8, x = .... and y = .... moving x, y location of player according to arrow keys pressed. (kh& = 19200) returns -1 or 0 (true or false respectively) if the left arrow was pressed (x > 0) returns -1 or 0 (true or false respectively) if x > 0 when both these are true the we have -1 * -1 = 1 and we multiply that by -5 so x = x - 5 !!! likewise for (kh& = 19712) * (x < sw) when both of those are true, we get x = x + 5*(-1)*(-1) ' same as x = x + 5 and likewise for the y line when the up arrow is pressed and y > 0 then y = y -5 OR if the down arrow is pressed and y < sh then y = y + 5. These move the player around the screen but prevents the player from going too far up, down, left or right. Nicely done in 2 lines of code!The next line draws the rectangle according to where x, y are. _Display ' updates the screen without nasty blinking we did not have available in old QB stuff we use to have to black out old position before redrawing new skipping CLS because of the blinking it caused. _Limit ' controls how fast to loop around the Do... Loop here no faster than 300 updates per second. BTW if drawing takes longer then it will be less than 300 updates per sec, _Limit just sets an upper limit on how fast it can loop around. Again we had No Handy control like this in the old QB stuff and we did all kinds of crap to try and slow down the updates, never very well! If kh& = 27 that's the escape key press, the user wants to quit. System not only exits the program but also clears the screen, you may want to leave showing the last screen shot, then use END instead. Next avoiding obstacles
|
|
|
Post by bplus on Feb 17, 2024 19:55:24 GMT
Before getting into making objects, obstacles like walls or prizes or killer monsters we need to start discussion on collision detection so I did here: qb64.boards.net/thread/288/collisionThought that might be considered first before making objects for game. How are you going to detect when one object runs into another? I plan on using 2BoxesCollision detection from link I gave above.
|
|
|
Post by bplus on Feb 18, 2024 20:25:25 GMT
Oh! Before I got sorta side-tracked on subject of Collision, I was and still am going to track ALL the objects on just the game board. So if I want to move the player into cell (x, y) if there is a space say "S" there I can. If there is a prize, "P", there I get it! if there is a Monster,"M", there I get eaten! So to setup the Board$(cells_wide, cells_high) I need to setup a game space = where I can freely move the player = "S". I have 2 Methods to setup that Game Space: 1. Random Walk - start at the center of board and randomly walk in any of 4 directions. 2. Target walk - set a random target, walk to it, setup another target and walk to it... do that 20 times or so and return to starting point. This creates a really neat circuit that I will likely continue from this option. Here is what a sample board would look like from a random walk, player can walk in white spaces. _Title "Little game: carve space random walk" 'b+ 2024-02-17 Randomize Timer sw = 800: sh = 600 Screen _NewImage(sw, sh, 32) Dim board$(1 To 80, 1 To 60) dx1 = .25: dy1 = .5: dx2 = .75 cx = Int(UBound(board$, 1) / 2): cy = Int(UBound(board$, 2) / 2) For i = 1 To 4000 r = Rnd If r < dx1 And cx - 1 > 0 Then cx = cx - 1: ndx1 = ndx1 + 1 ElseIf r < dy1 And cy - 1 > 0 Then cy = cy - 1: ndy1 = ndy1 + 1 ElseIf r < dx2 And cx + 1 <= UBound(board$, 1) Then cx = cx + 1: ndx2 = ndx2 + 1 ElseIf cy + 1 <= UBound(board$, 2) Then cy = cy + 1 End If board$(cx, cy) = "w" ' walk space
Line ((cx - 1) * 10, (cy - 1) * 10)-Step(9, 9), &HFFFFFFFF, BF
_Limit 300 Next Beep Sleep Here is the method I just perfected today, Circuit space: Option _Explicit _Title "Little game Circuit game space" 'b+ 2024-02-18 Randomize Timer Dim Shared SW, SH: SW = 800: SH = 600 Screen _NewImage(SW, SH, 32) _ScreenMove 200, 60 Dim As Long UbX, UbY, cx, cy, lastTarget, targets, tx, ty, dx, dy UbX = 80: UbY = 60 ' the max width and height of board cells Do ' test board layouts Cls: ReDim board$(1 To UbX, 1 To UbY) 'resets cx = UbX \ 2: cy = UbY \ 2: lastTarget = 30 For targets = 1 To lastTarget tryAgain: ' to avoid dead end streets If targets <> lastTarget Then ' stay off the edges tx = 2 * Int((Rnd * (UbX - 3) \ 2)) + 2: ty = 2 * Int(Rnd * (UbY - 3) \ 2) + 2 Else tx = UbX \ 2: ty = UbY \ 2 End If If tx = cx Or ty = cy Then GoTo tryAgain ' to avoid dead end streets dx = tx - cx: dy = ty - cy ' the distance and direction we have to go While cx <> tx: cx = cx + Sgn(dx): GoSub MakeWay: Wend While cy <> ty: cy = cy + Sgn(dy): GoSub MakeWay: Wend Next Sleep Loop Until _KeyDown(27) End MakeWay: board$(cx, cy) = "S": Line ((cx - 1) * 10, (cy - 1) * 10)-Step(9, 9), , BF: Return I hope you will like Circuit as much as I, it is like a maze but no dead end streets.
|
|
|
Post by bplus on Feb 19, 2024 13:30:15 GMT
It's really easy to make a game out of the first Random walk Game space. Not sure what we can do with 2nd system, so lets make a quick little game with first system.
While laying out spaces "S" lay out 1 "H" location for hero = player, lay out a bunch say 10, "$" for prizes and a few "#" for killer monsters. Save the location of H with Hx, Hy the prizes(index).x and prizes(index).y same with killers(index).x and killers(index).y
So we need a Type structure called Object, every Object of interest will have a location (x, y) pixel or cell a shape = 1 letter/symbol H, $, # and a color say blue for H, green for money prize $ and red death monster #.
Type Object char as string * 1 ' character symbol or letter x as integer y as integer c as _unsigned long ' for color's End Type
Dim Hero as Object Hero.char = "H" Hero.x Hero.y to be determined later Hero.c = _Rgb32(0,0,255)
nKillers = 3 Dim Killer(1 to nKillers) as Object for i = 1 to nKillers Killer(i).char = "#" Killer(i).c = _Rgb32(255, 0, 0) next
nPrizes = 10 Dim Prize(1 to nPrizes) as Object for i = 1 to nPrizes Prize(i).char = "$" Prize(i).c = _RGB32(0, 128, 0) next
PrizeValue = 100 Score = 0 Deaths = 0
Need a sub for Drawing Board DrawBoard with Objects after Setup of Game Space that also places the Objects.
lets see where all this gets us...
|
|
|
Post by bplus on Feb 19, 2024 14:33:52 GMT
Update: Oh I forgot, I have to fit the character symbol or letter inside the cell!
OK make the cells 20x20 pixels... (fits 8x16 font character) so that would be 40 x 30 cells for the board. Will be calling them Ubx and Uby for UpperBound of Board$(x, y) Ubx = 40 : Uby = 30
Also to lay out the prizes and killers among the nWalks it takes to make the board layout, I divide nWalks by number of prizes so if nWalks = 2000 then a prize every 2000/10 every 200 steps but if I do that with prizes and killers then the last step will be both prize and monster, no good!
So I will subtract nKillers to nWalks and distribute a little earlier, ie slightly less than last walk. Oh I should call them steps BTW.
So say there are 2000 steps in Random walk and 3 killers to distribute that will be ModKillers = (2000 - nKillers) \ nKillers = 665.666 rounded to 665
so if steps mod ModKiller = 0 then 'place a killer at step number 665, 1330 and 1995
And for prizes 10 ModPrizes = (2000 - nPrizes) \ nPrizes = 1990 \ 10 = 199 so If Steps Mod ModPrizes = 0 then ' place a prize here 199, 398, 597,... and 1990 for 10th prize.
Works fine as long as nKillers is not close to nPrizes.
|
|
|
Post by bplus on Feb 19, 2024 17:10:00 GMT
Here's what I got:
Option _Explicit ' DIM everything before start using it! _Title "Little game: Startup" 'b+ 2024-02-19 ' Startup sub gets Board$() setup and positions all Objects
Randomize Timer ' so every game is unique
' using variables so can change screen size and cell size as needed for asthetics Dim Shared As Integer SW, SH: SW = 800: SH = 600 'the screen width and height Screen _NewImage(SW, SH, 32) _ScreenMove 200, 60 _PrintMode _KeepBackground
Type Object char As String * 1 ' character symbol or letter x As Integer ' location on x axis horizontal, cells not pixels y As Integer ' location on y axis vertical, cells not pixels c As _Unsigned Long ' for color's End Type
' each cell of game board is going to be 20 x 20 pixels to fit a 8x16 font inside Dim Shared As Integer CellWidth, CellHeight: CellWidth = 20: CellHeight = 20 ' pixels
' so can fit 40 cells across and 30 down Dim Shared As Integer UBX, UBY: UBX = SW \ CellWidth: UBY = SH \ CellHeight Dim Shared board$(1 To UBX, 1 To UBY)
Dim Shared Hero As Object ' Main Player shared for sub calls Hero.char = "H" Hero.c = _RGB32(0, 0, 255) 'Hero.x Hero.y to be determined later
Dim i As Integer ' as a general index to use for arrays in FOR... Next loops
' Monsters or Killers or Villians we will animate later Dim Shared As Integer nKillers: nKillers = 3 Dim Shared Killer(1 To nKillers) As Object For i = 1 To nKillers ' these wont change Killer(i).char = "K" Killer(i).c = _RGB32(255, 0, 0) Next
' Prizes to score points Dim Shared As Integer nPrizes: nPrizes = 10 Dim Shared Prize(1 To nPrizes) As Object For i = 1 To nPrizes Prize(i).char = "$" Prize(i).c = _RGB32(0, 128, 0) Next
Dim Shared As Integer PrizeValue, Score, Lives PrizeValue = 100 ' points per prize Score = 0 ' running score display in title bar? along with Lives Lives = 0 ' lives left StartUp Sleep
Sub StartUp ' get the game Board setup with Objects layed out Dim As Integer cx, cy, i, nSteps, placeHero, placeKiller, placePrize, cPrize, cKiller Dim r 'starts at center of board cx = Int(UBound(board$, 1) / 2): cy = Int(UBound(board$, 2) / 2) ' while laying out board distribute the objects nSteps = 2500 placeHero = nSteps \ 2 placeKiller = (nSteps - nKillers) \ nKillers ' notice integer division placePrize = (nSteps - nPrizes) \ nPrizes For i = 1 To nSteps r = Rnd If r < .25 And cx - 1 > 0 Then cx = cx - 1 ElseIf r < .5 And cy - 1 > 0 Then cy = cy - 1 ElseIf r < .75 And cx + 1 <= UBound(board$, 1) Then cx = cx + 1 ElseIf cy + 1 <= UBound(board$, 2) Then cy = cy + 1 End If board$(cx, cy) = "w" ' walk space Line ((cx - 1) * CellWidth, (cy - 1) * CellHeight)-Step(CellWidth - 1, CellHeight - 1), &HFFFFFFFF, BF If i = placeHero Then Hero.x = cx: Hero.y = cy If (i Mod placeKiller = 0) Then cKiller = cKiller + 1: Killer(cKiller).x = cx: Killer(cKiller).y = cy If (i Mod placePrize = 0) Then cPrize = cPrize + 1: Prize(cPrize).x = cx: Prize(cPrize).y = cy Next labelCell Hero.x, Hero.y, Hero.char, Hero.c For i = 1 To nPrizes labelCell Prize(i).x, Prize(i).y, Prize(i).char, Prize(i).c Next For i = 1 To nKillers labelCell Killer(i).x, Killer(i).y, Killer(i).char, Killer(i).c Next _Title "Little game score:" + Str$(Score) + " Lives:" + Str$(Lives) End Sub
Sub labelCell (cellX, cellY, Text$, Colr~&) Dim saveColor~&, x As Integer, y As Integer saveColor~& = _DefaultColor Color Colr~& 'center in cellwidth and translate cell number to screen pixel number for _printstring x = (cellX - 1) * CellWidth + (CellWidth - _PrintWidth(Text$)) \ 2 'center in cellheight and translate cell number to screen pixel y = (cellY - 1) * CellHeight + ((CellHeight - 16) \ 2) _PrintString (x, y), Text$ Color saveColor~& End Sub
Because Random Walk can cover same spot more than once some of $ and K cells overlap. Easy to fix! In fact I should probably have chosen the object cells after the space was laid out. Also I could use the code I am using for setup as display updating code.
|
|
|
Post by bplus on Feb 19, 2024 21:34:39 GMT
OK Setup sub fixed up along with the ShowBoard and installed code for moving the Hero blue H around the board. I also tested code with different cellWidth and cellHeight currently using 40, 30 Option _Explicit ' DIM everything before start using it! _Title "Little game: Startup 2" 'b+ 2024-02-19 ' Startup sub gets Board$() setup and positions all Objects ' 2024-02-19 Little game: Startup 2 - Fix startup ' Split out board display code to reuse in main game loop. ' Added code to move player around in main screen
Randomize Timer ' so every game is unique
' using variables so can change screen size and cell size as needed for asthetics Dim Shared As Integer SW, SH: SW = 800: SH = 600 'the screen width and height Screen _NewImage(SW, SH, 32) _ScreenMove 200, 60 _PrintMode _KeepBackground
Type Object char As String * 1 ' character symbol or letter x As Integer ' location on x axis horizontal, cells not pixels y As Integer ' location on y axis vertical, cells not pixels c As _Unsigned Long ' for color's End Type
' each cell of game board is going to be 20 x 20 pixels to fit a 8x16 font inside Dim Shared As Integer CellWidth, CellHeight: CellWidth = 40: CellHeight = 30 ' pixels
' so can fit 40 cells across and 30 down Dim Shared As Integer UBX, UBY: UBX = SW \ CellWidth: UBY = SH \ CellHeight Dim Shared board$(1 To UBX, 1 To UBY)
Dim Shared Hero As Object ' Main Player shared for sub calls Hero.char = "H" Hero.c = _RGB32(0, 0, 255) 'Hero.x Hero.y to be determined later
Dim i As Integer ' as a general index to use for arrays in FOR... Next loops
' Monsters or Killers or Villians we will animate later Dim Shared As Integer nKillers: nKillers = 3 Dim Shared Killer(1 To nKillers) As Object For i = 1 To nKillers ' these wont change Killer(i).char = "#" Killer(i).c = _RGB32(200, 0, 0) Next
' Prizes to score points Dim Shared As Integer nPrizes: nPrizes = 10 Dim Shared Prize(1 To nPrizes) As Object For i = 1 To nPrizes Prize(i).char = "$" Prize(i).c = _RGB32(0, 190, 0) Next
Dim Shared As Integer PrizeValue, Score, Lives Dim kh&, tx%, ty% PrizeValue = 100 ' points per prize Score = 0 ' running score display in title bar? along with Lives Lives = 0 ' lives left StartUp Do Until _KeyDown(27) showBoard kh& = _KeyHit If (kh& = 19200) And (Hero.x > 1) Then ' make sure in bounds then check board$() If board$(Hero.x - 1, Hero.y) <> "" Then Hero.x = Hero.x - 1 ElseIf (kh& = 19712) And (Hero.x < UBX) Then If board$(Hero.x + 1, Hero.y) <> "" Then Hero.x = Hero.x + 1 ElseIf (kh& = 18432) And Hero.y > 1 Then If board$(Hero.x, Hero.y - 1) <> "" Then Hero.y = Hero.y - 1 ElseIf (kh& = 20480) * (Hero.y < UBY) Then If board$(Hero.x, Hero.y + 1) <> "" Then Hero.y = Hero.y + 1 End If _Display _Limit 30 Loop
Sub StartUp ' get the game Board setup with Objects layed out Dim As Integer cx, cy, i, fx, fy Dim r 'Cls ' using default white, black set the black for snapshot of board 'starts at center of board cx = UBX / 2: cy = UBY / 2 For i = 1 To UBX * UBY * 5 r = Rnd If r < .25 And cx - 1 > 0 Then cx = cx - 1 ElseIf r < .5 And cy - 1 > 0 Then cy = cy - 1 ElseIf r < .75 And cx + 1 <= UBound(board$, 1) Then cx = cx + 1 ElseIf cy + 1 <= UBound(board$, 2) Then cy = cy + 1 End If board$(cx, cy) = "w" ' walk space 'Line ((cx - 1) * CellWidth, (cy - 1) * CellHeight)-Step(CellWidth - 1, CellHeight - 1), &HFFFFFFFF, BF Next
'assign objects FindFreeCell fx, fy Hero.x = fx: Hero.y = fy: board$(fx, fy) = "H" 'labelCell Hero.x, Hero.y, Hero.char, Hero.c For i = 1 To nKillers FindFreeCell fx, fy Killer(i).x = fx: Killer(i).y = fy: board$(fx, fy) = "#" Next For i = 1 To nPrizes FindFreeCell fx, fy Prize(i).x = fx: Prize(i).y = fy: board$(fx, fy) = "$" Next End Sub
Sub FindFreeCell (ffx As Integer, fy As Integer) tryAnother: ffx = Int(Rnd * UBX) + 1: fy = Int(Rnd * UBY) + 1 If board$(ffx, fy) <> "w" Then GoTo tryAnother End Sub
Sub showBoard Dim As Integer cx, cy, i For cy = 1 To UBY: For cx = 1 To UBX If board$(cx, cy) <> "" Then Line ((cx - 1) * CellWidth, (cy - 1) * CellHeight)-Step(CellWidth - 2, CellHeight - 2), &HFFEEEEFF, BF End If Next Next labelCell Hero.x, Hero.y, Hero.char, Hero.c For i = 1 To nPrizes labelCell Prize(i).x, Prize(i).y, Prize(i).char, Prize(i).c Next For i = 1 To nKillers labelCell Killer(i).x, Killer(i).y, Killer(i).char, Killer(i).c Next _Title "Little game score:" + Str$(Score) + " Lives:" + Str$(Lives) End Sub
Sub labelCell (cellX, cellY, Text$, Colr~&) Dim x As Integer, y As Integer Line ((cellX - 1) * CellWidth, (cellY - 1) * CellHeight)-Step(CellWidth - 2, CellHeight - 2), Colr~&, BF 'center in cellwidth and translate cell number to screen pixel number for _printstring x = (cellX - 1) * CellWidth + (CellWidth - _PrintWidth(Text$)) \ 2 'center in cellheight and translate cell number to screen pixel y = (cellY - 1) * CellHeight + ((CellHeight - 16) \ 2) _PrintString (x, y), Text$ End Sub
Code is not so little anymore
|
|
|
Post by bplus on Feb 20, 2024 17:14:26 GMT
OK last night I did the easy stuff of detecting scores and losing lives. Option _Explicit ' DIM everything before start using it! _Title "Little game: Startup 2" 'b+ 2024-02-19 ' Startup sub gets Board$() setup and positions all Objects ' 2024-02-19 Little game: Startup 2 - Fix startup ' Split out board display code to reuse in main game loop. ' Added code to move player around in main screen
Randomize Timer ' so every game is unique
' using variables so can change screen size and cell size as needed for asthetics Dim Shared As Integer SW, SH: SW = 800: SH = 600 'the screen width and height Screen _NewImage(SW, SH, 32) _ScreenMove 200, 60 _PrintMode _KeepBackground
Type Object char As String * 1 ' character symbol or letter x As Integer ' location on x axis horizontal, cells not pixels y As Integer ' location on y axis vertical, cells not pixels c As _Unsigned Long ' for color's End Type
' each cell of game board is going to be 20 x 20 pixels to fit a 8x16 font inside Dim Shared As Integer CellWidth, CellHeight: CellWidth = 40: CellHeight = 30 ' pixels
' so can fit 40 cells across and 30 down Dim Shared As Integer UBX, UBY: UBX = SW \ CellWidth: UBY = SH \ CellHeight Dim Shared board$(1 To UBX, 1 To UBY)
Dim Shared Hero As Object ' Main Player shared for sub calls Hero.char = "H" Hero.c = _RGB32(0, 0, 255) 'Hero.x Hero.y to be determined later
Dim i As Integer ' as a general index to use for arrays in FOR... Next loops
' Monsters or Killers or Villians we will animate later Dim Shared As Integer nKillers: nKillers = 3 Dim Shared Killer(1 To nKillers) As Object For i = 1 To nKillers ' these wont change Killer(i).char = "#" Killer(i).c = _RGB32(200, 0, 0) Next
' Prizes to score points Dim Shared As Integer nPrizes: nPrizes = 10 Dim Shared Prize(1 To nPrizes) As Object For i = 1 To nPrizes Prize(i).char = "$" Prize(i).c = _RGB32(0, 190, 0) Next
Dim Shared As Integer PrizeValue, Score, Lives, fx, fy, r Dim kh& PrizeValue = 100 ' points per prize Score = 0 ' running score display in title bar? along with Lives Lives = 3 ' lives left StartUp Do Until _KeyDown(27) showBoard kh& = _KeyHit If (kh& = 19200) And (Hero.x > 1) Then ' make sure in bounds then check board$() If board$(Hero.x - 1, Hero.y) <> "" Then Hero.x = Hero.x - 1 ElseIf (kh& = 19712) And (Hero.x < UBX) Then If board$(Hero.x + 1, Hero.y) <> "" Then Hero.x = Hero.x + 1 ElseIf (kh& = 18432) And Hero.y > 1 Then If board$(Hero.x, Hero.y - 1) <> "" Then Hero.y = Hero.y - 1 ElseIf (kh& = 20480) * (Hero.y < UBY) Then If board$(Hero.x, Hero.y + 1) <> "" Then Hero.y = Hero.y + 1 End If 'check if picked up any $ For i = 1 To nPrizes If Hero.x = Prize(i).x And Hero.y = Prize(i).y Then Score = Score + PrizeValue FindFreeCell fx, fy Prize(i).x = fx: Prize(i).y = fy Exit For End If Next 'check for kills For i = 1 To nKillers If Hero.x = Killer(i).x And Hero.y = Killer(i).y Then Lives = Lives - 1 If Lives = 0 Then For r = 1 To 100 Step 5 Circle ((Hero.x - .5) * CellWidth, (Hero.y - .5) * CellHeight), r, &HFFFF0000 _Display _Limit 3 Next Cls _PrintString ((SW - _PrintWidth("Game Over")) / 2, 300 - 8), "Game Over" End Else FindFreeCell fx, fy Killer(i).x = fx: Killer(i).y = fy Exit For End If End If Next _Display _Limit 30 Loop
Sub StartUp ' get the game Board setup with Objects layed out Dim As Integer cx, cy, i, fx, fy Dim r 'Cls ' using default white, black set the black for snapshot of board 'starts at center of board cx = UBX / 2: cy = UBY / 2 For i = 1 To UBX * UBY * 5 r = Rnd If r < .25 And cx - 1 > 0 Then cx = cx - 1 ElseIf r < .5 And cy - 1 > 0 Then cy = cy - 1 ElseIf r < .75 And cx + 1 <= UBound(board$, 1) Then cx = cx + 1 ElseIf cy + 1 <= UBound(board$, 2) Then cy = cy + 1 End If board$(cx, cy) = "w" ' walk space 'Line ((cx - 1) * CellWidth, (cy - 1) * CellHeight)-Step(CellWidth - 1, CellHeight - 1), &HFFFFFFFF, BF Next
'assign objects FindFreeCell fx, fy Hero.x = fx: Hero.y = fy: board$(fx, fy) = "H" 'labelCell Hero.x, Hero.y, Hero.char, Hero.c For i = 1 To nKillers FindFreeCell fx, fy Killer(i).x = fx: Killer(i).y = fy: board$(fx, fy) = "#" Next For i = 1 To nPrizes FindFreeCell fx, fy Prize(i).x = fx: Prize(i).y = fy: board$(fx, fy) = "$" Next End Sub
Sub FindFreeCell (ffx As Integer, fy As Integer) tryAnother: ffx = Int(Rnd * UBX) + 1: fy = Int(Rnd * UBY) + 1 If board$(ffx, fy) <> "w" Then GoTo tryAnother End Sub
Sub showBoard Dim As Integer cx, cy, i For cy = 1 To UBY: For cx = 1 To UBX If board$(cx, cy) <> "" Then Line ((cx - 1) * CellWidth, (cy - 1) * CellHeight)-Step(CellWidth - 2, CellHeight - 2), &HFFEEEEFF, BF End If Next Next labelCell Hero.x, Hero.y, Hero.char, Hero.c For i = 1 To nPrizes labelCell Prize(i).x, Prize(i).y, Prize(i).char, Prize(i).c Next For i = 1 To nKillers labelCell Killer(i).x, Killer(i).y, Killer(i).char, Killer(i).c Next _Title "Little game score:" + Str$(Score) + " Lives:" + Str$(Lives) End Sub
Sub labelCell (cellX, cellY, Text$, Colr~&) Dim x As Integer, y As Integer Line ((cellX - 1) * CellWidth, (cellY - 1) * CellHeight)-Step(CellWidth - 2, CellHeight - 2), Colr~&, BF 'center in cellwidth and translate cell number to screen pixel number for _printstring x = (cellX - 1) * CellWidth + (CellWidth - _PrintWidth(Text$)) \ 2 'center in cellheight and translate cell number to screen pixel y = (cellY - 1) * CellHeight + ((CellHeight - 16) \ 2) _PrintString (x, y), Text$ End Sub
The only thing that remains is animating the killers and maybe giving the game a proper name. Then there are all sorts of bell and whistles you could add like tracking high score(s) by whom and when, doing levels of play,... you could even offer color options and board sizes. And bplus could come alone and mod the whole thing for mouse play instead of key press play. I was disappoimted I could not use the code I started this thread with. It would have been a nightmare to restrict keypress handling code to 2 lines. The problem is the added logic required to first make sure the keypress keeps you inbounds of the Board$() AND in same breath (Line of code) check that the cell is a place where you could move. It might be possible to do that in one line but it would be an awfully long line of code! Certaingly not easy to read let alone debug! Ah! but you know what? I look forward to seeing WTH? I come up with for that 2nd way to set up a game space, the one like a maze but more like a city map or a circuit board. That! I look forward to seeing.
|
|
|
Post by bplus on Feb 20, 2024 17:24:18 GMT
Oh hey! maybe the killers can move around the prizes! or even steal them.
|
|
|
Post by bplus on Mar 2, 2024 15:04:06 GMT
Huh! lost interest in this... I tire of monologues without outside interest being shown.
|
|