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, Magic, etc type code example.

Author
Message
EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 26th Aug 2005 02:13
I know I have been asking a lot of questions but I have never programmed before and this is how I learn.

Anyways, my question, how would you write code for health, magic, and other types of things that would diminish durring a game?

For example, you have 1 type of enemy but there are multiple instances of this enemy in the level. When they get hurt, their health goes down, when they use magic...etc

How would you write the code for that 1 enemy type so that each instance of the enemy isnt effected by the others. Basically, how would you write the code so that when one of those instances gets hurt, the health of the other instances doesnt go down. Same for magic etc.
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 26th Aug 2005 03:23
I don't know if this would work in Classic, I know it works in Pro. A concept you might like to get to grips with is 'Types'. This is where you define something as a Type, and you can then create lots of different examples of that Type. Like creating a blueprint and then using it to make lots of copies.


Here, I've created a Type called Baddie. I can then create 'variables' of the Type, Baddie. For example -

That's the same as doing...


In the topmost example, I've created an array of Baddies called Enemies[]. I've made that size 10. So now, I have space in my game for a list of 10 Enemies, of the type Baddie. That means that Enemies(0), Enemies(1), Enemies(2) etc etc, all have a set of variables unique to them.

To access those variables, I do this...


Because they're in an array, I can run through the list of them, using a 'for' loop. Eg


So, with that, I now have 10 Enemies, all with different (or the same if you don't want to use rnd) stats. You can then access them individually with Enemies(number) and the stats of one will not affect the stats of another. Hope that helps a little!
EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 26th Aug 2005 03:54
Ok thanks! I understand that. Now I got another question, how would I make it so that enemies show up in the place I put them on the map? Like in Cartography shop I can place entities and stuff. How would I tell me game to "convert" those to the actual enemy?

Like for example, if I put the "ghost" enemy in 5 spots in my cartography shop level, how would I tell my game to replace those objects with the actual "ghost" enemy and give them each individual stats like in my last question?
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 26th Aug 2005 04:09
'Fraid I don't have Cartography Shop, so I can't help you directly.

However, once you have the x,y,z of those dummy objects, you just do

Because thats where you store the object number of your enemy number 1. Does that help?
EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 26th Aug 2005 04:30
Ok so lets say I have 5 locations where I need to put enemies. Lets laso say I used Enemies as my array like you did in your last post. If I used Enemies(1) for each of the 5 positions, then played the game and hurt 1 in which he got hurt 10 health points, would all 5 of them get hurt or does DarkBASIC look at each of them individualy even though all 5 are "Enemy(1)"???
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 26th Aug 2005 06:53
All five couldn't be, Enemies(1). They'd have to be Enemies(1), Enemies(2), Enemies(3), Enemies(4) and Enemies(5).

Then, when you damage Enemies(1), only that enemy will take the damage. In my earlier code snippet, I was being lazy and only showed one part of it. Sorry
EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 26th Aug 2005 07:06
So what you're saying is you can't program the game to act like Quake 3 and other games where if you place an enemy in a level editor then extract it and load it into a game, the game replaces that object with the actual enemy? How would you make a modable game then? Like a game where people can make maps and place enemies within the map? Because if you did it this way they would need the source code.
Tinkergirl
21
Years of Service
User Offline
Joined: 1st Jul 2003
Location: United Kingdom
Posted: 26th Aug 2005 07:50 Edited at: 26th Aug 2005 07:51
Hang on, that's not what I'm saying.

If that's what you wanted to do, you could create one type - and feed it in the info for the classes of enemies. (Lets say, BlueMob, RedMob and YellowMob).


So, what you do then, is find how many enemies you have on your map and create an array with that many enemies.

For example. Say you have a map with 3 BlueMobs, and 2 RedMobs.

Your engine reads the level file and sees that Objects 1,2, and 3 are tagged as BlueMob, and objects 4, and 5 are tagged as RedMob.

It then knows that you want 5 enemies in total, so it does...

It runs through some code you have to see if you want a red mob, a blue mob, or a yellow mob. (Depending on the object you have in your level editor, I suppose that would be Cartography - but I don't know about that. It then sets the stats depending on the mob type.
Something like...


That any good?
[edit] Please note - I'm at work and hurried - hence all the 'etc's
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Aug 2005 08:25 Edited at: 26th Aug 2005 08:28
Jaquio didn't say if he/she was using DBC or DBPro, but if it's DBC, it doesn't support types.

If it is DBC, then you would still use arrays to do it, but I would use multi-dimensioned arrays.

Dim Enemy(99,4) would create an array to handle up to 5 attributes (0-4) of 100 enemies (0-99). Just alter the 4 to accomodate the number of attributes you wish to store for each enemy.

When you create the first enemy (enemy 0), the enemy number would be stored the first array element (0-99) and the attributes in the second array elements (0-4).

This would give you:

Enemy(0,0) = 100 (Enemy 1's starting health)
Enemy(0,1) = 20 (Enemy 1's spellcasting strength)
Enemy(0,2) = 0 (Enemy 1's tiredness)
Enemy(0,3) = 0 (Enemy 1's hunger)

and so on.

When you create the next one, that would be enemy number 1, so you repeat the above, but with a 1 as the first array element at which point you can use 0 to 4 again as the second element index:

Enemy(1,0) = 100 (Enemy 2's starting health)
Enemy(1,1) = 20 (Enemy 2's spellcasting strength)
Enemy(1,2) = 0 (Enemy 2's tiredness)
Enemy(1,3) = 0: (Enemy 2's hunger)

At any time in the game, Enemy(19,1) would equal the spellcasting strength of enemy 20! If you battle with enemy 32 then hit points are deducted from Enemy(31,0).

See how it works?

Obviously a hundred enemies would be a lot of typing, so you do it in a loop using variables:



(This assumes that all enemies start off with the same attributes).

During the game, another loop can decrease the values in the array.

For example:

Enemy(44,2) = Enemy(44,2)+1

...will increase the tiredness of enemy 45 by 1. If you create a float array, you can slow down the attributes increase or reduction by adding or subtracting 0.1 (or less) each time - instead of 1.

TDK_Man

EsteemDE
19
Years of Service
User Offline
Joined: 5th Aug 2005
Location:
Posted: 26th Aug 2005 10:42
Thanks guys. I understand how to do that stuff now. Oh, and sorry for not saying that I use DBP and not DBC. I should put that into my sig or something.

1 final question though, how do I tag an object in Cartography Shop (like in tinkergirl's post)? I see stuff like keys in the entity editor so im not sure if you mean make a key called "objectname$" and have he value as "RedMob" or something.

If you guys use a different level editor like DeleD instead of Cartography Shop, just explain as if you are using that program. And if you think that program would be better to use, say so, because I want to use the easiest/best one for DBP.

Login to post a reply

Server time is: 2024-09-24 03:28:15
Your offset time is: 2024-09-24 03:28:15