you have indeed solved the problem!!
many thanks man,and to all the others who helped!
could you explain how it works though? I tried this :
sync on
sync rate 60
rand = rnd(100)
randomize rand
hide mouse
`set display mode 800,600,16
autocam off
set camera range 0.01,100
set normalization on
`sparky collision
global numSpheres as integer : numSpheres = 5
global radius# as double float : radius# = 3.0
`level
load object "models/level.x",1
scale object 1,400,400,400
position object 1,0,0,0
makeLevel(1)
`kenny torso
torso = 2
load object "models/kt.x",torso
position object torso,2,1,2
makePlayer(torso)
`kenny head
head = 3
load object "models/kh.x",head
`kenny legs
legs = 4
load object "models/kl.x",legs
`weapon
`make object cylinder 5,1
load object "models/sling.x",5
scale object 5,10,10,10
position object 5,object position x(5),3,object position z(5)
type bird
health as integer
minspeed as integer
maxspeed as integer
objno as integer
destx as float
desty as float
destz as float
time as integer
status as integer
endtype
type target
health as integer
objno as integer
name as string
endtype
type bullet
speed as float
grav as float
objno as integer
endtype
type plain
objno as integer
xvect as float
zvect as float
status as integer
alpha as integer
endtype
type part
life as integer
time as integer
sar as integer
ear as integer
endtype
`sparky collision
rem player movement vector
global vx# as double float
global vy# as double float
global vz# as double float
global normy# as float
global gravity# as double float : gravity# = -0.1
global slope# as double float : slope# = 0.5
global ground as integer : ground = 1
global jumptimer as integer : jumptimer = 0
global dim birds(0) as bird
global dim targets(0) as target
global dim bullets(0) as bullet
global dim parts(0) as plain
global dim pbunch(0) as part
firetimer = timer()
rotx = 0
roty = 0
fire# = 0
`this determines whether targets lose health
`when u hit them
selfhit = 1
`the bird number (like a handle ) is returned
`make_bird(initx#,inity#,initz#,health,minspeed,maxspeed)
bird1 = make_bird(1,10,5,1,1,2)
make_target("tree1",100,"models/tree.x",-1,0.5,4,200,200,200)
`object map:
`1-10 level,player,weap etc
`20-49 targets
`50-100 enemies
`101-200 bullets
`201-300 enemy crap(bullets)
`301-... particles
partstart = 301
mouseout(0)
`image map:
`30- gamestuff
load image "models/leaf.png" , 1 , 1
do
`mouseout check
mout = mouseout(1)
`enemies move
run_bird(bird1)
`moving the torso
`using WASD
`params: obj,speed#
MovePlayer(2,0.3)
`turn player and weap
gosub turn
`firing
if mouseclick() = 1
`cooldown
if timer() - firetimer => 500
`hold down mouse to pull sling back
if object frame(5) = 0
play object 5,0,50
endif
firetimer = timer()
endif
if object frame(5) <> 50
fire# = fire# + 0.01
endif
text 100,100,str$(fire#)
else
`u let go of mouse? means its throwing time
if object frame(5) <> 0
`make bullet n orientate
for bt = 100 to 200
if object exist(bt) = 0
`store bullet info like speed
array insert at bottom bullets(0)
bcount = array count(bullets(0))
bullets(bcount).objno = bt
bullets(bcount).speed = fire#
bullets(bcount).grav = bullets(bcount).speed/4.0
make object sphere bt,.3
color object bt,RGB(128,128,128)
glueObj(bt,5,0,.2,.5)
rotate object bt,object angle x(5),object angle y(5),0
exit
endif
next bt
stop object 5
set object frame 5,0
fire# = 0
endif
endif
`bullets
if array count(bullets(0)) > 0
for t = 1 to array count(bullets(0))
bobjno = bullets(t).objno
if object exist(bobjno) = 1
`move them and del them when hit
oldbx# = object position x(bobjno)
oldby# = object position y(bobjno)
oldbz# = object position z(bobjno)
`slowly decrease rate of bullet's y pos increase
`eventually it becomes negative to create a projectile
`grav impression
if bullets(t).grav => - 0.1
bullets(t).grav = bullets(t).grav - 0.002
endif
position object bobjno,newxvalue(oldbx#,object angle y(bobjno),bullets(t).speed),newyvalue(oldby#,object angle x(bobjno),bullets(t).speed)+(bullets(t).grav),newzvalue(oldbz#,object angle y(bobjno),bullets(t).speed)
bx# = object position x(bobjno)
by# = object position y(bobjno)
bz# = object position z(bobjno)
bray = sc_Raycast(0,oldbx#,oldby#,oldbz#,bx#,by#,bz#,0)
`text 10,100,str$(bullets(t).grav)
if bray > 0
bobj = sc_getobjecthit()
delete object bobjno
array delete element bullets(0),t
`level hit
if bobj = 1
else
`if self hitting on targets is enabled
if selfhit = 1
`check all targets to see if they were hit
tcount = array count(targets(0))
for tr = 1 to tcount
if targets(tr).objno = bobj
targets(tr).health = targets(tr).health - 1
`make damage on trees visible
`in form of particles
`params: no,initial object number,imgno,alpha fade,life,radius#,x#,y#,z#
make_fparts(22,partstart,1,1,1000,0.2,SC_getStaticCollisionX(),SC_getStaticCollisionY(),SC_getStaticCollisionZ())
partstart = partstart + 22
exit
endif
next tr
endif
`for selfhit
endif
endif
endif
next t
endif
run_fparts()
`camera
position camera object position x(head),object position y(head),object position z(head)
rotate camera object angle x(2),object angle y(2),object angle z(2)
text 0,10,"FPS: "+str$(screen fps())
sync
loop
turn:
`torso and hence legs n head can be rotated by mouse
rotx# = rotx# + (mousemovex()*0.5)
rotate object 2,0,rotx#,0
`then make legs n head follow
glueObj(legs,2,0,-0.2,0)
`only head can be affected by torso looking up/down
oldroty# = roty#
roty# = roty# + (mousemovey()*0.5)
if roty# > 60 or roty# < -90
roty# = oldroty#
endif
rotate object 2,roty#,object angle y(2),0
glueObj(head,2,0,0.5,0)
`weap
`position object 5,object position x(torso),object position y(torso),object position z(torso)
glueObj(5,torso,0,0,1)
rotate object 5,object angle x(torso),object angle y(torso),0
return
`last three params are for scaling
function make_target(name$,health,file$,x#,y#,z#,sx,sy,sz)
for tar = 20 to 49
if object exist(tar) = 0
array insert at bottom targets(0)
tcount = array count(targets(0))
targets(tcount).health = health
targets(tcount).name = name$
load object file$,tar
scale object tar,sx,sy,sz
position object tar,x#,y#,z#
`one with the floor/level group
sc_setupComplexObject tar,1,2
set object light tar,1
targets(tcount).objno = tar
exit
endif
next tar
endfunction
`params: numbers of parts,object number to start from,
`imgno,alpha,life,radius,xyz#
function make_fparts(no,init,imgno,alpha,life,radius#,x#,y#,z#)
init = init - 1
array insert at bottom pbunch(0)
pbc = array count(pbunch(0))
pbunch(pbc).life = life
pbunch(pbc).time = timer()
pbunch(pbc).sar = array count(parts(0))
if pbunch(pbc).sar = -1 then pbunch(pbc).sar = 0
for t = 1 to no
make object plain init+t,radius#,radius#
texture object init+t,imgno
set object transparency init+t,1
array insert at bottom parts(0)
prtcnt = array count(parts(0))
parts(prtcnt).objno = init+t
parts(prtcnt).xvect = (rnd(200)-100.0)/100.0
parts(prtcnt).zvect = (rnd(200)-100.0)/100.0
zrotate object init+t,wrapvalue(rnd(140)-70)
fix object pivot init+t
position object init+t,x#+parts(prtcnt).xvect,y#+((rnd(200)-100.0)/100.0),z#+parts(prtcnt).zvect
parts(prtcnt).xvect = parts(prtcnt).xvect/10.0
parts(prtcnt).zvect = parts(prtcnt).zvect/10.0
`zero not up for deletion
parts(prtcnt).status = 0
if alpha = 0
parts(prtcnt).alpha = -1
else
parts(prtcnt).alpha = 100
endif
next t
pbunch(pbc).ear = array count(parts(0))
endfunction
function run_fparts()
pbcount = array count(pbunch(0))
for pb = 0 to pbcount
if timer() - pbunch(pb).time > pbunch(pb).life
for pt = pbunch(pb).sar to (pbunch(pb).ear)
`exit prompt str$(pb),"as"
pcount = array count(parts(0))
if pt<0 or pt>pcount
text 100,100,"pt"+str$(pt)+" pcount"+str$(pcount)+" pbunch(pb).ear"+str$(pbunch(pb).ear)+"pbunch(pb).sar"+str$(pbunch(pb).sar)+"pb:"+str$(pb)+"pbcount:"+str$(pbcount)
sync
wait key
endif
parts(pt).status = 1
next pt
tempdiff = pbunch(pb).ear - pbunch(pb).sar
`when a particle bunch is deleted, this means the next part bunch
`start and end array nos (ear/sar) must be shifted backwards
if pb <> pbcount
for shift = (pb) to pbcount
pbunch(shift).ear = pbunch(shift).ear - tempdiff
pbunch(shift).sar = pbunch(shift).sar - tempdiff
next shift
endif
array delete element pbunch(0),pb
pbcount = array count(pbunch(0))
endif
next pb
pcount = array count(parts(0))
for p = 0 to pcount
if parts(p).alpha = -1
if parts(p).status <> 1
px# = object position x(parts(p).objno)
pz# = object position z(parts(p).objno)
py# = object position y(parts(p).objno)
if abs(parts(p).xvect) > 0.01
parts(p).xvect = parts(p).xvect/1.05
endif
if abs(parts(p).zvect) > 0.01
parts(p).zvect = parts(p).zvect/1.05
endif
position object parts(p).objno,px#+parts(p).xvect,py#-0.02,pz#-parts(p).zvect
set object to camera orientation parts(p).objno
else
`if status is 1
`exclude object on parts(p).objno
delete object parts(p).objno
array delete element parts(0),p
pcount = pcount - 1
endif
else
if parts(p).alpha > 0
px# = object position x(parts(p).objno)
pz# = object position z(parts(p).objno)
py# = object position y(parts(p).objno)
if abs(parts(p).xvect) > 0.01
parts(p).xvect = parts(p).xvect/1.05
endif
if abs(parts(p).zvect) > 0.01
parts(p).zvect = parts(p).zvect/1.05
endif
position object parts(p).objno,px#+parts(p).xvect,py#-0.02,pz#-parts(p).zvect
set object to camera orientation parts(p).objno
if parts(p).status = 1
parts(p).alpha = parts(p).alpha - 1
set alpha mapping on parts(p).objno , parts(p).alpha
endif
else
`exclude object on parts(p).objno
delete object parts(p).objno
array delete element parts(0),p
pcount = pcount - 1
endif
endif
next p
endfunction
function run_bird(no)
`zero dont mean notin
if no <> 0
objno = birds(no).objno
if object exist(objno) = 1
loop object objno,0,100
tempx# = object position x(objno)
tempy# = object position y(objno)
tempz# = object position z(objno)
`move up for a while then switch status n hence move down
`hover effect for the bird !
if timer() - birds(no).time => 1000
birds(no).status = birds(no).status * -1
birds(no).time = timer()
endif
position object objno,tempx#,tempy#+(birds(no).status*0.01),tempz#
sc_updateObject objno
endif
endif
endfunction
function make_bird(initx#,inity#,initz#,health,minspeed,maxspeed)
for t = 50 to 100
if object exist(t) = 0
load object "models/bird.x" , t
scale object t,200,200,200
set object speed t,250
position object t,initx#,inity#,initz#
sc_setupComplexObject t,0,2
array insert at bottom birds(0)
curno = array count(birds(0))
birds(curno).objno = t
birds(curno).health = health
birds(curno).minspeed = minspeed
birds(curno).maxspeed = maxspeed
birds(curno).destx = initx#
birds(curno).desty = inity#
birds(curno).destz = initz#
birds(curno).time = timer()
birds(curno).status = 1
birdno = curno
exitfunction curno
exit
endif
next t
endfunction birdno
function makeLevel(objno)
sc_setupComplexObject objno,1,2
`sc_setupObject 1,1,0
rem all level objects are group 1
endfunction
function makePlayer(objno)
sc_setupComplexObject objno,0,2
rem player has no group
endfunction
function movePlayer(objno,speed#)
oldx# = object position x(objno)
oldy# = object position y(objno)
oldz# = object position z(objno)
rem apply gravity, and user changes to movement
angy# = object angle y(objno)
vx# = 0
vz# = 0
rem if player is jumping or falling then apply 'normal' gravity
rem if not attempt to keep the player stuck to the floor
if vy#=0 and jumptimer=0 then vy# = vy# + 10*gravity# else vy# = vy# + gravity#
if keystate(31)=1 then vx# = vx# - sin(angy#) : vz# = vz# - cos(angy#)
if keystate(17)=1 then vx# = vx# + sin(angy#) : vz# = vz# + cos(angy#)
if keystate(32)=1 then vx# = vx# + cos(angy#) : vz# = vz# - sin(angy#)
if keystate(30)=1 then vx# = vx# - cos(angy#) : vz# = vz# + sin(angy#)
rem only jump if on ground, and a certain time after last jump
if ground=1
`if spacekey()=1 and jumptimer=0 then vy# = vy# + 3.0 : jumptimer = 20
endif
rem this would be the player's final position without collision
x# = oldx#+(vx#*speed#)
y# = oldy#+(vy#*speed#)
z# = oldz#+(vz#*speed#)
rem first handle gravity - seperated from horizontal movement
rem to achieve a more realistic effect
rem Method: simple - cast a sphere vertically down, if it hits the level then
rem position the object there (sticky collision) then move
rem on to horizontal movement
rem more complex - if we were to only use the simple method the player would be
rem allowed to climb almost vertical slopes. Alternative is to
rem get the normalY direction to work out how flat the gorund
rem below the player is, 0-slope# is flatter, slope#-1 is steeper.
rem if it's flat, use sticky collision, if it's steep slide the
rem player down the slope. Changing slope# determines how steep the
rem player can climb. NOTE: this also effects stairs.
collide = sc_SphereCastGroup(1,oldx#,oldy#,oldz#,oldx#,oldy#+vy#,oldz#,radius#,0)
if collide>0
rem how flat is this ground
ny# = sc_getCollisionNormalY()
normy# = ny#
nx# = sc_getCollisionNormalX()
nz# = sc_getCollisionNormalZ()
if abs(ny#)>slope#
rem FLAT, stick
oldy# = sc_getStaticCollisionY()
else
rem STEEP, slide
x# = x# - oldx# : z# = z# - oldz#
oldx# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
oldz# = sc_getCollisionSlideZ()
x# = x# + oldx# : z# = z# + oldz#
endif
rem ny#<0 means the player has hit a ceiling rather than a floor
if ny#>slope#
rem only on ground if standing on flat ground
ground = 1
vy# = 0
else
ground = 0
rem if player has hit a flat ceiling then stop vy# movement
if ny#<-slope# then vy# = gravity#
endif
else
rem nothing below player, not on ground, add vertical speed to player
oldy# = oldy# + vy#
ground = 0
endif
roldy# =oldy#
rem jumptimer will decrease only when player is back on ground
rem creates a pause between two successive jumps
if ground = 1 and jumptimer>0 then dec jumptimer
rem handle horizontal movement as sliding
rem player only collides with group 1 (level) objs and moves freely through others
collide = sc_SphereSlideGroup(1,oldx#,oldy#,oldz#,x#,oldy#,z#,radius#,0)
if collide>0
rem if hit, reposition player, halt movement vector
x# = sc_getCollisionSlideX()
oldy# = sc_getCollisionSlideY()
z# = sc_getCollisionSlideZ()
vx# = 0
vz# = 0
rem possible code for giving the player a jumping help up stairs...
rem might be useful if slope# is set very high but stairs are still required
`dy# = oldy#-sc_getStaticCollisionY()
`if dy#<slope# and dy#>0 and ground=1 then vy# = 0.5
endif
rem position the player
position object objno,x#,oldy#,z#
sc_updateObject objno
endfunction
function dist(x1#,y1#,z1#,x2#,y2#,z2#)
temp = make vector3(1)
set vector3 1,x1#-x2#,y1#-y2#,z1#-z2#
length# = abs(length vector3(1))
temp = delete vector3(1)
endfunction length#
function distxz(x1#,z1#,x2#,z2#)
temp = make vector2(1)
set vector2 1,x1#-x2#,z1#-z2#
length# = abs(length vector2(1))
temp = delete vector2(1)
endfunction length#
`Sparky's glueing function,must be repeated
function glueObj(hobj,toObj,offsetx#,offsety#,offsetz#)
position object hobj,object position x(toObj),object position y(toObj),object position z(toObj)
rotate object hobj,0,0,0
turn object right hobj,object angle y(toObj)
pitch object down hobj,object angle x(toObj)
move object hobj,offsetz#
turn object right hobj,90
move object hobj,offsetx#
turn object left hobj,90
pitch object up hobj,90
move object hobj,offsety#
pitch object down hobj,90
endfunction
function mouseout(ins)
if ins=0
dim mouse_click(0)
endif
if ins=1
if mouse_click(0)>0
if mouseclick()=0
mresult=mouse_click(0)
else
mresult=0
endif
endif
mouse_click(0)=mouseclick()
endif
if ins=2
undim mouse_click(0)
endif
endfunction mresult
poo = memblock exist(100)
(line 355) but it didn't work...
thx again man!
What is happening to them[the children] is the only thing they've known. The whole system of values is turned upside down: a child is appreciated and loved if it earns money by stealing