Ok here we go. A shot of night time and the code for those interested in just following the code instead of seeing the exe.
Rem Program: Tutorial SkySphere Example
` **************************************************
` PROGRAM INITIALIZATION
` Use <?> key to toggle user help display
` Globals - Use GB.nnnn in front to reference
` **************************************************
` OBJECT DIRECTORY
` 1 Matrix Landscape
` 100 Skysphere1
` 200 Skysphere2
` 500 Character
` **************************************************
set window on
set window size 800,600
set window title "Skyshpere Tutorial by CodeSlinger"
TYPE GlobalVariables
X# as FLOAT
Y# as FLOAT
Z# as FLOAT
GH# as FLOAT
CharX# as FLOAT
CharY# as FLOAT
CharZ# as FLOAT
CharAttack as BOOLEAN
EnemyHP as INTEGER
EnemyIdle as BOOLEAN
EnemyUnderAttack as BOOLEAN
CameraAngleX# as FLOAT
CameraAngleY# as FLOAT
CameraAngleZ# as FLOAT
MatrixSize# as FLOAT
Horizon# as FLOAT
WallSize# as FLOAT
Enlarge# as FLOAT
FogColor as INTEGER
FogDistance as INTEGER
Scenery as INTEGER
AmbientLevel as FLOAT
ClearMessages as BOOLEAN
UsingFog as BOOLEAN
CharRun as BOOLEAN
Time as FLOAT
AtEdge as BOOLEAN
ENDTYPE
GB as GlobalVariables
` Initialize Global Variables
GB.X#=0.0
GB.Y#=0.0
GB.Z#=0.0
GB.GH#=0
GB.CharX#=0.0
GB.CharY#=0.0
GB.CharZ#=0.0
GB.CharAttack=0
GB.CameraAngleX#=0.0
GB.CameraAngleY#=0.0
GB.CameraAngleZ#=0.0
GB.MatrixSize#=3000.0
CamX#=MatWidth#/2: Rem Start At Centre Of Matrix
CamZ#=MatHeight#/2
`GroundHeight#=Get Ground Height(1,CamX#,CamZ#)+100.0
GB.UsingFog=1
GB.FogColor=1
GB.Scenery=9
GB.AmbientLevel=20
GB.FogDistance=750
GB.Time=400
GB.CharRun=0
GB.AtEdge=0
GB.EnemyHP = 10
GB.EnemyIdle = 1
GB.EnemyUnderAttack = 0
`set display mode 1024,768,32
set text font "courier"
set text size 24
set text to bold
set text transparent
msg$="Loading Skysphere Tutorial Program and Images..."
Center Text Screen Width()/2,Screen Height()/2,msg$
WAIT 250
SYNC
`
fun_initial_settings()
`fun_Check_GraphicsCards()
fun_load_media()
fun_Setup_Objects()
fun_Create_Skysphere()
Create_Character()
Create_NPC()
` *************************************************
` MAIN PROGRAM LOOP
` *************************************************
WHILE ESCAPEKEY()=0
fun_key_controls()
fun_print_text()
fog_FX()
rotate_sky()
update_time()
`If our character is on screen we want to use the move character FUNCTION
`to move him around. Object exist will return a value of 1 if he does
if object exist(500)
Move_Character()
`if the directional keys are not being pressed play character idle animation
if scancode()=0
stop sound 1000:set object speed 500, 11:loop object 500, 251,300
endif
endif
`the npc
if object exist(501)
`face character if they come in contact with each other
if object collision(500,501)
YROTATE OBJECT 501, object angle y(500)+180
endif
if GB.EnemyIdle = 1
set object speed 501, 11:loop object 501, 206, 250
endif
`death animation
if GB.EnemyHP = 0
stop object 501:set object speed 501, 11:play object 501, 166, 173
GB.EnemyIdle = 0
GB.EnemyHP = 10
endif
`fight animation
if GB.EnemyUnderAttack = 1
GB.EnemyIdle = 0
set object speed 501, 8:loop object 501,32,44
endif
endif
if scancode()=51
`this is the code for the < key and will be used to look left
CameraAngleY# = wrapvalue(Camera Angle Y(0) - 20 )
YRotate Camera 0,CameraAngleY#
endif
if scancode()=52
`this is the code for the > key and will be used to look right
CameraAngleY# = wrapvalue(Camera Angle Y(0) + 20)
YRotate Camera 0,CameraAngleY#
endif
if scancode()=30
`this is the code for the letter a and will be used for attack animation
stop sound 1000:set object speed 500, 11: loop object 500,32,44
`alert npc that it is under attack
GB.EnemyUnderAttack = 1
if object collision(500,501)=1
`this is where we determine if out character has hit the enemy
`or not. From here we call the function for determining hit factors,
`damage, etc.
Melee_Calc()
endif
endif
if scancode()=37
`this is the code for the letter k and will be used for kick animation
`front kick
stop sound 1000:set object speed 500, 11: loop object 500,73,83
`side kick
`stop sound 1000:set object speed 500, 11: loop object 500,126,133
endif
if scancode()=36
`this is the code for the letter j and will be used for jump animation
`additional programming needed to adjust character height on jump
stop sound 1000:set object speed 500, 11: loop object 500,94,102
endif
`update the screen
SYNC
`***********************************************************
`
ENDWHILE
`
` End Program
`
END
`
` *********************************************************
` FUNCTIONS AND SUBROUTINES
` *********************************************************
`
FUNCTION fun_initial_settings()
` =========================================================
` Initial Program Setup
` =========================================================
` sync on
sync rate 0
hide mouse
autocam off
set global collision on
` ------------------------------------------------------
` Setup Camera 0
` ------------------------------------------------------
set camera range 0, 1.0, 10000.0
GB.X#=GB.MatrixSize#/2
`This is the camera height GB.GH#
GB.Y#=10
GB.Z#=GB.MatrixSize#/2
remstart
` ------------------------------------------------------
` Inset Camera 1 Setup - This camera is for the small debug window in upper right
` ------------------------------------------------------
Make Camera 1
Position Camera 1,GB.MatrixSize#/2,150.0,-1800.0
YRotate Camera 1, 0.0
Point Camera 1,GB.MatrixSize#/2,10.0,GB.MatrixSize#/2
Set Camera View 1, Screen Width()-200,10,Screen Width()-10,200
Set Camera Range 1,1.0,GB.MatrixSize# * 4
remend
` ------------------------------------------------------
` Set base lighting
` ------------------------------------------------------
Set Ambient Light GB.AmbientLevel
Fog Distance GB.FogDistance
sync
ENDFUNCTION
`
FUNCTION fun_load_media()
` =========================================================
` place loads for all images, textures, and sounds here
` =========================================================
load image "grass1.bmp",6
load 3dsound "media/footstep.wav",1000
set sound volume 1000, 95
load sound "media/BarrenWasteland.wav",1001
set sound volume 1001, 75
set sound speed 1001,30000
loop sound 1001
print "Media Loaded"
sync
ENDFUNCTION
`
FUNCTION fun_setup_objects()
` =========================================================
` Setup Matrix
` =========================================================
Make Matrix 1, GB.MatrixSize#, GB.MatrixSize#, 10, 10
Prepare Matrix Texture 1, 6, 1, 1
set matrix height 1,0,0,100
set matrix height 1,1,1,100
set matrix height 1,2,2,100
`the following two lines create a random ground height with 200 max height
randomize matrix 1, 200
update matrix 1
sync
ENDFUNCTION
`
FUNCTION fun_Create_Skysphere()
` =========================================================
` Create Skysphere
` =========================================================
load object "Skysphere.x",100
load object "Skysphere.x",200
scale object 100,40000,40000,40000
`object 200 will be another skysphere identical skysphere only
`it will be smaller. The purpose for this one is give the sky
`more depth. It will be rotated at a different rate of speed
`than object 100. This will give us lower clouds moving at a
`different rate of speed. Experiment with different textures and
`I'm sure some pretty amazing sky scenes can be created. One
`thing to try would be another sphere with a sun on one side and
`a moon on the other. Rotate them while adjusting ambient levels
`and you've got night and day!
scale object 200,30000,30000,30000
`I'm rotating one of the spheres so the textures start in a
`different spot in the sky.
rotate object 100,0,180,0
`position the spheres in the middle of the matrix
Position Object 100, GB.MatrixSize#/2, 0, GB.MatrixSize#/2
Position Object 200, GB.MatrixSize#/2, 0, GB.MatrixSize#/2
`turn on ghost for low skysphere to see through it, this way we
`see only clouds
ghost object on 200
sync
ENDFUNCTION
`
FUNCTION Create_Character()
load object "WhiteNinja.x",500
scale object 500, 900,900,900
set object speed 500, 11
set object collision on 500
set object collision to spheres 500
set object radius 500,.4
position object 500,GB.MatrixSize#/2, GB.GH#, GB.MatrixSize#/2
ENDFUNCTION
FUNCTION Create_NPC()
load object "GreenNinja.x",501
scale object 501, 900,900,900
set object speed 501, 11
set object collision on 501
set object collision to spheres 501
set object radius 501,.4
position object 501,GB.MatrixSize#/2+5, GB.GH#, GB.MatrixSize#/2+5
Ground_Height_Getter()
show object 501
ENDFUNCTION
FUNCTION Move_Character()
rem Track character with camera
CharX#=object position x(500)
CharY#=object position y(500)
CharZ#=object position z(500)
a#=object angle y(500)
d#=10.0
h#=get ground height(1,CharX#, CharZ#)
s#=9.0
set camera to follow 0,CharX#,CharY#,CharZ#,a#,d#,h#+9,s#,1
`print the values of my characters location to the screen for debugging
`* x and z cannot be neg to inforce boundary (i think)
set cursor 0,13
print "CharacterX: ", CharX#
print "CharacterY: ", CharY#
print "CharacterZ: ", CharZ#
print "FogDistance: ", GB.FogDistance
print "Ground Height: ", GB.GH#
print "Scancode: ", scancode()
print "Keystate: ", keystate(1)
print "object collision: ";object collision(500,501)
`the following is temporary. There will be more but it will made later
`get keyboard input for movement
if upkey()=1
Edge_Detect()
`begin character walk animation. The walk cycle spans frames 1-13
loop object 500, 1, 13:loop sound 1000
if GB.AtEdge = 0
`this will be the run key eventually
if inkey$()="r"
move object 500, 10
else
move object 500, 1
endif
Ground_Height_Getter()
endif
endif
if downkey()=1
`begin character walk animation. The walk cycle spans frames 1-13
loop object 500, 1, 13:move object 500, -1
Ground_Height_Getter()
endif
if rightkey()=1 then yrotate object 500,wrapvalue(object angle y(500)+3)
if leftkey()=1 then yrotate object 500,wrapvalue(object angle y(500)-3)
` ------------------------------------------------------
` Ability to look upwards
` can look from 0-degees (level) to
` 90-degrees (directly overhead)
` If arrow keys used to move then reset to level
` ------------------------------------------------------
if InKey$()="u" OR InKey$()="U"
if (Camera Angle X(0) >= 272 OR Camera Angle X(0) = 0)
CameraAngleX# = wrapvalue(Camera Angle X(0) - 2)
XRotate Camera 0,CameraAngleX#
endif
endif
if InKey$()="j" OR InKey$()="J"
if (Camera Angle X(0) >= 2)
CameraAngleX# = wrapvalue(Camera Angle X(0) + 2)
XRotate Camera 0,CameraAngleX#
endif
endif
`keep the skyspheres with the player
position object 100, CharX#, CharY#-100, CharZ#
position object 200, CharX#, CharY#-100, CharZ#
ENDFUNCTION
FUNCTION Melee_Calc()
`get random number
temp=RND(100)
`this will give us a 50/50 chance of hitting the enemy
if temp>50
print "temp: ", temp
GB.EnemyHP = GB.EnemyHP - 1
if GB.EnemyHP < 0
GB.EnemyHP = 0
print "Enemy Destroyed"
endif
print "EnemyHP: ", GB.EnemyHP
endif
ENDFUNCTION
FUNCTION fog_FX()
` =========================================================
` FOG Effects
` Toggle on and off plus set color to one of (6) presets
` =========================================================
if GB.UsingFog=1
Fog On
else
Fog Off
endif
Select GB.FogColor
`Case 1
` Red
`Fog Color RGB(245,98,10) : EndCase
`Case 2
` Green
`Fog Color RGB(0,185,0) : EndCase
`Case 3
` Blue
`Fog Color RGB(17,200,238) : EndCase
`Case 4
` Yellow
`Fog Color RGB(231,202,3) : EndCase
Case 5
` Gray
Fog Color RGB(128,128,128) : EndCase
Case 6
` Black
Fog Color RGB(0,0,0) : EndCase
EndSelect
`
ENDFUNCTION
`
FUNCTION fun_key_controls()
` ======================================================
` Control camera 0 movement
` Can move at one of two speeds:
` ======================================================
Wait# = 250
` ------------------------------------------------------
` <?> key toggles Clear/Display on-screen messages
` ------------------------------------------------------
if InKey$()="?"
if (GB.ClearMessages=0)
GB.ClearMessages=1
wait Wait#
else
GB.ClearMessages=0
wait Wait#
endif
endif
` ------------------------------------------------------
` <f> key toggles Fog On/Off
` 1-5 selects red,yellow,gray,or black fog
` ------------------------------------------------------
if InKey$()="f" OR InKey$()="F"
if (GB.UsingFog=0)
GB.UsingFog=1
wait Wait#
else
`GB.UsingFog=0
wait Wait#
endif
endif
if (InKey$() >= "1" AND InKey$() <= "6")
GB.FogColor=Val(InKey$())
endif
` ------------------------------------------------------
` <+>,<-> Raise and lower ambient light (steps 10)
` Wraps around from 100->10->100
` ------------------------------------------------------
if InKey$()="-"
GB.AmbientLevel = GB.AmbientLevel - 10
if GB.AmbientLevel < 10 then GB.AmbientLevel = 100
wait Wait#
endif
if InKey$()="+"
GB.AmbientLevel = GB.AmbientLevel + 10
if GB.AmbientLevel > 100 then GB.AmbientLevel = 10
wait Wait#
endif
Set Ambient Light GB.AmbientLevel
` ------------------------------------------------------
` Move Camera based on UP,DOWN,RIGHT,LEFT arrow keys
` Check for edge of matrix,
` Move skybox with camera/player
` ------------------------------------------------------
` ------------------------------------------------------
` Ability to look upwards
` can look from 0-degees (level) to
` 90-degrees (directly overhead)
` If arrow keys used to move then reset to level
` ------------------------------------------------------
if InKey$()="u" OR InKey$()="U"
if (Camera Angle X(0) >= 272 OR Camera Angle X(0) = 0)
CameraAngleX# = wrapvalue(Camera Angle X(0) - 2)
XRotate Camera 0,CameraAngleX#
endif
endif
if InKey$()="j" OR InKey$()="J"
if (Camera Angle X(0) >= 2)
CameraAngleX# = wrapvalue(Camera Angle X(0) + 2)
XRotate Camera 0,CameraAngleX#
endif
endif
ENDFUNCTION
`
FUNCTION Edge_Detect()
CharX#=object position x(500)
CharY#=object position y(500)
CharZ#=object position z(500)
if CharX#<100
GB.AtEdge = 1
move object 500, -1
endif
` =========================================================
` Check for camera near the matrix edge
` Can be at 0,1 or 2 edges
` Returns: AtEdge=1 skybox is at any edge of matrix
` =========================================================
remstart
LimitHi# = (GB.MatrixSize# - GB.WallSize#/2)
LimitLo# = (GB.WallSize#/2)
`-------------------------------------------------------
` High-Check is matrix size less 1/2 skybox - move amt.
` Low-Check is 1/2 skybox size + move amount
` 1=at an edge, 0=Not at an edge
`-------------------------------------------------------
XHicheck = (Camera Position X(0) > LimitHi#)
XLocheck = (Camera Position X(0) < LimitLo#)
ZHicheck = (Camera Position Z(0) > LimitHi#)
ZLocheck = (Camera Position Z(0) < LimitLo#)
`-------------------------------------------------------
` Ability to move depends on attempted direction, and
` which directions are blocked (at an edge)
` Based on camera direction:
`-------------------------------------------------------
if XHicheck=1 OR XLocheck=1 OR ZHicheck=1 OR ZLocheck=1
AtEdge = 1
else
AtEdge = 0
endif
`
remend
ENDFUNCTION
`
FUNCTION fun_Print_Text()
` =========================================================
` Display on-screen messages
` <?> key to toggle user info display
` =========================================================
if GB.ClearMessages=0
msg$ = "To move camera use the arrow keys:"
Set Cursor 10,(16*Text Height(msg$))
print msg$
print ""
print GB.Time
print GB.AmbientLevel
print " UP Move Forward DOWN Move Backward"
print " LEFT Turn Left RIGHT Turn Right"
print " <U> Look Upward <J> Look Downward"
print ""
print "Use these keys to toggle features ON or OFF:"
print " <?> On-Screen HELP"
if GB.UsingFog=1
msg$="ON"
else
msg$="OFF"
endif
print " <F> FOG (Fog is " + msg$ + ")"
print ""
print " <1> Red Fog <4> Yellow Fog "
print " <2> Green Fog <5> Gray Fog "
print " <3> Blue Fog <6> Black Fog "
print " (Currently selected color=" + str$(GB.FogColor) + ")"
print ""
print " <-> Lower Ambient Light (each step - 10 %) "
print " <+> Raise Ambient Light (each step + 10 %) "
print " Current Ambient Level: " + str$(GB.AmbientLevel)
print ""
msg$ = " Camera:"
msg$ = msg$ + " X=" + str$(INT(Camera Position X(0)))
msg$ = msg$ + " Z=" + str$(INT(Camera Position Z(0)))
msg$ = msg$ + " Pan=" + str$(INT(Camera Angle Y(0)))
msg$ = msg$ + " Pitch=" + str$(INT(Camera Angle X(0)))
msg$ = msg$ + " FPS=" + str$(screen fps())
print msg$
endif
`
ENDFUNCTION
FUNCTION rotate_sky()
rem Rotate sky
yrotate object 100,wrapvalue(object angle y(100)+0.01)
yrotate object 200,wrapvalue(object angle y(200)+0.05)
ENDFUNCTION
FUNCTION update_time()
`rate is a tool used to speed up or slow down time
Rate as INTEGER
Rate=1
`update the time
GB.Time=GB.Time+.1*Rate
`start another day if 24 hours have passed
if GB.Time > 2400 then GB.Time=1
if GB.Time>400 and GB.Time<1000
`fog rolls out
fog distance GB.FogDistance
GB.FogDistance=GB.FogDistance + rate*4
if GB.FogDistance>5000 then GB.FogDistance=5000
`this is sunrise 4am-10. steadily increase ambient light
`level until it is daylight
`***************************************************************
`SOMETHING NEEDS TO BE DONE WITH LIGHT LEVEL ON THE GROUND AT
`NIGHT. IT STILL APPEARS TO BE DAYLIGHT ON THE GRASS. MAYBE CYCLE
`BLACK FOG ROLLING IN AT NIGHT AND OUT IN MORNING
`***************************************************************
GB.AmbientLevel=GB.AmbientLevel + .02*Rate
if GB.AmbientLevel>100 then GB.AmbientLevel = 100
endif
if GB.Time>1800 and GB.Time<2200
`this is sunset 6pm-10. steadily decrease ambient light
`level until it is night
GB.AmbientLevel=GB.AmbientLevel - .02*Rate
if GB.AmbientLevel<20 then GB.AmbientLevel = 20
endif
if GB.Time>2200 or GB.Time<400
`fog rolls in
fog distance GB.FogDistance
GB.FogDistance=GB.FogDistance - rate*3
if GB.FogDistance<600 then GB.FogDistance=600
endif
ENDFUNCTION
FUNCTION Ground_Height_Getter()
if object exist(500)
`Get the character's position in 3D space
CharX#=object position x(500)
CharY#=object position y(500)
CharZ#=object position z(500)
`Get the npc's position in 3D space
NPCX#=object position x(501)
NPCY#=object position y(501)
NPCZ#=object position z(501)
`Get the ground height at the character's position
GB.GH#=Get Ground Height(1,CharX#,CharZ#)
`and ensure he is indeed touching the ground by assigning his
`y position the value of the ground height
position object 500, CharX#, GB.GH#, CharZ#
`Get the ground height at the npc's position
GB.GH#=Get Ground Height(1,NPCX#,NPCZ#)
`and ensure he is indeed touching the ground by assigning his
`y position the value of the ground height
position object 501, NPCX#, GB.GH#, NPCZ#
endif
ENDFUNCTION
remstart
FUNCTION fun_Check_GraphicsCards()
` =========================================================
` Check for Graphics Cards
` Display names of those found
` Select only graphics card available, or
` permit user to select from checklist.
` =========================================================
perform checklist for graphics cards
if checklist quantity() > 1
print "Found Graphics Cards:"
for c=1 to checklist quantity()
name$=checklist string$(c)
lastcard=c
print str$(c) + "." + space$(1) + name$
next c
d=0
while (d < 1) or (d > lastcard)
input "Enter item number of desired graphics card: ",d
endwhile
name$ = checklist string$(d)
set graphics card name$
print "Using Graphics Card:";current graphics card$()
print "Press any key to continue..."
wait key
sync
else
set graphics card checklist string$(1)
print "Using Graphics Card:";current graphics card$()
sync
endif
SYNC
cls
`
ENDFUNCTION
remend
` **************************************************
` END OF SOURCE LISTING
` ******************************
Oh and by the way...
ALL MODELS AND ANIMATIONS WERE COMPLETED BY PSIONIC! ONCE AGAIN YOU CARRY US OUT HERE! THANKS!