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 Professional Discussion / multiple enemy bullets

Author
Message
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 12th Aug 2012 19:39
Hello,

I found a lot of posts about enemy bullets, but every game has something specific and dont work well if I wanna apply.
My question is what solution to apply if I have 30 enemies, and everyone to shoot directly in my user, 5 bullets, one second between bullets, if distance is lower than ...500, lets say. And if enemy is dead, stop shooting. A small example will be very helpfull. I 'm beginner, and no experience with arrays....know I need to learn more.
I tried with dark AI, but probably i made some mistakes, didnt worked. So...what is the best solution??? And please give me a small code if it's possible

Mihai
Daniel wright 2311
User Banned
Posted: 12th Aug 2012 20:50 Edited at: 12th Aug 2012 20:50


This is just a example

my signature keeps being erased by a mod So this is my new signature.
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 13th Aug 2012 17:48
Thank you, it sn interessing example.

For me the most important question here now its what command to use for enemy bullets to find the game user !!! (camera ), first person view

Mihai
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 13th Aug 2012 19:17 Edited at: 13th Aug 2012 19:18
hi!
I whipped up a working demo for you!
I'm afraid it's not an FPS, but it contains one way to handle bullets in a game... I hope it's not all too confusing. If you have any questions about the code, just shout it out!

Hope this helps some

/EDIT: forgot to mention: you control your player with the arrow keys and fire with space-bar. But watch out, the game is pretty tough!

mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 13th Aug 2012 21:44
thank you very much, its very usefull for me, i'm sure i can adapt this demo in my game.

Tx again !!!!

Mihai
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 13th Aug 2012 21:59
you're welcome!
the code is kind of intense in it's use of arrays and for-loops if you've never really worked with them before... but I hope it also demonstrates how useful arrays can be!
like i said, if you have any trouble understanding the code, just ask
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 16th Aug 2012 22:03 Edited at: 16th Aug 2012 22:07
I'm back,

I used your code, thank you again, it's working perfect.
My problem is: I inserted a terrain as dbo object, and tried to change to fps the player, but I cant do it. Here is the code, maybe you can give me an idea what to do...



Mihai
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 17th Aug 2012 23:37
Hey!
Sorry, only got the chance to look through your code just now..



Ahh... I'm sorry.. I've been writing on this answer for a while now and just can't find the proper way to do it I aplogize for any inconsistencies and half-completed sentences... I kept jumping around the lines when I was writing this...
To be honest, there are quite a number of issues with your code that prevent it from working the way you want it to. So instead of this being a real answer on how to "fix your code", it's more an overview of the concepts that cause the trouble with the current code / that you need to study a bit more before you can get this code to work:

COPYING S/B ELSES CODE INTO YOUR PROGRAM

So, it looks like you are cannibalizing a lot of the code from the shoot-the-floating-aliens demo, right? Believe me, I can remember very well the days when I did that!

In principle there is nothing wrong with using code that you've already got (whether from a demo like that or you wrote it for another project..) but you always have to make sure that it FITS in your current project!

Look for example at the first 40 lines of code: you have several commands about the sync rate (the last command counts and your last sync rate command is in line 39 "Sync On : Sync Rate 0" - in a program you usually need this kind of command "Sync On" and "Sync Rate ..." only once.
On a sidenote: "Sync Rate 0" essentially means that the program will run as fast as the computer can -- you normally want to avoid that (since it will result in unpredictable game play and very different results for players with slow computers compared to players with fast ones. Instead go for something like "Sync Rate 60" which will set the frame rate to 60 Frames Per Second, regardless of how fast the computer is, which is running the game (provided it is fast enough to handle 60 fps.. otherwise there will be lag. But the important thing is that better computers won't go FASTER than those 60 fps). So definitely go for "Sync Rate 60" or "Sync Rate 30" or what ever frame rate you want.
Though this is not a horrible mistake or anything, it kind of gives away that you patched the code together from different sources without really thinking about what you were doing (But don't worry, I think we will be able to disentangle this code )

And this patching together is also the main reason what keeps the fps from working:
The biggie in your code is that you are using TWO DIFFERENT WAYS OF CONTROLLING THE PLAYER!
One part is from my code, reffering to the cone object with object number "player" (defined as =1 earlier), controlled with the arrow keys. This part is from line 213 to 222.
But then there's ALSO the player control-part from the fps-demo! (Roughly line 388 to 436). The two approaches use DIFFERENT OBJECT NUMBERS to represent the player (in my code "player", which was defined as 1, in the fps-demo there is an invisible collider object with object number *2* to represent the player.
There is no real clarity on WHICH should be used! For example, note that in my AI-code for the turrets, the turrets aim at the object with the object number "player" (=1)! However, the camera is told to position and rotate along with the COLLIDER OBJECT (=2)!
See, this simply *cannot* work as you want it.


SUBROUTINES AND FUNCTIONS
Another concept you need to look at are so called "subroutines". They all have the structure:


Now, whenever in the MAIN LOOP of your program there is a line like "Gosub [Subroutine Name], the program JUMPS to the line of the code that is labelled with "[Subroutine Name]:" , executes whatever commands follow that until it hits the line with "return", which tells the program to RETURN to the point in the main loop where the subroutine was originally called. Complicated? I hope this example clears it up:


Notice how you have one subroutine called "LoadMap" (ca. line 80)? You never close this subroutine with a "return". Thus it contains EVERYTHING below the "LoadMap" Label, EVEN THE MAIN LOOP. Again, this is not a horrible mistake or anything, but it is really unclean coding and could lead to a bunch of bugs later on. Besides, the "LoadMap" Subroutine ISN'T EVEN NEEDED! You never call it anyway! (With a Gosub LoadMap). It is only executed, because the code goes through the lines from top to bottom, even if the code is nested into a subroutine.
Therefore it is also good practice to define Subroutines BELOW the main loop, so they are not executed when the game first starts (like in the example above).

In addition to subroutines, there are also so called "Fuctions". They work very similarly to subroutines, but there are a few differences.. I'm not the right person to explain that, though, and there are a bunch of threads discussing the advantages and disadvantages of both
One important point you have to remember however (and that's why I'm even bringing this up): Functions have to be "called" somewhere, in order to be executed!
See how you (or the fps-demo) define the functions "CheckCollision()" and "CheckFall()"? Note that you NEVER call the function "CheckCollision()". You would need a line "CheckCollision()" at some point in the main loop, so that the program actually CHECKS FOR COLLISION (and does whatever else is contained in that function, eg. camera control) in every frame.



COLLISION
Also, I believe the built in collision system of DBP has a pretty bad reputation.. best do a forum search on collision systems - Sparky's Collision .dll for example, is very good and relatively simple to use. But, again, it's NOT going to be simply a matter of copying code from a demo into your own game -- you can certainly do that but you will need to MAKE THE CODE FIT YOUR PROGRAM!


I'm sorry I could't really answer your question or get your code to work.. I might look at it tomorrow again if I have the time... Hope this was helpful in some way though... Too tired write anything sensible right now ... Anyways, my reccomendation right now would be:
Try to write code *yourself*, code which you 100% UNDERSTAND and know what every line does. Make an extremely simple program. Don't concern yourself with collision, guns, enemy ai... maybe just make a game where you walk around in First Person Mode (=moving the camera) on a simple plain. Then maybe add jumping! How would you go about that, for example? If you have that, and coded it yourself and know 100% how it works, it is a relatively small step to add features like collision, bullets and enemies. Look at other people's codes if you like, but really try to write something by yourself so that you really know every line and know exactly what it does and why you put it there...
If you have any questions about those starting steps I'd be happy to help (after I get some sleep though )
mihaid
14
Years of Service
User Offline
Joined: 24th Feb 2012
Location:
Posted: 18th Aug 2012 08:28
Hello,

I really want to thank you for your support, and I must admit you are right 100% in what you say.
I must confess I discovered dark basic 6 months ago, except the fact I learned the basic code language many years ago in the university. Yes, I must learn a lot in dark basic and what the code you seen is my first game, made by assembling a lot of codes, and making them to work together. I have the package "dark basic studio" and I supposed I will remember my acknowledges from university, but it's clear dark basic its much more then that. Still I really want to be a good programmer in dark basic because i like that very much. Anyway, even if I started like that, adapting codes which I found, I started to learn db, and to "understand" better how is functioning db.
Thank you again for your full support and I don't want to abuse to your patience , that's why I'll try not to buzz you so much.


Mihai
New World Order
21
Years of Service
User Offline
Joined: 31st Oct 2004
Location:
Posted: 18th Aug 2012 12:01
hey man, no worries you aren't abusing anyone's patience!
it's great that you discovered db and want to become a good programmer, that's why we are all here, and to help each other get there, right? ^^
I might have sounded a little impatient in that last post^^ sorry, wasn't intentional, was just tired

And I'm not saying don't look at or adapt code you find! It's probably the best way to see just how many possibilities there are to do something in db^^ But when you copy it, try to look up all the used commands in the help file ... And you'll be a good programmer in no time So do a forum search or otherwise just ask whatever is on your mind^^

Login to post a reply

Server time is: 2026-07-21 20:35:31
Your offset time is: 2026-07-21 20:35:31