i have some trouble contiuning programming my game, i started writing the combat animations thingy and i ran into some trouble. i'll only post my code here, not the media that's in my game. The problem is:
I have coded it so it plays the sword_attack animation when i press the mouse button, but when i press the mouse button, nothing happens! nothing at all! the sword animation frames are from 1 - 20 and i know it's animated because i did it myself, but dbc doesnt seem to want to play my sword animations
and btw, please dont judge me to harshly on how noobily this game is written. the code :
Remstart
stuff list
200+ = menu and hud
1001+ = Houses and world stuff
2001+ = Trees
3001+ = Weapons
4001+ = characters, enemies
Sounds list
1+ = Music
Remend
Sync On
Sync Rate 50
Set Display Mode 640,480,16
Hide mouse
load music "DataMenuField.mid",1
play music 1
set cursor 1,1
Set cursor 250,450
print "press SPACE to start..."
do
if spacekey()=1
gosub game
endif
sync
loop
Game:
cls
stop music 1
Backdrop on
Set camera range 1,5000
Fog on
Fog distance 4000
Fog color RGB(0,0,0)
Color Backdrop RGB(0,0,0)
Autocam off
set ambient light 50
hide mouse
#include functions.dba
Gosub Create_matrix
Gosub Create_WORLD
Gosub Create_Trees
Gosub Load_swords
Gosub Create_collision
Gosub Declare_levelshpandstuff
Gosub Create_menustuff
Gosub Create_enemies
`Set Follow Variable
Follow#=0
`texture object 1,1
`set object transparency 1,2
dir$=get dir$()
`Height cam is off the ground
charht#=245
`speed to move
spd#=8
`set the radius for collisions
radius#=100.0
position camera 5000,charht#,5000
checks=8
if checks<4 then checks=4
if checks>360 then checks=360
angwidth=360/checks
dim ang#(checks-1,2)
dim sort#(checks-1,2)
load sound "Datasoundsclouse.wav",1
load sound "Datasoundshell.wav",2
Rem main loop
DO
Set cursor 0,0
Print "Fps: ", screen fps()
Print "CamposX: ", Camera position X()
Print "CamposZ: ", Camera position Z()
Print "CamposY: ", Camera position Y()
position object 2, camera position x(), camera position y(), camera position z()
If Hp# > 101 then hp# = 100
position object 4002,object position x(4001),object position y(4001),object position z(4001)
position object 4003,object position x(4001),object position y(4001),object position z(4001)
`Find the angle from the ghost to the player
ANG#=AngleY(4001,2)
Yrotate object 4001, ANG#
ANG#=AngleY(4002,2)
Zrotate object 4002, ANG#
if OBJECT HIT(2, 4003)
`Move the Ghost
Move Object 4001,7
endif
REM HERE IT IS!!!!!
if mouseclick()=1
show object 3002
hide object 3001
play object 3002,1,20
endif
`Get initial positions and a revert set
oldx#=camera position x()
oldz#=camera position z()
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
ca#=camera angle y()
`generic mouselook
mx#=mousemovex()/4.0
my#=mousemovey()/4.0
xrotate camera wrapvalue(camera angle x()+my#)
yrotate camera wrapvalue(camera angle y()+mx#)
if camera angle x()>80 and camera angle x()<180 then xrotate camera 80
if camera angle x()<270 and camera angle x()>180 then xrotate camera 270
`keyboard controls
`WASD
if keystate(17)
cx# = newxvalue(cx#,ca#,spd#)
cz# = newzvalue(cz#,ca#,spd#)
endif
if keystate(31)
cx# = newxvalue(cx#,ca#,-1*spd#)
cz# = newzvalue(cz#,ca#,-1*spd#)
endif
if keystate(30)
cx# = newxvalue(cx#,wrapvalue(ca#-90.0),spd#)
cz# = newzvalue(cz#,wrapvalue(ca#-90.0),spd#)
endif
if keystate(32)
cx# = newxvalue(cx#,wrapvalue(ca#+90.0),spd#)
cz# = newzvalue(cz#,wrapvalue(ca#+90.0),spd#)
endif
if controlkey()=1 then crouch#=1
if controlkey()=0 then crouch#=0
If crouch#=1 then charht#=190
If crouch#=0 then charht#=245
position camera cx#,cy#,cz#
`Show the camera angle
print "Camera angle:",camera angle y()
`The main sliding collision code
gosub _collision
`My code to walk up a ramp if the angle isn't too steep
gosub _ramp
if OBJECT HIT(2, 1009)
position camera 95000,245#,802
Fog color RGB(135,3,3)
Color Backdrop RGB(135,3,3)
play sound 1
play sound 2
endif
Rem Hud text
Set cursor 200,405
Print "Health: ", Hp#
Set cursor 200,430
Print "Mana: ", Mana#
Set cursor 290,390
Print "Level: ", Level#
Set cursor 350,405
Print "Armor: ", Armor#
Set cursor 350,430
Print "Damage: ", Damage#
Rem Crosshair
dot 320,220
ink rgb(255,255,255),0
Sync
Loop
return
Sounds:
Return
create_enemies:
Make Object box 4001,200,600,200
Load object "DataObjectsCharactersBadGraveyardEnemysGhost.x",4002
Ghost object on 4002
scale object 4002,400,400,400
XRotate object 4002,270
Position object 4001,3800,20,3200
hide object 4001
make object box 4003,700,600,700
hide object 4003
Return
_ramp:
`get positions again
cx#=camera position x()
cz#=camera position z()
`Get your old height
oldht#=camera position y()
`calc new height using intersect object from the old height down charht# units
col=intersectObjectDBC(1,1,cx#,oldht#,cz#,cx#,oldht#-(charht#*2),cz#,0)
if col=0 Then sub#=0 Else sub#=abs(oldht#-getStaticCollisionY())
ht#=(oldht#+charht#)-sub#
if sub#=0 then ht#=charht#
`do some gravity
grav#=grav#-0.5
`if you are going up a ramp
if oldht#+grav#<ht#
grav#=0.0
`next line makes stairs climbing more natural
hup# = curvevalue(oldht#,ht#,1.5)
position camera cx#,hup#,cz#
else
`if you are falling
ht#=oldht#+grav#
position camera cx#,ht#,cz#
endif
return
_collision:
`make 72 collision points. You can use more or less, but this number seems to work good.
`These are vectors every 5 degrees from the camera position out.
`They return the distance when they hit an object
for x=0 to checks-1
chx#=newxvalue(cx#,x*angwidth,100)
chz#=newzvalue(cz#,x*angwidth,100)
col=intersectObjectDBC(1,1,cx#,cy#,cz#,chx#,cy#,chz#,0)
If col=0 Then ang#(x,1)=0 Else ang#(x,1)=sqrt((getStaticCollisionX()-cx#)^2+(getStaticCollisionZ()-cz#)^2)
if ang#(x,1)=0 then ang#(x,1)=999999
ang#(x,2)=x*angwidth
sort#(x,1)=ang#(x,1)
sort#(x,2)=ang#(x,2)
next x
`sort the array to find the closest object and it's degrees
for x=0 to checks-2
for y=x+1 to checks-1
if ang#(x,1)>ang#(y,1)
temp#=ang#(x,1)
temp2#=ang#(x,2)
ang#(x,1)=ang#(y,1)
ang#(x,2)=ang#(y,2)
ang#(y,1)=temp#
ang#(y,2)=temp2#
endif
next x
next y
`find +-90 degrees from the closest one for when you walk into a corner so it doesn't shake
prev=wrapvalue(ang#(0,2)-90)/angwidth
nxt=wrapvalue(ang#(0,2)+90)/angwidth
newd#=radius#-ang#(0,1)
newa#=wrapvalue(ang#(0,2)-180)
newd1#=radius#-sort#(prev,1)
newa1#=wrapvalue(sort#(prev,2)-180)
newd2#=radius#-sort#(nxt,1)
newa2#=wrapvalue(sort#(nxt,2)-180)
`if you are less than radius from a wall, push you out to 20 from it
if ang#(0,1)<radius# and ang#(0,1)>0.0
repx#=newxvalue(cx#,newa#,newd#)
repz#=newzvalue(cz#,newa#,newd#)
position camera repx#,cy#,repz#
endif
cx#=camera position x()
cz#=camera position z()
`this is if you are coming into a corner, this pushes you sideways
if sort#(prev,1)<radius# and sort#(prev,1)>0.0
repx1#=newxvalue(cx#,newa1#,newd1#)
repz1#=newzvalue(cz#,newa1#,newd1#)
position camera repx1#,cy#,repz1#
endif
cx#=camera position x()
cz#=camera position z()
`and the other way. above is left, this is right
if sort#(nxt,1)<radius# and sort#(nxt,1)>0.0
repx2#=newxvalue(cx#,newa2#,newd2#)
repz2#=newzvalue(cz#,newa2#,newd2#)
position camera repx2#,cy#,repz2#
endif
return
Create_matrix:
Rem make matrix
Make matrix 1,10000,10000,40,40
make matrix 2,10000,10000,40,40
make matrix 3,10000,10000,40,40
make matrix 4,10000,10000,40,40
make matrix 5,10000,10000,40,40
position matrix 5,0,0,-10000
position matrix 4,10000,0,0
position matrix 3,90000,0,0
position matrix 2,-10000,0,0
Load image "datatexturesgrass1.bmp",1
Load image "datatexturesgoal.bmp",2
Load image "datatexturesgravel09.bmp",3
for matrixtext = 1 to 2
Prepare matrix texture matrixtext,1,2,2
next matrixtext
prepare matrix texture 4,1,2,2
prepare matrix texture 5,1,2,2
prepare matrix texture 3,3,2,2
Rem Update the changes to the matrix
update matrix 1
Return
Create_WORLD:
Rem Part 1
Rem World
load object "DataObjectsGraveyardGraveyard.x",1001
position object 1001,4700,0,5400
setupObjectDBC( 1001, 1, 0 )
SetObjectCollisionOnDBC(1001)
load object "dataObjectsWilderness stuffwood fence.x",1002
position object 1002,4700,0,3200
setupObjectDBC( 1002, 1, 0 )
SetObjectCollisionOnDBC(1002)
load object "dataObjectsWilderness stuffwood fence.x",1003
position object 1003,4700,0,2500
setupObjectDBC( 1003, 1, 0 )
SetObjectCollisionOnDBC(1003)
load object "DataObjectsWilderness stuffteleporter.x",1008
position object 1008,-1226,0,5371
scale object 1008,150,150,150
setupObjectDBC( 1008, 1, 0 )
SetObjectCollisionOnDBC(1008)
make object box 1009,350,900,100
position object 1009,-1397,0,5624
hide object 1009
rem underworld
load object "DataObjectsHellhell wall.x",1010
position object 1010,94500,0,2910
yrotate object 1010,90
setupObjectDBC( 1010, 1, 0 )
SetObjectCollisionOnDBC(1010)
load object "DataObjectsHellhell wall.x",1011
position object 1011,94500,0,5500
yrotate object 1011,90
setupObjectDBC( 1011, 1, 0 )
SetObjectCollisionOnDBC(1011)
Rem town 1
Load object "dataobjectstownstown1.x",1004
position object 1004,400,0,7300
setupObjectDBC( 1004, 1, 0 )
SetObjectCollisionOnDBC(1004)
load object "dataobjectstownshouse1.x",1005
position object 1005,1200,0,9000
setupObjectDBC( 1005, 1, 0 )
SetObjectCollisionOnDBC(1005)
load object "dataobjectstownshouse2.x",1006
position object 1006,470,0,9000
yrotate object 1006,320
setupObjectDBC( 1006, 1, 0 )
SetObjectCollisionOnDBC(1006)
load object "DataObjectsCharactersGoodpesantpesant.X",1007
position object 1007,500,0,8400
scale object 1007,200,200,200
XRotate object 1007,270
zrotate object 1007,150
rem town 2
load object "DataObjectstownstown2.x",1012
position object 1012,15000,0,5100
yrotate object 1012,90
setupObjectDBC( 1012, 1, 0 )
SetObjectCollisionOnDBC(1012)
set object 1012,1,1,0,0
Return
Create_Trees:
Rem Create trees on the graveyard!
Load image "DataObjectsTreetree1.bmp",2001
Load image "DataObjectsTreetree.bmp",2002
Load image "dataObjectsTreeHell.bmp",2003
Make object plain 2001,600,600
position object 2001,4700,300,5800
Make object plain 2002,600,600
position object 2002,4700,300,5950
Make object plain 2003,600,600
position object 2003,5100,300,5950
Make object plain 2004,600,600
position object 2004,5000,300,5800
Make object plain 2005,600,600
position object 2005,5450,300,5950
Make object plain 2006,600,600
position object 2006,5300,300,5800
Make object plain 2007,600,600
position object 2007,5590,300,5950
Make object plain 2008,600,600
position object 2008,5500,300,5800
Make object plain 2009,400,600
position object 2009,5500,300,2800
Make object plain 2010,400,600
Position object 2010,5100,300,2800
Make object plain 2011,400,600
Position object 2011,4700,300,2800
Make object plain 2012,600,600
position object 2012,1272,300,7200
Make object plain 2013,600,600
position object 2013,1700,300,7000
Make object plain 2014,600,600
position object 2014,1917,300,7300
Make object plain 2015,600,600
position object 2015,1100,300,6700
for town = 2012 to 2015
texture object town,2001
set object town, 1, 0, 0
next town
For i = 2001 to 2008
set object i, 1, 0, 0
Texture object i,2001
next i
for u = 2009 to 2011
set object u, 1, 0, 0
Texture object u,2002
Next u
Return
Load_Swords:
load object "DataObjectsSwordsSword 1Sword.x",3001
Lock object on 3001
position object 3001,25,-45.9,40
fix object pivot 3001
Zrotate object 3001,90
Xrotate object 3001,290
set object speed 3001,10
load object "DataObjectsSwordsSword 1sword_attack.x",3002
Lock object on 3002
position object 3002,25,-45.9,40
fix object pivot 3002
Zrotate object 3002,90
Xrotate object 3002,290
hide object 3002
stop object 3002
Return
Create_collision:
make object box 2,20,230,20
setupObjectDBC( 2, 1, 0 )
SetObjectCollisionOnDBC(2)
HIDE OBJECT 2
Return
Declare_levelshpandstuff:
grass=1
Level# = 1
Hp# = 100
Damage# = 3
Armor# = 1
Mana# = 10
return
Create_menustuff:
rem make HUD
Make object Plain 200,3,1
position object 200,0,-1.9,4
Lock object on 200
Load image "DataHudHud_Back.bmp",200
texture object 200,200
Return
function Distance(Object1,Object2)
dist#=sqrt((object position x(Object1)-object position x(Object2))^2+(object position y(Object1)-object position y(Object2))^2+(object position z(Object1)-object position z(Object2))^2)
endfunction dist#
function AngleY(Object1,Object2)
angy#=wrapvalue(atanfull(object position x(Object2)-object position x(Object1),object position z(Object2)-object position z(Object1)))
endfunction angy#
oh and the code xynocythe made for me didnt work on .x files so i simplified it (hugely) but it IS on my to do list to make it better so dont go yelling about that

but if anyone can help me i will be very happy because i'm thinking about canceling my game if i dont figure this out!
One is the lonliest number...