@Shadow Legacy
Hey I understand how you feel about keeping your own codes private, cause I felt the same way when I started. I then learned that at such an early stage it didn't matter at all cause there are so many much more advanced open sourced codes floating around all over the internet. What you may want to hold onto are the media you created.
Every coder has their own unique way of coding, so it's not easy to use another person's codes but just about every coder is able to use another person's media. All I'm saying is revealing your coding is the least of your worries especially at the early stage. Heck even my own WIP codings don't mean much as just about every advanced algorithm I used can be Googled.
Back on topic. I'm currently not listed a DNG member but I worked on the last two DNG projects. I'll do a review to help out since Obese and the others are busy at the moment. It seems you've learned quite a bit from the tutorial, good job on that. Judging from the commands used it seems you're coding with DBPro probably using an alternative editor. Note that most of DNG may be using DBC or DBPro with regular editors and while coding as a team you'll want to be compatible with each others. So a // does not work as a REM and new commands in DBPro does not exist in DBC.
Review:
You know how to use subroutines and show a good understanding of a function. You've got different phases working "Menu,Game,Credit" and using flagging variables and good practical uses of Display and String commands.
You are on a good track. The thing I see you can improve more on is your code structure. You got a good start but if the project gets larger it'll get harder to follow.
Current Structure:
gosub settings
gosub main_menu
gosub SetupGame
Do
<GAME_CODES>
...
if spacekey()=1 then gosub main_menu
if status = 1 then gosub SetupGame
Sync
Loop
You can try using a subroutine for the GameCode and use a Flag variable to change phases:
gosub settings
Do
if Flag = 0 then gosub main_menu
if Flag = 1 then gosub GAME_CODE
Sync
Loop
main_menu:
<Menu_CODES>
...
if <Game is starting, clicked on newgame>
Flag = 1
gosub SetupGame
endif
return
GAME_CODE:
<GAME_CODES>
...
if <Game is done, Player dies going back to Menu>
Flag = 0
endif
return
You can also branch it out further for organization purpose:
gosub settings
Do
if Flag = 0 then gosub main_menu
if Flag = 1 then gosub GAME_CODE
Sync
Loop
main_menu:
<Menu_CODES>
if <Game is starting, clicked on newgame>
Flag = 1
gosub SetupGame
endif
return
GAME_CODE:
gosub MoveObject
gosub CheckDeath
return
MoveObject:
<Game_Code>
....
return
CheckDeath:
if <Game is done, Player dies or Spacekey()=1, going back to Menu>
Flag = 0
endif
return
Your codes using this different structure:
rem Project: dodging game tut
Rem Created: Saturday, November 20, 2010
Rem ***** Main Source File ****
`// ======= SET GAME GLOBAL SETTING ============
gosub settings
`// ==============Main Loop====================
do
if status = 0 then gosub main_menu `//start the main menu
if status = 1 then gosub main_game
if status = 2 then gosub Credits
loop
main_menu:
//show the mouse
show mouse
SET TEXT TO ITALIC
cls
set text size 25
ink RGB(255,255,255),0
PASTE IMAGE 1,0,0
// little info about game shown on main menu
center TEXT (ScrWid / 2) + 60,(ScrHgt / 2) + 20,"Left & Right Arrow keys to move"
center TEXT (ScrWid / 2) + 60,(ScrHgt / 2) + 80,"Avoid the blocks for as long...."
center TEXT (ScrWid / 2) + 60,(ScrHgt / 2) + 110,"as possible!"
SET TEXT TO NORMAL
set text size 30
center text (ScrWid / 2) + 220,(ScrHgt / 2) + 260,"Created by Shadow-Legacy"
// ============================================================
// ============================================================
// =============== MAIN MENU BUTTONS ========================
SET TEXT TO NORMAL
set text size 45
//if button pressed goto newgame
if button((ScrWid / 2) - 250,50,"New Game")=1
status = 1
PlyrHlth = 50
PlyScr = 0
gosub SetupGame
endif
//if button pressed then goto credits
if button((ScrWid / 2) - 250,120,"Credits")=1
status = 2
endif
//if button pressed exit game
If Button((ScrWid / 2) - 250,190,"Exit")=1 then end
return
// ================Main GAME==================
main_game:
HIDE MOUSE
set text size 40
// setup text
INK RGB(70,255,0),RGB(0,0,0)
SET TEXT SIZE 40
TEXT 10,20,"PLAYER HEALTH: "+ STR$(PlyrHlth)
TEXT 10,60,"PLAYER SCORE: "+ STR$(PlyScr)
//centers mouse in center of screen
POSITION MOUSE SCREEN WIDTH()/2,SCREEN HEIGHT()/2
//positions camera in center of board
POSITION CAMERA 0,30,145
POINT CAMERA 0,10,95
//move player left
IF LEFTKEY()=1 AND OBJECT POSITION X(1)<34.5
MOVE OBJECT LEFT 1,1.3
ENDIF
//move player right
IF RIGHTKEY()=1 AND OBJECT POSITION X(1)>-34.5
MOVE OBJECT RIGHT 1,1.3
ENDIF
MOVE OBJECT 2,3
IF OBJECT POSITION Z(2)>145 AND PlyrHlth>0
POSITION OBJECT 2,RND(37.5),5,-90
PlyScr=PlyScr+10
ENDIF
MOVE OBJECT 3,3
IF OBJECT POSITION Z(3)>145 AND PlyrHlth>0
POSITION OBJECT 3,RND(37.5)*-1,5,-90
PlyScr=PlyScr+10
ENDIF
MOVE OBJECT 4,2.3
IF OBJECT POSITION Z(4)>145 AND PlyrHlth>0
POSITION OBJECT 4,RND(25),5,-95
PlyScr=PlyScr+10
ENDIF
MOVE OBJECT 5,3
IF OBJECT POSITION Z(5)>145 AND PlyrHlth>0
POSITION OBJECT 5,RND(25)*-1,5,-95
PlyScr=PlyScr+10
ENDIF
MOVE OBJECT 6,1.7
IF OBJECT POSITION Z(6)>145 AND PlyrHlth>0
POSITION OBJECT 6,RND(3),5,-95
PlyScr=PlyScr+10
ENDIF
MOVE OBJECT 7,3
IF OBJECT POSITION Z(7)>145 AND PlyrHlth>0
POSITION OBJECT 7,RND(25)*-1,5,-95
PlyScr=PlyScr+10
ENDIF
MOVE OBJECT 8,3.1
IF OBJECT POSITION Z(8)>145 AND PlyrHlth>0
POSITION OBJECT 8,RND(25),5,-95
PlyScr=PlyScr+10
ENDIF
for obj = 2 to 8
IF OBJECT COLLISION(1,obj) = 1
PlyrHlth=PlyrHlth-1
POSITION OBJECT obj,RND(37.5),5,-90
ENDIF
next obj
IF PlyrHlth <= 0
PlyrHlth=0
POSITION OBJECT 1,0,OBJECT POSITION Y(1)-1,0
TEXT (ScrWid / 2) - 100,(ScrHgt / 2),"GAME OVER"
TEXT (ScrWid / 2) - 100,(ScrHgt / 2) + 40,"YOUR SCORE IS: "+ STR$(PlyScr)
TEXT (ScrWid / 2) - 100,(ScrHgt / 2) + 80,"PRESS SPACE TO EXIT..."
TEXT (ScrWid / 2) - 100,(ScrHgt / 2) + 120,"TO MAIN MENU"
ENDIF
if spacekey()=1 then status = 0
return
Credits:
cls 0
// deletes objects from last game (if any)
delete objects 1,9999
color backdrop 0
// because if game is played, but exitted before finish
// item are not removed properly + has a blue background
ink RGB(255,0,0),RGB(0,0,0)
PASTE IMAGE 1,0,0
SET TEXT SIZE 35
SET TEXT TO BOLD
center TEXT ScrWid / 2,(ScrHgt / 2) - 250,"Game Created By"
center TEXT ScrWid / 2,(ScrHgt / 2),"Thanks Goes To"
SET TEXT SIZE 28
SET TEXT TO ITALIC
center TEXT ScrWid / 2,(ScrHgt / 2) - 205,"Shaun Wilkinson"
center TEXT ScrWid / 2,(ScrHgt / 2) + 045,"Zaibatsu for tutorial"
center TEXT ScrWid / 2,(ScrHgt / 2) + 090,"Eminent, T4r4ntul4, Grog Grueslayer, and LBFN"
CENTER TEXT ScrWid / 2,(ScrHgt / 2) + 135,"for all the help"
set text size 30
ink RGB(255,255,255),0
center text ScrWid / 2,(ScrHgt / 2) + 250,"Press SPACE to exit credits."
if spacekey()=1 then status = 0
return
// =================================================================
// =================================================================
SetupGame:
// deletes objects from last game (if any)
delete objects 1,9999
//makes the game board (floor)
MAKE OBJECT BOX 9999,75,5,300
COLOR OBJECT 9999,RGB(36,0,192)
//makes game wall
make object box 9998,5,15,400
color object 9998,RGB(18,0,128)
position object 9998,40,0,50
//makes game wall
make object box 9997,5,15,400
color object 9997,RGB(18,0,128)
position object 9997,-40,0,50
//makes the player (default square for now)
MAKE OBJECT BOX 1,5,15,5
COLOR OBJECT 1,RGB(255,255,255)
POSITION OBJECT 1,0,10,95
YROTATE OBJECT 1,180
// MAKES DODGING BLOCK
MAKE OBJECT BOX 2,4.5,4.5,20
COLOR OBJECT 2,RGB(87,255,128)
POSITION OBJECT 2,RND(37.5),5,-90
// MAKES DODGING BLOCK
MAKE OBJECT BOX 3,4.5,4.5,20
COLOR OBJECT 3,RGB(0,0,255)
POSITION OBJECT 3,RND(37.5)*-1,5,-90
// MAKES DODGING BLOCK
MAKE OBJECT BOX 4,18,4.5,4.5
COLOR OBJECT 4,RGB(255,0,255)
POSITION OBJECT 4,RND(20),5,-95
// MAKES DODGING BLOCK
MAKE OBJECT BOX 5,18,4.5,4.5
COLOR OBJECT 5,RGB(0,255,255)
POSITION OBJECT 5,RND(20)*-1,5,-95
// MAKES DODGING BLOCK
MAKE OBJECT BOX 6,30,4.5,4.5
COLOR OBJECT 6,RGB(255,66,0)
POSITION OBJECT 6,0,5,-95
// MAKES DODGING BLOCK
make object box 7,15,4.6,4.5
color object 7,RGB(255,0,128)
position object 7,rnd(20),5,-95
// MAKES DODGING BLOCK
make object box 8,15,4.6,4.5
color object 8,RGB(78,0,192)
position object 8,rnd(20)*-1,5,-95
// SETS UP COLLISION BETWEEN PLAYER AND DODGING BLOCKS
FOR X=1 TO 8
SET OBJECT COLLISION ON X
SET OBJECT COLLISION TO BOXES X
NEXT X
// A NICE POLISH (SETS SHADOWS FOR GAME ITEMS)
SET SHADOW LIGHT 0,100,100,100,1000
POSITION LIGHT 0,100,100,100
SET LIGHT RANGE 0,1000
FOR X=1 TO 8
SET SHADOW SHADING ON X,-1,200,1
NEXT X
// PLAYER HEALTH & SCORE VARIABLES
PlyrHlth=10
PlyScr=0
return
settings:
SET WINDOW TITLE "Dodge Block"
SYNC ON
SYNC RATE 60
AUTOCAM OFF
SET GLOBAL SHADOWS ON
set display mode 800,600,32
set text font "papyrus"
ScrWid = screen width()
ScrHgt = screen height()
music = rnd(2)
load image "pixie.bmp",1
load image "End Screen.bmp",2
//set up music
LOAD MUSIC "a_california_morning.mp3",1
load music "venom.mp3",2
if music = 1 then
set music speed 1,200
loop music 1
endif
if music = 2 then
set music speed 1,150
loop music 2
endif
return
GameBoardClr:
cls 0
// deletes objects from last game (if any)
delete objects 1,9999
color backdrop 0
// because if game is played, but exitted before finish
// item are not removed properly + has a blue background
ink RGB(255,0,0),RGB(0,0,0)
PASTE IMAGE 1,0,0
SET TEXT SIZE 35
center TEXT ScrWid / 2,(ScrHgt / 2),"What gameboard do you want?"
set text size 20
center TEXT ScrWid / 2,(ScrHgt / 2) + 60,"Press 1 for dark, 2 for cheery, 3 for rainbow"
input color$
if color$ = 1 center TEXT ScrWid / 2,(ScrHgt / 2) +120,"DARK Board
if color$ = 2 center TEXT ScrWid / 2,(ScrHgt / 2) +120,"CHEERY Board
if color$ = 3 center TEXT ScrWid / 2,(ScrHgt / 2) +120,"RAINBOW Board
if spacekey() = 1 then Status = 0
return
function Button(x1,y1,WORDS$) //button function
Pressed=0
x2=Text Width(WORDS$)
y2=Text Height(WORDS$)
if mousex()>x1 and mousex()<x1+x2 and mousey()>y1 and mousey()<y1+y2
Pressed=1
endif
if pressed=1 then ink rgb(255,0,0),0 else ink rgb(255,255,255),0
if pressed=1
Pressed=Mouseclick()
else
pressed = 0
endif
text x1,y1,WORDS$
endfunction pressed
Ofcourse everyone is free to code however they like I'm just sharing what I know.
Other checks like:
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1 and mousey()<y1+y2
Pressed=1
endif
endif
Can be combined:
if mousex()>x1 and mousex()<x1+x2 and mousey()>y1 and mousey()<y1+y2
Pressed=1
endif
Personally I think you are capable of coding menus and bullet collision for their current project if not more. I'd wait for Obese to comment on that tho.