Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 2nd, 2017, 1:04 pm

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 :D

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 3rd, 2017, 2:24 am

Boss is giving me a headache :D 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

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;
	}
}
It gets called from Attack() which looks like this

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;
	}
}
Attack gets called from Move() here

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;
		}

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 3rd, 2017, 4:56 pm

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

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 3rd, 2017, 9:15 pm

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.

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 4th, 2017, 12:46 pm

W

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 4th, 2017, 12:46 pm

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

Code: Select all

if (!isReversed)
	{
		curFrame = frames.GetFrameCount();
		isReversed = true;
	}
well since the computer starts counting from 0 this wont work :D
12 frames = 0-11 and curframe would get set to 12.
Feels good finding the issue

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Noob learns to code in 3 months

Post by chili » March 4th, 2017, 3:53 pm

Haha, congrats man. That feeling of finally figuring out the elusive bug... it's a high like no other :D
Chili

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Noob learns to code in 3 months

Post by Yumtard » March 4th, 2017, 4:55 pm

Felt it started getting confusing in the boss class with a bunch of different timers. So made a small class for timers.

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;
}
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

Code: Select all

	if (coolDownTimer.Pause(dt))
			{
				coolDown = false;
				coolDownTimer.Reset();
			}
I suck at naming stuff
chili wrote:Haha, congrats man. That feeling of finally figuring out the elusive bug... it's a high like no other :D
For sure! This was literally me when I figured this out

https://www.youtube.com/watch?v=MykoU2Uot9A

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Noob learns to code in 3 months

Post by chili » March 5th, 2017, 10:20 am

Yumtard wrote:
And got to replace 10 variables with 5 timer objects.
Think it made the code a bit cleaner. Thought on this?
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.
Chili

User avatar
Battlefrog
Posts: 69
Joined: March 31st, 2015, 10:10 pm
Location: Florida, United States of America

Re: Noob learns to code in 3 months

Post by Battlefrog » March 5th, 2017, 5:23 pm

Yumtard wrote:W
Great fourm post.

;)

Joking aside, your progress is great. Cannot wait until a finished version is out :P
Broc W.

Sole Member of Sledgehog Software, trademark and LLC status pending.

Post Reply