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 Discussion / Getting a box to shoot spheres in the direction the player specifies?

Author
Message
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 15th Sep 2004 10:19
Hi!

I am working on a game in which the point is to keep the enemy from overruning your position, you have a bunch of objects to help you out, one is going to be a machine gun nest. Now My plan was that the player would have two objects to work with, first would be the actuall machine gun nest, and the other would be its target, the player would place the machine gun, and then drag the target object to wherever the player wants the machine gun fire to be concentrated. I know how to select the objects and move them around fine, but I dont understand how Im going to get the machine gun nests to shoot bullets in the direction of the targets. Any suggestions?

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 15th Sep 2004 17:03 Edited at: 15th Sep 2004 17:04
eh.. if I understood your question right, I would use this:


if mouseclick()=1 and fire=0 then fire=1
if fire=1
point object bullet, targetx, targety, targetz
move object bullet, bullet_speed
show object bullet
endif
if object collision(bullet, target)>0
fire=0
target_got_hit = 1
endif
if fire=0
hide object bullet
position object bullet, playerx, playery, playerz
endif


dont know if it works, and dont know if this is what you asked for..
hope I helped


I am not cool anymore... or am I?
http://n0id.proboards28.com/index.cgi - please join
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 16th Sep 2004 06:09 Edited at: 16th Sep 2004 13:19
Hello Major Payn..

After recently reading your post i decided to write up some basics for you

I've added it to the codebase so anyone can use it, it can be found here: http://www.thegamecreators.com/?m=codebase_view&i=d9ec182d634510ea5ec562870f59d1e8

But incase your in a hurry i'll add it as a code snippet here.. Hope it helps.. By the way, i've noticed some mistakes in the code i will change soon, so it's best you check the codebase every now and then for revisions.



Hope it helps.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 16th Sep 2004 07:22
Thanks! But there seems to have been a little missunderstanding, you see I dont want the player to have to press anything to get the box to fire, I want it to just start constantly firing a steady stream of bullets at a specific object, and if that object is moved it will still fire at it.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 16th Sep 2004 12:55
Well, based on the code above it's pretty simple to adapt it to do that, play around with it and i'm sure you'll get it working

If after some attempts you cant get it working, i'll post newly updated code for it.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 16th Sep 2004 13:03
Is there any way I can just use existing objects I have? I have 5 cubes, and each cube has another cube which is its target, I can move both cubes fine, I want it so that the first set of cubes will shoot bullets at its specific target cube, so for example I have a green machine gun nest, I take it and move it where I want it, and then I move the smaller green target cuber where I want it, and the bullets will shoot from the machine gun nest to that target. Here is the code I have so far....




My code doesnt have the target cubes yet, but the Big blue cubes are the machine guns.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 16th Sep 2004 13:07 Edited at: 16th Sep 2004 13:20
Heh, right before you posted i finished up what i -think- your trying to do, atleast partly.. try this out..



- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 16th Sep 2004 13:14 Edited at: 16th Sep 2004 13:15
Oh, i think i know what your trying to do now.. Basically the code i just gave you can be adapated to do exactly what you want.

You have 5 cubes(blue blocks-machine guns) which shoot bullets(which arent in yet), at a target which you can place.

So you place the machine gun object at the top left of the screen and place the target at the bottom right, and the bullet will still end up in that place.

[edit]

In my code, think of object 2 as being the target, if you move that somewhere else, the bullet will still follow it. The same goes if you move the cube around.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 17th Sep 2004 07:13
I get an unrcognized paremeters on the move object parts. Also, how could I get the bullets emplemented? Sorry, I have had DB for like a year and Im still a totall newbie to it.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 17th Sep 2004 07:45
You tried my code that i just posted and it doesnt work..

Hmm.. If this is true, then i guess it's because i'm using dbp and your using dbc, i was hoping it could convert right over..

Did any of the code i've shown in this forum work? First, or second? Because both use the same commands, but maybe i made a typo somewhere..

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 17th Sep 2004 08:39
None of the code snippets work, it gives me unrecognized paremeter at the lines containing the move object commands.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 17th Sep 2004 09:41 Edited at: 17th Sep 2004 09:41
Sorry about not answering very quickly.. i just edited the code and it should now work with dbc..

Note: the rem'd statements are the dbp commands, i left them in there just in case Either way, the new method works with dbp aswell.



- Merix
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 17th Sep 2004 11:01
Major Payn, as I said before I think you'll have to do a little re-ordering of your object numbers in the program, but the code presented is essentially correct. For the re-ordering I'd suggest "doublets" of machine gun nests and their associated target object, such as;

gun# -- target#
1 2
3 4
5 6

and so on. That way, once the player positions the nest the target location should be automatically selected for positioning, and that target is where the gun shoots.

Now, as for bullet code...

Well first, you have to make the bullets themselves and hide them so they aren't active. Then when it comes times for the bullet to fire, it places itself at the gun location, points to the target object, unhides itselfs and begins moving towards the target. When it hits anything, it vanishes, taking along with it the enemy if that was hit.

Now, to keep any single gun from firing all of the bullets, use an array to store whether or not that gun is shooting. This way, you can, by adjusting the value of the number of bullets fired by any gun, allow say "up to five" active bullets from any single gun at one time. (Makes the result more interesting that way...)

Anyway, that's my two cents here... good luck and keeping playing with it.
s.

Any truly great code should be indisguishable from magic.
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 17th Sep 2004 11:30 Edited at: 17th Sep 2004 11:31
I get an unrecognized command at the global commands. I can not test it right now, but will Noids idea work? It seems very simple, and I understand his code completely.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 17th Sep 2004 12:31
Yup, should work similarily to my code.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 18th Sep 2004 10:27
I got problems, I tried to use n0ids code to do the bullets, and I get a couple of erros, for some reason it keeps saying "no such array enitialized" at the bullet section of my code which I will enclude here...


for b=1000 to 1020
for t=202 to 203
for m=200 to 201
if fire=1
point object b,x(t),y(t),z(t)
move object b, 1
endif
if object collision(b,t)>0
fire=0
endif
if fire=0
hide object b
position object b,x(m),y(m),z(m)
endif
next b
next t
next m


there is is, the errors seem to be coming from the "x(),y(),Z()" section of the the code. Im sure an experienced DB coder can figure out whats wrong with my stupid mistakes

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 18th Sep 2004 13:39


Should be reffering to what you want the object your talking about to point at which object..

In any case, it should be


I believe that should help a little.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 18th Sep 2004 13:43
Doh! I knew I was doing something incredibly stupid. Thanks, I will try that!

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 18th Sep 2004 13:48
No problem

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 18th Sep 2004 14:05 Edited at: 18th Sep 2004 14:09
Ok! I got it working (kind of) the problem is that the bullet is not very "machine gun" like, its seems more like a single shot rifle now lol, I want it to be a constant spray of bullets in the direction of the target, now another problem, is that after reaching the target the bullet does not re-locate to the machine gun nest anymore, and thus just stops, here is what I go so far...



and this is the bullet code for quick reference....



Another thing I found stange, is that the newly created machine gun nest seems to duplicate when I click to drag it, I think its just that two were created somhow, but I dont see where or how, sense I only commanded one cube to be made.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 18th Sep 2004 15:34 Edited at: 18th Sep 2004 15:40
I fixed the machine gun part a bit.. havent fixed the extra box however.. here's the updated firing.



[Edit]... i think i found out what's making that extra machine gun nest... will update once i fixed it.

Got it.. i think this is what you want



- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 18th Sep 2004 15:47 Edited at: 18th Sep 2004 15:53
After you try it, tell me if that's what your looking for.. Regardless if it is or isnt, i'm headin to bed for the night after i find out from you, i'm tired as hades.

[edit] Heh, screw it.. i'm going to bed.. will check here tomorrow morning.

Also, if you want a streaming line of bullets you'll have to add in more objects for the bullets.. then do exactly the same thing you have for yours.. but make a check for example..

Send 5 moving bullets down the screen, check that they're still on the screen, if only 4 for example are on the screen then shoot another one etc.

Hope the new code i gave ya helped

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 01:16
Well, i'm up again.. did the new code suit your fancy?

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 02:12
Dang Merix, I cant thank you enough, you have been a lifesaver, at first I though "this project is going to die away like all the others" but now I actually think I can make it work, in fact I only need to empliment a little more collision, a few more objects, and will have a early alpha to play with. Thanks Merix!

By the way, how did you get rid of the duplicating box? Because I need to do the same thing with the target object.

Thanks

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 02:40 Edited at: 19th Sep 2004 02:45
Glad it's working the way you wanted..

Well i made some minor changes to your normal code.. the first problem was this...



The problem was you made a for loop of m to create the machine gun nest. Instead m should've been a solid number of 200.

Thus the code should be this.


You can see that i changed it so there is only one gun turret now.. Now because i changed it this way i had to go down to everywhere you had a for loop with an m, and take it out.. you dont even need to add anything considering m is already = to 200.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 02:44
Ok, thanks, I didnt notice that.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 02:46
Give me a few minutes to fix the target, having a couple difficulties as it seems to be slightly different of a problem(but mostly the same)

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 02:49 Edited at: 19th Sep 2004 02:53
Ok, got it.. i think. Try it out and tell me if it's how ya wanted it.



The changes for the target were as followed...


Changed to


And later on in the code changed this part..


To this...


- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 03:05
Thanks! but Im having a bit of a confusing problem with the collision. I want it so that that wave 1 and 2 will die if they touch the target object of the machine gun, but looking at the collision part, I dont understand how to do such.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 03:12 Edited at: 19th Sep 2004 03:17
I'm sorry... could you please explain just a little more..

When the waves come, and hit the machine target you want them to die?, or the machine nest or the bullets?

[Edit] Be back in a bit, eating lunch

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 03:38
Ok, back.. see you havent posted yet, i'll just wait till then.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 03:42
Sorry, I was off watching TV, anyway, I have a bit of a design desision to make, at first I was going to make it so that if the waves of enemys hits the machine gun target object, they die. This was because I believed that if the bullets killed them, the player could simply move the machine gun nest to one corner, and the target to the other, thus making the game extremely easy to win. So I want the enemys to die, if they hit the target object.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 03:50
Ok... but as the code is right now.. you cant move the target object right.. i just want to make sure we're talking about the same block.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 03:53 Edited at: 19th Sep 2004 03:54
I got the target object movin, here is my code.....

Im talking about the block that the bullets move toward.



I just need the target object to kill the enemys now. By the way, do you think the bullets should kill the enemys, or will that make the game to easy?

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 03:58
Well.. you could make the game slightly different and have quadrants set up with various tasks..

For example.. the bottom right quadrant would have it's own wave, where you can only use the machine gunes bullets to take out the objects. Then the top right quadrant you need to use blocks etc.. something like that? I dunno, but your right.. as of what's appearing right now the bullets taking out the blocks would make it too easy.. Gimme a minute or two to try and fix the code for the object collision of that target.

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 04:02


I think that's what your lookin for.

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 04:04
Also, based on your last post..

I think with the bullets working.. you should have the whole part of the bottom section of the screen sending up the enemies.

That way you have to spread the gun, and you also have to put your boxes down strategically.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 04:45
My whole idea revolved around stradegy, I wanted the machine gun to have only a limited zone in which it could kill(the target box) that way the player would have to create choke points on the beach, so that the enemys would be forced into a killing zone. I still have a few things to add, including concrete barriers that force the enemys to move around them, I had an idea to create a little bit of pathfinding.....

`lets say that t is the concrete barriers
for e=100 to 150
for t=204 to 208
if object collision(e,t)>0
Position object e, object position x(e)+1, object position y(e), object position z(e)
next e
next t

wouldnt that make the enemy object move over 1 place if its colliding with an object, thus going around it? And how could I randomize it, so that the enemy could go either left or right randomly?

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 04:56
Yup, that appears to be exactly what it would do.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 05:57
I tried it, and its not working Here is my code....



The enemys dont move around the barriers, instead they simply collide and dissapear.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 06:21 Edited at: 19th Sep 2004 06:25
Yeah, i ran it and i get the same problem.. well, most of the time.. sometimes they do slide around it.. I'll take a look right now at the code.

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 06:39 Edited at: 19th Sep 2004 06:41
I havent been able to figure out yet what's causing it to happen..

[edit] I think part of the problem is the fact that for some reason, if two reds collide they destroy one another.

- Merix
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 07:12
I havent quite been able to figure it out.. this one may a) be past me, or b) right in front of me and i cant see it.

I'll keep overlooking the code when i get my chances, but i've also been programming a game so my time is a tad limited.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 07:52
Thanks!

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
Dot Merix
21
Years of Service
User Offline
Joined: 15th Oct 2003
Location: Canada
Posted: 19th Sep 2004 10:38
I'm sorry Major Payn.. i just cant seem to figure it out.. My guess it has something to do with you declaring the objects as collision boxes.. I know in dbp you dont need to do that.. as soon as you create an object, you can use the OBJECT COLLISION () on any object you've made.

- Merix
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 19th Sep 2004 10:55
No need to apologize, you have done to much to do that! Thanks for the support. I will figure this out eventually, might take a new post, but Ill figure it out

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 20th Sep 2004 09:37
Major,
Can you post your code again please? Two reds should never wipe each other out, unless you've changed the way you're making detections. What I gave ya does it "by the numbers" and reds were not tested against each other, so I'd like to see what you've done thusfar.
S.

Any truly great code should be indisguishable from magic.
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 20th Sep 2004 09:40
Here is the code....



I also have all this posted, and a detailed description of what is supposed to happen, in my new thread titled "help collision is all screwed up!".

The problem started when I added my little pathfinding function.

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 20th Sep 2004 09:59
Yeah, I just caught the other thread and grabbed a copy of the code, will look at it in a few minutes and see what's what. I really am beginning to suspect some kind of an error in the object collision(x,y) code that's causing you this problem, such that I'd suggest re-writing to use object collision(x,0) = n and then testing what n is. It would appear, at least on the surface, that trying to run more than one (x,y) collision gives this problem, as though DBC isn't doing the test of Y being the object hit on each pass. I'll look it over and see what results I get and get back to you...
S.

Any truly great code should be indisguishable from magic.
Major Payn
21
Years of Service
User Offline
Joined: 16th Dec 2003
Location: United States of America
Posted: 20th Sep 2004 10:23
Awsome, thanks!

Guns arnt the problem, people are the problems, shoot all the people and guns arnt a problems anymore.

Login to post a reply

Server time is: 2025-05-24 20:11:35
Your offset time is: 2025-05-24 20:11:35