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:
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?
; 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?