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.

Code Snippets / [DBC] simple Damage/health which may work for your game

Author
Message
stoned coder
17
Years of Service
User Offline
Joined: 6th May 2007
Location:
Posted: 6th May 2007 16:00

rem variable at start of prog
damage=0
rem you need to insert the correct names for your bullet rem and the object you want damage to work for!Also
rem collision needs to be set on (I just used global
rem collision!)You may find that the bullet passes through rem the entity which causes damage to be detected
rem constantly while it passes through, which gives an
rem imbalanced damage output.So you need to make sure the rem bullet is repositioned or deleted when collision
rem occurs too.
rem main loop...
if object collision (bullet,entity)=1 then hit=1
if object collision (bullet,entity)=0 then hit=0
rem change the +15.7 to any ammount that works for your rem game,this is the ammount of damage, also the +500 on rem the next line can be changed, this is the ammount
rem of "health".Also after damage=0 on same line you can rem add your death or respawn code!
if hit=1 then damage=damage+15.7
if damage=500 then damage=0
text 10,50,"Damage: "+str$ (damage)
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 6th May 2007 16:34 Edited at: 6th May 2007 16:41
if object collision (bullet,entity)=1 then hit=1
if object collision (bullet,entity)=0 then hit=0
could be
hit=object collision (bullet,entity)

damage=damage+15.7
could be
inc damage,15.7
make sure at the top of your code you have
damage as float

stoned coder
17
Years of Service
User Offline
Joined: 6th May 2007
Location:
Posted: 6th May 2007 17:47
yea thanks much more efficient, ah well i just wanted to make some kind of offering !
Im making a space colonising game in 3d ,i started from scratch with no programming knowledge 2 years ago and havnt got very far but learned quite a bit in the process..Ive made a basic space ship movement and cannon turrets which aim and fire ,also missiles and missile turrets all based on the same idea but what i cant get anywere near is how to make a laser beam effect with lines (or preferably a cool looking particle effect i think) which draw from one ship to another object within a certain range.Any help would be a great help.
Thanks..
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 7th May 2007 08:12
use the code tags guys.
be careful to drug references in your name mate.
If we get a complaint you will have to ask a mod to change it.

[ c o d e ] yourcode [ / c o d e ]



stoned coder
17
Years of Service
User Offline
Joined: 6th May 2007
Location:
Posted: 8th May 2007 13:55
what do you call a coder whos so bad people throw stones?
ans=get-out clause!
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 8th May 2007 19:30 Edited at: 8th May 2007 19:31
That aside, you should still edit your post and use the Code button just above the smilies.

Highlight your code and click on it. If your code had any indentation, then using this button would retain it.

Note:

if hit=1 then damage=damage+15.7

As Daemon points out, what do you think this line does? Hint: It doesn't!

TDK_Man

stoned coder
17
Years of Service
User Offline
Joined: 6th May 2007
Location:
Posted: 8th May 2007 19:51
heres the code using the code button!!
stoned coder
17
Years of Service
User Offline
Joined: 6th May 2007
Location:
Posted: 8th May 2007 19:58
well i thought it meant while the condition is true that hit=1 the value damage increases by 15.7
if it doesnt then how come the counter works for me?
Vampiric
18
Years of Service
User Offline
Joined: 30th Oct 2006
Location:
Posted: 23rd May 2007 19:19
Don't increase the damage, just subtract 15.7 away from the health

Computer says n00bed
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 27th May 2007 02:37 Edited at: 27th May 2007 02:39
Quote: "well i thought it meant while the condition is true that hit=1 the value damage increases by 15.7"


I think it adds 15 to the value damage. Here is why:


If you don't want to declare your variables as floats (able to have decimal), then you must name them with a # at the end of them.

P.S. There is supposed to be a very small rounding problem with damage 2, this always happens.

Login to post a reply

Server time is: 2024-11-22 18:31:30
Your offset time is: 2024-11-22 18:31:30