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.

2D All the way! / New to Dark Basic and need advice

Author
Message
Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 8th Jul 2004 11:37
This is in regards to the tutorial found here:
http://forum.thegamecreators.com/?m=forum_view&t=27598&b=4
I posted in that thread, but also posted it here to increase exposure.

Hi there, I'm new to posting so I hope I've done this right. Actually I'm new to DarkBasic, and have only been trying to learn it for 5 days now. I have put my version of this tutorial below. I was hoping to get some advice on how I can correct the following problems:

1. After making modifications to the original code, my sprite based collision detection is no longer functioning and I have no idea why or how to fix it.

2. The actual fire weapons method I have setup, seems to be cumbersome, with jumping from Playerfire to Shoot, for basically a very similar function. Any thoughts on the proper way to address this?

3.I had the hardest time figuring out how to get this program(the original to loop), while I think I have it looping well now, I'd like to know the best way to do so, as I'm really trying to learn as much as I can.

Thank you for your help!

Nathan

Hello.
Goodbye.
Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 9th Jul 2004 23:09
Wow, don't everybody reply at once or anything like that.

Thought help from this community would be faster than this, but I guess I was wrong on that. If any of you viewing this thread need clarification of what I'm asking, or any extra info in order to help me, please ask. I'm new to this, so just ask or say whatever, it's a learning process for me. Thank you!

Hello.
Goodbye.
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 10th Jul 2004 08:51 Edited at: 10th Jul 2004 08:53
hey xatnys

1. In the function blowup() try replacing

with


The reason i think this is not working is, the bullet is travelling very fast and not impacting against the side of the player's ship, but more neer to the middle of the players ship; and since Sprite Hit() only checks to see if a sprite is touching another sprite (not whether its colliding with the middle of it), the command is "not working".

2. I'm not sure what sure what your hoping to achieve with your weapons system could you elaborate on it? Also there is no point having the function Playerfire(), because you have the shoot function in your main loop, so you should delete it.

Quote: "3.I had the hardest time figuring out how to get this program(the original to loop), while I think I have it looping well now, I'd like to know the best way to do so, as I'm really trying to learn as much as I can."


3. Not really sure what you mean here, but if your looking for a general guide on how a program should be set up then follow this guide.



Also to break up your code into readable bits you should use lots of gosub's, function's, and spaces between chuncks of code.

Also in the future state whether your using DBpro, DBC - from your code i think your using DBC.

Please post back and i'll try and help you more
pizzaman
Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 11th Jul 2004 01:50
Hi there Pizzaman,

Thanks for the advice. I really appreciate your time and help. I gave the If sprite collision() idea a try, and it didn't work, well that's not exactly true, let me explain a bit better:


Ok basically, I can get the "game" up and running, player position is fine, enemy position is fine, controls are responsive etc. I also am able to press the "Z" button and get my laser to fire, travel across the screen to the enemy ship, and collide, running my explosion sequence.

The problem is that this only happens once. After that, the game loops, but collision detection no longer works, nor does the shooting of the laser.

After that first loop occurs, you must hold down the "fire" button in order to get the laser image to move across the screen. What's more, when the lazer does finally get over to the enemy sprite, it passes right over, with no collision detection present whatsoever. I've tried all that my limited understanding of this could think of, but to no avail.

I believe it has to do with *where* the program loops to after the initial run through. What I mean is that I believe that after I have the program shoot, and detect the impact of the laser, it then is in the blowup sub, and for whatever reason, it's unable to make use of some parts of the program(proper shooting routine and updating of the laser sprite / enemy sprite collision detection).

If I could overcome this hurdle, I can move on to implementing my ideas for minor A.I., score keeping, powerups, etc. But It will be useless until I figure this out.

I'm sure it's something very basic, hope you can see what I'm missing.

Xatnys
Updated code included, so you can see the recent changes.

Hello.
Goodbye.
Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 11th Jul 2004 01:58
Oh also,

You can go here:

http://www.cybcity.com/dolphinsoft/html/untitled2.html

[href]

And get all related media files, just in case you want to plug it all in to see what all is going on.

Thanks again for the help!

Hello.
Goodbye.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Jul 2004 02:31 Edited at: 11th Jul 2004 02:32
I think your problem is with you not setting LX and LY in front of the ship in your main loop.


Shoot:
If pf=1
sprite 2,lx,ly,4
Play Sound 1
lx=lx+10
endif
pf=0
gosub moveall
return

Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 11th Jul 2004 03:05
Pincho,

Hi, thanks for your help. Interesting thought, let me see if I follow you.

Do you mean to put Sprite 2,lx,ly,4 (Sprite 2's positional update) in front of Sprite 1,ysx,ysy,1 (my ship's positional update)?
example:

Sprite 2,lx,ly,4
Sprite 1,ysx,ysy,1


If I do that, then the green laser is constantly updated on the screen, so I don't think that'll work. But maybe I'm missing re-updating it somewhere, and that's why it doesn't fire right?



Or did you mean to define the values of lx and ly before my ship's values?
example:
lx= Sprite x(1)+20
ly= Sprite y(1)+10

I tried to put that right above the updating of my ship in the main loop. Example:

lx= Sprite x(1)+20
ly= Sprite y(1)+10
Sprite 1,ysx,ysy,1

But then my "fire" button "Z" became totally unresponsive.


Those are the only 2 options I can see as far as putting the laser info ahead of my ship's, but I'm really new to this, so I'm sure I could be missing something.

Let me know what ya think, if anyone has any other thoughts or ideas related to it, feel free to jump on in.

Thanks for your time and help with this, it's truly appreciated.

Xatnys

Hello.
Goodbye.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Jul 2004 03:19
I meant, do it when you press fire, then ignore the fire button until the laser has collided.

Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 11th Jul 2004 04:00
Pincho,

Ok I'm not sure I follow still, I put this in:

If pf=1
lx=lx+10
sprite 2,lx,ly,4
sprite 1,ysx,ysy,1
Play Sound 1
endif

But I'm unsure how to ignore the fire button until a collision occurs. It sounds like a really good idea, any tips?

Thanks again!
Xatnys


Updated code again with a scorekeeper.

Hello.
Goodbye.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Jul 2004 04:07
Something like this.......

If scancode()=44 and Sprite Exist(2)=0 then Gosub shoot : pf=1

Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 11th Jul 2004 04:29
Pincho

Put that in, still fires the first shot perfect, second will only move across the screen as you hold fire down. No collision detection on the second shot either. But you got me looking at the whole picture, and I noticed that when the second shot got >640, it didn't reset for a third shot. So what if the error isn't so much in the fire routine, but in the moveall: movement routine? Here it is:


MoveAll:
If Sprite Exist(2)=1
If Sprite X(2)<640
lx=lx+10
sprite 2,lx,ly,4
endif
endif

If Sprite Exist(2)=1
If Sprite X(2)>640 and pf=0
delete sprite 2
lx=Sprite x(1)+20
ly=Sprite y(1)+10
endif
endif
return


Let me know what you think, thank you.

Xatnys

Hello.
Goodbye.
Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 11th Jul 2004 04:41 Edited at: 11th Jul 2004 04:42
Actually you should use <= instead of <. That might fix it.

Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 11th Jul 2004 04:59
Pincho,

Nope still not working properly. I just can't pinpoint where the problem is with the code. I think it has to do with the laser being redrawn too fast per shot, maybe.

The strangest part is that it goes through the code just fine once, and then stops working after the loop. I've looked at the sub routine over and over: Blowup: it's the one that loops the program back, unless the loop is messed up somewhere, I'm at a loss.

Here's that subroutine:

Blowup:

delete sprite 2
lx=sprite x(1) +20
ly=Sprite y(1) +10
play sound 2
for t=6 to 11
sprite 3,500,200,t
wait 1
next t
delete sprite 3

sprite 1,ysx,ysy,1
sprite 3,500,200,2
Sprite 9999,10,10,9999
return

But remember that after the first shot, collision detection doesn't work, if that means anything specific.


Any thoughts greatly appreciated!

Xatnys

Hello.
Goodbye.
pizzaman
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location: Gateshead, UK
Posted: 12th Jul 2004 04:13 Edited at: 12th Jul 2004 04:43
hey Xatnys

i tryed to fix your code; i sorted one problem and another came - just typical . Then I saw that the problem was a bug with the delete sprite command, for some reason if you delete the sprite it turns off its collision when you make it again and so i had hide the sprite instead of deleting it. However, it was just to hard for me to get used to your coding style (not many comments, very short variable names, structure of the code not the way i like it - which is my problem admittitly); therefore i dedecided to recode your code (and i did it quickly to ).

The only thing i would like you to do is compare the code with your original code, see where it differs and how works; then you'll know next time how to solve a similar problem and even help someone else with a similar problem .

Heres the code



Also you might want to do the eplosion routine a different way, as currently your game stops when it activates - maybe you could put images in a free animator and get an animation in an .avi file or gif if DBC supports them; or even make your own animation routine to display the correct image for the sprite at the correct time or whatever.

If you need anymore help just ask the forums again, also just wondering; are you going to make this into a big game, or are you just doing this to test your skills to see what works and what doesn't.

pizzaman
Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 12th Jul 2004 10:29 Edited at: 12th Jul 2004 10:35
Pizzaman,

Hey there. I don't know how to thank you for the recoding, I'm going ot study it, and see if I can use your code as a template for my code, that way I can really build on your method, as I'm so new to this I don't really have a method . Yeah, I plan on making the shooter into about 10 levels, with at least 3 "Bosses", power-ups, and minor enemy A.I. . I figure it'll teach me a lot if I can pull it off, maybe even if I can't. At the same time, yes, it is a "stress test" to see my bounds in DBC, and to get a feel for syntax and structure.

I'll look into that animation routine, that really sounds like a good way to go.

Also on another note: While that project has been in limbo, I decided to go to codebase and get a 2D Pong and spice it up a bit. I've added it's "AI" routine, not much but it works, some sound effects, a system of levels, and increasing difficulty each level. I'll attach the code in case anyone cares to look it over, for critique or whatnot.



Want to make a background for it, change the paddles to something better(texture them or something), maybe refine the A.I. if it's in my ability, but it was really good for [learning] some things.


Thanks for all the help and all your time spent on this, I'll be working on it later this evening. *crosses fingers*

Xatnys

Hello.
Goodbye.
Xatnys
20
Years of Service
User Offline
Joined: 8th Jul 2004
Location:
Posted: 12th Jul 2004 10:42
Wow, gotta say, you're code is very orderly and organized well, I'll try to implement the same structure in my work!

Xatnys

Hello.
Goodbye.

Login to post a reply

Server time is: 2025-05-15 15:41:29
Your offset time is: 2025-05-15 15:41:29