Quote: "So, first of all. You guys are just editing the whole code right? How can everyone else tell what changes you made with 300 lines.
"
That is a good question. Since the code is always being worked on, I am keeping the most updated, stable version in a snippet in the first post of this thread. I have just finished incorporating thisotherguy's changes and made some changes myself to the code. For your convenience, I am including it here. Please use this to complete your work on the soundFX. There are two .bmp files you will need in the media folder. A link to them is included in the first post of the thread.
To say we have really moved forward would be an understatement. We have a character that moves around the maze from room to room, and when he goes through the door of one room, he enters another that has a doorway at the same place as the one he just left. If he gets too close to the walls, he is fried (well, not really, but it does print it on the screen). Much of the code has had additional comments placed to help everyone see what is being done.
We still need to work on the wall placements within the rooms, but it is coming along nice.
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
rem INITIAL VALUES OF SOME VARIABLES
ScrWid = screen width() : ScrHgt = screen height()
GameState = false : GameOver = false : score = false : CurrSprite = 99 : CurrImage = 99
MoveToggle = false
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
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, orient
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
status, image, XSpeed, YSpeed, AnimDelay, LowImage, HighImage, SprNum
endtype
dim robot(0) as RobotData
`type RoomData
` visited as boolean
` x,y, cell, doorN, doorE, doorS, doorW
`endtype
`dim maze(36) as RoomData
// setup player TYPE variable
// 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()
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
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()
endif
MovePlayer() : // get input from the player to move the character 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.
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)
` ink rgb(255,0,255),0
`box (bx - 1) * 32,by * 32,(bx * 32),(by + 1) * 32
`` ink rgb(0,255,0),0
`box bx * 32, by * 32, (bx + 1) * 32, (by + 1) * 32
if coo = 0 and coo2 = 0
dec player.y,3
play sprite player.SprNum,1,14,100
else
text 200,200,"Player just fried!" : sync : wait 750
endif
endif
if l
player.aim=4
if player.orient=0 then mirror sprite player.SprNum
player.orient=1
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)
` ink rgb(255,0,255),0
` box (bx - 1) * 32,((by - 1) * 32),(bx * 32),(by * 32)
`ink rgb(0,255,0),0
`box (bx - 1) * 32, by * 32, bx * 32, (by + 1) * 32
if coo = 0 and coo2 = 0
dec player.x,3
play sprite player.SprNum,1,14,100
else
text 200,200,"Player just fried!" : 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)
` ink rgb(255,0,255),0
` box (bx - 1) * 32,by * 32,(bx * 32),(by + 1) * 32
` ink rgb(0,255,0),0
` box bx * 32, by * 32, (bx + 1) * 32, (by + 1) * 32
if coo = 0 and coo2 = 0
inc player.y,3
play sprite player.SprNum,1,14,100
else
text 200,200,"Player just fried!" : sync : wait 750
endif
endif
if r
player.aim=2
if player.orient=1 then mirror sprite player.SprNum
player.orient=0
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)
`ink rgb(255,0,255),0
`box (bx - 1) * 32,((by - 1) * 32),(bx * 32),(by * 32)
`ink rgb(0,255,0),0
`box (bx - 1) * 32, by * 32, bx * 32, (by + 1) * 32
if coo = 0 and coo2 = 0
inc player.x,3
play sprite player.SprNum,1,14,100
else
text 200,200,"Player just fried!" : 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()
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
remstart
`function SetupMaze() : // do the initial setup of the entire maze
dim map(144,144)
CurrRoom = 1
for y = 1 to 6 : // we want a 6 X 6 grid of rooms for 36 total
for x = 1 to 6
// pick random interior walls for the room
maze(CurrRoom).cell = rnd(2) : // 0 - 2 for right now, but eventually rnd(17) + 1
BurnRoom(maze(CurrRoom).cell,x,y)
// store x and y coords
maze(CurrRoom).x = x : maze(CurrRoom).y = y
// show that the room has not been visited yet
maze(CurrRoom).visited = false
inc CurrRoom
next x
next y
StartX = 24 : StartY = 24 : CurrRoom = 8 : // we'll start at room 8 for now
DisplayMap(StartX, StartY)
remend
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,14,player.image
sprite player.SprNum,-100,-100,player.image
offset sprite player.SprNum,18,24
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 SetupRobots()
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 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
remstart
function SetOuterWalls(StartX,StartY, colr, x, y)
// this function will store the outer wall images in the map array
// and will setup doors on the walls
if colr = 1
img0 = blue(0) : img1 = blue(1) : img2 = blue(2) : img3 = blue(3)
img4 = blue(4) : img5 = blue(5)
endif
// using color 1 (blue tiles) for now - ditto for other colors
for a = 1 to 24
for b = 1 to 24
if a = 1 or a = 24 then map(StartX + a,StartY + b) = img0
if b = 1 or b = 24 then map(StartX + a,StartY + b) = img1
next b
next a
// fix the corners
map(StartX + 1,StartY + 1) = img2 : map(StartX + 24,StartY) = img3
map(StartX + 1,StartY + 24) = img5 : map(StartX + 24,StartY + 24) = img4
// make door at top
dx = rnd(12) + 4
if y > 1
if maze(CurrRoom -6).DoorS > 0 : // is there a door on the south end of the room above?
maze(CurrRoom).DoorN = maze(CurrRoom - 6).DoorS : // set the x on this door the same
// as the x of the south door in the room above
for door = maze(CurrRoom).DoorN to maze(CurrRoom).DoorN + 4 : // place a door on the north side
map(StartX + door,StartY + 1) = 0
next door
endif
endif
// make door for the right
dy = rnd(12) + 4
for door = dy to dy + 4
map(StartX + 24,StartY + door) = 0
next door
maze(CurrRoom).DoorE = dy
// make door for the left
dy = rnd(12) + 4
for door = dy to dy + 4
map(StartX + 1,StartY + door) = 0
next door
maze(CurrRoom).DoorW = dy
// make door for the bottom
dx = rnd(12) + 4
for door = dx to dx + 4
map(StartX + door,StartY + 24) = 0
next door
maze(CurrRoom).DoorS = dx
endfunction
function DisplayMap(StartX,StartY)
cls : // clears the screen
for y = 1 to 24
for x = 1 to 24 : // if the map array holds a value greater than 0, the value it holds is
// an image and it is pasted on the screen
if map(StartX + x,StartY + y) > 0 then paste image map(StartX + x,StartY + y),(x - 1)* 32, (y - 1) * 32
next x
next y
endfunction
remend
EDIT:
MrValentine, when I click the links or paste it into my browser, it plays the sound effect, but I cannot download it. We need the actual .mp3 files themselves.