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 / Do i need a new gosub for each enemy?

Author
Message
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 16th Oct 2003 22:48
MMM...this is a question that i would like to know.
Do i need a new gosub for each enemy, because my game will have around i dunno 5 different enemies, so would i need:

do
gosub _control_enemy_one
gosub _control_enemy_two
gosub _control_enemy_three

would i need this? or could i have this?

Also another thing, i have been given some weird complaints about something called "IRC Chat"
I have know idea what IRC Chat is? where is it?
Just thought i would let you know, if it's a chatroom, and someone is using my name, it is'nt me!!!
thanks

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Oct 2003 23:09
You may need to write a single routine for each type of enemy - writing one for each enemy is overkill.

To get to the DarkBASIC chat to defend your honour, click on the Developers button above, then select the IRC option from the 'Forums & Chat' menu on the left
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 16th Oct 2003 23:40
So i would only need to use 1 gosub for all of them then.

so if i did, would i have this:
_control_enemy:
enemy 1 movement, attacks, health, dist etc goes here + if character attacks this enemy

enemy 2 movement, attacks, health, dist etc goes here + if character attacks this enemy

enemy 3 movement, attacks, health, dist etc goes here + if character attacks this enemy

seems to be ok

Life is just a dream - you are not really alive, so get a gun and start killing evil people.
Rikku of final fantasy 10 and 10.2 is well fit/cool
the_winch
21
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 17th Oct 2003 00:47 Edited at: 17th Oct 2003 00:49
If the different enemys are going to behave a lot different to each other then you could use 5 different go subs.
If they are similar then you could just use 1 function to control them.

do
for num = 1 to 5
control_enemy(num)
next num
loop

function control_enemy(num)
move sprite num,2
if sprite hit(num,1) then gosub _kill_player
`more code to do other stuff
endfunction
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Oct 2003 01:09
yup...you need to get a grip of arrays. You would use a 2D array (no. of enemies * number of characteristics), and simply loop through them as The_Winch has shown above.

If you haven't used arrays yet, read up on them and have a play first.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 17th Oct 2003 01:11
this is the art of reusable code

-RUST-
Andrew
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: United Kindom (what makes it important?)
Posted: 17th Oct 2003 10:52
OK thanks!!!


chill

I can remeber most codes now this is great.
My website has great flash on it. go there http://www.marleygames.com

Login to post a reply

Server time is: 2024-11-25 12:31:20
Your offset time is: 2024-11-25 12:31:20