Quote: "LBFN any advice on how to get the robots to wait for the explosion animation before they "die"?"
The way you have set it up, you could simply check to see if it is exploding. If it is not exploding, you move it. If it is, you keep playing the exploding anim until it is done. Then you set robot(i).destroyed = 1 once it is done exploding.
Quote: "now that i look at the code i realise we should have had a separate moverobot and animaterobot function."
Not 100% sure that we need to do that. I'll need to look over the code at length. Unfortunately, I do not have the time today before I go to work.
EDIT: I believe I have the robots exploding okay with this code.
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
global Chicken, RobotsWin, GetHuman, GotHuman, HaHaHa, Intruder, NotEscape, CurrMusic, TimeToPlay
global OldMusic, welcome
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 DESTINATION 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 POSITION THE WINDOW IN THE MIDDLE OF THE SCREEN
rem SETUP User Defined Type (UDT) variable for the maze data
type direction
n, s, e, w
endtype
rem SETUP UDT FOR THE ROOM DATA
type RoomData
door as direction
corner as direction
exitflag, visited as boolean
design as integer
robotsleft as integer
endtype
dim done(36) as integer
dim coord(36,24,24) as integer
// SETUP UDT FOR THE PLAYER
type PlayerData
lives, image, EnterX, EnterY, XSpeed, YSpeed, AnimDelay, SprNum
LowImage, HighImage, Room, X, Y, aim
endtype
player as PlayerData
// setup robot UDT. 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, destroyed,
LowImage, HighImage, Room, X, Y, aim, status, turn, axis, robu, robd, robr, robl, scannerbearing
Edelay
endtype
dim robot(11) as RobotData
Init() : // initialize game data
LoadImages() : // loads all of the images needed for the game
rem STORE OUTER WALL INFORMATION IN THE COORD ARRAY
rem EACH ROOM IS 24 x 24 TILES (EACH TILE IS 32 x 32 PIXELS)
REM THERE ARE 36 ROOMS, PLACED IN A 6 X 6 GRID
repeat
for room = 1 to 36
for x = 1 to 24
coord(room,x,1) = blue(1)
coord(room,x,24) = blue(1)
next x
for y = 1 to 24
coord(room,1,y) = blue(0)
coord(room,24,y) = blue(0)
next y
next room
empty array maze()
dim maze(36) as RoomData
MazeSuccessful = SetupMaze()
until MazeSuccessful = true
for i = 1 to 36
BurnRoom(i)
maze(i).RobotsLeft = rnd(8) + 3
next i
SetupPlayer() : // initializes the player info
SetupRobots() : // initializes the info for the robots
roomchange = 1
player.room = rnd(35) + 1 : rem RANDOMLY PLACES THE PLAYER IN A ROOM
LoadMusic() : // set up the games' sounds / music
OldMusic = 1
rem SETUP MANUAL SYNCING - WE REDRAW THE SCREEN WHEN WE ARE READY
sync on : sync rate 60
// Main Game loop *************************************************************************************
repeat
sync
until music playing(welcome) = false
TimeToPlay = timer() + 1200
repeat
if GameState = 0 then 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
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.
if timer() > TimeToPlay
if music playing(OldMusic) = true then stop music OldMusic
m = rnd(6) + 1 : OldMusic = m
select m
case 1
play music Chicken
endcase
case 2
play music RobotsWin
endcase
case 3
play music GetHuman
endcase
case 4
play music GotHuman
endcase
case 5
play music HaHaHa
endcase
case 6
play music Intruder
endcase
case 7
play music NotEscape
endcase
endselect
TimeToPlay = timer() + 4000
endif
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 returnkey() > false then GameOver = true : // temporary to allow user to exit
until GameOver = true
// Main Game loop *************************************************************************************
DeleteAll() : rem DELETE ALL MEDIA
end
function MovePlayer()
// THIS FUNCTION MOVES THE PLAYER AROUND THE SCREEN AND CHECKS TO SEE IF HE RUNS INTO A WALL
// OR IF HE ENTERS A DOOR TO ANOTHER ROOM
u = upkey() : r = rightkey() : d = downkey() : l = leftkey() : rem STORE THE USER'S KEYBOARD INPUT
if u
player.aim = 1
bx = int((player.x + 16) / 32) : by = int((player.y + 16) / 32)
coo = coord(player.room,bx ,by ) : rem CHECK UP
coo2 = coord(player.room,bx + 1,by) : rem CHECK UP AND OVER ONE
if coo = 0 and coo2 = 0 : rem DID THE PLAYER RUN INTO ANYTHING?
dec player.y,3 : rem NOPE, MOVE THE PLAYER
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
rem PLAYER RAN INTO A WALL
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
rem THE FOLLOWING CHECKS WILL SEE IF HTE PLAYER WALKED THORUGH A DOOR
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).destroyed = 0
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
else
play sprite robot(i).SprNum,85,90,100
set sprite frame robot(i).SprNum,85
robot(i).destroyed = 1 : robot(i).Edelay = timer() + 100
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
else
play sprite robot(i).SprNum,98,103,100
set sprite frame robot(i).SprNum,98
robot(i).destroyed = 2 : robot(i).Edelay = timer() + 100
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
else
play sprite robot(i).SprNum,79,84,100
set sprite frame robot(i).SprNum,79
robot(i).destroyed = 3 : robot(i).Edelay = timer() + 100
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
else
play sprite robot(i).SprNum,92,97,100
set sprite frame robot(i).SprNum,92
robot(i).destroyed = 4 : robot(i).Edelay = timer() + 100
endif
endif
paste sprite robot(i).SprNum,robot(i).x,robot(i).y
else
frame = sprite frame(robot(i).SprNum)
select robot(i).destroyed
case 1
if frame = 90
robot(i).destroyed = 5 : dec maze(player.room).robotsleft
hide sprite robot(i).SprNum
else
play sprite robot(i).SprNum,85,90,100
paste sprite robot(i).SprNum,robot(i).x,robot(i).y
endif
endcase
case 2
if frame = 103
robot(i).destroyed = 5 : dec maze(player.room).robotsleft
hide sprite robot(i).SprNum
else
play sprite robot(i).SprNum,98,103,100
paste sprite robot(i).SprNum,robot(i).x,robot(i).y
endif
endcase
case 3
if frame = 84
robot(i).destroyed = 5 : dec maze(player.room).robotsleft
hide sprite robot(i).SprNum
else
play sprite robot(i).SprNum,frame,84,100
paste sprite robot(i).SprNum,robot(i).x,robot(i).y
endif
endcase
case 4
if frame = 97
robot(i).destroyed = 5 : dec maze(player.room).robotsleft
hide sprite robot(i).SprNum
else
play sprite robot(i).SprNum,frame,97,100
paste sprite robot(i).SprNum,robot(i).x,robot(i).y
endif
endcase
endselect
endif
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()
rem data for button position
restore ButtonData
dim buttons(6,4)
for a = 1 to 6
for b = 1 to 4
read buttons(a,b)
next b
next a
ButtonData:
// x1, y1; width, height
data 55,171,185,26
data 36,204,225,26
data 50,237,195,27
data 67,270,163,26
data 41,303,214,26
data 104,336,88,26
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
rem load Main Menu images
dim MMImages(7)
MMImages(1) = GetFreeImage()
load image "media\MainMenu.bmp",MMImages(1)
MMImages(2) = GetFreeImage()
load image "media\PlayGameLighted.bmp",MMImages(2)
MMImages(3) = GetFreeImage()
load image "media\DinputLighted.bmp",MMImages(3)
MMImages(4) = GetFreeImage()
load image "media\DiffLighted.bmp",MMImages(4)
MMImages(5) = GetFreeImage()
load image "media\SFXLighted.bmp",MMImages(5)
MMImages(6) = GetFreeImage()
load image "media\HSLighted.bmp",MMImages(6)
MMImages(7) = GetFreeImage()
load image "media\QuitLighted.bmp",MMImages(7)
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(3) + 1 `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)
rem THIS FUNCTION CREATES THE INNER WALLS OF THE ROOMS
maze(room).design = rnd(14) + 1
`maze(room).design = 15
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 = 6 to 12
coord(room,x,8) = blue(1)
next x
for y = 12 to 18
coord(room,8,y) = blue(0)
next y
for x = 12 to 18
coord(room,x,17) = blue(1)
next x
for y = 6 to 12
coord(room,17,y) = blue(0)
next y
endcase
case 4
for y = 5 to 10
coord(room,5,y) = blue(0)
if y < 10 then coord(room,12,y + 5) = blue(0)
coord(room,19,y + 9) = blue(0)
next y
for x = 5 to 10
coord(room,x,19) = blue(1)
coord(room,x + 9,5) = blue(1)
next x
endcase
case 5
for x = 8 to 16
coord(room,x,8) = blue(1)
coord(room,x,16) = blue(1)
if x < 16 then coord(room,16,x) = blue(0)
next x
endcase
case 6
x = 6
for y = 6 to 11
coord(room,x,y) = blue(0)
coord(room,x + 12,y + 6) = blue(0)
next y
for x = 6 to 18
coord(room,x,12) = blue(1)
next y
endcase
case 7
x = 12
for y = 5 to 8
coord(room,x,y) = blue(0)
coord(room,x,y + 11) = blue(0)
next y
y = 12
for x = 5 to 8
coord(room,x,y) = blue(1)
coord(room,x + 11,y) = blue(1)
next x
endcase
case 8
for x = 5 to 11
coord(room,x + 1,18) = blue(1)
coord(room,x + 8,6) = blue(1)
next x
for y = 7 to 13
coord(room,19,y) = blue(0)
coord(room,6,y + 5) = blue(0)
next y
endcase
case 9
for y = 7 to 13
coord(room,7,y) = blue(0)
coord(room,17,y) = blue(0)
if y > 8 then coord(room,12,y + 6) = blue(0)
next y
for x = 7 to 17
coord(room,x,6) = blue(1)
next x
for x = 12 to 16
coord(room,x,19) = blue(1)
next x
endcase
case 10
for y = 5 to 9
coord(room,11,y) = blue(0)
coord(room,12,y + 5) = blue(0)
coord(room,13,y + 10) = blue(0)
next y
endcase
case 11
if maze(room).door.n > 0
if maze(room).door.n < 17
x = maze(room).door.n + 2
ey = rnd(5) + 5
for y = 2 to ey
coord(room,x,y) = blue(0)
next y
if x > 6
inc ey
ex = x - (rnd(6) + 3)
if ex < 5 then ex = 5
for q = ex to x
coord(room,q,ey) = blue(1)
next q
endif
else
x = maze(room).door.n - 2
ey = rnd(4) + 5
for y = 2 to ey
coord(room,x,y) = blue(0)
next y
inc ey
ex = x - (rnd(4) + 3)
for q = ex to x
coord(room,q,ey) = blue(1)
next q
endif
endif
if maze(room).door.s > 0
if maze(room).door.s < 17
x = maze(room).door.s + 2
ey = rnd(5) + 14
for y = 23 to ey step -1
coord(room,x,y) = blue(0)
next y
if x > 6
dec ey
ex = x - (rnd(6) + 3)
if ex < 5 then ex = 5
for q = ex to x
coord(room,q,ey) = blue(1)
next q
endif
else
x = maze(room).door.s - 2
ey = rnd(4) + 16
for y = 23 to ey step -1
coord(room,x,y) = blue(0)
next y
dec ey
ex = x - (rnd(6) + 3)
for q = ex to x
coord(room,q,ey) = blue(1)
next q
endif
endif
if maze(room).door.s = 0 and maze(room).door.n = 0
if maze(room).door.e > 0
y = maze(room).door.e : x = rnd(6) + 13
if y > 12
dec y,2
else
inc y,2
endif
for q = x to 23
coord(room,q,y) = blue(1)
next q
endif
if maze(room).door.w > 0
y = maze(room).door.w : x = rnd(6) + 6
if y > 12
dec y,2
else
inc y,2
endif
for q = 2 to x
coord(room,q,y) = blue(1)
next q
endif
endif
endcase
case 12
if maze(room).door.w > 0
y = maze(room).door.w
if y > 12
dec y,6
if y < 4 then y = 4
ey = y + rnd(4) + 4
if ey > 19 then ey = 19
if ey > (maze(room).door.w - 2) then ey = maze(room).door.w - 2
else
inc y,2
ey = y + rnd(4) + 4
endif
else
y = rnd(6) + 6
ey = y + rnd(4) + 4
endif
ex = rnd(6) + 4
for q = y to ey
for x = 2 to ex
coord(room,x,q) = blue(1)
next x
next q
sy = rnd(4) + 4 : ey = sy + (rnd(4) + 4)
x = rnd(5) + 14
for y = sy to ey
coord(room,x,y) = blue(0)
next y
endcase
case 13
sx = rnd(8) + 6 : ex = sx + (rnd(2) + 3)
bsx = rnd(8) + 6 : bex = bsx + (rnd(2) + 3)
topS = rnd(2) + 4 : botS = rnd(2) + 13
height = rnd(2) + 3
for y = topS to (topS + height)
for x = sx to ex
coord(room,x,y) = blue(1)
next x
next y
height = rnd(2) + 3
for y = botS to (botS + height)
for x = bsx to bex
coord(room,x,y) = blue(1)
next x
next y
endcase
case 14
if maze(room).door.e > 0
mrde = maze(room).door.e
y = rnd(10) + 6
if y = mrde then inc y,2
if y - 1 = mrde then inc y,2
if y + 1 = mrde then dec y,2
else
y = rnd(10) + 6
endif
sx = 13 + rnd(6)
for x = sx to 23
coord(room,x,y) = blue(1)
next x
if maze(room).door.w > 0
mrdw = maze(room).door.w
y = rnd(10) + 6
if y = mrdw then inc y,2
if y - 1 = mrdw then inc y,2
if y + 1 = mrdw then dec y,2
else
y = rnd(10) + 6
endif
sx = 4 + rnd(6)
for x = 2 to sx
coord(room,x,y) = blue(1)
next x
endcase
case 15
if maze(room).door.s > 0
mrds = maze(room).door.s
x = rnd(4) + 6
if x + 1 = mrds or x = mrds then dec x,2
if x - 1 = mrds then inc x,2
else
x = rnd(4) + 6
endif
sy = rnd(4) + 13
for y = sy to 23
coord(room,x,y) = blue(0)
next y
ex = x + (rnd(4) + 5)
y = sy - 1
for q = x to ex
coord(room,q,y) = blue(1)
next q
dec y
sy = y - (rnd(4) + 4)
for q = sy to y
coord(room,ex,q) = blue(0)
next q
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 11
robot(i).image = GetFreeImage()
robot(i).SprNum = GetFreeSprite()
create animated sprite robot(i).SprNum,"media\Robot1.bmp",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
robot(i).destroyed=0
next i
endfunction
function MainMenu()
show mouse
// center the main menu image
xpos = (ScrWid - image width(MMImages(1) )) / 2 : ypos = (ScrHgt - image height(MMImages(1) )) / 2
repeat
paste image MMImages(1),xpos,ypos : // paste main menu graphic
mx = mousex() : my = mousey() : mc = mouseclick() : // store the mouse x / y / clicked status
for b = 1 to 6 : // check to see if the mouse is hovering over one of the menu buttons
bx1 = buttons(b,1) + xpos : by1 = buttons(b,2) + ypos : // calculate upper left x,y
bx2 = bx1 + buttons(b,3) : by2 = by1 + buttons(b,4) : // calculate lower right x,y
if mx > bx1 and mx < bx2 : // check to see if the mouse is hovering over one
if my > by1 and my < by2 : // of the buttons
// mouse is hovering over a button - paste the lighted version of the button
paste image MMImages(b + 1),xpos + buttons(b,1),ypos + buttons(b,2)
// check to see if the user has selected it with the LMB
if mc = true then GameState = b : // set the value of Gamestate to the button value
endif
endif
next b
sync
until GameState = 1 or GameState = 6 : // either play game or quit
hide 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 GetFreeMusic() : // this creates music #'s in chronological order
repeat
inc CurrMusic
until music exist(CurrMusic) = false
endfunction CurrMusic
function Clear(n)
robot(n).robu=0
robot(n).robd=0
robot(n).robr=0
robot(n).robl=0
endfunction
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 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
function LoadMusic()
Welcome = GetFreeMusic()
load music "media\WELCOMETOBERZERK.mp3",Welcome
play music welcome
Chicken = GetFreeMusic()
load music "media\ChickenFightlikearobotV1.mp3",Chicken
RobotsWin = GetFreeMusic()
load music "media\GameoverrobotswinV1.mp3",RobotsWin
GetHuman = GetFreeMusic()
load music "media\GetthehumanoidV1.mp3",GetHuman
GotHuman = GetFreeMusic()
load music "media\GotthehumanoidV1.mp3",GotHuman
HaHaHa = GetFreeMusic()
load music "media\HaHaHaHumanoiddestroyedV1.mp3",HaHaHa
Intruder = GetFreeMusic()
load music "media\IntruderAlertIntruderAlertV1.mp3",Intruder
NotEscape = GetFreeMusic()
load music "media\ThehumanoidmustnotescapeV1.mp3",NotEscape
endfunction
POST EDIT:
Okay, it is not perfect yet, but getting there.