WhatI changed:
1)
Ok, in that code where you have:
Else
Hide Object 1
Position Object 1, -1000,0,-1000
EndIf
I Have Changed this to:
Else
If Object Visible(1) = 1 Then Hide Object 1 : Position Object 1, -1000,1000,-1000
EndIf
If put in the new If function so that it wouldn't have to hide the object and reposition it each loop if it was already hidden.
I changed the x position so that when i put in If Object Position X <= Get Ground Height(1,x#,z) for when the object hits the ground, it won't coninually return true when the grenade is at rest.
2)
I Moved This from inside Item_Info:
If explode = 1 Then _explosion(3,tx#,ty#,tz#)
To inside Grenade_attack:
3)
Where you had:
`stop movement if object hits ground
If Object Position Y(1) <= obj_size#
explode = 1
shoot = 0
`make sure object's last position is above ground
Position Object 1,oldtx#,obj_size#,oldtz#
EndIf
I changed it so that you wouldn't get the explosion following the grenade across the gound by adding in an Else statement:
`stop movement if object hits ground
If Object Position Y(1) <= obj_size#
explode = 1
shoot = 0
`make sure object's last position is above ground
Position Object 1,oldtx#,obj_size#,oldtz#
Position Object 3,oldtx#,0,oldtz# : Show Object 3
Else
If shoot = 1 Then explode = 0
EndIf
Also, you will notice i added the line
Position Object 3,oldtx#,0,oldtz# : Show Object 3 This just positions the explosion at the same coordinates as the grenade when hitting the ground and then shows it.
4)
This is the actuall explosion code ( at the end of grenade_attack ):
`Explosion
If explode = 1
scale = scale + 400
Scale Object 3,scale,scale,scale
If scale >= 25000
Hide Object 3
scale = 0
fade = 0
explode = 0
EndIf
EndIf
I simply got rid of the function because of the amount of variables you were useing could not all be used in the function, then returned to be used again, unless you made them global ( ie made them array's ).
Also, the fade command doesn't really seem to do anything, so, after alot of trial and error, I came to the conclution that it is useless.
And here it is, The working code:
Sync On : Sync Rate 60
Hide Mouse : Autocam Off
GoSub declare_varables
GoSub load_images
GoSub make_matrix
GoSub make_objects
Set Camera view 5,5,635,400
Make Object Sphere 1, obj_size# * 2
Hide Object 1
`**********************
`* MAIN LOOP *
`**********************
Do
GoSub player_controls
GoSub camera_status
GoSub item_info
angle# = 360.0 - Camera Angle X()
Text 5,5,"Explode : " + Str$(explode)
Text 5,25,"Object Size X(3) : " + Str$(Object Size X(3))
Sync
Loop
` control player's movement
PLAYER_CONTROLS:
runspeed# = 0.0
Ink 0,0
`UP-LEFT-RIGHT-DOWN User Controls.
If UpKey() = 1 Or KeyState(17)
x# = NewXValue(x#,a#,6)
z# = NewZValue(z#,a#,6)
EndIf
If DownKey() = 1 Or KeyState(31)
x# = NewXValue(x#,a#,-6)
z# = NewZValue(z#,a#,-6)
EndIf
If LeftKey() = 1 Or KeyState(30)
x# = NewXValue(x#,WrapValue(a# - 90.0),5.0)
z# = NewZValue(z#,WrapValue(a# - 90.0),5.0)
EndIf
If RightKey() = 1 Or KeyState(32)
x# = NewXValue(x#,WrapValue(a# + 90.0),5.0)
z# = NewZValue(z#,WrapValue(a# + 90.0),5.0)
EndIf
`if the grenade is selected, then goto the commands that are available
If weapon = 2 Then GoSub grenade_attack
`switch weapon to grenade
If KeyState(3)
Set Cursor 5,400
Print "Weapon: "; weapon$
If weapon <> 2 Then weapon = 2
EndIf
Return
`====================
` control player's angle of site/rotation and position
`====================
CAMERA_STATUS:
` rotate camera according to mouse
a# = WrapValue(a# + (MouseMoveX() / 3.0))
` position and rotate camera
cxa# = cxa# + (MouseMoveY() / 3.0)
If cxa# < -90.0 Then cxa# = -90.0
If cxa# > 90.0 Then cxa# = 90.0
Position Camera x#,(Get Ground Height(1,x#,z#) + player_height#),z#
Rotate Camera WrapValue(cxa#),a#,0
RETURN
`=====================
` iterator sub to constantly update position of thrown object
`=====================
throw_grenade:
` store old positions
oldtpx# = tpx#
oldtx# = tx#
oldtz# = tz#
` TPX# is the distance the object has traveled from the origin
TPX# = F# * COS(tPitch#) * T#
` TPY# is the height of the object's arc.
TPY# = F# * SIN(tPitch#) * T# - (0.5 * grav_str#) * (T# ^ 2)
` dist# is the distance that the object has traveled during this iteration
dis# = abs(oldtpx# - tpx#)
` tx# and tz# transforms that distance from 2D into a 3D distance based
` on the character's Y rotation.
tx# = NewXValue(tx#,tYA#,dis#)
tz# = NewZValue(tz#,tYA#,dis#)
` incriment time index
Inc T#
` positions the object
Position Object 1,tx#,(ty# + TPY#),tz#
`stop movement if object hits ground
If Object Position Y(1) <= obj_size#
explode = 1
shoot = 0
`make sure object's last position is above ground
Position Object 1,oldtx#,obj_size#,oldtz#
Position Object 3,oldtx#,0,oldtz# : Show Object 3
Else
If shoot = 1 Then explode = 0
EndIf
Return
`==============
`=Player stats=
`==============
item_info:
Ink RGB(255,255,255),0
`Show how hard you are throwing
Set Cursor 5,415
Print "Force: "; tF#-10
`Show what angle you are throwing at
Set Cursor 5,430
Ink RGB(255,255,255),0
Print "Angle: "; angle#
`Show what item you have selected
Set Cursor 5,400
`makes the certain numbers strings for there corrisponding weapon
If weapon = 2 : rem if weapon = grenade
GoSub grenade_attack
EndIf
Print "Weapon: "; weapon$
Return
`==========
`=Varables=
`==========
declare_varables:
player_height# = 100.0 : `height of the player's eyes
grav_str# = 1.0 : `gravity strength
obj_size# = 10.0 : `size of throwing object (in this case, the sphere's radius)
tF# = 60 : `Starting Power
weapon = 2 : `What weapon is selected
bulletlife=0 : `if bulletlife = 0, then you can shoot
Return
`==========
`==Matrix==
`==========
make_matrix:
Make Matrix 1, 10000,10000,40,40
Return
`==========
`==Object==
`==========
make_objects:
`make the explosion
Make Object Sphere 3, 1
Position Object 3, -1000, 0, -1000 : `positions off the screen
Ghost Object On 3
Hide Object 3
Return
`==================
`==Grenade Attack==
`==================
grenade_attack:
`if press page up, increase the power
If tF# < 110 And weapon = 2
If KeyState(201) = 1
Set Cursor 5,415
Print "Force: "; tF#-10
Inc tF#
EndIf
EndIf
`if press page down, decrease the power
If tF# > 10 And weapon = 2
If KeyState(209) = 1
Set Cursor 5,415
Print "Force: "; tF#-10
Dec tF#
EndIf
EndIf
` if left mouse button clicked, initialize the variables for
` throwing the object.
` tx#,ty#,tz# are the object's starting positon (character's current position).
` tYA# is the character's Y rotation.
` tPitch# is the characters X rotation or the angle at which the character
` is looking either up or down.
` T# is the time index. Since the object is just starting to be thrown,
` current time is 0 seconds.
` F# is the amount of force that's used to throw the object.
` tpx# is just a temp variable that needs to be reset.
If MouseClick() And shoot = 0
shoot = 1
explode = 0
tx# = x#
tz# = z#
ty# = (Get Ground Height(1,x#,z#) + player_height#)
tYA# = a#
tPitch# = 360.0 - Camera Angle X() : `will eventually use "object angle x()" on page 121
T# = 0.0
F# = tF#
tpx# = 0
Show Object 1
EndIf
If shoot = 1 And weapon = 2
GoSub throw_grenade
Else
If Object Visible(1) = 1
Hide Object 1
Position Object 1, -1000,1000,-1000
EndIf
EndIf
`Explosion
If explode = 1
scale = scale + 400
Scale Object 3,scale,scale,scale
If scale >= 25000
Hide Object 3
scale = 0
fade = 0
explode = 0
EndIf
EndIf
Return
`======
`=Load=
`======
load_images:
Return
You will notice that i have mabey put in some text commands in the loop, this is just for Debugginf purposes, feel free to take them out.!
Hope I Helped...
PS i noticed you are using alot of Print commands which really do kill your FPS, i recomd using the Text command which don't take away so many FPS.
PSS i also noticed that you are uneccessaraly changing the Ink colours in the loop, for example, you had an Ink RGB(255,255,255),0 comand on one line, a Print on the next, then the very same Ink command on the next line! This is bad codeing and could cost you FPS if you're not careful...
PSSS If there's spellign mistakes, screw em, This post is so long and im so tired, i don't really care.

Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy