Download attached.
Code:
Rem Project: Simple Fighting
Rem Created: Sunday, January 25, 2009
Rem ***** Main Source File *****
`Set up the prog with sync, fog, and bd.
Sync On : Sync Rate 60
Backdrop On : Color Backdrop 0
Fog On : Fog Color RGB(14, 19, 30) : Fog Distance 250
Autocam Off
Hide Mouse
GoSub _Var:
`Set up the matrix.
Make Matrix 1, 1500, 1500, 50, 50
Randomize Matrix 1, 15 : Update Matrix 1
Position Camera 0, 0, 15, 0
`Texture the matrix.
Load Image "mediagrass_T.bmp", 1
Prepare Matrix Texture 1, 1, 1, 1
Set Matrix 1, 0, 0, 1, 1, 1, 1, 1
`Slightly smoothen the matrix so it will not be nearly as jagged.
For X=0 to 50
For Z=1 to 49
BeforeH#=Get Matrix Height(1, X, Z-1)
AfterH#=Get Matrix Height(1, X, Z+1)
AvrH#=(BeforeH#+AfterH#)/2
Set Matrix Height 1, X, Z, AvrH#
Next
Next
For Z=0 to 50
For X=1 to 49
BeforeH#=Get Matrix Height(1, X-1, Z)
AfterH#=Get Matrix Height(1, X+1, Z)
AvrH#=(BeforeH#+AfterH#)/2
Set Matrix Height 1, X, Z, AvrH#
Next
Next
Update Matrix 1 : `Apply changes.
` Load the skybox.
Load Image "mediasky.dds", 2
Make Object sphere 1000, -1500
Position Object 1000, 250, -100, 250
Texture Object 1000, 2
Xrotate Object 1000, 180
Set Object 1000, 1, 0, 1, 1, 0, 0, 0
` Make the enemy
Make Object Sphere 1, 5
Temp1=RND(1500) : Temp2=RND(1500)
Position Object 1, Temp1, Get Ground Height(1, Temp1, Temp2)+2.5, Temp2
Color Object 1, RGB(255, 255, 0)
Do
TempY2#=Get Ground Height(1, Camera Position X(0), Camera Position Z(0))+10
EnemyY#=Get Ground Height(1, Object Position X(1), Object Position Z(1))+2.5
PlayerCurHP$=Str$(Player(1).CurHP) : PlayerMaxHP$=Str$(Player(1).MaxHP)
Text 1, 1, STR$(Screen FPS())
Text 1, 11,"HP: " + PlayerCurHP$ + "/" + PlayerMaxHP$
Control Camera Using Arrowkeys 0, 2, 2 : `Move Cam.
If Keystate(29)=1 and Jump=0
GoSub _StartJump:
Endif
If Jump=1
Gosub _Jumping:
Endif
Point Object 1, Camera Position X(0), 0, Camera Position Z(0)
Move Object 1, .75
Position Object 1, Object Position X(1), EnemyY#, Object Position Z(1)
Position Object 1000, Camera Position X(0), Camera Position Y(0)-25, Camera Position Z(0)
If Jump=0
Position Camera Camera Position X(0), TempY2#, Camera Position Z(0)
Endif
Dist#=DistanceFromCam(1)
If Dist#<25
If Hit=0
Player(1).CurHP=Player(1).CurHP-1
Hit=1
Endif
Endif
If Hit=1
Time=Time+1
If Time=30
Time=0
Hit=0
Endif
Endif
If Player(1).CurHP<1
End
Endif
Sync : `Update
Loop
`Set up variables.
_Var:
#Constant G (9.81/60)
Type StatsP
MaxHP as Dword
CurHp as Dword
MaxMp as Dword
CurMP as Dword
Str as Integer
Def as Integer
EndType
Type StatsM
MaxHP
CurHP
MaxMP
CurMP
DmgMin
DmgMax
Block
EndType
Dim Player(1) as StatsP
Dim Monster(1) as StatsM
Player(1).MaxHP=60 : Player(1).CurHP=60
Return
_StartJump:
Jump=1
YChange#=3
Return
_Jumping:
TempY#=Camera Position Y(0)
TempY#=TempY#+YChange#
YChange#=YChange#-G
If TempY2#>TempY#
TempY#=TempY2#
Jump=0
Endif
Position Camera Camera Position X(0), TempY#, Camera Position Z(0)
Return
Function DistanceFromCam(ObjNum)
Dist#=(Camera Position X(0)-Object Position X(ObjNum))^2+(Camera Position Z(0)-Object Position Z(ObjNum))^2
Endfunction Dist#
Not well commented right now, but it what it is.
Tell me what you think.
I will be adding more spheres to attack, will make a cube to play as the character, and will make the spheres killable. This is a very crappy, basic rpg-like skeleton prog.