Jump to content
  • Advertisement
Sign in to follow this  
caldiar

Unity 2D Projectiles Continued

This topic is 4667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

well.. didn't think about the break but that makes sense now. I tried that and I have a new bug.

Shoot one bullet. It hits end screen. I can shoot a new bullet. Shoot new bullet in opposite direction and the original bullet comes back in the same direction as new bullet.

Shoot another bullet. All bullets stop. Shoot another bullet in any direction and ALL bullets follow that direction.

Odd stuff. But i like that I have some progress and the game doesn't crash now lol =)

Share this post


Link to post
Share on other sites
Advertisement
well alright here's the deal.

The Sprite class handles initiating the image used to represent the object. It controls size, speed, movement units etc... that kind of thing.

The Bullet Struct handles creating multiple instances of the one bullet sprite instance and assigning damage, life, and individual direction of travel.

The linked list is what is keeping track of what bullet is which and if its active or not. It's easier to use a linked list for my multiple bullets since I can easily detatch from one bullet and start working with a new one by saying this_bullet = this_bullet->next
and delete the old bullet by going this_bullet->previous->dead = true;

however... deleting a bullet isn't actually working at the moment......

Share this post


Link to post
Share on other sites
WOOT!

Guess what? I now have working bullets! =D
Only 20 can be shot at a time. Tested. That works.
Bullets delete when off-screen. Tested. That works.
Bullets are free to be reshot after being deleted. Tested. Works.

One problem that shouldn't be too hard to fix - one way bullet. Only moves right not left. Ill just grab the players facing direction when firing the bullet to determine which direction it moves in.

Again, WOOT!

Share this post


Link to post
Share on other sites
I put together a pretty interesting particle system in C# known as SdlDotNet.Particles. Although you won't be able to use it (you're using C++), you can apply the concepts introduced in the system. It's built using particles, emitters, and manipulators. The emitters shoot out particles and the manipulators change the particles somehow. It's a very nice system to use and you could easily implement the concepts presented in it into your system.

Share this post


Link to post
Share on other sites
Thank you very much! =)

This looks very interesting and Ill be taking a closer look at it when I get back home and have some more time on my hands.

Currently the bullets work I just need to add some collision detection which wont be too hard to do. Once I get a working demo ready for people to download Ill start focusing on optimizing the code.

Thanks again!

~Caldiar~

Share this post


Link to post
Share on other sites
Gotta be kidding me.....

got bullets working right but I have an extremely weird bug that I can't pinpoit in the code... the players now move up and down rather than left and right. Bullets move up and down rather than left and right. It's almost as if... the x value of the movement is being swapped with the y value so any changes to x is actually affecting y. This makes no sense however since the bullet code I added can be seen here:


void NewBullet()
{
for(int i=0;i<BULLETS;i++){
if(bdraw==0){
Bullet.set(mario.getx()+0, mario.gety()+0);
bdraw = 1;
if(face_right==1){
Bullet.bface_right = true;
}
else{
Bullet.bface_right = false;
}
return;
}
}
}

void RenderBullet()
{
for(int i=0;i<BULLETS;i++){
if(bdraw == 1){
Bullet.draw();
}
}
}

void UpdateBullet()
{
for (int i=0;i<BULLETS;i++){
if(bdraw == 1){
Bullet.updateBG();
}
}
}

for(int i=0;i<BULLETS;i++){
UpdateBullet();
if(bdraw == 1){
if(Bullet.bface_right == true){
Bullet.xadd(2);
}
if(Bullet.bface_right == false){
Bullet.xadd(-2);
}
if(Bullet.getx()>640){
bdraw = 0;
}
}
}

for (int i=0;i<BULLETS;i++){
Bullet.init(&bulletbase,screen);
Bullet.setSpeed(2.0);
}



note that the movement is just temporary to get a working demo out there.

Share this post


Link to post
Share on other sites
*sighs*

Well, finally fixed it. Don't know how really... just copied the clean source into the folder where the files being tested were held... worked fine.

No direction control now though =\ Ill try adding that and see if that damn bug pops its ugly head up. If not Ill move on to collision detection and then A DEMO! whoohoo!

Share this post


Link to post
Share on other sites
seems I've found the problem.

Here's the code I added that came up with the same exact bug.


bool b_dir;

if(face_right == 1){
bullets.b_dir = true;
}
else{
bullets.b_dir = false;
}

.......

if(bullets.b_dir == true){
bullets.xadd(2)
}
else{
bullets.xadd(-2)
}




yep. that's it. I have no idea why it's doing what its doing but I know that if I remove that code its fixed. So Im removing that chunk of code. =P

EDIT: um... oddly the problem still stands even after removing the code that spawned the bug. what the hell.....

[Edited by - caldiar on May 12, 2006 12:30:02 AM]

Share this post


Link to post
Share on other sites
Bullets work great.

Added collision detection just now and decided to just make a new bullet when a bullet hit player 2. Works great. I shot 20 bullets at the character then turned around to see those same bullets suddenly pop up from player 1 as if they were being shot again into the opposite direction. I got a kick out of that =)

Just need to add life to player 1 and 2 and give player 2 a fire function and Ill have a small working demo ready for download! I'm so close I can smell it. No... wait... that's the coffee Im brewing.

Share this post


Link to post
Share on other sites
and an alpha demo is released! Read about it here
http://www.gamedev.net/community/forums/topic.asp?topic_id=392730

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!