Noob learns to code in 3 months
Re: Noob learns to code in 3 months
Going through a bunch of code adding dt to stuff I noticed something that could be part of the issue. I was calling checkCollision() for boss state in the draw function instead of the update function
Edit yep this was obv it
Edit yep this was obv it
Re: Noob learns to code in 3 months
Boss is giving me a headache obv pretty challenging to make movement pattern for a boss with my very limited programming experience. Basically just making up logic as I go.
Using millions of bools and timers to get it done.
Feel like the game slightly lags sometimes, not sure if i'm just paranoid though.
Anyways, added another special attack and have rng to choose between the 2.
Here's the code for the attack
It gets called from Attack() which looks like this
Attack gets called from Move() here
Using millions of bools and timers to get it done.
Feel like the game slightly lags sometimes, not sure if i'm just paranoid though.
Anyways, added another special attack and have rng to choose between the 2.
Here's the code for the attack
Code: Select all
void Boss::BulletSpread(float dt, float playerPos)
{
Vec2 canonPos = pos + centerCanon;
if ((lightBallTimer += dt) >= fireLightball)
{
if (!hasPlayerPos)
{
if (playerPos <= GetCollisionRect().GetCenterX())
{
lightBallDir = -400.0f;
lightBallIncrement = 126.0f;
}
else
{
lightBallDir = 400.0f;
lightBallIncrement = -126.0f;
}
hasPlayerPos = true;
}
Vec2 dest = Vec2(lightBallDir, 600.0f);
Vec2 diff = centerCanon - dest;
diff *= 1.3f;
centerBulletM.FireBullet(canonPos, diff, bulletHalfWidth, bulletHalfHeight, bulletRectSize, bulletDmg, bulletPitch);
centerBulletM.ResetShotsFired();
lightBallTimer = 0.0f;
++lightBallCounter;
lightBallDir += lightBallIncrement;
}
if (lightBallCounter == 8)
{
lightBallCounter = 0;
lightBallTimer = 0.0f;
isAttacking = false;
lightBallDir = -400.0f;
specialAttackTimer = 0.0f;
choiceWasMade = false;
hasPlayerPos = false;
}
}
Code: Select all
void Boss::Attack(float dt, float playerPos, short choice)
{
switch (choice)
{
case 1:
Thrust(dt, playerPos);
break;
case 2:
BulletSpread(dt, playerPos);
break;
}
}
Code: Select all
if ((specialAttackTimer += dt) > specialAttack)
{
if (!choiceWasMade)
{
std::random_device rd;
std::mt19937 rng(rd());
std::uniform_int_distribution<short> Choice(1, 2);
AttackChoice = Choice(rng);
choiceWasMade = true;
}
isAttacking = true;
Attack(dt, playerPos, AttackChoice);
attackTimer = 0.0f;
}
Re: Noob learns to code in 3 months
Not creative enough to start working on another special attack. So will play around in ae and try to make a dope explosion for the end boss instead.
few ideas for special attacks though.
Homing missile
shoot black holes
....... dunno
think I want at least 3-4 special attacks
suggestions are welcome
few ideas for special attacks though.
Homing missile
shoot black holes
....... dunno
think I want at least 3-4 special attacks
suggestions are welcome
Re: Noob learns to code in 3 months
Dunzo with boss explosion. That's all I'm gonna have time for today. Might have gone a bit overboard with it lol, but think it'll look alrightish when I learn alpha blending
edit increase speed and thrust speed and decrease time betwen special attack as boss gets low on health.
edit increase speed and thrust speed and decrease time betwen special attack as boss gets low on health.
Re: Noob learns to code in 3 months
stepped away from the boss to take a look at the level. Now all of a sudden the game crashes when exiting black holes. No idea why
edit. wow I actually found the issue debugging. And it seems like it might have solved my issue from earlier with the game crashing in x86 release too!!!!
debugger said something like vector out of range, and since the crash happens when when calling my reverse function in animation I decided to take a look at it
well since the computer starts counting from 0 this wont work
12 frames = 0-11 and curframe would get set to 12.
Feels good finding the issue
edit. wow I actually found the issue debugging. And it seems like it might have solved my issue from earlier with the game crashing in x86 release too!!!!
debugger said something like vector out of range, and since the crash happens when when calling my reverse function in animation I decided to take a look at it
Code: Select all
if (!isReversed)
{
curFrame = frames.GetFrameCount();
isReversed = true;
}
12 frames = 0-11 and curframe would get set to 12.
Feels good finding the issue
Re: Noob learns to code in 3 months
Haha, congrats man. That feeling of finally figuring out the elusive bug... it's a high like no other
Chili
Re: Noob learns to code in 3 months
Felt it started getting confusing in the boss class with a bunch of different timers. So made a small class for timers.
And got to replace 10 variables with 5 timer objects.
Think it made the code a bit cleaner. Thought on this?
not sure I like the name "pause" though. Looks a bit weird as a bool
I suck at naming stuff
https://www.youtube.com/watch?v=MykoU2Uot9A
Code: Select all
#pragma once
class Timer
{
public:
Timer(float time);
bool Pause(float dt);
void Reset();
void SetWaitTime(float newTime);
private:
float timer = 0.0f;
float waitTime;
};
Code: Select all
#include "Timer.h"
Timer::Timer(float time)
:
waitTime(time)
{}
bool Timer::Pause(float dt)
{
return (timer += dt) >= waitTime;
}
void Timer::Reset()
{
timer = 0.0f;
}
void Timer::SetWaitTime(float newTime)
{
waitTime = newTime;
}
Think it made the code a bit cleaner. Thought on this?
not sure I like the name "pause" though. Looks a bit weird as a bool
Code: Select all
if (coolDownTimer.Pause(dt))
{
coolDown = false;
coolDownTimer.Reset();
}
For sure! This was literally me when I figured this outchili wrote:Haha, congrats man. That feeling of finally figuring out the elusive bug... it's a high like no other
https://www.youtube.com/watch?v=MykoU2Uot9A
Re: Noob learns to code in 3 months
sounds good man. A big part of refactoring your code is seeing places where you're repeating the same shit and making classes. I often start by adding functionality to an existing class, and then promoting that functionality to its own class when it grows beyond a certain point, or when I see that i am needing to replicated it.Yumtard wrote:
And got to replace 10 variables with 5 timer objects.
Think it made the code a bit cleaner. Thought on this?
Chili
- Battlefrog
- Posts: 69
- Joined: March 31st, 2015, 10:10 pm
- Location: Florida, United States of America
Re: Noob learns to code in 3 months
Great fourm post.Yumtard wrote:W
Joking aside, your progress is great. Cannot wait until a finished version is out
Broc W.
Sole Member of Sledgehog Software, trademark and LLC status pending.
Sole Member of Sledgehog Software, trademark and LLC status pending.