Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / shooting enemies

Author
Message
Red general
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: United Kingdom
Posted: 22nd Dec 2002 20:55
I m stuck with this nothing happens - how do I sort my code out so I can have something when the bullets hit the enemy
THis is my code so far - can anyone help?
Rem ++++++++++++++++++++++++++++++++++++++++++++
Rem +++++++++ Star Wars - Hoth wars ++++++++++++
Rem ++++++++++++++++++++++++++++++++++++++++++++


rem Initialisation
sync on
sync rate 30
randomize timer()
hide mouse
autocam off


Rem star wars theme tune
load music "starwars.mid",1
play music 1
loop music 1

rem Make a terrain to fly over
make matrix 1,10000,10000,50,50
rem texture matrix
load image "grass10.bmp",2
Prepare matrix texture 1,2,2,2

rem skysphere
make object sphere 2,10000
load image "test1.bmp",4
set object 2,1,0,0
Texture object 2,4

rem tie fighter
load object "tie fighter.x",1
position object 1,0,0,100


rem background texture
texture backdrop 4

REm load the bullet
Make object sphere 3,3
color object 3,RGB(20,100,40)


rem Set up initial positions and angles
x#=5000
y#=200
z#=5000
theta#=0
phi#=0
thruststep#=0.1

Rem cockpit for ship
rem Set the ink to white and paper color to black
ink rgb(244,214,210),1
rem Load a bitmap on to the screen
load bitmap "tie3.bmp",1
rem Use this command to set drawing to the screen
set current bitmap 1
rem Grab image 1 from bitmap
get image 1,0,0,640,480,2
rem Now we will make the sprite
sprite 1,0,0,1




do
rem Mouseclicks control speed
`if mouseclick()=1 then thrust#=thrust#+thruststep#
`if mouseclick()=2 then thrust#=thrust#-thruststep#

rem Now the joystick button controls speed
if joystick fire b()=1 then thrust#=thrust#+thruststep#



rem Mouse movements control angles
`theta#=wrapvalue(theta#+mousemovex())
`phi#=wrapvalue(phi#+mousemovey())

rem Joystick controls angles
rem Change the value (currently 0.005) to set sensitivity
theta#=wrapvalue(theta#+(joystick x()*0.005))
phi#=wrapvalue(phi#-(joystick y()*0.005))

rem Decay the thrust so you don't go really fast
thrust#=thrust#*0.9
xaxisstrafe#=xaxisstrafe#*0.9
yaxisstrafe#=yaxisstrafe#*0.9

rem Accelerate the velocities (this took ages to work out)
xvel#=xvel#+(sin(theta#)*cos(phi#)*thrust#)
yvel#=yvel#-(sin(phi#)*thrust#)
zvel#=zvel#+(cos(theta#)*cos(phi#)*thrust#)

xvel#=xvel#+(sin(theta#+90)*xaxisstrafe#)
zvel#=zvel#+(cos(theta#+90)*xaxisstrafe#)

xvel#=xvel#+(sin(theta#)*cos(phi#+90)*yaxisstrafe#)
yvel#=yvel#-(sin(phi#+90)*yaxisstrafe#)
zvel#=zvel#+(cos(theta#)*cos(phi#+90)*yaxisstrafe#)

rem Some friction to stop you going too fast
xvel#=xvel#*0.99
yvel#=yvel#*0.99
zvel#=zvel#*0.99

rem Simple velocity
x#=x#+xvel#
y#=y#+yvel#
z#=z#+zvel#

rem Rotate and position the camera
position camera x#,y#,z#
yrotate camera theta#
xrotate camera phi#

Rem shoot bullet
if joystick fire a()=1 and BulletLife=0
Position object 3,x#,y#,z#
Set object to camera orientation 3
BulletLife =25
Show object 3
Endif

Rem where the bullet moves
if BulletLife > 0
Dec BulletLife
Move object 3,20
if BulletLife = 0 then Hide object 3
Endif

Rem this is for the shooting
rem object positions for the shooting
obj1x# = object position x(1)
obj1y# = object position y(1)
obj1z# = object position z(1)

obj3x# = object position z(3)
obj3y# = object position z(3)
obj3z# = object position z(3)

rem distance form bullet and the target
dist# = getdist(obj1x#,obj3x#,obj1y#,obj3y#,obj1z#,obj3z#)

rem hitting it
if dist#
Hockey07
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: United States
Posted: 23rd Dec 2002 01:05
I have no clue, but I hope someone helps you with this because I can use the help, too!

AlamDV, NHL, NHL 2K3....... The best combination ever!
asgood
21
Years of Service
User Offline
Joined: 23rd Dec 2002
Location:
Posted: 23rd Dec 2002 16:08
will this be any use to u Redgeneral

Sync On
Sync Rate 30
Hide mouse
Backdrop on
Set camera range 1,5000

Fog off
Fog distance 1500
Fog color RGB(128,128,128)
Color Backdrop RGB(128,128,128)

Rem make matrix
Make matrix 1,5000,5000,20,20

Rem texture matrix
Load image "grass.bmp",1
Prepare matrix texture 1,1,1,1
Fill matrix 1,0,1

rem hide mouse
hide mouse

rem Make Gun
Make object cylinder 1,2
XRotate Object 1,90
Fix object pivot 1
Scale object 1,100,100,500
position object 1,0,-7,12
Lock object on 1

Rem Make bullet
Make Object Sphere 2,2
Hide Object 2

rem ppl in level
LOAD OBJECT "idle.x",5 : APPEND OBJECT "walk.x",5,100
YROTATE OBJECT 5,180 : FIX OBJECT PIVOT 5
mx#=1020
my#=1
mz#=2000
position object 5,mx#,my#,mz#
LOOP OBJECT 5,0,20 : set object speed 5,15
object5life=50

do
Rem check for key presses and control movement
Rem forward and backward movement
if upkey()=1 then x#=newxvalue(x#,a#,20):z#=newzvalue(z#,a#,20)
if downkey()=1 then x#=newxvalue(x#,a#,-20):z#=newzvalue(z#,a#,-20)
Rem sidesteps
if leftkey()=1 then x#=newxvalue(x#,wrapvalue(a#-90),20):z#=newzvalue(z#,wrapvalue(a#-90),20)
if rightkey()=1 then x#=newxvalue(x#,wrapvalue(a#+90),20):z#=newzvalue(z#,wrapvalue(a#+90),20)

Rem turning and camera movement using mouse
a#=wrapvalue(a#+mousemovex()/4)
a2#=wrapvalue(a2#+mousemovey()/4)

Rem limit vertical camera movement
if a2#>=60 and a2#<100 then a2#=60
if a2#<=300 and a2#>200 then a2#=300

Rem find ground height and position camera relative to it
y#=get ground height(1,x#,z#)+100

Rem position camera
position camera x#,y#,z#
yrotate camera a#
xrotate camera a2#

Rem detect for bullet firing
if mouseclick()=1 and bulletlife=0
show object 2
Rem position bullet using triganometry
bx#=x#+sin(a2#)*sin(a#)*-7
by#=y#+cos(a2#)*-7
bz#=z#+sin(a2#)*cos(a#)*-7
position object 2,bx#,by#,bz#
set object to camera orientation 2
bulletlife=25
endif

Rem move bullet if bulletlife is more than 0
if bulletlife>0
move object 2,10
dec bulletlife
bx#=object position x(2)
by#=object position y(2)
bz#=object position z(2)
else
hide object 2
endif

Rem calculate how far away bullet is from man and if it is close enough then type "HIT!!!"
if sqrt((mx#-bx#)^2+(my#+75-by#)^2+(mz#-bz#)^2)<100 and bulletlife<>0
delete object 5
bulletlife=0
endif

Rem update screen and loop
sync
loop

Red general
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: United Kingdom
Posted: 23rd Dec 2002 19:06
I only saw your message as I was about to put up this one. I have found a way of doing it for several stuff but only using the same equaton

Rem ++++++++++++++++++++++++++++++++++++++++++++
Rem +++++++++ Star Wars - Hoth wars ++++++++++++
Rem ++++++++++++++++++++++++++++++++++++++++++++


rem Initialisation
sync on
sync rate 30

hide mouse
autocam off


Rem star wars theme tune
load music "starwars.mid",1
play music 1
loop music 1

rem Make a terrain to fly over
make matrix 1,10000,10000,50,50
rem texture matrix
load image "grass10.bmp",2
Prepare matrix texture 1,2,2,2

rem skysphere
make object sphere 2,10000
load image "test1.bmp",4
set object 2,1,0,0
Texture object 2,4

rem tie fighter
load object "tie fighter.x",1
position object 1,100,100,400


rem background texture
texture backdrop 4

REm load the bullet
Make object sphere 3,3
color object 3,RGB(20,100,40)


rem Set up initial positions and angles
x#=5000
y#=200
z#=5000
theta#=0
phi#=0
thruststep#=0.1

Rem cockpit for ship
rem Set the ink to white and paper color to black
ink rgb(244,214,210),1
rem Load a bitmap on to the screen
load bitmap "tie3.bmp",1
rem Use this command to set drawing to the screen
set current bitmap 1
rem Grab image 1 from bitmap
get image 1,0,0,640,480,2
rem Now we will make the sprite
sprite 1,0,0,1


do
rem Mouseclicks control speed
`if mouseclick()=1 then thrust#=thrust#+thruststep#
`if mouseclick()=2 then thrust#=thrust#-thruststep#

rem Now the joystick button controls speed
if joystick fire b()=1 then thrust#=thrust#+thruststep#



rem Mouse movements control angles
`theta#=wrapvalue(theta#+mousemovex())
`phi#=wrapvalue(phi#+mousemovey())

rem Joystick controls angles
rem Change the value (currently 0.005) to set sensitivity
theta#=wrapvalue(theta#+(joystick x()*0.005))
phi#=wrapvalue(phi#-(joystick y()*0.005))

rem Decay the thrust so you don't go really fast
thrust#=thrust#*0.9
xaxisstrafe#=xaxisstrafe#*0.9
yaxisstrafe#=yaxisstrafe#*0.9

rem Accelerate the velocities (this took ages to work out)
xvel#=xvel#+(sin(theta#)*cos(phi#)*thrust#)
yvel#=yvel#-(sin(phi#)*thrust#)
zvel#=zvel#+(cos(theta#)*cos(phi#)*thrust#)

xvel#=xvel#+(sin(theta#+90)*xaxisstrafe#)
zvel#=zvel#+(cos(theta#+90)*xaxisstrafe#)

xvel#=xvel#+(sin(theta#)*cos(phi#+90)*yaxisstrafe#)
yvel#=yvel#-(sin(phi#+90)*yaxisstrafe#)
zvel#=zvel#+(cos(theta#)*cos(phi#+90)*yaxisstrafe#)

rem Some friction to stop you going too fast
xvel#=xvel#*0.99
yvel#=yvel#*0.99
zvel#=zvel#*0.99

rem Simple velocity
x#=x#+xvel#
y#=y#+yvel#
z#=z#+zvel#

rem Rotate and position the camera
position camera x#,y#,z#
yrotate camera theta#
xrotate camera phi#

Rem shoot bullet
if joystick fire a()=1 and BulletLife=0
Position object 3,x#,y#,z#
Set object to camera orientation 3
BulletLife =25
Show object 3
Endif

Rem where the bullet moves
if BulletLife > 0
Dec BulletLife
Move object 3,80
if BulletLife = 0 then Hide object 3
Endif

Rem this is for the shooting
rem object positions for the shooting
obj1x# = object position x(1)
obj1y# = object position y(1)
obj1z# = object position z(1)

obj3x# = object position x(3)
obj3y# = object position y(3)
obj3z# = object position z(3)


rem distance form bullet and the target
dist# = getdist(obj1x#,obj3x#,obj1y#,obj3y#,obj1z#,obj3z#)

rem kill the enemy when bullet is close
if dist#<100 then Hide object 1

rem distance from camera and target
camdist# = getdist(obj1x#,x#,obj1y#,y#,obj1z#,z#)
rem enemy moves if you are close
if camdist#<1000 then move object 1,20


sync
loop

function getdist(obj1x#,obj2x#,obj1y#,obj2y#,obj1z#,obj2z#)
distance# = SQRT((obj1x#-obj2x#)^2+(obj1y#-obj2y#)^2+(obj1z#-obj2z#)^2)
endfunction distance#


This means that I can check if the project is close to the enemy to kill the enemy and I can see I am close to it so that it can run away, or (with some adaption) towards you.

Thanks for your help asgood and I hope that darkjedi07 finds both of our solutions helpful.

Login to post a reply

Server time is: 2024-03-28 23:02:08
Your offset time is: 2024-03-28 23:02:08