Killed Zombie Inc Scores by 10 -
Higscore Table Implementation -
Every 10 Zombie Kills inc the count of Zombies on screen -
I`ll greatly appretiate if you make credits in your game and put my name in it because it`s at least the right to do after i do this for you.You need to align the code because it`s a mess now, but it`s late now and this isn`t that big problem.I allready cleared the bugs that pop in the process of coding the above.
To run this code you need Matrix1 plugin, it`s because the highscore table use it.If you are not happy with this you allways can port everything to clean dbpro code if you like.But i think downloading and installing the plugin would be faster.And it`s a good one, a must have one!
I assume this is some school project or something and you hit the deadline so i helped here and there, but please read the code i wrote to understand what is doing what and why.It`s not complicated.
Best regards!
I can`t wait to see the game in program announcements when you finish it.
I suggest to rewrite the menus, because now they are somehow unnecessery complicated.Making them with sprites by my opinion is easier to maintain.
Cheers!
I allmost forget to post the code here...
Here it is:
Rem Game Revamped
Set Display Mode 800,600,16
sync on : sync rate 100 : backdrop on
Hide Mouse
draw to front
Set Text transparent
Set Image ColorKey 255, 0, 255
#constant true = 1
#constant false = 0
global TotalZombies : TotalZombies = 10
global scorecount
global killedzombies
type playerData
x,y,status,img,SprNum,speed
endtype
player as playerData
type ZombieData
x,y,status,img,SprNum,speedX,speedY,DieFade
endtype
type highscore
name$ as string
points as integer
endtype
#CONSTANT max_board = 9
dim highscores(max_board) as highscore
dim listing$(max_board) as string
pos_offset = max_board
FileID = find free datafile()
if file exist ("highscore.dat") = 0
open datafile to write FileID,"highscore.dat"
for write = 0 to max_board
highscores(pos_offset-write).name$ = "anarhist"
write datafile string FileID,highscores(pos_offset-write).name$
highscores(pos_offset-write).points = (pos_offset-write)*10
write datafile integer FileID,highscores(pos_offset-write).points
next write
close datafile FileID
endif
if file exist ("highscore.dat") = 1
open datafile to read FileId,"highscore.dat"
for reading = 0 to max_board
highscores(reading).name$ = datafile string$ (FileID)
highscores(reading).points = datafile integer (FileID)
next reading
close datafile FileID
endif
dim zombie(TotalZombies) as ZombieData
gosub Initialize
LoadImages()
InitZombies(1,TotalZombies)
State = 0
do
select State
case 0
gosub Menu
endcase
case 1
gosub Info : state = 2
endcase
case 2
show sprite player.SprNum
for p = 1 to TotalZombies
if zombie(p).status = 1 then show sprite zombie(p).SprNum
next p
gosub Game
exit
endcase
endselect
sync
loop
Initialize:
MaxRight = 800 : MaxDown = 600
MaxBullets = 20 : BulletSpeed = 3
white = rgb(255,255,255) : red = rgb(255,0,0)
global NPCMoveDelay : global NPCMoveMaster : NPCMoveMaster = 20
global ZombieStatus : global ZombieDieFade
global ScrWid : ScrWid = screen width() : global ScrHgt : ScrHgt = screen height()
global BulletCount : BulletCount = 0
global FieldImage : FieldImage = 1 : global BulletImage : BulletImage = 2
dim bullet(MaxBullets,3)
player.x = 320 : player.y = 240 : player.img = 50
player.SprNum = 50 : player.speed = 3
FireBulletDelay = timer() + 200 : NPCMoveDelay = timer() + NPCMoveMaster
return
Menu:
repeat
ink white,0
center text 320,220,"Play Game"
center text 320,240,"High Score"
center text 320,260,"Instructions"
center text 320,280,"Story"
center text 320,300,"Exit"
select SelectedItem
case 0
ink red,0
center text 320,220,"Play Game"
endcase
case 1
ink red,0
center text 320,240,"High Score"
endcase
case 2
ink red,0
center text 320,260,"Instructions"
endcase
case 3
ink red,0
center text 320,280,"Story"
endcase
case 4
ink red,0
center text 320,300,"Exit"
endcase
endselect
if upkey()
if KeyU = 0
dec SelectedItem
if SelectedItem < 0 then SelectedItem = 2
endif
KeyU = 1
else
KeyU = 0
endif
if downkey()
if KeyD = 0
inc SelectedItem
if SelectedItem > 4 then SelectedItem = 0
endif
KeyD = 1
else
KeyD = 0
endif
if returnkey()
if KeyR = 0
if SelectedItem = 0
State = StateGame
MoveCount = 0
SheepMove = 1
FarmerX = 320
FarmerY = 400
State = 2
endif
if SelectedItem = 1
cls
for listing = 0 to max_board
if listing <> max_board
listing$(listing) = str$(listing+1)+". "+highscores(listing).name$ +" "+str$(highscores(listing).points)
else
listing$(listing) = str$(listing+1)+". "+highscores(listing).name$ +" "+str$(highscores(listing).points)
endif
text 200,50+(15*listing),listing$(listing)
next listing
sync
wait key
ENDIF
if SelectedItem = 2 then state = 1
if SelectedItem = 3
` wait until the user lets go of the ENTER key
repeat
until scancode() = 0
repeat
cls
print "Johnny Frostmelt, who is an experienced racing pilot, has been longing to race around"
print "the Bermuda Triangle. He plans on trying to break the record time for racing around"
print "the Bermuda Triangle." : print
print "Johnny Frostmelt is the only person left on the remote island of Isowaloway. It is an"
print "undiscovered island located in the Bermuda Triangle. He was a race pilot who accidently"
print "strayed into the triangle due to an engine failure. He arrives on the island to see many"
print "planes that had been noted of disappearing. He tries to make contact several times,"
print "noticing he is in a farm yard. He looks around and notices that the place is completely"
print "deserted. Johnny tries the radio for back up 'Come in skittles this is Johnny can you"
print "read me' The radio is just the sound of high interference. Johnny sets off in what seems"
print "like a wasteland searching for someone who will get him back home."
print : print "After searching around for some time he comes across a note that has been left"
print " stuck to wooden post. The hordes are coming... they cannot be stopped, I am so sorry..."
print " Try and hold out but I’m afraid that no one will come to rescue you... You’ll just have"
print "to survive as long as you can, but I’m afraid it will be to no avail." : print
print "If you manage to somehow make it through then I wish you luck...Keep pushing till you can’t"
print "push anymore...for mankind!" : print
print "Johnny laughs out thinking it’s a joke and continues down the dirt road he sees a shadowy"
print "figure slowly moving closer and closer it looks deformed from this distance. All of a sudden"
print " more shadowy figures appear and more and more. "
print "'What the hell is going on here?' Johnny mutters under his breath. He walks towards the crowd,"
print "hoping that it’s just a crowd of people coming home from a party. More and more shadowy "
print "figures appear from all other angles and close around Johnny. He looks closer and see’s a"
print " deformed face. “Oh my god” Screams Johnny, pulling out his gun he always carries on him."
print "'What’s happening?' Johnny calls out the deformed figure closest to him. It grunts and"
print "continues to move closer to him, the stench is foul and shaking clutching his note he looks"
print "down the at the letter. It falls from his hand and blows away with the wind. He’s alone"
print "surrounded by what seems a never ending army of zombies. He raises his gun......"
print : print : print "Press any key to continue."
sync
until scancode() > 0
endif
if SelectedItem = 4
End
endif
endif
KeyR = 1
else
KeyR = 0
endif
sync
until returnkey() = true
return
Info:
repeat
ink rgb(255,0,0),0
center text 320,280,"Use the Directional keys to move the character and space bar to fire the gun"
center text 320,300,"Survive as long as you can!"
center text 320,340,"Click the left mouse button to return to the main menu."
REM Returnkey will send you back to Menu
if returnkey()
if KeyR = 0
State = StateMenu
SelectedItem = 0
endif
KeyR = 1
else
KeyR = 0
endif
sync
until mouseclick() = 1
return
Game:
NPCMoveDelay = timer() + NPCMoveMaster
Rem *********************** Main Program Loop *********************************
Do
Gosub UserInput
Gosub MoveBullet
if timer() > NPCMoveDelay
Gosub MoveNPC : NPCMoveDelay = timer() + NPCMoveMaster
endif
gosub LEVEL
Debug()
sync
Loop
Rem *********************** Main Program Loop *********************************
end
UserInput:
If Spacekey() = true and timer() > FireBulletDelay Then Gosub AddBullet
if upkey()
move sprite player.SprNum,Player.Speed
Xpos = sprite x(player.SprNum) : Ypos = sprite y(player.SprNum)
` check to make sure it will stay on - screen
if Xpos < sprite width(player.SprNum) or Xpos > (MaxRight - sprite width(player.SprNum)) then move sprite player.SprNum,-player.Speed
if Ypos < Sprite height(player.SprNum) or Ypos > (MaxDown - sprite height(player.SprNum)) then move sprite player.SprNum,-player.Speed
endif
if downkey()
move sprite player.SprNum,-player.Speed
Xpos = sprite x(player.SprNum) : Ypos = sprite y(player.SprNum)
` check to make sure it will stay on - screen
if Xpos < sprite width(player.SprNum) or Xpos > (MaxRight - sprite width(player.SprNum)) then move sprite player.SprNum,player.Speed
if Ypos < Sprite height(player.SprNum) or Ypos > (MaxDown - sprite height(player.SprNum)) then move sprite player.SprNum,player.Speed
endif
` Add one to SpriteAngle and rotate sprite
if leftkey()
xa# = wrapvalue(Sprite Angle(player.SprNum) - 3)
rotate sprite player.SprNum,xa#
endif
` Subtract one from SpriteAngle and rotate sprite
if rightkey()
xa# = wrapvalue(Sprite Angle(player.SprNum) + 3)
rotate sprite player.SprNum,xa#
endif
return
MoveBullet:
BulletCount = 0
For N = 1 To MaxBullets
If bullet(n,1) = true
move sprite 199 + n,BulletSpeed
Rem Check For Bullet Going Off Top Of Screen Here And Deal With It
Xpos = sprite x(199 + n) : Ypos = sprite y(199 + n)
If Xpos < 0 or Xpos > MaxRight or Ypos < 0 or Ypos > MaxDown
bullet(n,1) = false : ` status = off
if sprite exist(199 + n) = true then delete sprite 199 + n
Else
for p = 1 to TotalZombies
if Zombie(p).Status = 1 and sprite exist(199 + n) = true: ` check only if the Zombie is alive
Rem Check For Hit Enemy Here And Deal With It
if sprite collision(199 + n,zombie(p).SprNum) = true
` got the zombie!
` erase the bullet
bullet(n,1) = false : ` status = off
if sprite exist(199 + n) = true
delete sprite (199 + n)
endif
inc score,100
Zombie(p).Status = 2 : ` dying
Zombie(p).DieFade = 200
set sprite alpha zombie(p).SprNum,Zombie(p).DieFade
endif
endif
next p
Endif
if bullet(n,1) = true then inc BulletCount
Endif
Next N
Return
AddBullet:
available = 0
For N = 1 To MaxBullets
If bullet(n,1) = 0 then available = n : exit
next n
if available > 0
bullet(available,1) = 1 : ` status = fired
bullet(available,2) = sprite x(player.SprNum) : ` set bullet's intial X position
bullet(available,3) = sprite y(player.SprNum) : ` set bullet's initial Y position
xa# = sprite angle(player.SprNum)
sprite 199 + available,bullet(available,2),bullet(available,3),BulletImage
rotate sprite 199 + available,xa#
FireBulletDelay = timer() + 200
endif
Return
MoveNPC:
for p = 1 to TotalZombies
if zombie(p).status = 1 : ` active
px = sprite x(player.SprNum) : py = sprite y(player.SprNum)
zx = sprite x(Zombie(p).SprNum) : zy = sprite y(Zombie(p).SprNum)
XDiff = abs(px - zx) : YDiff = abs(py - zy)
if Xdiff <= 18 and Ydiff <= 18
` if sprite collision(player.SprNum,zombie(p).SprNum) = true
` got the player
clear entry buffer
repeat
text 100,100,"A Zombie got you!!"
text 100,120,"Press any mouse button to try again."
playername$ = entry$(1)
text 100,140,"Your Name: "+playername$
sync
until keystate(28)
name$ = playername$
points = scorecount
if points > highscores(max_board).points
highscores(max_board).name$ = name$
highscores(max_board).points = points
sort array highscores(),-2
open datafile to write FileID,"highscore.dat"
for write = 0 to max_board
write datafile string FileID,highscores(write).name$
write datafile integer FileID,highscores(write).points
next write
close datafile FileID
endif
cls
gosub ReStart
return
endif
if (px > zx) and (px - zx) > 16
zx = zx + zombie(p).SpeedX
else
if (zx - px) > 3
zx = zx - zombie(p).SpeedX
endif
endif
if (py > zy) and (py - zy) > 16
zy = zy + zombie(p).SpeedY
else
if (zy - py) > 16
zy = zy - zombie(p).SpeedY
endif
endif
sprite zombie(p).SprNum,zx,zy,zombie(p).img
rotate sprite zombie(p).SprNum,atanfull(sprite x(player.SprNum)-sprite x(zombie(p).SprNum),sprite y(zombie(p).SprNum)-sprite y(player.SprNum))
endif
if zombie(p).status = 2 : ` dying
Zombie(p).DieFade = Zombie(p).DieFade - 5
if Zombie(p).DieFade > 0
set sprite alpha zombie(p).SprNum,Zombie(p).DieFade
else
` regenerate Zombie off the screen
InitZombies(p,p)
`THIS MAKE SCORES INC BY 10
scorecount = scorecount +10
inc killedzombies
show sprite zombie(p).SprNum
zombie(p).DieFade = 255 : set sprite alpha Zombie(p).SprNum,zombie(p).DieFade
endif
endif
next p
return
LEVEL:
if killedzombies/10 = TotalZombies
inc TotalZombies
dim zombie(TotalZombies)
ENDIF
for p = 1 to TotalZombies
if Zombie(p).Status = 0
Zombie(p).Status = 1
InitZombies(p,TotalZombies)
`show sprite zombie(p).SprNum
ENDIF
NEXT
return
Rem SCORE
`IF ZombieStatus = 1
`inc score = str$ (scorecount) + 10
function InitZombies(start,finish)
For p = start to finish
zombie(p).SprNum = 99 + p
select p
case 0 : ` left
x = rnd(50) - 100 : y = rnd(ScrHgt)
endcase
case 1 : ` up
x = rnd(ScrWid) : y = rnd(50) - 100
endcase
case 2 : ` right
x = ScrWid + rnd(50) + 50 : y = rnd(ScrHgt)
endcase
case 3 : ` down
x = rnd(ScrWid) : y = ScrHgt + rnd(50) + 50
endcase
case default
x = rnd(50) - 100 : y = rnd(ScrHgt)
endcase
endselect
zombie(p).x = x : zombie(p).y = y : zombie(p).img = 100
sprite zombie(p).SprNum,zombie(p).x,zombie(p).y,zombie(p).img
Zombie(p).status = 1 : Zombie(p).SpeedX = rnd(2) + 1 : zombie(p).SpeedY = rnd(1) + 1
offset sprite Zombie(p).SprNum,16,16
show sprite zombie(p).SprNum
` zombie(p).DieFade = 255 : set sprite alpha zombie(p).SprNum,zombie(p).DieFade
next p
endfunction
ReStart:
cls
scorecount = 0
player.x = 320 : player.y = 240 : player.img = 50
player.SprNum = 50 : player.speed = 3
sprite player.SprNum,player.x,player.y,player.img
InitZombies(1,TotalZombies)
for p = 1 to TotalZombies
if zombie(p).status = 1
zombie(p).status = 0
zombie(p).SprNum = 99 + p
if sprite exist(zombie(p).SprNum) = 1 then delete sprite zombie(p).SprNum
endif
next p
TotalZombies = 1
killedzombies = 0
return
function LoadImages()
load image "elkdamage2100ft.jpg",FieldImage
`Sprite 1, 0, 0, 1
texture backdrop FieldImage
rem bullet image
load image "bullet.bmp",BulletImage
rem setup player sprite
load image "player.bmp",player.img
sprite player.SprNum,player.x,player.y,player.img
` Offset the sprite so it rotates in the center
offset sprite player.SprNum,16,16
` SpriteAngle is a number between 0 and 359
rotate sprite player.SprNum,0
hide sprite player.SprNum
rem get zombie image
load image "C zombie.bmp",100
endfunction
function Debug()
ink rgb(255,255,0),0
text 10,10,"FPS: " + str$(screen fps())
Text 10,50,"Bullets On Screen: "+Str$(BulletCount)+" "
text 10, 100, "Score: "+str$(scorecount)+ " "
endfunction
Where there is a will, there is a way.
I often edit my posts, that`s who i am