I have rewritten a program of mine with a different theme now, and it now has an animated player (or was supposed to), and with this code, and it unfortunately, gives me an "Illegal Memory Address" message when I actually go and play it. I'm not too sure where that would occur, since all of my graphics do exist. This is the weirdest thing I believe I've ever seen. Here's the code below:
Yeah, it's the same code as DodgeFlight, but I'm making an "RPG-Shooter" hybrid out of it now, just getting away from that flight thing altogether. It's gonna be called "Plasmorg." Weird name, but once you play it, you'll understand why I call it that, that is, once this "Illegal Memory Address" is resolved.
; Plasmorg.bb - This is the source code for the game project, "Plasmorg: Star of Celestial Combat" ; (c)2006, Robert A. Morin, RAM Digital Media ; ------------------------------------------- ; First, set the graphics resolution to 640x480 Graphics3D 800,600 ; Initialize the default settings for AutoMidHandle and BackBuffer AutoMidHandle True SetBuffer BackBuffer() ; Now, load in the images for the background and foreground images ; 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") ; 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 = 5 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 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 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,6) Global enemy.enemy = New enemy enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-5,5) enemy\yv = Rand(-5,5) enemy\image = LoadImage("enemy.bmp") ; Start playing the sound while the background loads LoopSound backsound PlaySound backsound ; 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() CollisionCrash() If KeyDown(57) bullets.bullet = New bullet bullets\x = player\x bullets\y = player\y bullets\image = LoadImage("bullet.bmp") bullets\bullettype = NORMALBULLET PlaySound bulletsound EndIf If KeyDown(14) bullets.bullet = New bullet bullets\x = player\x bullets\y = player\y bullets\image = LoadImage("block.bmp") bullets\bullettype = MISSILE PlaySound magicsound EndIf UpDateBullets() ; Below is the enemy's image specifications enemy\image = LoadImage("enemy.bmp") ; Move the airplane in the same direction as the player does, thus, trying to crash into him If player\y > enemy\y enemy\y = enemy\y + ENEMYSPEED EndIf If player\x < enemy\x enemy\x = enemy\x - ENEMYSPEED EndIf If player\y < enemy\y enemy\y = enemy\y - ENEMYSPEED EndIf If player\x > enemy\x enemy\x = enemy\x + ENEMYSPEED 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 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 ; Once the frame exceeds its maximum value, reset it to the zero position If player\frame > 5 player\frame = 0 ; One that same token, if the frame is lower than the minimum value, reset it to the middle frame ElseIf player\frame < 0 player\frame = 5 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 > 5 player\frame = 0 ElseIf player\frame < 0 player\frame = 5 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 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 End Function Function UpDateBullets() For bullets.bullet = Each bullet bullets\y = bullets\y - 5 DrawImage bullets\image,bullets\x,bullets\y If (ImagesOverlap(enemy\image,enemy\x,enemy\y,bullets\image,bullets\x,bullets\y)) PlaySound explosionsound Cls Text 300,300, "Enemy Down! 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,6) ; Now, place the enemy's position enemy\x = 400 enemy\y = 200 ; Provide the velocity range for the enemy enemy\xv = Rand (-5,5) enemy\yv = Rand (-5,5) Return EndIf If bullets\y = 0 Delete bullets EndIf Next End Function Function CollisionCrash() If (ImagesOverlap(player\image,player\x,player\y,enemy\image,enemy\x,enemy\y)) PlaySound explosionsound Cls Text 300,300, "The enemy crashed into you! 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,6) enemy\x = 400 enemy\y = 200 enemy\xv = Rand(-5,5) enemy\yv = Rand(-5,5) 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 Quit: " WaitKey End Function
Yeah, it's the same code as DodgeFlight, but I'm making an "RPG-Shooter" hybrid out of it now, just getting away from that flight thing altogether. It's gonna be called "Plasmorg." Weird name, but once you play it, you'll understand why I call it that, that is, once this "Illegal Memory Address" is resolved.
