Where'd everybody go?
I have been playing some more. I read the state machine tuts and restructred the program (thanks Steve).
Added:
menu - Options is on the menu, but not active yet.
add Daves menu graphic to the media folder
name it TempTitle2.png
menu music - from my DarkBasicPro CD.
sounds - from my DarkBasicPro CD.
`tunes
load music "music triumph.mp3", MenuMusic
`bells and whistles
load sound "Abduction.wav", StartUpSound
load sound "Rematerialization.wav", ShutDownSound
load sound "UFO 2.wav", MotionSound
load sound "Rippler.wav", DeadSound
load sound "Magic Tree.wav", MadeItSound
load sound "Time Box loop 1.wav", SwapSound
score - not all there yet.
cloud animation - uses Daves cloud image - gets modified on creation.
iso camera - above level 3.
move camera - above level 6. Use numpad to control camera.
compass - available with moveable camera. Media attached - unpack the bitmaps to your projects media folder.
`=====================================
`== DarkBASIC Pro Community Project ==
`== "Changing Pathways" ==
`=====================================
`Started: 3/19/08 by David Gervais
`When you want to add a new effect to the project, please put it in a function.
`Add the function to the end of the code with a short description of what it does,
`and call it at the appropriate location in the main loop. This keeps most of your
`stuff from interfering with stuff that is already in the program.
`To compile, you'll need to save David's media into a folder named "Media" that is
`in the same folder as this file. Find it on the forum thread.
`============================
`== Variable Setup ==
type Block
object as integer
direction as integer `Direction: 0-left : 1-up : 2-right : 3-down
item as integer `The index of the item at this point or zero if none
filled as boolean `Is this block walkable
endtype
type Item ` Item such as powerup or something
alive as boolean `Does this thing even work?
itemtype as integer ` What is this thing?
endtype
`These are the base objects, which should be instanced in the main game
#Constant PlayerObject 1
#Constant HeartObject 2
#Constant ClockObject 3
#Constant CrossObject 4
#Constant StarObject 5
#Constant BlankPyramidObject 6
#Constant GratePyramidObject 7
#Constant CrossPyramidObject 8
#Constant StarPyramidObject 9
#Constant HeartPyramidObject 10
#Constant LoopPyramidObject 11
#Constant BoostPyramidObject 12
#Constant ClockPyramidObject 13
#Constant ArrowPyramidObject 14
#Constant RadiationPyramidObject 15
#Constant CloudObject 16
`gonna need something to hold the grid image
#Constant GridObject 17
`Images
#Constant CloudsImage 1
#Constant GridImage 2
#Constant CompassFaceImage 3
#constant CompassNeedleImage 4
`Animation
#constant CloudAnimation 1
`Music
#constant MusicVolume 100
#Constant MenuMusic 1
`Sounds
#Constant StartUpSound 1
#Constant ShutDownSound 2
#Constant MotionSound 3
#Constant DeadSound 4
#Constant MadeItSound 5
#Constant SwapSound 6
` these are constants for our state machine
#constant cDEAD 3
#constant cALIVE 2
#constant cSTARTGAME 0
#constant cSTARTLEVEL 1
#constant cSTARTLIFE 4
#constant cENDLEVEL 5
#constant cENDGAME 6
`
#constant cStartLives 3
`global variables
`menu variables - menu graphics
global menuImage1
global menuImage2
global menuSprite1
global menuSprite2
`these variables control board creation and placement
global boardObjectStart = 100
global boardSize = 7
global boardEven = 0
global startPoint as Block
global startPosition = 1
global endPoint as Block
global endPosition = 1
`variables for player control
global playerRow = 0
global playerColumn = 0
global playerRowOld=0
global playerColumnOld=-2
global playerSwaps=2
global playerMoves=0
global playerScore=0
global playerLives=3
global playerHealth=100
global playerLevel=0
`gui variables
global GuiButtonStart=100
global GuiButtonWidth=50
global GuiButtonHeight=18
global GuiTextSize=36
global GuiButtonX=25
global GuiButtonY=50
global moveButton=1
global swapButton=2
global leftButton=3
global upButton=4
global rightButton=5
global downButton=6
global okButton=7
global redoButton=8
`swap variables
global swapSource=4
global swapTarget=4
global swapSourceSave
global swapTargetSave
`main loop run state
`
` 0=fresh start
` 1=new level
` 2=in play
` 3=player died
` 4=start life
` 5=level over
` 6=end level
global runState=0
`Compass for when the camera goes mobile at level 3
global CompassFaceSprite=0
global CompassNeedleSprite=0
`message Box variables
global messageBoxMap=0
global messageBoxSprite=0
global messageBoxImage=0
global messageBoxDisplay=0
`look ahead
`these variables are for a recursive routine that
`will determine if a board can be crossed.
`the routine has been removed until all play features have been added.
`I will leave the variables in place (for now).
global searchObject=0
global searchColumn=0
global SearchRow=0
global searchUnmoves=0
global winable=0
`this is for test purposes and will be removed later
global test$
global recursion=0
global searchMin=0
global searchMax=0
global searchTime as dword
`===============================================
`======== Main Code ========
`===============================================
Initialize()
BuildGui()
Build_Message_Box()
Menu()
deInitialize()
end
`=============================================
`==== Functions ====
`=============================================
`=====================================
`== Initializing the Game ==
`This gets the game ready to play by loading objects and setting up variables and stuff
function Initialize()
GeneralSetup()
InitializePlayerEffects() `This sets up certain variables for rotating and hovering the player
LoadGameMedia()
SetupGround()
endfunction
`Basic setup stuff
function GeneralSetup()
set display mode 1024,768,32
sync on : sync rate 60
autocam off
randomize timer()
position camera 0,250,0
point camera 0,0,0
move camera 0,(11-boardSize)*20
endfunction
`This sets up some variables that are used to hover the player and rotate it
function InitializePlayerEffects()
global HoverSpeed as Float
`global RotateSpeed as Float
HoverSpeed=0.01
endfunction
function deInitialize()
`code here
endfunction
`=====================================
`== Run the Menu ==
function Menu()
makeMenu()
play music MenuMusic
`** Our main menu loop simply waits for a keypress and acts on it
`** 1 = Play Game, 2 = Exit Game, Anything else does nothing
do
Animation()
hide object playerObject
`show sprite menuSprite1
show sprite menuSprite2
`paste image menuImage1,screen width()/2-image width(menuImage1)/2,screen height()/4-image height(menuImage1)/2
select inkey$()
case "1"
`cls
`hide sprite menuSprite1
hide sprite menuSprite2
if music playing(MenuMusic)
stop music MenuMusic
endif
play sound StartUpSound
show object playerObject
gamePlay()
while sound playing(ShutDownSound)
endwhile
play music MenuMusic
endcase
case "2"
Options()
endcase
case "3"
end
endcase
endselect
if playerScore>0 then center text 512, 650, "Score : " + str$(playerScore)
sync
loop
endfunction
`build the menu
function makeMenu()
menuImage1=1
while image exist(menuImage1)
inc menuImage1
endwhile
load image "TempTitle2.png",menuImage1,1
bm=1
while bitmap exist(bm)
inc bm
endwhile
create bitmap bm,image width(menuImage1),image height(menuImage1)*2
`create image of opitions
tf$=text font$()
ts=text size()
set text font "Arial"
set text size 48
t1$="1 Play game"
t2$="2 Options"
t3$="3 Exit"
ink rgb(255,255,255),0
text image width(menuImage1)/6,2+image height(menuImage1),t1$
text image width(menuImage1)/6,2+text height(t1$)+image height(menuImage1),t2$
text image width(menuImage1)/6,2+text height(t2$)*2+image height(menuImage1),t3$
blur bitmap bm,2
paste image menuImage1,0,0
menuImage2=1
while image exist(menuImage2)
inc menuImage2
endwhile
get image menuImage2,0,0,bitmap width(bm),bitmap height(bm)
delete bitmap bm
menuSprite2=1
while sprite exist(menuSprite2)
inc menuSprite2
endwhile
sprite menuSprite2,screen width()/2-image width(menuImage2)/2,screen height()/2-image height(menuImage2)/2,menuImage2
set text font tf$
set text size ts
endfunction
` set some stuff (easy-hard,board size etc.) OOOOOOOO
function Options()
endfunction
`*************************************
`** Play the Game
`*************************************
function GamePlay()
` This function Starts the Game
`** Initialise the Game Play
GamePlayInit()
`** Game Playing Code goes here!!!
runState = cSTARTGAME
`** M A I N G A M E L O O P
do
Animation()
select runState
case cSTARTGAME
`** Start the level at 1,
`** reset the lives then move on immediately
`** This state is for one cycle only
playerLevel = 1
playerLives = cStartLives
playerScore = 0
runState = cSTARTLEVEL
endcase
case cSTARTLEVEL
BuildField()
SetField()
PlayerInit()
runState=cALIVE
CameraInit()
CameraControl()
`this may become part of the program
`Winable=SeekPath()
while sound playing(StartUpSound)
endwhile
endcase
case cALIVE
`** While the player is alive, there is a
`** host of actions to carry out. these are neatly
`** packaged into functions
Player_Information()
MoveOrSwap()
CameraControl()
Hide_Message_Box()
messageBoxText$(7)=test$
center text screen width()/2,10,str$(Screen fps())
endcase
case cDEAD
`for now if the player dies, just start him over
play sound DeadSound
i=100
while sound playing(DeadSound)
`could place kill off player effects here
if i>0
set alpha mapping on playerObject,i
dec i
endif
Player_Information()
sync
endwhile
set alpha mapping on playerObject,100
runState=cSTARTLIFE
dec playerLives
if playerLives=0
runState=cENDGAME
endif
endcase
case cSTARTLIFE
`player died redraw the field
runState=cALIVE
SetField()
PlayerInit()
CameraInit()
CameraControl()
`Winable=SeekPath()
endcase
case cENDLEVEL
`this is where we bump the level
`** need to add the code for that
play sound MadeItSound
while sound playing(MadeItSound)
`could place end of level effects here
endwhile
destroyField()
runState = cSTARTLEVEL
`give some points and bump the level
inc playerScore,playerLevel*20
playerSwaps=2
inc playerLevel
endcase
case cENDGAME
`** At the end of the game, the loop is exited after
`** displaying the score
`** The natural progression of the game forces us back
`** to the menu
hideButtons()
messageBoxText$(3)="Swaps: "+str$(playerSwaps)
messageBoxText$(4)="Lives: "+str$(playerLives)
messageBoxText$(5)="Score: "+str$(playerScore)
messageBoxText$(16)="Left Click for Menu"
Show_Message_Box(800,50,100,255)
sync
repeat
`let them see it
until mouseclick()=1
play sound ShutDownSound
fade bitmap 0,40
hide sprite messageBoxSprite
sync
while sound playing(ShutDownSound)
endwhile
Clear_Message_Box()
destroyField()
if boardSize>=5
dec boardSize,2
endif
exit
endcase
endselect
sync
loop
`** DeInitialise the Game Play
GamePlayDeInit()
endfunction
`player variables are initialized here
function GamePlayInit()
CompassFaceSprite=1
while sprite exist(CompassFaceSprite)
inc CompassFaceSprite
endwhile
sprite CompassFaceSprite,750,50,CompassFaceImage
set sprite alpha CompassFaceSprite,100
hide sprite CompassFaceSprite
CompassNeedleSprite=CompassFaceSprite
while sprite exist(CompassNeedleSprite)
inc CompassNeedleSprite
endwhile
sprite CompassNeedleSprite,774,74,CompassNeedleImage
offset sprite CompassNeedleSprite,8,24
set sprite alpha CompassNeedleSprite,100
hide sprite CompassNeedleSprite
endfunction
`player players are de-initialized here
function GamePlayDeInit()
delete sprite CompassNeedleSprite
delete sprite CompassFaceSprite
endfunction
`This will contain the code and function calls to setup a board for the player
`to play on
function BuildField()
boardEven=((boardSize mod 2)=0)
dim playField(boardSize-1,boardSize-1) as Block
`play field squares
for i=0 to boardSize-1
for j=0 to boardSize-1
playField(i,j).object=boardObjectStart+i*boardSize+j
playField(i,j).item=ArrowPyramidObject
instance object playField(i,j).object,playField(i,j).item
`set shadow shading on playField(i,j).object
next j
next i
`players start square
startPoint.object=boardObjectStart+boardSize*boardSize
startPoint.item=BoostPyramidObject
instance object startPoint.object,startPoint.item
`set shadow shading on startPoint.object
`players end square
endPoint.object=boardObjectStart+boardSize*boardSize+1
endPoint.item=GratePyramidObject
instance object endPoint.object,endPoint.item
`set shadow shading on endPoint.object
make light 1
set point light 1,0,-1000,0
set light range 1,1200
position light 0,0,1000,0
`set point light 0,0,1000,0
set light range 0,1200
endfunction
`destroy play field to be rebuilt next round
function destroyField()
`destroy board squares
for i=boardObjectStart to boardObjectStart+boardSize*boardSize+1
if object exist(i)
delete object i
endif
next i
undim playField()
delete light 1
`destroy power ups here
endfunction
`reset the playing field
function SetField()
boardEven=((boardSize mod 2)=0)
`play field squares
for i=0 to boardSize-1
for j=0 to boardSize-1
playField(i,j).item=ArrowPyramidObject
playField(i,j).direction=rnd(3)
playField(i,j).filled=1
position object playField(i,j).object,25*((boardSize/2-i)-boardEven),-25,25*((boardSize/2-j)-boardEven)
yrotate object playField(i,j).object,90*(playField(i,j).direction+1)
show object playField(i,j).object
next j
next i
`players start square
startPoint.object=boardObjectStart+boardSize*boardSize
startPoint.item=BoostPyramidObject
startPoint.direction=3
startPosition=rnd(boardSize-1)
position object startPoint.object,25*((boardSize/2)+1-boardEven),-25,25*((boardSize/2-startPosition)-boardEven)
yrotate object startPoint.object,90
`players end square
endPoint.object=boardObjectStart+boardSize*boardSize+1
endPoint.item=GratePyramidObject
endPosition=rnd(boardSize-1)
position object endPoint.object,25*((boardSize/2-boardSize)-boardEven),-25,25*((boardSize/2-endPosition)-boardEven)
yrotate object endPoint.object,90
`position the player
position object PlayerObject,25*((boardSize/2)+1-boardEven),0,25*((boardSize/2-startPosition)-boardEven)
yrotate object PlayerObject,270
endfunction
function PlayerInit()
playerColumn=-1
playerRow=startPosition
playerColumnOld=-2
playerRowOld=0
playerSwaps=2
`set shadow shading on playerObject
endfunction
`This loads the game's media
function LoadGameMedia()
cd "Media"
Load Object "Heart01.x", HeartObject
Load Object "Player02.x", PlayerObject
Load Object "Star01.x", StarObject
Load Object "Watch01.x", ClockObject
Load Object "RedCross.x", CrossObject
Load Object "Pyrmid0.x", BlankPyramidObject
Load Object "Pyrmid1.x", ArrowPyramidObject
Load Object "Pyrmid2.x", RadiationPyramidObject
Load Object "Pyrmid3.x", GratePyramidObject
Load Object "Pyrmid4.x", CrossPyramidObject
Load Object "Pyrmid5.x", StarPyramidObject
Load Object "Pyrmid6.x", HeartPyramidObject
Load Object "Pyrmid7.x", LoopPyramidObject
Load Object "Pyrmid8.x", BoostPyramidObject
Load Object "Pyrmid9.x", ClockPyramidObject
for a=2 to 15
Exclude Object On a
`Hide the objects we loaded, because all of them except the player object
`will be instanced when we use them in the game.
next a
`load images
Load Image "Clouds1.png", CloudsImage,1
Load Image "Grid_Fill01.bmp", GridImage
load image "Compass face.bmp", CompassFaceImage
load image "Compass needle.bmp", CompassNeedleImage
`tunes
load music "music triumph.mp3", MenuMusic
`bells and whistles
load sound "Abduction.wav", StartUpSound
load sound "Rematerialization.wav", ShutDownSound
load sound "UFO 2.wav", MotionSound
load sound "Rippler.wav", DeadSound
load sound "Magic Tree.wav", MadeItSound
load sound "Time Box loop 1.wav", SwapSound
set sound volume SwapSound,80
endfunction
`make a bunch of buttons
function BuildGui()
`code here
ts=text size()
set text size GuiTextSize
t$="+Right+"
GuiButtonWidth=10+text width(t$)
GuiButtonHeight=4+text height(t$)
set text size ts
moveButton= BuildButton("Move", GuiButtonY)
swapButton= BuildButton("Swap", GuiButtonY+ GuiButtonHeight+2)
leftButton= BuildButton("West", GuiButtonY+2*GuiButtonHeight+2)
upButton= BuildButton("North",GuiButtonY+3*GuiButtonHeight+2)
RightButton=BuildButton("East", GuiButtonY+4*GuiButtonHeight+2)
downButton= BuildButton("South",GuiButtonY+5*GuiButtonHeight+2)
okButton= BuildButton("OK", GuiButtonY+6*GuiButtonHeight+2)
redoButton= BuildButton("Re-Do",GuiButtonY+7*GuiButtonHeight+2)
hideButtons()
endfunction
function MoveOrSwap()
if playerSwaps=0
`no choice left - force a move
`runState=cAlive
playerMoves=3
PlayerMotion()
else
hideButtons()
show sprite moveButton
show sprite swapButton
if mouseclick()=1
mxp=(mousex()>=GuiButtonX)*(mousex()<=(GuiButtonX+GuiButtonWidth))
myp=(mousey()>=GuiButtonY)*(mousey()<=(GuiButtonY+GuiButtonHeight))
myp=myp+2*(mousey()>=(GuiButtonY+GuiButtonHeight+2))*(mousey()<=(GuiButtonY+2+2*GuiButtonHeight))
endif
gc=mxp*myp
if gc=1
hideButtons()
playerMoves=3
PlayerMotion()
endif
if gc=2
chooseArrows()
endif
endif
endfunction
`<--- select arrows --->
function chooseArrows()
swapSource=4
swapTarget=4
Done=0
repeat
Animation()
hideButtons()
show sprite moveButton
show sprite leftButton
show sprite upButton
show sprite rightButton
show sprite downButton
if swapSource<>4
if swapTarget=4
hide sprite moveButton
`select target
select swapSource
case 0
hide sprite leftButton
endcase
case 1
hide sprite upButton
endcase
case 2
hide sprite rightButton
endcase
case 3
hide sprite downButton
endcase
case default
`still looking for source
endcase
endselect
swapTarget=pickArrow()
if swapTarget=swapSource
swapTarget=4
else
if swapTarget<>4
swapSourceSave=swapSource
swapTargetSave=swapTarget
swapArrows()
endif
endif
else
hideButtons()
showArrow(swapSource)
showArrow(swapTarget)
show sprite okButton
show sprite redoButton
if mouseclick()=1
mxp=(mousex()>=GuiButtonX)*(mousex()<=(GuiButtonX+GuiButtonWidth))
spy=GuiButtonY+6*GuiButtonHeight+2
myp=(mousey()>=spy)*(mousey()<=(spy+GuiButtonHeight))
myp=myp+2*(mousey()>=(spy+GuiButtonHeight+2))*(mousey()<=(spy+2+2*GuiButtonHeight))
vt=mxp*myp
if vt=1
`ok to swap
dec playerSwaps
swapSource=4
swapTarget=4
hideButtons()
Done=1
endif
if vt=2
`re-select arrows
swapSource=swapTargetSave
swapTarget=swapSourceSave
swapArrows()
swapSource=4
swapTarget=4
endif
endif
endif
else
`select source
if mouseclick()=1
mxp=(mousex()>=GuiButtonX)*(mousex()<=(GuiButtonX+GuiButtonWidth))
myp=(mousey()>=GuiButtonY)*(mousey()<=(GuiButtonY+GuiButtonHeight))
if (mxp*myp)=1
hideButtons()
playerMoves=3
PlayerMotion()
Done=1
else
`get the source arrow
swapSource=pickArrow()
endif
endif
endif
CameraControl()
Player_Information()
sync
until Done
endfunction
function pickArrow()
ap=4
if mouseclick()=1
mxp=(mousex()>=GuiButtonX)*(mousex()<=(GuiButtonX+GuiButtonWidth))
aspy=GuiButtonY+2*GuiButtonHeight+2
myp=(mousey()>=aspy)*(mousey()<=(aspy+GuiButtonHeight))
myp=myp+2*(mousey()>=(aspy+GuiButtonHeight+2))*(mousey()<=(aspy+2+2*GuiButtonHeight))
myp=myp+3*(mousey()>=(aspy+2*GuiButtonHeight+2))*(mousey()<=(aspy+2+3*GuiButtonHeight))
myp=myp+4*(mousey()>=(aspy+3*GuiButtonHeight+2))*(mousey()<=(aspy+2+4*GuiButtonHeight))
ap=mxp*myp-1
if ap<0 then ap=4
endif
endfunction ap
function showArrow(a)
select a
case 0
show sprite leftButton
endcase
case 1
show sprite upButton
endcase
case 2
show sprite rightButton
endcase
case 3
show sprite downButton
endcase
case default
`still looking for source
endcase
endselect
endfunction
function hideButtons()
hide sprite moveButton
hide sprite swapButton
hide sprite rightButton
hide sprite leftButton
hide sprite upButton
hide sprite downButton
hide sprite okButton
hide sprite redoButton
endfunction
`Build buttons for the GUI
function BuildButton(t$,by)
ts=text size()
set text size GuiTextSize
bmw=GuiButtonWidth
bmh=GuiButtonHeight
bm=1
while bitmap exist(bm)
inc bm
endwhile
create bitmap bm,bmw,bmh
blazeColor=rgb(255,255,0)
backColor=rgb(255,0,0)
outlineColor=rgb(22,22,22)
textColor=rgb(250,250,250)
ink outlineColor,0
box 0,0,bw,bh
box 2,2,bmw/2,bmh/2,backColor,backColor,blazeColor,backColor
box bmw/2,bmh/2,bmw-1,bmh-1,backColor,blazeColor,backColor,backColor
box 2,bmh-1,bmw/2,bmh/2,backColor,backColor,blazeColor,backColor
box bmw/2,bmh/2,bmw-1,2,backColor,blazeColor,backColor,backColor
dot 1,1,0:dot bmw,1,0:dot 1,bmh,0:dot bmw,bmh,0
dot 2,2,outlineColor:dot bmw-1,2,outlineColor
dot 2,bmh-1,outlineColor:dot bmw-1,bmh-1,outlineColor
center text bmw/2+1,3,t$
ink textColor,0
center text bmw/2,2,t$
bi=1
while image exist(bi)
inc bi
endwhile
get image bi,1,1,bmw,bmh
delete bitmap bm
bs=GuiButtonStart
while sprite exist(bs)
inc bs
endwhile
sprite bs,GuiButtonX,by,bi
set sprite alpha bs,175
set text size ts
endfunction bs
`swap the arrows <------>
function SwapArrows()
if sound playing(SwapSound)=0
play sound SwapSound
endif
hide sprite messageBoxSprite
for i=0 to boardSize-1
for j=0 to boardSize-1
if playField(i,j).direction=swapSource
playField(i,j).direction=swapTarget
else
if playField(i,j).direction=swapTarget
playField(i,j).direction=swapSource
endif
endif
yrotate object playField(i,j).object,90*(playField(i,j).direction+1)
Animation()
sync
next j
next i
sync
while sound playing(SwapSound)
Animation()
sync
endwhile
endfunction
`move the player ////////
function PlayerMotion()
if sound looping(MotionSound)=0
loop sound MotionSound
endif
repeat
RotatePlayer()
MovePlayer()
playerTest()
until playerMoves=0
if sound looping(MotionSound)
stop sound MotionSound
endif
endfunction
function MovePlayer
if playerMoves>0
playerColumnOld=playerColumn
playerRowOld=playerRow
if playerColumn=-1
pd=0
else
pd=playField(playerColumn,playerRow).direction
endif
select pd
case 0
inc playerColumn
endcase
case 1
dec playerRow
endcase
case 2
dec playerColumn
endcase
case 3
inc playerRow
endcase
case default
endcase
endselect
`position object PlayerObject,25*((boardSize/2-playerColumn)+1-boardEven),0,25*((boardSize/2-playerRow)-boardEven)
`position object playerObject,25*((boardSize/2-playerColumn)-boardEven),0,25*((boardSize/2-playerRow)-boardEven)
playerGlide()
if playerColumnOld<>-1
playField(playerColumnOld,playerRowOld).filled=0
hide object playField(playerColumnOld,playerRowOld).object
endif
dec playerMoves
endif
endfunction
function playerGlide()
sxpos=object position x(playerObject)
szpos=object position z(playerObject)
expos=sxpos+25*(playerColumn-playerColumnOld)
ezpos=szpos+25*(playerRow-playerRowOld)
cx=(sxpos-expos)/25
cz=(szpos-ezpos)/25
for i=1 to 25
position object playerObject,object position x(playerObject)+cx,object position y(playerObject),object position z(playerObject)+cz
if playerColumnOld<>-1
op=playField(playerColumnOld,playerRowOld).object
position object op,object position x(op),object position y(op)-((i-12)/2)*(i>12),object position z(op)
`might want to fade it out too
set alpha mapping on op,(100*(25-i))/25
endif
t=timer()+(1000/60)
while timer()<t
endwhile
CameraControl()
`Show_Message_Box(800,50,100,255)
Animation()
Player_Information()
sync
next i
`Show_Message_Box(800,50,100,255)
Player_Information()
sync
position object playerObject,25*((boardSize/2-playerColumn)-boardEven),0,25*((boardSize/2-playerRow)-boardEven)
endfunction
`test player condition ????????????
function playerTest()
if playerColumnOld<>-2
if playerColumn>=0 and playerColumn<=boardSize-1 and playerRow>=0 and playerRow<=boardSize-1
if playField(playerColumn,playerRow).filled=1
`still in the game
inc playerScore,10
`test for powerups here (or hazards)
if playerMoves=0
inc playerSwaps
endif
else
`oops
messageBoxText$(9)="In the last round you"
messageBoxText$(10)="fell down a hole"
messageBoxText$(11)="of your own making!"
playerMoves=0
runState=cDEAD
playerSwaps=2
endif
else
if playerColumn=boardSize and playerRow=endPosition
`whew - you finaly made it!
messageBoxText$(9)="In the last round you"
messageBoxText$(10)="completed the round"
messageBoxText$(11)="Congratulations!"
playerMoves=0
runState=cENDLEVEL
else
`biffed
messageBoxText$(9)="In the last round you"
messageBoxText$(10)="did a man overboard"
messageBoxText$(11)=""
playerMoves=0
runState=cDEAD
playerSwaps=2
endif
endif
endif
endfunction
`Handle all of the animations here AAAAAAAAAAA
function Animation()
MoveClouds()
HoverPlayer(150,3)
endfunction
`This will eventually scroll the clouds below the playing field
function MoveClouds()
scroll object texture cloudObject,0.001,0.001
endfunction
`This will make the player object bob up and down for a neat effect
function HoverPlayer(SpeedMultiplier,Distance)
HoverSpeed=HoverSpeed+(0.00001*SpeedMultiplier)*((object position y(PlayerObject)<Distance/2)-(object position y(PlayerObject)>Distance/2))
position object PlayerObject,object position x(PlayerObject),object position y(PlayerObject)+HoverSpeed,object position z(PlayerObject)
endfunction
`This will cause the player to rotate 90 degrees in a direction
`Based on left and right arrowkeys
function RotatePlayer()
`turnDirection=turnDirection+((turnDirection=0)*(rightkey()))-((turnDirection=0)*(leftkey()))
`set the players turn direction based on current position
`and the direction of the arrow below
if turnDirection=0
if playerColumnOld<>-2
turnAngle=object angle y(PlayerObject)-object angle y(playField(playerColumn,playerRow).object)
else
turnAngle=0
endif
if turnAngle<>0
turnDirection=turnAngle/abs(turnAngle)
turnAngle=abs(turnAngle)
endif
select turnAngle
case 90
`this is what we were looking for
endcase
case 180
`this is an about face - it spells doom
turnAngle=0
turnDirection=0
endcase
case 270
turnAngle=90
turnDirection=turnDirection*(-1)
endcase
case 360
`don't turn a full circle
turnAngle=0
turnDirection=0
endcase
case default
turnAngle=0
turnDirection=0
endcase
endselect
endif
if turnDirection<>0
sa=object angle y(playerObject)
for ta=sa to sa+(turnAngle*turnDirection) step turnDirection
yrotate object playerObject,ta
Animation()
CameraControl()
Player_Information()
sync
next ta
turnAngle=0
turnDirection=0
endif
endfunction
function SetupGround()
`code here
make object box GridObject,800,0.01,800
texture object GridObject,GridImage
set alpha mapping on GridObject,50
position object GridObject,0,-29,0
`Convert Dave's Cloud image
bm=1
while bitmap exist(bm)
inc bm
endwhile
create bitmap bm,image width(CloudsImage),image height(CloudsImage)
ts=1
while sprite exist(ts)
inc ts
endwhile
sprite ts,0,0,CloudsImage
paste sprite ts,0,0
delete image CloudsImage
delete sprite ts
get image CloudsImage,0,0,bitmap width(bm),bitmap height(bm)
delete bitmap bm
make object box CloudObject,800,0.01,800
texture object CloudObject,CloudsImage
position object CloudObject,0,-30,0
endfunction
` Information displayed while player lives
function Player_Information()
Grayscale_Area(800,50,800+150,50+15+70)
center text 800+75,50+6,"Score: "+Str$(playerScore)
center text 800+75,50+6+15,"Lives: "+str$(playerLives)
center text 800+75,50+6+30,"Swaps: "+str$(playerSwaps)
center text 800+75,50+6+45,"Level: "+str$(playerLevel)
`center text 800+75,50+6+60,left$("non",3*(winable<>2))+"winable"
`center text 800+75,50+6+60,"CamX: "+str$(camera angle x(0))
`center text 800+75,50+6+75,"CamY: "+str$(camera angle y(0))
`center text 800+75,50+6+90,"CamZ: "+str$(camera angle z(0))
if playerLevel>=7
show sprite CompassFaceSprite
show sprite CompassNeedleSprite
`rotate the Compass needle
rotate sprite CompassNeedleSprite,wrapvalue(0-camera angle y(0))
endif
endfunction
`this is a little message box setup I came up with
`using a David Gervais graphic
`these global variables are now required by the message box functions
`global messageBoxMap=0
`global messageBoxSprite=0
`global messageBoxImage=0
`global messageBoxDisplay=0
`
` and these are their calls
` Build_Message_Box()
` Show_Message_Box(200,50,100,255)
` Clear_Message_Box()
`
`put your messages in messageBoxText$(n) n=0 through 10
function Build_Message_Box()
messageBoxImage=1
while image exist(messageBoxImage)
inc messageBoxImage
endwhile
load image "dialog01.png",messageBoxImage
messageBoxSprite=1
while image exist(messageBoxSprite)
inc messageBoxSprite
endwhile
sprite messageBoxSprite,0,0,messageBoxImage
stretch sprite messageBoxSprite,60,60
messageBoxMap=1
while bitmap exist(messageBoxMap)
inc messageBoxMap
endwhile
create bitmap messageBoxMap,sprite width(messageBoxSprite),sprite height(messageBoxSprite)
paste sprite messageBoxSprite,0,0
delete image messageBoxImage
get image messageBoxImage,0,0,bitmap width(messageBoxMap),bitmap height(messageBoxMap),1
set sprite alpha messageBoxSprite,224
messageBoxDisplay=1
while image exist(messageBoxDisplay)
inc messageBoxDisplay
endwhile
get image messageBoxDisplay,0,0,bitmap width(messageBoxMap),bitmap height(messageBoxMap),1
set current bitmap 0
dim messageBoxText$(18)
messageBoxText$(0)="Pathways"
messageBoxText$(18)="<<<LAST LINE>>>"
hide sprite messageBoxSprite
endfunction
function Show_Message_Box(mbx,mby,bs,sa)
bmw=bitmap width(messageBoxMap)
bmh=bitmap height(messageBoxMap)
Grayscale_area(mbx+2,mby+15,mbx+bmw-2,mby+bmh-2)
set current bitmap messageBoxMap
paste image messageBoxImage,0,0
set current bitmap messageBoxMap
ink rgb(255,255,255),0
for i=0 to 18
center text bmw/2,i*15,messageBoxText$(i)
next i
if image exist(messageBoxDisplay) then delete image messageBoxDisplay
get image messageBoxDisplay,0,0,bitmap width(messageBoxMap),bitmap height(messageBoxMap),1
sprite messageBoxSprite,mbx,mby,messageBoxDisplay
stretch sprite messageBoxSprite,bs,bs
set sprite alpha messageBoxSprite,sa
show sprite messageBoxSprite
set current bitmap 0
endfunction
function Clear_Message_Box()
for i=1 to 18
messageBoxText$(i)=""
next i
endfunction
function Hide_Message_Box()
if mouseclick()=2
hide sprite messageBoxSprite
endif
endfunction
function Grayscale_area(xs,ys,xe,ye)
if mouseclick()<>2
local gppnt as dword
local gpptc as integer
local ppnt as dword
xsize=(xe-xs)*4
ysize=ye-ys
tsize=xsize*ysize*4
pstep=bitmap depth(0)/8
lock pixels
gppnt=get pixels pointer()
gpptc=get pixels pitch()
for x=xs*4 to (xe*4)-1 step pstep
for y=ys to ye
ppnt=gppnt+x+(y*gpptc)
color=*ppnt
gray=rgbr(color)
inc gray,rgbg(color)
inc gray,rgbb(color)
gray=int(gray/3)
`gray=gray-64*(gray>80)
*ppnt=rgb(gray,gray,gray)
next y
next x
unlock pixels
endif
endfunction
`give the player a nice view
function CameraInit()
ccs=1+(playerLevel-1)/3
ccs=ccs*(ccs<=3)+3*(ccs>3)
select ccs
case 1
set camera fov 0,12
position camera 0,1500,0
point camera 0,0,0
move camera 0,(11-boardSize)*120
endcase
case 2
set camera fov 0,60
position camera 0,250-70,0-200
point camera 0,0,0
move camera 0,(11-boardSize)*20
endcase
case 3
set camera fov 0,90
position camera 0,250-70,0-200
point camera 0,0,0
move camera 0,(11-boardSize)*20
endcase
case default
set camera fov 0,90
position camera 0,250-70,0-200
point camera 0,0,0
move camera 0,(11-boardSize)*20
endcase
endselect
endfunction
function CameraControl()
ccs=1+(playerLevel-1)/3
ccs=ccs*(ccs<=3)+3*(ccs>3)
select ccs
case 1
`do nothing
endcase
case 2
`do nothing
endcase
case default
`level 7 and up
point camera 0,object position x(playerObject),0,object position z(playerObject)
CameraMovement()
endcase
endselect
endfunction
function CameraMovement()
d#=CameraDistance()
while d#<25
move camera 0,-1
inc d#,25.0
endwhile
while d#>2000
move camera 0,1
dec d#,25.0
endwhile
sc=scancode()
select sc
case 72
if camera angle x(0)<88
d#=CameraDistance()
move camera 0,d#
pitch camera down 0,1
move camera 0,-d#
endif
endcase
case 73
d#=CameraDistance()
if d#>25
move camera 0,1
endif
endcase
case 75
d#=CameraDistance()
move camera 0,d#
yrotate camera 0,wrapvalue(camera angle y(0)+1)
move camera 0,-d#
endcase
case 76
`restore to default
set camera fov 0,90
position camera 0,250-70,0-200
point camera 0,0,0
move camera 0,(11-boardSize)*20
endcase
case 77
d#=CameraDistance()
move camera 0,d#
yrotate camera 0,wrapvalue(camera angle y(0)-1)
move camera 0,-d#
endcase
case 80
if camera angle x(0)>2
d#=CameraDistance()
move camera 0,d#
pitch camera up 0,1
move camera 0,-d#
endif
endcase
case 81
d#=CameraDistance()
if d#<2000
move camera 0,-1
endif
endcase
case default
`nothing yet
endcase
endselect
endfunction
function CameraDistance()
x#=camera position x(0)-object position x(playerObject)
y#=camera position y(0)-object position y(playerObject)
z#=camera position z(0)-object position z(playerObject)
d#=sqrt((x#*x#)+(y#*y#)+(z#*z#))
endfunction d#
function showpick()
if mouseclick()=1
messageBoxText$(8)="object: "+str$(pick object(mousex(),mousey(),boardObjectStart,2+boardObjectStart+boardSize*boardSize))
endif
endfunction
Have fun.
Whatever...