Noob learns to code in 3 months
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Noob learns to code in 3 months
Yeah, if you add a reference to Bullet, then the default copy constructor/assignment operator won't be able to work, because you can't reassign references. This limitation/restriction with references is usually why I have avoided storing references in classes.
I suppose another way to fix the issue is to declare it as static. Static in a class means that it will only ever produce that one instance, no matter how many instance of Bullet you create, they will all share the same reference.
I suppose another way to fix the issue is to declare it as static. Static in a class means that it will only ever produce that one instance, no matter how many instance of Bullet you create, they will all share the same reference.
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: Noob learns to code in 3 months
interesting! Thanks papa
Very happy with how my bullets turned out. They will need alpha blending too though since if they overlap with something you can see a rect around them
Edit: Not sure how necessary the animation for ships and small ships bullets was though, can barely see it
edit 2:
Might try to do something with the shield in after effects too. at least when I can do alpha blending
Very happy with how my bullets turned out. They will need alpha blending too though since if they overlap with something you can see a rect around them
Edit: Not sure how necessary the animation for ships and small ships bullets was though, can barely see it
edit 2:
Might try to do something with the shield in after effects too. at least when I can do alpha blending
Re: Noob learns to code in 3 months
Started adding a boss. Will take a bit more work than a normal enemy but think I'll have him done in a couple days
Re: Noob learns to code in 3 months
Yeah, references and const member basically preclude objects of a class from being handled with value semantics (fancy word meaning you can assign an existing object to another existing object). For a lot of entities that I make, I don't treat them in that way. You can't magically assign one ship object to another, each ship object is its own beast, cradle to grave, and keeping them separate like that helps. But certain other lightweight types might benefit from a simpler model of value semantics. Things like particles.
The alternative to references when you want to maintain a handle on another objects but still have assignment/move is the pointer. Coming somewhat soon to a tutorial near you
The alternative to references when you want to maintain a handle on another objects but still have assignment/move is the pointer. Coming somewhat soon to a tutorial near you
Chili
Re: Noob learns to code in 3 months
got it! I think :p
Noticed that if frame rate drops, then collision detection wont work as well. For example if I record the screen and a shoot the boss then the bullets mostly fly right over him.
Tried to decrease the time step but that messes up animations.
Also, couple things
Curious, Is there a way to make it possible to resize the screen?
Noticed if the game is playing and I start moving around the screen. Then the game isn't updating on screen but the song is still playing. Then when I release the screen the stars are all messed up :p Can I somehow detect when the player is moving around the screen and if so not update the game?
Noticed that if frame rate drops, then collision detection wont work as well. For example if I record the screen and a shoot the boss then the bullets mostly fly right over him.
Tried to decrease the time step but that messes up animations.
Also, couple things
Curious, Is there a way to make it possible to resize the screen?
Noticed if the game is playing and I start moving around the screen. Then the game isn't updating on screen but the song is still playing. Then when I release the screen the stars are all messed up :p Can I somehow detect when the player is moving around the screen and if so not update the game?
Re: Noob learns to code in 3 months
Boss might take a few more days longer to finish than expected. Making movement and attack pattern is turning out pretty tricky. Even though I don't need some fancy patterns it quickly becomes a mess with tons of bools and if else if
Re: Noob learns to code in 3 months
Had a few different ideas for the movement pattern. They all turned out trickier than expected so decided to settle for what I think will be the simplest option.
Basically the standard for the boss will be to just move side to side and shoot normal bullets, then after a certain time has elapsed (5 seconds for now) the boss will use rng to choose between a set of 3-4 special attacks.
So far I've added one of these special attacks (no rng yet). It works the way I wanted it too but I'm guessing the code is overcomplicated because it was pretty tricky and confusing.
The attack is called thrust. The ship drives forward until it reaches the end of the screen. Then it chooses left or right based on the players position and go that direction until it hits the end of the screen, then it goes back to a starting position.
in boss update I call move
Move(dt, playerPos);
in move if the boss is AliveState
thrust
bring back
Later I will replace thrust() with attack and in attack one of the special attacks like thrust will be chosen
Basically the standard for the boss will be to just move side to side and shoot normal bullets, then after a certain time has elapsed (5 seconds for now) the boss will use rng to choose between a set of 3-4 special attacks.
So far I've added one of these special attacks (no rng yet). It works the way I wanted it too but I'm guessing the code is overcomplicated because it was pretty tricky and confusing.
The attack is called thrust. The ship drives forward until it reaches the end of the screen. Then it chooses left or right based on the players position and go that direction until it hits the end of the screen, then it goes back to a starting position.
in boss update I call move
Move(dt, playerPos);
in move if the boss is AliveState
Code: Select all
if (state == AliveState)
{
if (!isAttacking)
{
pos.x -= vel.x * dt;
if (pos.x <= 0.0f || (pos.x + width) >= Graphics::ScreenWidth)
{
vel.x = -vel.x;
}
}
if ((specialAttackTimer += dt) > specialAttack)
{
isAttacking = true;
Thrust(dt, playerPos);
}
}
}
Code: Select all
void Boss::Thrust(float dt, float playerPos)
{
if (((pos.y + height) < Graphics::ScreenHeight) && !attackOver)
{
pos.y += thrustY * dt;
}
else if (!attackOver)
{
if (!hasPlayerPos)
{
if (playerPos <= pos.x)
{
thrustX = thrustLeft;
}
else
{
thrustX = thrustRight;
}
hasPlayerPos = true;
}
pos.x += thrustX * dt;
}
if (pos.x <= 0.0f || ((pos.x + width) >= Graphics::ScreenWidth) && !attackOver)
{
attackOver = true;
hasPlayerPos = false;
}
if (attackOver)
{
BringBack();
}
}
bring back
Code: Select all
void Boss::BringBack()
{
RectF bossRect = RectF(pos, width, height);
bossCenter = bossRect.GetCenter();
Vec2 diff = bossCenter - midPoint;
if (diff.GetLengthSq() > 5.0f)
{
diff.Normalize();
diff *= 3.5f;
pos -= diff;
}
else
{
attackOver = false;
isAttacking = false;
specialAttackTimer = 0.0f;
}
}
Re: Noob learns to code in 3 months
Added bullets for the boss (not special attack)
Already the feel of playing a boss is there imo a very easy one tho.
Sometimes when the boss is supposed to change direction, he starts vibrating for a second before doing so.
The code looks like this which seems fine imo
So I assume the problem is there's too big of a time step? Bit annoying
Already the feel of playing a boss is there imo a very easy one tho.
Sometimes when the boss is supposed to change direction, he starts vibrating for a second before doing so.
The code looks like this which seems fine imo
Code: Select all
if (!isAttacking)
{
pos.x -= vel.x * dt;
if (pos.x <= 0.0f || (pos.x + width) >= Graphics::ScreenWidth)
{
vel.x = -vel.x;
}
Re: Noob learns to code in 3 months
1) Yes. It will be a minor (major?) pita though.Yumtard wrote: Also, couple things
Curious, Is there a way to make it possible to resize the screen?
Noticed if the game is playing and I start moving around the screen. Then the game isn't updating on screen but the song is still playing. Then when I release the screen the stars are all messed up :p Can I somehow detect when the player is moving around the screen and if so not update the game?
2) what you can do is, move the timer into MainWindow, and then when you get a WM_ message for window moving, you can adjust the timer so that the time spent during the moving isn't counted as part of dt.
Chili
Re: Noob learns to code in 3 months
Decided to decrease timestep after all. Will try to go through the stuff that becomes too fast like animation and change it up a bit so it becomes normal again.
Annoying thing is after I decreased time step. First thing that happened is that a bullet flew right over the boss :p
I find it hard to figure out what the problem is when there's an issue that only happens sometimes.
Do not know if these will solve the issues but I'm making these changes and will hope for the bust
To stop the boss from sometimes getting stuck to the sides just vibrating I will reposition him before I change the direction of the velocity.
to stop bullets from sometimes missing I will add a normal rect for the boss to check collision with bullets. Right now I have 4 thin rects, one for each side to check for collision with the ship.
@chili so the dt, ftmark call would be inside of mainwindow? Or which timer to you mean?
Annoying thing is after I decreased time step. First thing that happened is that a bullet flew right over the boss :p
I find it hard to figure out what the problem is when there's an issue that only happens sometimes.
Do not know if these will solve the issues but I'm making these changes and will hope for the bust
To stop the boss from sometimes getting stuck to the sides just vibrating I will reposition him before I change the direction of the velocity.
to stop bullets from sometimes missing I will add a normal rect for the boss to check collision with bullets. Right now I have 4 thin rects, one for each side to check for collision with the ship.
@chili so the dt, ftmark call would be inside of mainwindow? Or which timer to you mean?