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 / airplane minigame problem

Author
Message
boymonkey 130
18
Years of Service
User Offline
Joined: 16th Oct 2005
Location:
Posted: 1st Dec 2005 05:36
This is the first time me and a friend programmed realy anything in darkbasic, so it's really simple.(He has since gotte much, much better) but one thing I've never been able to figure out is shooting. I've never really gotten it to work right. I've looked at the tutorial games, but haven't been able to quite understand it.

I want the shot to appear where the ship is, fly forward a little, then dissapear after a while(for now). But it's just telling me object already exists, and I can't get it to work.
RalphY
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: 404 (UK)
Posted: 1st Dec 2005 14:12 Edited at: 1st Dec 2005 14:25
You need to think through what happens each time you go through the loop, it often helps you find problems if you try running through your code on paper.

In this case once the mouse has been clicked and the bullet has been created you have the first problem, that the bullet wont appear to move as each time the loop executes your repositioning the bullet at the players location.
Quote: "position object a, object position X(1), object position Y(1), Object position Z(1)"

This can be solved by changing the if statment where you create the bullet.


However there is still the problem, that each time the loop executes its going to try and move the bullet, what if you haven't clicked the mouse? There wont be a bullet to move. This can be solved by first checking that the object your trying to move exists. (There is also the problem that you increased a so a no longer corresponds to your bullet, see final code for a possible soloution to that).


You also need to keep track of the objects you have created, Once you have created one bullet your incrementing a so it no longer coresponds to the first bullet. How you do this depends on how you want shooting to work and how you are managing objects you create. One way is to say that from a set number (for example 2) up, there will be no other objects except bullets created. This way you can keep track each time you create a bullet of how many you have and then loop through them moving them each frame. The final code would be somthing like:


[EDIT] Cripes, hope i've edited out all the mistakes now, I seem to be having a bad day - For having the bullet disappear after a while you could simply have it delete the object once its moved a set amount.

Hope this helps.
Train04
18
Years of Service
User Offline
Joined: 14th Nov 2005
Location:
Posted: 1st Dec 2005 20:35
his a example just put in your object numbers.

any good

(=:
boymonkey 130
18
Years of Service
User Offline
Joined: 16th Oct 2005
Location:
Posted: 1st Dec 2005 21:27
thank you, that helps alot. ^_^

Login to post a reply

Server time is: 2024-09-24 09:30:13
Your offset time is: 2024-09-24 09:30:13