rem Project Name: DNG - Berzerk!
rem Began: 23/8/2011
rem ENSURE THAT THE GAME PLAYS IN A RANDOM FASHION
randomize timer()
rem **DECLARE CONSTANTS - THESE WILL ALWAYS HOLD THE SAME VALUE**
#constant false 0
#constant true 1
rem **INIT GLOBAL VARIABLES - EVEN IN A FUNCTION, THESE WILL MAINTAIN THEIR VALUE**
global ScrWid, ScrHgt, GameState, GameOver, score, StartX, StartY
global StackNum, RoomNumber, NumberVisited, Roomchange, walltile, walkcycle, exited
global MoveToggle, CurrRoom, CurrImage, CurrSprite, CurrMusic
rem INITIAL VALUES OF SOME VARIABLES
ScrWid = screen width() : ScrHgt = screen height()
GameState = false : GameOver = false : score = false : CurrSprite = 99 : CurrImage = 99
MoveToggle = false : CurrMusic = 0
rem CHECK THE SCREEN RESOLUTION TO MAKE SURE THE DETINATION COMPUTER CAN RUN IT
RezOkay = CheckRez()
if RezOkay = false
a$ = "Sorry, screen resolution for this game not available."
b$ = "Press any key to exit."
repeat
center text ScrWid / 2,ScrHgt / 2, a$
center text ScrWid / 2, ScrHgt - 100,b$
sync
until scancode() > false
end
endif
set display mode 1024,768,32
rem **INIT WINDOW**
set window on
set window title " Dark Noob Games - BerZerk!"
dw = desktop width() : dh = desktop height()
set window position (dw - ScrWid) / 2, (dh - ScrHgt) / 2
rem SETUP User Defined Type (UDT) variable for the maze data
type direction
n as integer
s as integer
e as integer
w as integer
endtype
type RoomData
door as direction
exitflag as boolean
visited as boolean
design as integer
corner as direction
robotsleft as integer
endtype
dim done(36) as integer
dim coord(36,24,24) as integer
// setup player TYPE variable
type PlayerData
lives, image, EnterX, EnterY, XSpeed, YSpeed, AnimDelay, SprNum
LowImage, HighImage, Room, X, Y, aim
endtype
player as PlayerData
// setup robot TYPE variable. We don't know how many robots we will need
// so we set it up with zero and add to it at SetupRobots()
type RobotData
lives, image, EnterX, EnterY, XSpeed, YSpeed, AnimDelay, SprNum
LowImage, HighImage, Room, X, Y, aim, status, turn, axis, robu, robd, robr, robl, scannerbearing
endtype
dim robot(3) as RobotData
Init() : // initialize game data
LoadImages() : // loads all of the images needed for the game
repeat
for room = 1 to 36
for x = 1 to 24
coord(room,x,1) = blue(0)
coord(room,x,24) = blue(0)
next x
for y = 1 to 24
coord(room,1,y) = blue(1)
coord(room,24,y) = blue(1)
next y
next room
empty array maze()
dim maze(36) as RoomData
MazeSuccessful = SetupMaze()
until MazeSuccessful = true
for i = 1 to 36
BurnRoom(i)
next i
for i = 1 to 36
maze(i).robotsleft=rnd(3)
next i
SetupPlayer() : // initializes the player info
SetupRobots() : // initializes the info for the robots
roomchange = 1
player.room = rnd(35) + 1
rem SETUP MANUAL SYNCING - WE REDRAW THE SCREEN WHEN WE ARE READY
sync on : sync rate 60
// Main Game loop
repeat
GameState = MainMenu() : // this goes to the MainMenu function and returns the current game state
// it currently is setup to simply play the game as the MainMenu function
// has not yet been installed
select GameState : // this selects the value of the variable GameState, and branches based upon that
case 1
// play game
LoadRoom()
if roomchange = true
Setplayer()
if maze(player.room).robotsleft>0 then setrobots()
endif
MovePlayer() : // get input from the player to move the character around
if maze(player.room).robotsleft>0 then MoveRobots() : // move the robots around
MoveEvilOtto() : // check to see if it is time for Evil Otto to come out and
// if so, it moves him and will check for collision with the
// player and with the robots
MoveShots() : // moves all shots, whether player or robot and checks for collision
Debug() : // useful tool to display text on the screen - used to determine frame rate,
// values of variables that we want to see, etc.
sync : // manually sync the screen
endcase
case 2
// device input
endcase
case 3
//difficulty
endcase
case 4
// sound FX options
endcase
case 5
// high scores
endcase
case 6
// quit
GameOver = true
endcase
endselect
if mouseclick() > false then GameOver = true : // mouseclick() is temporary to allow user to exit
until GameOver = true
DeleteAll()
end
function MovePlayer()
u = upkey() : r = rightkey() : d = downkey() : l = leftkey()
if u
player.aim = 1
bx = int((player.x + 16) / 32) : by = int((player.y + 16) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx + 1,by)
if coo = 0 and coo2 = 0
dec player.y,3
frame = sprite frame(player.SprNum)
lftc = 29 : uftc = 42 : // frames to check to see if the user has changed directions
if r then lftc = 57 : uftc = 70 : // while the animation is playing
if l then lftc = 71 : uftc = 84
if frame < lftc or frame > uftc
set sprite frame player.SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite player.SprNum,lftc,uftc,50
else
text 200,200,"Player just fried!" : sync : wait 750
endif
endif
if l
player.aim = 4
bx = int((player.x + 20) / 32) : by = int((player.y + 16) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx,by + 1)
if coo = 0 and coo2 = 0
dec player.x,3
frame = sprite frame(player.SprNum)
lftc = 15 : uftc = 28 : // frames to check to see if the user has changed directions
if u then lftc = 71 : uftc = 84 : // while the animation is playing
if d then lftc = 85 : uftc = 98
if frame < lftc or frame > uftc
set sprite frame player.SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite player.SprNum,lftc,uftc,50
else
text 200,200,"You are toast!" : sync : wait 750
endif
endif
if d
player.aim = 3
bx = int((player.x + 16) / 32) : by = int((player.y + 56) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx + 1,by)
if coo = 0 and coo2 = 0
inc player.y,3
frame = sprite frame(player.SprNum)
lftc = 43 : uftc = 56 : // frames to check to see if the user has changed directions
if r then lftc = 99 : uftc = 112 : // while the animation is playing
if l then lftc = 85 : uftc = 98
if frame < lftc or frame > uftc
set sprite frame player.SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite player.SprNum,lftc,uftc,50
else
text 200,200,"Smokin!" : sync : wait 750
endif
endif
if r
player.aim = 2
bx = int((player.x + 40) / 32) : by = int((player.y + 16) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx,by + 1)
if coo = 0 and coo2 = 0
inc player.x,3
frame = sprite frame(player.SprNum)
lftc = 1 : uftc = 14 : // frames to check to see if the user has changed directions
if u then lftc = 57 : uftc = 70 : // while the animation is playing
if d then lftc = 99 : uftc = 112
if frame < lftc or frame > uftc
set sprite frame player.SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite player.SprNum,lftc,uftc,50
else
text 200,200,"That's going to leave a mark!" : sync : wait 750
endif
endif
paste sprite player.SprNum,player.x,player.y
if player.x > 750 then roomchange = true : inc player.room : exited = 2
if player.x < 16 then roomchange = true : dec player.room : exited = 4
if player.y > 740 then roomchange = true : inc player.room,6 : exited = 3
if player.y < 24 then roomchange = true : dec player.room, 6 : exited = 1
endfunction
function MoveRobots()
for i= 1 to maze(player.room).robotsleft
if robot(i).turn<50
inc robot(i).turn
else
robot(i).turn=0
robot(i).axis = 1 + rnd(2)
endif
if robot(i).axis=1
if player.x<robot(i).x then clear(i) : robot(i).robl=1
if player.x=robot(i).x then robot(i).robl=0 : robot(i).robr=0
if player.x>robot(i).x then clear(i) : robot(i).robr=1
endif
if robot(i).axis=2
if player.y<robot(i).y then clear(i) : robot(i).robu=1
if player.y=robot(i).y then robot(i).robu=0 : robot(i).robd=0
if player.y>robot(i).y then clear(i) : robot(i).robd=1
endif
if robot(i).axis =3
clear(i)
robot(i).scannerbearing=acos((player.x-robot(i).x)/sqrt(((player.x-robot(i).x)*(player.x-robot(i).x))+((player.y-robot(i).y)*(player.y-robot(i).y))))
if player.y>robot(i).y then robot(i).scannerbearing = 360 - robot(i).scannerbearing
look=int(wrapvalue(robot(i).scannerbearing)/15)+1
angleframe=52+look
if look>12 then inc angleframe
set sprite frame robot(i).SprNum, angleframe
`text robot(i).x-5, robot(i).y+30, STR$(robot(i).scannerbearing)+" "+STR$(look)
endif
if robot(i).robu
robot(i).aim = 1
bx = int((robot(i).x + 16) / 32) : by = int((robot(i).y + 16) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx + 1,by)
if coo = 0 and coo2 = 0
dec robot(i).y,1
frame = sprite frame(robot(i).SprNum)
lftc = 14 : uftc = 26 : // frames to check to see if the user has changed directions
if frame < lftc or frame > uftc
set sprite frame robot(i).SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite robot(i).SprNum,14,26,50
endif
endif
if robot(i).robl
robot(i).aim = 4
bx = int((robot(i).x + 20) / 32) : by = int((robot(i).y + 16) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx,by + 1)
if coo = 0 and coo2 = 0
dec robot(i).x,1
frame = sprite frame(robot(i).SprNum)
lftc = 27 : uftc = 39 : // frames to check to see if the user has changed directions
if frame < lftc or frame > uftc
set sprite frame robot(i).SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite robot(i).SprNum,27,39,50
endif
endif
if robot(i).robd
robot(i).aim = 3
bx = int((robot(i).x + 16) / 32) : by = int((robot(i).y + 56) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx + 1,by)
if coo = 0 and coo2 = 0
inc robot(i).y,1
frame = sprite frame(robot(i).SprNum)
lftc = 40 : uftc = 52 : // frames to check to see if the user has changed directions
if frame < lftc or frame > uftc
set sprite frame robot(i).SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite robot(i).SprNum,40,52,50
endif
endif
if robot(i).robr
robot(i).aim = 2
bx = int((robot(i).x + 40) / 32) : by = int((robot(i).y + 16) / 32)
coo = coord(player.room,bx ,by )
coo2 = coord(player.room,bx,by + 1)
if coo = 0 and coo2 = 0
inc robot(i).x,1
frame = sprite frame(robot(i).SprNum)
lftc = 1 : uftc = 13 : // frames to check to see if the user has changed directions
if frame < lftc or frame > uftc
set sprite frame robot(i).SprNum,lftc : // user changed directions - set it to the start frame
endif
play sprite robot(i).SprNum,1,13,50
endif
endif
paste sprite robot(i).SprNum,robot(i).x,robot(i).y
next i
endfunction
function MoveEvilOtto()
endfunction
function MoveShots()
endfunction
function CheckRez() : // check tp see if the user's machione can display a 1024 X 768 X 32 screen
rezOkay = check display mode(1024,768,32)
endfunction rezOkay
function Init()
endfunction
function LoadImages()
// load in all of the images we need for the game
load bitmap "media\blue.bmp",1 : // blue tiles
dim blue(11)
for img = 0 to 5
blue(img) = GetFreeImage()
get image blue(img),img * 32,0, (img * 32) + 32,32
next img
delete bitmap 1
dim WalkRight(7)
`load bitmap "media\Man.bmp",1 : // man images - walking right
`for k = 1 to 7
` WalkRight(k) = GetFreeImage()
` get image WalkRight(k),(k - 1) * 36,0,k * 36,48
`next k
`delete bitmap 1
endfunction
function SetupMaze()
//this function sets up the doors between cells so that you have a maze
//provide corner information before starting
for i=1 to 6
maze(i).corner.n=1
next i
for i= 1 to 31 step 6
maze(i).corner.w=1
next i
for i = 6 to 36 step 6
maze(i).corner.e=1
next i
for i=31 to 36
maze(i ).corner.s=1
next i
//choose random cell
stacknum=1
roomnumber=1+rnd(35)
numbervisited=1
maze(roomnumber).visited=1
done(stacknum)=roomnumber
//generate maze
while numbervisited<36
moved=0 `variable to establish whether the generator has moved to another cell in this cycle
badbearing=0 `variable to establish what directions the generator should not move in
bearing=rnd(4) `randomize initial direction
repeat
if bearing=1 and roomnumber>6
if maze(roomnumber-6).visited=0
maze(roomnumber-6).door.s=4+rnd(16)
maze(roomnumber).door.n=maze(roomnumber-6).door.s
for i = -1 to 1
coord(roomnumber,maze(roomnumber).door.n+i,1)=0
coord(roomnumber-6,maze(roomnumber).door.n+i,24)=0
next i
roomnumber=roomnumber-6
done(stacknum)=roomnumber
stacknum=stacknum+1
maze(roomnumber).visited=1
moved=1
inc numbervisited
endif
endif
if bearing=2 and maze(roomnumber).corner.e=0 `as an example, if the direction determined is east, it checks if the room is on the eastern wall...
if roomnumber<36
if maze(roomnumber+1).visited=0 `then checks if it hasn't already visited and adjusted that cell...
maze(roomnumber+1).door.w=4+rnd(16) `then makes a door in that cell pointing where you came from...
maze(roomnumber).door.e=maze(roomnumber+1).door.w `and a door in the cell you came from pointing to where you've come...
for i = -1 to 1
coord(roomnumber,24,maze(roomnumber).door.e+i)=0
coord(roomnumber+1,1,maze(roomnumber).door.e+i)=0
next i
roomnumber=roomnumber+1 `then updates what room number you're in...
done(stacknum)=roomnumber `and stores it in a stack.
stacknum=stacknum+1 `increment stack index
maze(roomnumber).visited=1 `set the visited flag to one for the room you're in
moved=1 `tell the loop you've moved to an adjacent room.
inc numbervisited `increment the number of cells that have already been adjusted
endif
endif
endif
if bearing=3 and roomnumber<31
if maze(roomnumber+6).visited=0
maze(roomnumber+6).door.n=4+rnd(16)
maze(roomnumber).door.s=maze(roomnumber+6).door.n
for i = -1 to 1
coord(roomnumber,maze(roomnumber).door.s+i,24)=0
coord(roomnumber+6,maze(roomnumber).door.s+i,1)=0
next i
roomnumber=roomnumber+6
done(stacknum)=roomnumber
stacknum=stacknum+1
maze(roomnumber).visited=1
moved=1
inc numbervisited
endif
endif
if (bearing=4 and maze(roomnumber).corner.w=0)
if roomnumber>0
if maze(roomnumber-1).visited=0
maze(roomnumber-1).door.e=4+rnd(16)
maze(roomnumber).door.w=maze(roomnumber-1).door.e
for i = -1 to 1
coord(roomnumber,1,maze(roomnumber).door.w+i)=0
coord(roomnumber-1,24,maze(roomnumber).door.w+i)=0
next i
roomnumber=roomnumber-1
done(stacknum)=roomnumber
stacknum=stacknum+1
maze(roomnumber).visited=1
moved=1
inc numbervisited
endif
endif
endif
if moved=0 `if you haven't moved,
inc bearing `it could be because the direction was blocked, check another
if bearing=5 then bearing=1 `bearing should be modulo4
inc badbearing `tells the loop how many directions you've tried
endif
until moved=1 or badbearing=3 `the generator has either moved or
if moved = 0 `it didnt move and it has walked into a dead end
done(stacknum)=0 `it goes back till it finds a room with available neighbors
dec stacknum
if stacknum = 0 then exitfunction 0
roomnumber=done(stacknum)
endif
endwhile `do it again till all rooms have been visited
maze(36).door.e=4+rnd(16)
for i= -1 to 1
coord(36,24,maze(36).door.e+i)=0
next i
maze(36).exitflag=1
endfunction 1
function BurnRoom(room)
maze(room).design = rnd(3)
select maze(room).design
case 1
// make some inner walls
for x = 12 to 18
coord(room,x,12) = blue(1)
next x
for y = 6 to 12
coord(room,8,y) = blue(0)
next y
for x = 6 to 10
coord(room,x,6) = blue(1)
next x
for y = 13 to 19
coord(room,18,y) = blue(0)
next y
endcase
case 2
// make some inner walls
for x = 5 to 12
coord(room,x,5) = blue(1)
next x
for y = 11 to 17
coord(room,18,y) = blue(0)
next y
for x = 6 to 10
coord(room,x,16) = blue(1)
next x
for y = 13 to 19
coord(room,8,y) = blue(0)
next y
endcase
case 3
for x = 2 to 8
coord(room,x,8) = blue(1)
next x
for y = 17 to 23
coord(room,8,y) = blue(0)
next y
for x = 17 to 23
coord(room,x,17) = blue(1)
next x
for y = 2 to 8
coord(room,17,y) = blue(0)
next y
endcase
endselect
endfunction
function SetupPlayer() : // setup the necessary info for the player
player.image = GetFreeImage()
player.SprNum = GetFreeSprite()
create animated sprite player.SprNum,"media\Man.bmp",7,16,player.image
sprite player.SprNum,-100,-100,player.image
offset sprite player.SprNum,18,24
hide sprite player.SprNum
endfunction
function SetupRobots()
for i = 1 to 3
robot(i).image = GetFreeImage()
robot(i).SprNum = GetFreeSprite()
create animated sprite robot(i).SprNum,"media\Robot.jpg",13,8,robot(i).image
sprite robot(i).SprNum,-100,-100,robot(i).image
offset sprite robot(i).SprNum,18,24
hide sprite robot(i).SprNum
next i
endfunction
function SetPlayer()
if exited = 0 then player.x = 68+rnd(632) : player.y = 68+rnd(632)
if exited = 1
flag = 0
for i=1 to 24
if flag=0
if coord(player.room,i,24)=0 then player.x=(i*32)-16 : player.y= 700 : flag=1
endif
next i
endif
if exited = 3
flag = 0
for i=1 to 24
if flag=0
if coord(player.room,i,1)=0 then player.x=(i*32)-16 : player.y= 68 : flag=1
endif
next i
endif
if exited = 2
flag = 0
for i=1 to 24
if flag=0
if coord(player.room,1,i)=0 then player.x=68 : player.y=(i*32)-16 : flag=1
endif
next i
endif
if exited = 4
flag = 0
for i=1 to 24
if flag=0
if coord(player.room,24,i)=0 then player.x=700 : player.y=(i*32)-16 : flag=1
endif
next i
endif
roomchange=0
endfunction
function SetRobots() `only call this function if there are any robots in the room as indicated in the maze array
for i = 1 to maze(player.room).robotsleft
repeat
wrongposition=0
robot(i).x= 32+ rnd(704)
robot(i).y= 32+ rnd(704)
if ((coord(player.room,int((robot(i).x+16)/32)+1,int(robot(i).y/32)+1) + coord(player.room,int(robot(i).x/32)+1,int(robot(i).y/32)+1) + coord(player.room,int((robot(i).x-16)/32)+1,int(robot(i).y/32)+1)) + (coord(player.room,int(robot(i).x/32)+1,int((robot(i).y+16)/32)+1) + coord(player.room,int(robot(i).x/32)+1,int(robot(i).y/32)+1) + coord(player.room,int(robot(i).x/32)+1,int((robot(i).y-16)/32)+1)))=0
else
wrongposition=1
endif
until wrongposition = 0
next i
endfunction
function MainMenu()
// paste the graphic up
GameState = 1 : // play game - allows the game code to run
//show mouse
endfunction GameState
function DeleteAll()
// deletes all images and sprites prior to exiting the game
endfunction
function GetFreeSprite() : // this creates sprite #'s in chronological order
repeat
inc CurrSprite
until sprite exist(CurrSprite) = false
endfunction CurrSprite
function GetFreeImage() : // this creates image #'s in chronological order
repeat
inc CurrImage
until image exist(CurrImage) = false
endfunction CurrImage
function Debug()
// shows info needed during development
text 800,250,"FPS: " + str$(screen fps())
text 800,0,"You are in Room "+STR$(player.room)
text 800,50,"Co-ordinates"+STR$(player.x)+","+STR$(player.y)
xoffset = player.room-(6*int(player.room/6))-1
if xoffset=-1 then xoffset=5
text 800,100,"Room X offset: " + str$(xoffset*24)
text 800,150,"Room Y offset: " + str$(int((player.room-1)/6)*24)
text 800,200,"Press arrow keys to move"
text 800,300,STR$(maze(player.room).robotsleft)
` text 10,100,"coo = " + str$(coo)
` text 10,120,"coo2 = " + str$(coo2)
` text 100,140,"frame: " + str$(sprite frame(player.SprNum))
endfunction
function LoadRoom()
for x = 1 to 24
for y= 1 to 24
if coord(player.room,x,y)>0
paste image coord(player.room,x,y),(x-1)*32,(y-1)*32
endif
next y
next x
endfunction
//temporary function
function DrawMaze()
ink rgb(255,0,0),0
for i=1 to 6
if maze(i).door.s=0 then line ((i-1)*128), 128, i*128, 128
if maze(i).door.e=0 then line i*128,0,i*128,128
next i
for i=1 to 6
if maze(i+6).door.s=0 then line ((i-1)*128), 256, i*128, 256
if maze(i+6).door.e=0 then line i*128,128,i*128,256
next i
for i=1 to 6
if maze(i+12).door.s=0 then line ((i-1)*128), 384, i*128, 384
if maze(i+12).door.e=0 then line i*128,256,i*128,384
next i
for i=1 to 6
if maze(i+18).door.s=0 then line ((i-1)*128), 512, i*128, 512
if maze(i+18).door.e=0 then line i*128,384,i*128,512
next i
for i=1 to 6
if maze(i+24).door.s=0 then line ((i-1)*128), 640, i*128, 640
if maze(i+24).door.e=0 then line i*128,512,i*128,640
next i
for i=1 to 6
if maze(i+30).door.s=0 then line ((i-1)*128), 768, i*128, 768
if maze(i+30).door.e=0 then line i*128,640,i*128,768
next i
line 0,0,0,768
line 0,0,768,0
for y = 1 to 6
for x= 1 to 6
center text 64+((x-1)*128),64+((y-1)*128),STR$(((y-1)*6)+x)
next x
next y
endfunction
function Clear(n)
robot(n).robu=0
robot(n).robd=0
robot(n).robr=0
robot(n).robl=0
endfunction
much better. they walk a little, then stop and watch you, all at random. youll need the new robot image. working on rotation before changing direction of movement.
Darkseid?