adv lesson 10
adv lesson 10
(english is not my native language, so I apologize in advance for grammar errors and spelling )
Hey guys, I've been having fun trying to make games out of these tutorials and now I'm stuck. I was going to try and make a simple space shooter out of what we had after adv. lesson 10. And I ran into a wall when I tryed to make our litle space ship shoot projectiles. I think my problem is that I dont completely understand how the camera system(drawable and all that) works. I was kinda hoping someone here could help me out by rigging up a super simple shooting system so that I could see how it ties into all the other parts.
This is what I have tried so far:
made a bullet class to keep track of and update bullets.
ship now contains an array of bullets that gets added to if you press space.
tryed to draw the bullets in drawable that the ship implements.
update bullets in the ships update function.
to make it as simple as possiable I just made the bullets a circle.
here is my project also if you want to take a look. All help is appricated.
Hey guys, I've been having fun trying to make games out of these tutorials and now I'm stuck. I was going to try and make a simple space shooter out of what we had after adv. lesson 10. And I ran into a wall when I tryed to make our litle space ship shoot projectiles. I think my problem is that I dont completely understand how the camera system(drawable and all that) works. I was kinda hoping someone here could help me out by rigging up a super simple shooting system so that I could see how it ties into all the other parts.
This is what I have tried so far:
made a bullet class to keep track of and update bullets.
ship now contains an array of bullets that gets added to if you press space.
tryed to draw the bullets in drawable that the ship implements.
update bullets in the ships update function.
to make it as simple as possiable I just made the bullets a circle.
here is my project also if you want to take a look. All help is appricated.
- Attachments
-
- simple_space_game.zip
- I hope I didnt screw up in cleaning up the files
- (268.12 KiB) Downloaded 148 times
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: adv lesson 10
Well, would have been nicer for you to include what you had up to that point, with the bullet class.
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
Re: adv lesson 10
oh great so I did mess up and included the wtong project lol. Here is the right one. I'm sorry about that mix up.
- Attachments
-
- simple_space_game.zip
- (268.81 KiB) Downloaded 141 times
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: adv lesson 10
Bullets aren't traveling anywhere. When fired, you pass the ship's velocity to the bullet, but let's assume the ship isn't moving. The velocity passed would be 0.0f and your formula is speed * velocity, 0 * 10 = 0. What you need from the ship is the angle in which the ship is facing and multiply that by the speed, now you have velocity which is direction and length.
I'll keep looking and see if that's the only thing, but that should get the bullets moving anyway.
Update:
The second issue is the range based for loop that updates the bullets. It's creating a new instance of Bullet for each bullet in bullets vector, a copy. Instead, should be a reference to a bullet in bullets vector, like this.
That way, when position updates, it updates the position of the bullet x is referencing.
The first thing I told you about passing in the ship's angle, works...kind of.
Normally, cosine would go to X and sine would go with Y, however, the ship's original orientation is not correct for what the angle is initialized to. The ship points up, and angle is 0. Cosine of angle 0 is 1, and sine of 0 is 0. So, the bullet travels in the positive X direction, to the right. You can either switch them around and do sin for X and cos for Y instead, or rotate Vec2(cos(angle), sin(angle)).CCW90() upon initialization or use the Vec2(0.0f, -1.0f).Rotation(angle) function that chili uses for the ship.
Another issue I am running in to is even after doing that is you are using the ship's transformation matrix. I think this is causing issues, I'll keep looking.
I'll keep looking and see if that's the only thing, but that should get the bullets moving anyway.
Update:
The second issue is the range based for loop that updates the bullets. It's creating a new instance of Bullet for each bullet in bullets vector, a copy. Instead, should be a reference to a bullet in bullets vector, like this.
Code: Select all
for (Bullet &x : bullets)
{
x.UpdateBullet();
}
The first thing I told you about passing in the ship's angle, works...kind of.
Code: Select all
Bullet(float angle)
:
bulletVel(Vec2(cos(angle), sin(angle)))
{}
Another issue I am running in to is even after doing that is you are using the ship's transformation matrix. I think this is causing issues, I'll keep looking.
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
Re: adv lesson 10
wow thx for helping me with this all the stuff you said makes perfect sence to me and I also thought that using the ships transformation matrix might be the wrong thing to do but I didn't know of any other way to translate the position to screen coordinates. I'm going to go implement those changes and will report back if I get this to work properly. Thanks again for helping me you are awesome.
until next time
Update:
I think all I need now is a DrawCircleClipped() and handle the collisions
until next time
Update:
I think all I need now is a DrawCircleClipped() and handle the collisions
Last edited by hugecow on March 27th, 2015, 3:50 pm, edited 1 time in total.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: adv lesson 10
Hey, no problem. As far as the transformations, you might have to implement a Drawable subclass in Bullet, I'm having troubles understanding that part of the code, but perhaps you will figure it out.
Before I do that is.
Before I do that is.
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
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: adv lesson 10
The quickest and dirties way to get the transformed position from the ship, is this:
Vec2 tPos(trans.elements[0][2], trans.elements[1][2]);
gfx.DrawCircle(tPos + x.GetBulletPos(), x.GetSize(), parent.shieldColor);
I'm sure I'm having you do it the wrong way since it's not using the matrix transformations, but eh it works.
Of course the other issues are going to be clipping to screen and the ship's position will be updated thus causing the bullet to be drawn using the ship's new translated position. So yeah, still have to create bullet transformations...ok, disregard...
Vec2 tPos(trans.elements[0][2], trans.elements[1][2]);
gfx.DrawCircle(tPos + x.GetBulletPos(), x.GetSize(), parent.shieldColor);
I'm sure I'm having you do it the wrong way since it's not using the matrix transformations, but eh it works.
Of course the other issues are going to be clipping to screen and the ship's position will be updated thus causing the bullet to be drawn using the ship's new translated position. So yeah, still have to create bullet transformations...ok, disregard...
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
Re: adv lesson 10
Ok I was so excited to see something working that I went way ahead of my slef there hehe.
New problems(after doing some better tests ):
1. the bullets for some reason follow the rotaition of the ship, as in if you turn the ship you move the bullet also.
2. the rotation is of somehow. If you dont move the ship the bullet goes streight and everything is fine but if you turn the ship say 90 deg the bullet comes out as if you had turned the ship 180, it's like the rotation is doubleing somehow.
What I added:
updateBUllet now has delta time passed to it
the Bullet constructor is now like this
until next time
New problems(after doing some better tests ):
1. the bullets for some reason follow the rotaition of the ship, as in if you turn the ship you move the bullet also.
2. the rotation is of somehow. If you dont move the ship the bullet goes streight and everything is fine but if you turn the ship say 90 deg the bullet comes out as if you had turned the ship 180, it's like the rotation is doubleing somehow.
What I added:
updateBUllet now has delta time passed to it
Code: Select all
void UpdateBullet(float dt)
{
bulletPos += bulletVel * bulletSpeed * dt;
}
Code: Select all
Bullet(float angle)
:
bulletVel(Vec2{0.0f, -1.0f}.Rotation(angle))
{}
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: adv lesson 10
K, I think I got this one lol.
New drawable class in Bullet
New Bullet constructor:
New Bullet initializer:
New function added to Ship, to get the bullet vector:
Bullet draw calls, have to go through the cam, so had to go all the way back out to Game.cpp
Just need to figure out the clipping.
New drawable class in Bullet
Code: Select all
class Drawable : public ::Drawable
{
public:
Drawable(Bullet& parent)
:
parent(parent)
{
Transform(Mat3::Translation(parent.bulletPos));
}
virtual void Rasterize(D3DGraphics& gfx) const override
{
Vec2 tPos = trans * Vec2(0.0f, 0.0f);
gfx.DrawCircle(tPos, parent.GetSize(), parent.color);
}
private:
Bullet& parent;
};
Code: Select all
Bullet(Vec2 startPos, float angle)
:
bulletPos(startPos),
bulletVel(Vec2(sin(angle), -cos(angle)))
{}
// Added a color member to Bullet
D3DCOLOR color = GREEN;
Code: Select all
void Shoot()
{
bullets.push_back(Bullet(pos, angle));
}
Code: Select all
vector<Bullet> &GetBulletVector()
{
return bullets;
}
Code: Select all
std::vector<Bullet> &bullets(ship.GetBulletVector());
for (Bullet x : bullets)
{
cam.Draw(x.GetDrawable());
}
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
Re: adv lesson 10
Ok so I think I got this to work pretty well now.
What I did:
had the bullet class implement its own drawable class.
in compase frame we now get the bullets from the ship and render them using the bullets drawable object.
change the updateBullet function again to match chilis algorithm for updateing position and velocity.
added position to the Bullet constructor so as to start the bullets of from the ship.
I think that is all good now so I can begin work on the drawCliped stuff.
Let me know if you find some bugs in this and if you have any cool ideas for a drawCircleClipped function.
I was thinking to sjust get a working prototype that I would just stop rendering the circle as it reaches the border of the screen, and then later figuring out something cooler.
here is the updated project(hopefully the right one this time)
What I did:
had the bullet class implement its own drawable class.
in compase frame we now get the bullets from the ship and render them using the bullets drawable object.
change the updateBullet function again to match chilis algorithm for updateing position and velocity.
added position to the Bullet constructor so as to start the bullets of from the ship.
I think that is all good now so I can begin work on the drawCliped stuff.
Let me know if you find some bugs in this and if you have any cool ideas for a drawCircleClipped function.
I was thinking to sjust get a working prototype that I would just stop rendering the circle as it reaches the border of the screen, and then later figuring out something cooler.
here is the updated project(hopefully the right one this time)
- Attachments
-
- Simple_space_game_V1.1.zip
- (269.94 KiB) Downloaded 153 times