How do I set various difficulty settings?
Blitz3D Forums/Blitz3D Programming/How do I set various difficulty settings?
| ||
Hi, I am wondering how to implement difficulty settings into my game, "Plasmorg: Science Chaos Theory." This is another mystery for that game again. You remember that I was querying in another thread regarding another issue earlier, that's resolved now, as you can see in the code below:; Plasmorg.bb - This is the source code for the game project, "Plasmorg: Science Chaos Theory" ; (c)2006, Robert A. Morin, RAM Digital Media ; ------------------------------------------- ; First, set the graphics resolution to 800x600 Graphics 800,600 ; Below is the copyright information, the logo screen, and the game title logo sequence... ; First, make sure that the screen is clear before continuing Cls ; First, load the images for the copyright, the title, and the game logo Global copyrightimage = LoadImage("copyright.bmp") Global logoimage = LoadImage("logo.bmp") Global titleimage = LoadImage("title.bmp") Global epilogueimage = LoadImage("epilogue.bmp") ; This first image is the red/purple/magenta smoke in the background Global redimage = LoadImage("redsmoke.bmp") ; The front image is the yellow/cyan/periwinkle image of smoke Global yellowimage = LoadImage("yellowsmoke.bmp") ; Now, load in the spooky background sound in the background Global backsound = LoadSound("background.wav") Global bulletsound = LoadSound("zapper.wav") Global magicsound = LoadSound("magic.wav") Global explosionsound = LoadSound("explode.wav") Global ambientsound = LoadSound("ambience.wav") ; Now, take a variable to track the scrolling of these images scrolly = 0 ; The following are the constants used for this game Const PLAYERSPEED = 10 Const ENEMYSPEED = 10 Const NORMALBULLET = 1, MISSILE = 2 ; Below, load the type used to move the player's object around the screen Type player Field x, y ; These define the coordinates that the player moves on Field frame ; This defines the frames that are drawn from the animation Field collision ; This defines the collision done between you and your enemy Field hits ; These are the hits that you knock down your enemy with Field image ; This defines the image for the player End Type Type enemy Field x, y ; These define the coordinates that the enemy moves on Field xv, yv ; These define the velocity that the enemy AI uses Field image ; This defines the image that the enemy uses Field frame ; This will define the frames used in the rotation of the enemy when he moves End Type Type bullet Field x, y ; These define the coordinates that the bullet takes Field image ; This is the image definition for the bullet Field bullettype ; This defines whether you have a short spike or a magic brick block Field frame ; This defines the frame for the animations when the bullet or missile is fired End Type ; Now, the following will create the player for the game ; Provide the starting values for the player and the enemy Global player.player = New player player\x = 400 player\y = 400 player\frame = 0 player\collision = 0 player\image = LoadAnimImage("player.bmp",64,64,0,8) Global enemy.enemy = New enemy enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-5,5) enemy\yv = Rand(-5,5) enemy\image = LoadAnimImage("enemy.bmp",64,64,0,8) enemy\frame = 0 ; Display the copyright/credits screen first ; Make sure the screen is clear Cls DrawImage copyrightimage,0,0 Delay 5000 ; Now, clear the screen and display the RAM Digital Media logo Cls DrawImage logoimage,0,0 Delay 5000 ; Then, load the game title screen Cls DrawImage titleimage,0,0 ; Play and loop the spooky ambience for this game LoopSound ambientsound PlaySound ambientsound ; Start playing the sound while the background loads LoopSound backsound PlaySound backsound Delay 5000 ; Next, load the epilogue, and wait for the player to press a key to start Cls DrawImage epilogueimage,0,0 WaitKey ; Initialize the default settings for AutoMidHandle and BackBuffer AutoMidHandle True SetBuffer BackBuffer() ; Below starts the main loop for this part of the program While Not KeyDown(1) ; Next, make sure that the screen is clear before setting the smoke Cls ; Now, tile the red smoke below, and the brighter smoke on the second layer TileImage redimage,0,scrolly TileImage yellowimage,0,scrolly*2 ; Increase the value of the scrolly variable scrolly = scrolly + 1 ; Once the tracking variable exceeds the maximum value, reset it to 0 If scrolly >= ImageHeight(yellowimage) scrolly = 0 EndIf ; Display the image's coordinates for his movements Text 0,0, "X Coord:\> " + player\x Text 0,12, "Y Coord:\> " + player\y Text 0,500, "PLAYER SCORE:\> " + player\hits Text 0,512, "ENEMY SCORE :\> " + player\collision TestEnemyCollisions() TestKeys() CollisionCrashMedium() If KeyDown(57) bullets.bullet = New bullet bullets\x = player\x bullets\y = player\y bullets\image = LoadAnimImage("bullet.bmp",12,12,0,8) bullets\bullettype = NORMALBULLET bullets\frame = 0 PlaySound bulletsound EndIf If KeyDown(14) bullets.bullet = New bullet bullets\x = player\x bullets\y = player\y bullets\image = LoadAnimImage("block.bmp",32,32,0,8) bullets\bullettype = MISSILE bullets\frame = 0 PlaySound magicsound EndIf UpDateBullets() ; Below is the enemy's image specifications enemy\image = LoadAnimImage("enemy.bmp",64,64,0,8) ; Move the enemy in the same direction as the player does, thus, trying to crash into him If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEED enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEED enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEED enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEED enemy\frame = enemy\frame + 1 EndIf If enemy\frame > 7 enemy\frame = 0 ElseIf enemy\frame < 0 enemy\frame = 7 EndIf ; The following will keep the enemy in motion and try to fly around you, and collide into you enemy\x = enemy\x + enemy\xv enemy\y = enemy\y + enemy\yv ; Once the enemy reaches the edges of the screen, move him back into range If enemy\x <= 0 enemy\x = 0 ElseIf enemy\x >= 800 enemy\x = 800 EndIf If enemy\y <= 0 enemy\y = 0 ElseIf enemy\y >= 600 enemy\y = 600 EndIf ; Now, draw the images of both you and the enemy DrawImage enemy\image, enemy\x, enemy\y, enemy\frame DrawImage player\image, player\x, player\y, player\frame ; Once the left key is pressed, move the player in that direction and decrease the frame If KeyDown (203) player\x = player\x - PLAYERSPEED player\frame = player\frame - 1 EndIf ; Once the right key is pressed, move the player in that direction, and increase the frame If KeyDown (205) player\x = player\x + PLAYERSPEED player\frame = player\frame + 1 EndIf ; Once the down key is pressed, move the player in that direction, and decrease the frame If KeyDown (208) player\y = player\y + PLAYERSPEED player\frame = player\frame - 1 EndIf ; Once the up key is pressed, move the player in that direction, and increase the frame If KeyDown (200) player\y = player\y - PLAYERSPEED player\frame = player\frame + 1 EndIf ; Set the frag limit to 20, and display the final score and game over If player\hits = 20 GameOver() EndIf If player\collision = 20 GameOver() EndIf If player\frame > 7 player\frame = 0 ElseIf player\frame < 0 player\frame = 7 EndIf ; Allow for a brief delay Delay 100 Flip Wend ; This officially ends the program loop Function TestEnemyCollisions() ; Reverse the enemy's velocity if he hits an edge of the screen If enemy\x < 0 enemy\xv = -enemy\xv EndIf If enemy\x > 800 enemy\xv = -enemy\xv EndIf If enemy\y < 0 enemy\yv = -enemy\yv EndIf If enemy\y > 600 enemy\yv = -enemy\yv EndIf End Function Function TestKeys() ; Once the left key is pressed, move the player in that direction and decrease the frame If KeyDown (203) player\x = player\x - PLAYERSPEED EndIf ; Once the right key is pressed, move the player in that direction, and increase the frame If KeyDown (205) player\x = player\x + PLAYERSPEED EndIf ; Once the down key is pressed, move the player in that direction, and decrease the frame If KeyDown (208) player\y = player\y + PLAYERSPEED EndIf ; Once the up key is pressed, move the player in that direction, and increase the frame If KeyDown (200) player\y = player\y - PLAYERSPEED EndIf End Function Function UpDateBullets() For bullets.bullet = Each bullet bullets\y = bullets\y - 10 bullets\frame = bullets\frame + 1 If bullets\frame > 7 bullets\frame = 0 ElseIf bullets\frame < 0 bullets\frame = 7 EndIf DrawImage bullets\image,bullets\x,bullets\y,bullets\frame If (ImagesOverlap(enemy\image,enemy\x,enemy\y,bullets\image,bullets\x,bullets\y)) PlaySound explosionsound Cls Text 300,300, "ENEMY HIT!!! Player Scores..." player\hits = player\hits + 1 Text 300,312, "Player:\> " + player\hits Text 300,324, "Enemy :\> " + player\collision Flip Delay 4000 ; Remove all bullets from the screen For bullets.bullet = Each bullet Delete bullets Next ; Place the positions of the enemy and yourself player\x = 400 player\y = 400 ; Load the player image player\image = LoadAnimImage("player.bmp",64,64,0,8) ; Now, place the enemy's position enemy\x = 400 enemy\y = 200 ; Provide the velocity range for the enemy enemy\xv = Rand (-10,10) enemy\yv = Rand (-10,10) Return EndIf If bullets\y = 0 Delete bullets EndIf Next End Function Function CollisionCrashMedium() If (ImagesOverlap(player\image,player\x,player\y,enemy\image,enemy\x,enemy\y)) PlaySound explosionsound Cls Text 300,300, "CRASH!!! Enemy Scores..." player\collision = player\collision + 1 Text 300,312, "Player:\> " + player\hits Text 300,324, "Enemy :\> " + player\collision Flip Delay 4000 ; Remove all bullets from the screen For bullets.bullet = Each bullet Delete bullets Next player\x = 400 player\y = 400 player\image = LoadAnimImage("player.bmp",64,64,0,8) enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-10,10) enemy\yv = Rand(-10,10) EndIf End Function Function GameOver() Cls For bullets.bullet = Each bullet Delete bullets Next Text 300,300, "G A M E O V E R ! ! !" Text 300,312, "-----------------------" Text 300,324, "Final Score..." Text 300,336, "Player:\> " + player\hits Text 300,348, "Enemy :\> " + player\collision Text 0,512, "Press <ESC> to Return to Desktop: " Text 0,524, "Press <TAB> to Start New Round : " If KeyDown (15) Cls Text 300,300, "Resetting Game, Please Wait..." Flip Delay 4000 ; Now, reset the scores for the hits and collisions player\hits = 0 player\collision = 0 ; Reset the images for the player and enemy player\x = 400 player\y = 400 player\image = LoadAnimImage("player.bmp",64,64,0,8) enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-10,10) enemy\yv = Rand(-10,10) EndIf End Function Now, the question is, I set the default difficulty setting to medium. However, I'd like to set different tiers of enemy speeds to make the game more difficult and faster, if you choose to make the game harder, or slower and easier if you opt for the easiest of settings. This will be more enjoyable of a game if I can adjust the speed based on different levels of play. Obviously the physical code would be similar, but the enemy's speed would be factored in, and possibly the speed that the bullets fly, too, not too sure. Where would you place the menu for adjusting the difficulty, and would you need to write different functions for each difficulty level? |
| ||
Put your difficulty options menu code directly after these lines:; Next, load the epilogue, and wait for the player to press a key to start Cls DrawImage epilogueimage,0,0 WaitKeyand change the WaitKey to key = WaitKey() Then check what key was pressed and change to your difficulty menu or start the game, depending on which key was pressed. |
| ||
Err, okay, now, how would this menu interact with the program loop? This way, I wanted to really use this hand-in-hand with the functions, and the main program loop, which it has to obviously do. I obviously need about three to five different functions for the different difficulty levels, on the other hand, the main program loop really can't use all five of these functions at once, or else it'll foul up the wazoo on the enemy AI. |
| ||
This code hardly does anything at all to the enemy AI, as a matter of fact, he doesn't even have a "brain" at all, he's just a free-floating sprite without having any commands to sense and crash into you at all. This wasn't the type of code I was expecting, how should this really be done? Here's the updated code: ; Plasmorg.bb - This is the source code for the game project, "Plasmorg: Science Chaos Theory" ; (c)2006, Robert A. Morin, RAM Digital Media ; ------------------------------------------- ; First, set the graphics resolution to 800x600 Graphics 800,600 ; Below is the copyright information, the logo screen, and the game title logo sequence... ; First, make sure that the screen is clear before continuing Cls ; First, load the images for the copyright, the title, and the game logo Global copyrightimage = LoadImage("copyright.bmp") Global logoimage = LoadImage("logo.bmp") Global titleimage = LoadImage("title.bmp") Global epilogueimage = LoadImage("epilogue.bmp") Global menuimage = LoadImage("mainmenu.bmp") Global difficultyimage = LoadImage("difficulty.bmp") ; This first image is the red/purple/magenta smoke in the background Global redimage = LoadImage("redsmoke.bmp") ; The front image is the yellow/cyan/periwinkle image of smoke Global yellowimage = LoadImage("yellowsmoke.bmp") ; Now, load in the spooky background sound in the background Global backsound = LoadSound("background.wav") Global bulletsound = LoadSound("zapper.wav") Global magicsound = LoadSound("magic.wav") Global explosionsound = LoadSound("explode.wav") Global ambientsound = LoadSound("ambience.wav") Global logosound = LoadSound("whoosh.wav") ; Now, take a variable to track the scrolling of these images scrolly = 0 ; The following are the constants used for this game Const PLAYERSPEED = 10 Const ENEMYSPEEDEASY = 5, ENEMYSPEEDMEDIUM = 10, ENEMYSPEEDHARD = 20, ENEMYSPEEDCHAOS = 30 Const NORMALBULLET = 1, MISSILE = 2 ; Below, load the type used to move the player's object around the screen Type player Field x, y ; These define the coordinates that the player moves on Field frame ; This defines the frames that are drawn from the animation Field collision ; This defines the collision done between you and your enemy Field hits ; These are the hits that you knock down your enemy with Field image ; This defines the image for the player End Type Type enemy Field x, y ; These define the coordinates that the enemy moves on Field xv, yv ; These define the velocity that the enemy AI uses Field image ; This defines the image that the enemy uses Field frame ; This will define the frames used in the rotation of the enemy when he moves End Type Type bullet Field x, y ; These define the coordinates that the bullet takes Field image ; This is the image definition for the bullet Field bullettype ; This defines whether you have a short spike or a magic brick block Field frame ; This defines the frame for the animations when the bullet or missile is fired End Type ; Now, the following will create the player for the game ; Provide the starting values for the player and the enemy Global player.player = New player player\x = 400 player\y = 400 player\frame = 0 player\collision = 0 player\image = LoadAnimImage("player.bmp",64,64,0,8) Global enemy.enemy = New enemy enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-5,5) enemy\yv = Rand(-5,5) enemy\image = LoadAnimImage("enemy.bmp",64,64,0,8) enemy\frame = 0 ; Display the copyright/credits screen first ; Make sure the screen is clear Cls DrawImage copyrightimage,0,0 Delay 5000 ; Now, clear the screen and display the RAM Digital Media logo Cls DrawImage logoimage,0,0 PlaySound logosound Delay 5000 ; Then, load the game title screen Cls DrawImage titleimage,0,0 ; Play and loop the spooky ambience for this game LoopSound ambientsound PlaySound ambientsound ; Start playing the sound while the background loads LoopSound backsound PlaySound backsound Delay 5000 ; Next, load the epilogue, and wait for the player to press a key to start Cls DrawImage epilogueimage,0,0 start=WaitKey() ; Go to the main menu screen Cls DrawImage menuimage,0,0 resume=WaitKey() ; Once player chooses to start, bring up the different difficulty levels for the game If resume = KeyHit(3) End EndIf ; If the start game was hit, continue, if the quit game was hit, quit Cls DrawImage difficultyimage,0,0 key=WaitKey() ; Initialize the default settings for AutoMidHandle and BackBuffer AutoMidHandle True SetBuffer BackBuffer() ; Below starts the main loop for this part of the program While Not KeyDown(1) ; Next, make sure that the screen is clear before setting the smoke Cls ; Now, tile the red smoke below, and the brighter smoke on the second layer TileImage redimage,0,scrolly TileImage yellowimage,0,scrolly*2 ; Increase the value of the scrolly variable scrolly = scrolly + 1 ; Once the tracking variable exceeds the maximum value, reset it to 0 If scrolly >= ImageHeight(yellowimage) scrolly = 0 EndIf ; Display the image's coordinates for his movements Text 0,0, "X Coord:\> " + player\x Text 0,12, "Y Coord:\> " + player\y Text 0,500, "PLAYER SCORE:\> " + player\hits Text 0,512, "ENEMY SCORE :\> " + player\collision TestEnemyCollisions() CollisionCrash() If KeyDown(57) bullets.bullet = New bullet bullets\x = player\x bullets\y = player\y bullets\image = LoadAnimImage("bullet.bmp",12,12,0,8) bullets\bullettype = NORMALBULLET bullets\frame = 0 PlaySound bulletsound EndIf If KeyDown(14) bullets.bullet = New bullet bullets\x = player\x bullets\y = player\y bullets\image = LoadAnimImage("block.bmp",32,32,0,8) bullets\bullettype = MISSILE bullets\frame = 0 PlaySound magicsound EndIf UpDateBullets() ; Below is the enemy's image specifications enemy\image = LoadAnimImage("enemy.bmp",64,64,0,8) ; Move the enemy in the same direction as the player does, thus, trying to crash into him If key = KeyHit(2) If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEEDEASY enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEEDEASY enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEEDEASY enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEEDEASY enemy\frame = enemy\frame + 1 EndIf EndIf If key = KeyHit(3) If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEEDMEDIUM enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEEDMEDIUM enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEEDMEDIUM enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEEDMEDIUM enemy\frame = enemy\frame + 1 EndIf EndIf If key = KeyHit(4) If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEEDHARD enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEEDHARD enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEEDHARD enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEEDHARD enemy\frame = enemy\frame + 1 EndIf EndIf If key = KeyHit(5) If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEEDCHAOS enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEEDCHAOS enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEEDCHAOS enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEEDCHAOS enemy\frame = enemy\frame + 1 EndIf EndIf If enemy\frame > 7 enemy\frame = 0 ElseIf enemy\frame < 0 enemy\frame = 7 EndIf ; The following will keep the enemy in motion and try to fly around you, and collide into you enemy\x = enemy\x + enemy\xv enemy\y = enemy\y + enemy\yv ; Once the enemy reaches the edges of the screen, move him back into range If enemy\x <= 0 enemy\x = 0 ElseIf enemy\x >= 800 enemy\x = 800 EndIf If enemy\y <= 0 enemy\y = 0 ElseIf enemy\y >= 600 enemy\y = 600 EndIf ; Now, draw the images of both you and the enemy DrawImage enemy\image, enemy\x, enemy\y, enemy\frame DrawImage player\image, player\x, player\y, player\frame ; Once the left key is pressed, move the player in that direction and decrease the frame If KeyDown (203) player\x = player\x - PLAYERSPEED player\frame = player\frame - 1 EndIf ; Once the right key is pressed, move the player in that direction, and increase the frame If KeyDown (205) player\x = player\x + PLAYERSPEED player\frame = player\frame + 1 EndIf ; Once the down key is pressed, move the player in that direction, and decrease the frame If KeyDown (208) player\y = player\y + PLAYERSPEED player\frame = player\frame - 1 EndIf ; Once the up key is pressed, move the player in that direction, and increase the frame If KeyDown (200) player\y = player\y - PLAYERSPEED player\frame = player\frame + 1 EndIf ; Set the frag limit to 20, and display the final score and game over If player\hits = 20 GameOver() EndIf If player\collision = 20 GameOver() EndIf If player\frame > 7 player\frame = 0 ElseIf player\frame < 0 player\frame = 7 EndIf ; Allow for a brief delay Delay 100 Flip Wend ; This officially ends the program loop Function TestEnemyCollisions() ; Reverse the enemy's velocity if he hits an edge of the screen If enemy\x < 0 enemy\xv = -enemy\xv EndIf If enemy\x > 800 enemy\xv = -enemy\xv EndIf If enemy\y < 0 enemy\yv = -enemy\yv EndIf If enemy\y > 600 enemy\yv = -enemy\yv EndIf End Function Function TestKeys() ; Once the left key is pressed, move the player in that direction and decrease the frame If KeyDown (203) player\x = player\x - PLAYERSPEED EndIf ; Once the right key is pressed, move the player in that direction, and increase the frame If KeyDown (205) player\x = player\x + PLAYERSPEED EndIf ; Once the down key is pressed, move the player in that direction, and decrease the frame If KeyDown (208) player\y = player\y + PLAYERSPEED EndIf ; Once the up key is pressed, move the player in that direction, and increase the frame If KeyDown (200) player\y = player\y - PLAYERSPEED EndIf End Function Function UpDateBullets() For bullets.bullet = Each bullet bullets\y = bullets\y - 10 bullets\frame = bullets\frame + 1 If bullets\frame > 7 bullets\frame = 0 ElseIf bullets\frame < 0 bullets\frame = 7 EndIf DrawImage bullets\image,bullets\x,bullets\y,bullets\frame If (ImagesCollide(enemy\image,enemy\x,enemy\y,enemy\frame,bullets\image,bullets\x,bullets\y,bullets\frame)) PlaySound explosionsound Cls Text 300,300, "ENEMY HIT!!! Player Scores..." player\hits = player\hits + 1 Text 300,312, "Player:\> " + player\hits Text 300,324, "Enemy :\> " + player\collision Flip Delay 4000 ; Remove all bullets from the screen For bullets.bullet = Each bullet Delete bullets Next ; Place the positions of the enemy and yourself player\x = 400 player\y = 400 ; Load the player image player\image = LoadAnimImage("player.bmp",64,64,0,8) ; Now, place the enemy's position enemy\x = 400 enemy\y = 200 ; Provide the velocity range for the enemy enemy\xv = Rand (-10,10) enemy\yv = Rand (-10,10) Return EndIf If bullets\y = 0 Delete bullets EndIf Next End Function Function CollisionCrash() If (ImagesCollide(player\image,player\x,player\y,player\frame,enemy\image,enemy\x,enemy\y,enemy\frame)) PlaySound explosionsound Cls Text 300,300, "CRASH!!! Enemy Scores..." player\collision = player\collision + 1 Text 300,312, "Player:\> " + player\hits Text 300,324, "Enemy :\> " + player\collision Flip Delay 4000 ; Remove all bullets from the screen For bullets.bullet = Each bullet Delete bullets Next player\x = 400 player\y = 400 player\image = LoadAnimImage("player.bmp",64,64,0,8) enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-10,10) enemy\yv = Rand(-10,10) EndIf End Function Function GameOver() Cls For bullets.bullet = Each bullet Delete bullets Next Text 300,300, "G A M E O V E R ! ! !" Text 300,312, "-----------------------" Text 300,324, "Final Score..." Text 300,336, "Player:\> " + player\hits Text 300,348, "Enemy :\> " + player\collision Text 0,512, "Press <ESC> to Return to Desktop: " Text 0,524, "Press <TAB> to Start New Round : " If KeyDown (15) Cls Text 300,300, "Resetting Game, Please Wait..." Flip Delay 4000 ; Now, reset the scores for the hits and collisions player\hits = 0 player\collision = 0 ; Reset the images for the player and enemy player\x = 400 player\y = 400 player\image = LoadAnimImage("player.bmp",64,64,0,8) enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-10,10) enemy\yv = Rand(-10,10) EndIf End Function This really didn't do as I expected whatsoever, there has to be a better approach than this for doing difficulty settings for the enemy AI. |
| ||
First of all, edit your posts and change your code listings using the [codebox] commands please. |
| ||
this bit of code:; Go to the main menu screen Cls DrawImage menuimage,0,0 resume=WaitKey() ; Once player chooses to start, bring up the different difficulty levels for the game If resume = KeyHit(3) End EndIf ; If the start game was hit, continue, if the quit game was hit, quitshould really be a loop. It doesn't handle a situation such as the player pressing an incorrect key. You can't do this: If key = KeyHit(4)because it will only be true the FIRST time you use it. After that, (unless the player pressed the key again), it will return false. You have to use it like so: If key = 4 By the way, I would rename your variable "key" to something more intuitive, such as "difficultysetting" or the like. You should change this section of code: Cls DrawImage difficultyimage,0,0 key=WaitKey()to a loop and read something like this: Repeat Cls DrawImage difficultyimage,0,0 key=WaitKey() Select key Case 49 difficultysetting = 1 Case 50 difficultysetting = 2 ;etc... End Select Until difficultysetting > 0 |
| ||
Also there's no need to have 4 sections of code that read exactly the same:If difficultysetting = 3 If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEEDHARD enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEEDHARD enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEEDHARD enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEEDHARD enemy\frame = enemy\frame + 1 EndIf EndIfInstead, change your Constants into an array. This way you can reuse your code. Something like this: ;in the beginning of your program Dim enemyspeed(4) enemyspeed(1) = 5 enemyspeed(2) = 10 enemyspeed(3) = 20 enemyspeed(4) = 30 ;in you main loop If player\y > enemy\y enemy\y = enemy\y + enemyspeed(difficultysetting) enemy\frame = enemy\frame - 1 EndIf If player\x < enemy\x enemy\x = enemy\x - enemyspeed(difficultysetting) enemy\frame = enemy\frame - 1 EndIf If player\y < enemy\y enemy\y = enemy\y - enemyspeed(difficultysetting) enemy\frame = enemy\frame + 1 EndIf If player\x > enemy\x enemy\x = enemy\x + enemyspeed(difficultysetting) enemy\frame = enemy\frame + 1 EndIf |
| ||
Ahh, okay, I'll be sure to use all that in the code sometime tonight or tomorrow. It looks like a go. However, after this keyboard/mouse version of the game is done, I'm probably going to make a joystick/console-style version of this game, so I'll probably need assistance programming this game around a PS2-style gamepad (or the style that most gamepads use for PCs). Should be interesting to make a console-style game out of this (probably won't be ported to XBox rather easily, but at least it's worth doing as a cool PC arcade-style game). |