adv lesson 10

The Partridge Family were neither partridges nor a family. Discuss.
hugecow
Posts: 41
Joined: November 25th, 2013, 3:36 am

Re: adv lesson 10

Post by hugecow » March 27th, 2015, 5:00 pm

Great minds think alike I would say :D

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: adv lesson 10

Post by albinopapa » March 27th, 2015, 5:01 pm

lol, must have updated around the same time.

I agree.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

hugecow
Posts: 41
Joined: November 25th, 2013, 3:36 am

Re: adv lesson 10

Post by hugecow » March 28th, 2015, 8:45 pm

Hello again! I have a new problem :) I'm trying to get the collison to work and not getting anywhere,
I thought it was just going to be super simple because all the implementation is all there I just have to call it.

What I've done so far:
I made a super simple DrawCircleClip function that works fine.
Bullet inherits from collidablecircle and implements all the function from it.
I call the collision function on the map in the UpdateModel function like this

Code: Select all

	for (Bullet &x : ship.GetBullets())
	{
 		map.HandleCollision(x);
	}
I thought for sure this was going to work but my "bullets" just pass trough the walls all the same.
Do you have any ideas?

all help welcome I'll include my project in case someone wants to look at it.
Attachments
Simple_space_game_v1.1.zip
(270.02 KiB) Downloaded 101 times

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: adv lesson 10

Post by albinopapa » March 29th, 2015, 6:50 pm

Ok, so my initial findings is that calculating velocity by angle every frame isn't going to work. The rebound changes velocity, but then the velocity is recalculated by angle, which is still in the direction before the collision.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: adv lesson 10

Post by albinopapa » March 30th, 2015, 1:20 am

Ok, so found your second problem. The GetBullets() function, returns a copy of the vector instead of a reference to the vector of bullets.

Needs to be like this:

Code: Select all

	vector<Bullet> &GetBullets()
	{
		return bullets;
	}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

hugecow
Posts: 41
Joined: November 25th, 2013, 3:36 am

Re: adv lesson 10

Post by hugecow » March 30th, 2015, 4:06 am

AWESOME!! thank you man! the damn refrence vs copy always gets me, one of these days I'll remember to but "&" there hahaha.

what I did:
I calculated the velocity sepret from the update funtion and then just added the velocity to the posistion in the update function.
And of course put the damn refrence operator on the getbullets function like you said and it works beautifully.

I can shoot out all the little bubbles I want and it doesn't even lag. This is awesome.
Next on the agenda is I think figuring out the collision with the ship. It looks simple when I think about it in my head but I'll prebubly be back here asking for help again in no time.

Again thank you so much for the help. Until next time :)
(if someone wants to try and take this on and do something with it just leave a replay here and I'll post my project here for you guys to have fun with)

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: adv lesson 10

Post by albinopapa » March 30th, 2015, 4:36 am

Something I don't know if you have implemented, is deleting the bullets. Erasing the vector elements can be as simple as bullets.erase(iterator); where iterator is the offset from the beginning of the vector. Also, there is another way that is more efficient if you don't need the order of the vector to be preserved.

Since erasing an element in the beginning of the list causes all the elements to be copied down, element[1] get copied to element[0] and so on to the end of the vector, it's more efficient to just copy the last element of the list to the spot you want to erase, then erase the last element in the list. That way there is only one copy and one erase instead of 1 erase and several copies.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply