Ok,i have made it!
(I'm very happy 'cause i'm not a mathemathical guy hehe)
I admit that i have read some tutorial and some code(in the code archive)and my code isn't mine interely(i think so...).
Here's the code:
Very very very thanks to the people who wrote tutorial and code in the archive!
Many thanks
(I'm very happy 'cause i'm not a mathemathical guy hehe)
I admit that i have read some tutorial and some code(in the code archive)and my code isn't mine interely(i think so...).
Here's the code:
Graphics 640,480,32,2 SetBuffer BackBuffer() Global sfondo=LoadImage("d:\sfondo.bmp") ; a simple sprite Global nemico=LoadImage("d:\torretta.bmp") ;look up :P Global aereo=LoadImage("d:\jet.tga") ; ^ Global bullet=LoadImage("d:\bullet1.bmp") ; ^ Global jetx ;declaration of the 2 variable of the jet(at mouse position)... Global jety ;Not of use now but For future updates MidHandle sfondo MidHandle nemico MidHandle aereo MidHandle bullet ;the bullet type....the fields looks a little odd but those stuff are only for calculations... Type bullet Field px#,py#,pa#,ex#,ey#,ps#,bs#,a#,p#,e#,ba#,bx#,by#,durata End Type Global b.bullet ;i declare global the type so i can access it's variable outside the function where i declare it ;MAIN While Not KeyHit(1) ;while not esc key is hit jetx=MouseX() jety=MouseY() Cls DrawImage aereo,jetx,jety ;the player under mouse position DrawImage nemico,100,100 ;an enemy :) If MouseHit(1) ;if i hit mousebutton(1) the enemy shoot! create_bullet(100,100,jetx,jety,200,25) EndIf update_bullet() ;update of all bullets fired Flip Wend End ;END MAIN Function create_bullet(xfrom,yfrom,xto,yto,life,velocity) b.bullet = New bullet b\durata=life ;of no use now but for future update i use it for simulating a lifespan of ;the bullet (examples:it's course it's only 100 Or 200 pixel total... ;initialise the bullet position b\px#=xto ;player position b\py#=yto ;player position b\pa#=Rand(-180,180) ;player angle b\ex#=xfrom ;enemy position b\ey#=yfrom ;enemy position b\ps#=1 ;player speed b\bs#=velocity ;bullet speed....try changin this :P ;calculate routine b\a#=ATan2(b\ey-b\py,b\ex-b\px) ;used to calculate from 'coordinate system relative' to 'player relative' b\p#=-b\pa-b\a b\e#=ASin((Sin(b\p)/b\bs*b\ps)) ; the main formula.... ;get bullet parameters from stuff b\ba#=-b\a+180+b\e ;bullet angle: calculation return to system relative coords b\bx#=b\ex ;bullet coordinates b\by#=b\ey ; ^ End Function Function update_bullet() For b.bullet=Each bullet b\bx=b\bx+Cos(b\ba)*b\bs*.1 ;update bullet according to calculated angle b\by=b\by-Sin(b\ba)*b\bs*.1 DrawImage bullet,b\bx,b\by ;my little bullet... :P Next End Function
Very very very thanks to the people who wrote tutorial and code in the archive!
Many thanks