Hi, I have below a small section on my darts engine code. I have tried several methods to get sin/cos rotation to speed up but if I do speed it up it looses its per pixel collision. ie it skips. If I speed up by 2 it skips 2 and if i speed up by 4 it skips 4 pixels.
I need help to speed up the rotation. I will post the full source if need be as its not going to be commercial anymore, but I would like to avoid that if possible.
Here is the molebox packed exe.
http://www.kamikazekrow.com/storage/prodarts.rar
Here is a small section of the engine code that deals with the sin/cos aiming system
Function engine()
Repeat
mh2 = MouseHit(2)
Cls
DrawImage fpscr,0,0
DrawImage boardsbig,dartx,darty,picked_board
Rect MouseX()+Sin(xangle#)*80,MouseY()+Cos(yangle#)*80,5,5
xangle# = xangle + 1
yangle# = yangle + 1
If xangle# >360 Then xangle# = 0
If yangle# >360 Then yangle# = 0
mx#=dartx+ix
my#=darty+ix
dx#=MouseX()+Sin(xangle#)*80-mx
dy#=MouseY()+Cos(yangle#)*80-my
ang#=ATan2(dy,dx)
If ang<0 ang=ang+360
Text 1,1,MouseX()+"-"+MouseY()+" A:"+ang+" L>"+MouseZ()
Text 1,20,lastScore#
drawZ(ang,MouseZ())
ang=ang+100
If ang<0 ang=360-Abs(Ang)
If ang>360 ang=ang-360
zone# =ang#/18.0
lastScore=int2(zone+1.)
If lastscore>20
lastScore=20
EndIf
If lastScore<1
lastScore=1
EndIf
lastScore=score(lastScore)
td#=dist(MouseX()+Sin(xangle#)*80,MouseY()+Cos(yangle#)*80,dartx+ix,darty+iy)
If td>218
scor = 0
;foulshot
EndIf
If td<209
scor=lastscore*2 ;double
EndIf
If td<192
scor=lastScore ;normal zone
EndIf
If td<140
scor=lastscore*3 ;triple
EndIf
If td<116
scor=lastScore ;normal
EndIf
If td<27
scor=25 ;25 points
EndIf
If td<14
scor=50; bullseye
EndIf
;EndIf
;--Score Check
If MouseHit(1)And shot < 3 And canthrow = 1
playScore=playScore-scor
lastScor=scor
totScore=totScore+scor
shot=shot+1
msg$="Shot Number "+shot
d.dartt = New dartt
d\x# = MouseX()-45+(Sin(xangle#)*80)
d\y# = MouseY()-42+(Cos(yangle#)*80)
EndIf
If shot = 3
canthrow = 0
EndIf
If mh2 = True And canthrow = 0
shot=0
canthrow = 1
For d.dartt = Each dartt
Delete d
Next
totScore=0
EndIf
If totScore=180
msg$="ONE HUNDRED AND EIGHTY!"
Else
msg$=" Player 1 Scored >"+totScore
EndIf
For d.dartt = Each dartt
DrawImage dart,d\x#,d\y#,2
Next
Text 1,540,"Player 1 Needs>"+playScore
If lastScor>0
Text 200,540,"Player 1 Scored>"+lastscor
EndIf
Text 100,560,msg
Flip
Until KeyDown(1)
End Function
|