Bullet follow by Dot Merix15th Sep 2004 9:18
|
---|
Summary The bullet will start within a box, and shoot to either an object or to the mouse. Description Move to the left or right, up and down with the arrow keys to move the box. If you press shift, the bullet will fly from the box to the sphere on the screen(bullet to object). Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com make object sphere 2,.1 make object sphere 3,.2 make object cube 1,.5 move object down 1,.5 move object up 2,.8 move object left 2,.8 hide object 3 sync on sync rate 60 do if upkey() = 1 move object up 1, .1 endif if downkey() = 1 move object down 1, .1 endif if rightkey() = 1 move object right 1,.1 endif if leftkey() = 1 move object left 1,.1 endif if shiftkey() = 1 x#=object position x(1) y#=object position y(1) z#=object position z(1) ox# = object position x(2) oy#=object position y(2) oz#=object position z(2) osx# = object screen x(2) osy# = object screen y(2) position object 3,x#,y#,z# point object 3, ox#,oy#,oz# show object 3 global bullet=1 endif if mouseclick() = 1 x#=object position x(1) y#=object position y(1) z#=object position z(1) mx = mousex() my = mousey() fix object pivot 3 position object 3, x#,y#,z# show object 3 global bullet=2 endif if bullet = 1 gosub bulletfollowobject endif if bullet = 2 gosub bulletfollowmouse endif if object hit (2,3) then print "collision!" if object collision(2,3) then print "collision" sync:loop bulletfollowobject: if object screen x(3) <> osx# move object 3,.1 endif if object screen y(3) <> osy# move object 3,.1 endif if object collision (3,2) bullet = 0 endif return bulletfollowmouse: if object screen x(3) > mx move object left 3,.1 endif if object screen y(3) < my move object down 3,.1 endif if object screen x(3) < mx move object right 3,.1 endif if object screen y(3) > my move object up 3,.1 endif return |