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.

Newcomers DBPro Corner / Health: pure and simple

Author
Message
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 24th Jan 2007 02:17 Edited at: 14th Mar 2007 19:31
Hello

Will anyone give me an example of how to make health and how to make it go down and damage and all of that stuff. I'm not looking for a bar really I think they take up too much space, so just health numbers.

Also, if it's not asking to much could someone mod my code for it?



DBPro

If at first you don't succeed, lower your expectations.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 24th Jan 2007 03:32
No, go back, read the starter tutorials, pay attention to them, and experiment. What you're asking for is extremely, extremely basic variable manipulation. If you dont understand how to use variables, then you're getting way ahead of yourself and should, as I just said, read the starter tutorials, along with possibly a few general programming structure tutorials from the web, before continuing on.

Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 24th Jan 2007 06:33 Edited at: 24th Jan 2007 06:38
hmm a "gimme teh codez" post, o well im not gonna flame you.

lets seeeeee if you want health its easy



RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 24th Jan 2007 13:30
And now he will skip over what I said and continue to ask questions like this.

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 24th Jan 2007 23:52
Ruccus, what's your problem? He asked a question, and you went out of your way to refuse to answer it.

What you want to do is make a health variable. Like this:



In your game loop, let's say the player gets hit. In this case, you'd subtract a number of health points from health, like this:



That will lower the health by 5 points.

Let's say you pick up a health box that adds 25 points. You'd do this:



You also wouldn't want the health to go over the maximun (100) so use an if statment to set it back to 100 if it goes over.

Also, you'll want a game over message to appear when health reaches 0. That's when you got to do this:



Quote: "Gimme teh code!"

Thank you for not flooding the forums with posts like this.
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 25th Jan 2007 00:30
yeah that was a bit mean ruccus, no offence but you could have said it in a nicer way

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 25th Jan 2007 01:19
Would you go into a car dealership and ask how to drive? Im sorry if I came off harsh, but adding/subtracting values from variables is the first thing the tutorials that come with DB mention. That beginner's tutorial is there for a reason, and its extremely helpful, more so than anyone will be on the forums. Proof? Im not trying to single anyone out, but Code Dragon, you used float variables to hold integer values, from what Ive read of his code its safe to say he doesnt know the difference between float and integer cast variables, and will now assume that # sign is used for all variables.

Itd help him and us if he just read the tutorials in the first place, a) he'd learn how to use variables the proper way, and b) he wouldnt make several posts on the forums asking what the "$ symbol means", "how to use arrays", etc.

- RUC'


:: Check out the new FPS Tutorials Progress at http://www.freewebs.com/ruccus
Kieran
18
Years of Service
User Offline
Joined: 6th Aug 2006
Location: Hamilton, New Zealand
Posted: 25th Jan 2007 02:25
u got a point ruccus but yes u were a bit harsh

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 25th Jan 2007 21:42 Edited at: 25th Jan 2007 21:46
He understands that variables don't need the #. If you look at his code, you'll see that he used an integer variable, so it must work for him. I wasn't sure weither he wanted health to use integers or floating points, so better safe than sorry. I didn't mislead him, I gave examples of how to use a health variable. Even if I did mislead him he'd figure out the difference between floats and integers soon enough, it's only a matter of time before he stumbles upon a tutorial that explains it.

This forum was established so newcomers could get help with DBP. A polite mention of a tutorial that explains variables is acceptable, but examples are even better. No need to sound like a flammer.

Quote: "Gimme teh code!"

Thank you for not flooding the forums with posts like this.
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 25th Jan 2007 23:12 Edited at: 25th Jan 2007 23:20
Ty for all of your help. Oh, and by the way Ruccus. I know the difference between integers and floats and all of that stuff. I've read through the principals part of my DBPro manual. I just needed a few examples because all of the stuff I tried didn't work.

Sometimes you need more than a few tutorials to get you started.

I don't suffer from laziness... I enjoy every minute of it!
Jerok
19
Years of Service
User Offline
Joined: 7th May 2005
Location: Mars. Wait a sec I\'m on MARS. OMG
Posted: 26th Jan 2007 03:31 Edited at: 26th Jan 2007 03:32
Quote: "Ruccus, what's your problem? He asked a question, and you went out of your way to refuse to answer it."


It may have been harsh but ruccus has a very good reason to be. First of all Dark Basic is very much meant for learning and you don't learn much when you just ask for code. Second health is covered in Ruccus's FPS tutorial which he wrote to help people with questions like this, so he has plenty of reason to say to look at tutorials.

Not all posts like this are made just out of lazyness, but after reading many posts like this where the answers can be solved with seemingly little effort it is easy for a person to get fed up with this. Ruccus has been helping people on these forums far longer then eighter of you and he has right to get mad over such posts as this.
RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 26th Jan 2007 14:35
Im not mad, and my tutorial isnt the tutorial to help with this, and yes people may need a few tutorials to get them going, but (and this is a serious question), unless you're dislexic (not sure of the spelling), the tutorial that comes with DB that explains variables, combined with a quick look-up of "collision" in the db index, would solve the answer. I agree the newcommer's corner is a place for help for newcommers, however, its not a tool for people to ask for code to be put into their current game so they dont have to understand it, and when its something as simple as this (that has been answered multiple times on these forums, in the code base, in various tutorials found all over the site, and in the FPS tutorial that comes with DB IIRC), it gets a bit frustrating.

My position stands, its great that people help, but he would've learnt more if he read a few tutorials that go into great detail explaining the topic.


:: Check out the new FPS Tutorial's Progress at http://www.freewebs.com/ruccus
along with code, media, and more.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Jan 2007 01:16
Ruccus, you're out of line!

Quote: "if it's not asking to much could someone mod my code for it?"


woh, wait.... what?

Nevermind Ruccus, you tell him!

I don't see someone writing their own tank game without knowing how to subtract variables.

my1929mb
17
Years of Service
User Offline
Joined: 25th Jan 2007
Location:
Posted: 27th Jan 2007 19:56
I tried doing this but for some reason my game wont load.
i keep getting this error: "runtime error 105- file does not exist on line 157."
my code is under this. if you could tell me what the problem is that would be wonderful.



`set display mode 800,600,16
sync on
sync rate 0
hide mouse

backcolor=rgb(0,0,0)

backdrop on
color backdrop backcolor
cls

` Attention ... This value is the size of the map ! change it to fit your map file
mapsize=512
dim map$(mapsize,mapsize)

maxcubes=16
cubesize=200
collisionstep=int(cubesize/10)

fog on
fog color backcolor
fog distance (int(maxcubes)*cubesize)
set camera range 1,(maxcubes*cubesize)

` Current map
loadmap("media/dungeon.map",mapsize)
autocam off

load image "media/wall2.jpg",1
load image "media/ground.jpg",2
load image "media/wall.jpg",3

` Wall
for i=1 to maxcubes*maxcubes
make object cube 100+i,cubesize
` make object sphere 100+i,cubesize
` make object box 100+i,cubesize,cubesize*2,cubesize
` make object cone 100+i,cubesize
` make object cylinder 100+i,cubesize+((cubesize/100)*10)
texture object 100+i,1
next i

` floor
for i=1 to maxcubes*maxcubes
make object plain 10000+i,cubesize,cubesize
rotate object 10000+i,90,0,0
texture object 10000+i,2
next i

` ceiling
for i=1 to maxcubes*maxcubes
make object plain 20000+i,cubesize,cubesize
rotate object 20000+i,270,0,0
texture object 20000+i,3
next i

set ambient light 30
make light 1
make light 2
set point light 1,0,0,0
set spot light 2,45,90
color light 2,RGB(252,216,141)
color light 1,RGB(236,182,100)
color light 0,RGB(0,0,0)

` Search startpoint
for z=1 to mapsize
for x=1 to mapsize
if map$(x,z)="O"
cx=x*cubesize
cz=z*cubesize
endif
if map$(x,z)="U"
ex=x
ez=z
endif
next x
next zd
position camera cx,0,cz

oldpositionx#=camera position x()
oldpositionz#=camera position z()

randomize timer()
cls

do
if mouseclick()=1 then move camera maxcubes
if mouseclick()=2 then move camera maxcubes*(-1)
ry#=wrapvalue(ry#+mousemovex())
rotate camera rx#,ry#,0

cx#=int(camera position x()/cubesize)-int(maxcubes/2)
cz#=int(camera position z()/cubesize)-int(maxcubes/2)

tx#=camera position x()
tz#=camera position z()

zzz=0
for zz=1 to maxcubes
for xx=1 to maxcubes
zzz=zzz+1
curposx=int(cx#)+xx
curposz=int(cz#)+zz
if curposx<=1 then curposx=1
if curposx>=mapsize then curposx=mapsize
if curposz<=1 then curposz=1
if curposz>=mapsize then curposz=mapsize

` wall
if map$(int(curposx),int(curposz))="#" or map$(int(curposx),int(curposz))="S"
show object 100+zzz
position object 100+zzz,curposx*cubesize,0.0,curposz*cubesize
` Collisiondetection
if map$(int(curposx),int(curposz))="#"
if tx#>=((curposx*cubesize)-(cubesize/2))-collisionstep and tx#<=((curposx*cubesize)+(cubesize/2))+collisionstep and tz#>=((curposz*cubesize)-(cubesize/2))-collisionstep and tz#<=((curposz*cubesize)+(cubesize/2))+collisionstep
position camera oldpositionx#,camera position y(),oldpositionz#
oldpositionx#=camera position x()
oldpositionz#=camera position z()
endif
endif
else
hide object 100+zzz
endif

` floor
if map$(int(curposx),int(curposz))=":" or map$(int(curposx),int(curposz))="D" or map$(int(curposx),int(curposz))="S" or map$(int(curposx),int(curposz))="T"
show object 10000+zzz
position object 10000+zzz,curposx*cubesize,(cubesize/2)*(-1),curposz*cubesize
else
hide object 10000+zzz
endif

` ceiling
if map$(int(curposx),int(curposz))=":" or map$(int(curposx),int(curposz))="D" or map$(int(curposx),int(curposz))="S" or map$(int(curposx),int(curposz))="T"
show object 20000+zzz
position object 20000+zzz,curposx*cubesize,(cubesize/2),curposz*cubesize
else
hide object 20000+zzz
endif

next xx#
next yy#

oldpositionx#=camera position x()
oldpositionz#=camera position z()

position light 1,camera position x(),camera position y(),camera position z()
position light 2,camera position x(),camera position y(),camera position z()
color light 1,RGB(200+int(rnd(70)-50),120,60)
rotate light 2,camera angle x(),camera angle y(),camera angle z()

sync
loop

function loadmap(filename$,size)
open to read 1,filename$
for y=1 to size
for x=1 to size
read byte 1,tmp
map$(x,y)=chr$(tmp)
next x
next y
close file 1
endfunction

health# = 100
if object collision(player, enemy) then dec health#, 5
if object collision(player, healthbox)
inc health#, 25
if health# > 100 then health# = 100
delete object healthbox
endif
if health# <= 0
center text screen width()/2, screen height()/2, "Game Over"
sync
wait 2000
end
endif

thnx
Allanon Shadeslayer
17
Years of Service
User Offline
Joined: 28th Dec 2006
Location:
Posted: 14th Mar 2007 19:29
Well, I didn't mean to make anyone angry. I never exploit someone's given code unless I understand it first.

If at first you don't succeed, lower your expectations.
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 15th Mar 2007 02:04
I would suggest checking this out. I know you dont like bars but the essence of what you require is in a code snippet for you to pull apart.


As ive progressed as well I would substitute the 2d elements and paint the graphic onto a 3d panel stuck to the screen.

http://forum.thegamecreators.com/?m=forum_view&t=37583&b=6

Login to post a reply

Server time is: 2024-09-25 19:12:42
Your offset time is: 2024-09-25 19:12:42