C++ Progress ish

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: C++ Progress ish

Post by Yumtard » June 17th, 2017, 3:14 pm

Oh I saw that game on chilis update.
Looks dope! Well done

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

Re: C++ Progress ish

Post by chili » June 17th, 2017, 4:21 pm

ceofil wrote:What's the best way to aproch this kind of stuff? Try to do it on your own ( and probably spend a lot of time on it) or search and use a method that is already tested and it's more efficient and all?
Definitely search and research and find algorithms. Don't reinvent the wheel; it takes a lot of time and the results aren't gonna beat what humanity has already produced. You can learn some skills by implementing stuff like that from scratch, but researching and implementing existing algorithms is also a super important (probably more important) skill that needs to be exercised early and often. And also you wanna get shit done.
Chili

ceofil
Posts: 39
Joined: April 13th, 2017, 8:35 pm

Re: C++ Progress ish

Post by ceofil » June 20th, 2017, 5:50 pm

Where I'm at so far.
This is like a demo or something. Just added a bunch of enemies and some wall for a "playable" level.
I plan on adding a level editor like in the tanks game but now it will be saving and loading levels from files. Also change the AI to be a little more responsive for what's happening around. Probably change the graphics too.
Attachments
super hotline miami.rar
wasd to move, left click to shoot, slow motion if you don't move, r to restart
(2.34 MiB) Downloaded 182 times

ceofil
Posts: 39
Joined: April 13th, 2017, 8:35 pm

Re: C++ Progress ish

Post by ceofil » June 24th, 2017, 5:23 pm

Hi there!
Finished the level editor...kind of. Still have to figure out why when loading the level all the angles are set to 0. Also want to make it so you can load and save multiple levels and change the interface so it fits more levels.
There is already a level in there. load -> level editor -> implement to play it.

screenshot
github

Any feedback is appreciated.
Attachments
super hot.rar
(2.94 MiB) Downloaded 145 times

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: C++ Progress ish

Post by Zedtho » June 24th, 2017, 5:57 pm

Just a quick question, how far into the tutorials are you? That seems like some advanced stuff, and I'd like to help you with this , so wanted to know if I could.

ceofil
Posts: 39
Joined: April 13th, 2017, 8:35 pm

Re: C++ Progress ish

Post by ceofil » June 24th, 2017, 5:59 pm

The last tutorial I've watched is Intermediate 4.

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

Re: C++ Progress ish

Post by albinopapa » June 24th, 2017, 7:18 pm

Did you know?

instead of the slow length <= radius

Code: Select all

	for (int i = 0; i < nOtherBullets; i++)
	{
		if (otherBullets[i].IsSpawned())
		{
			if (Vec2(otherBullets[i].GetPosition() - pos).GetLength() <= radius )
			{
				alive = false;
				otherBullets[i].Destroy();
			}
		}
	}
You can check for LengthSq <= radiusSq

Code: Select all

	// Calculate square radius outside of loop to avoid recalculating each iteration.
	const auto radiusSq = radius * radius;
	for (int i = 0; i < nOtherBullets; i++)
	{
		if (otherBullets[i].IsSpawned())
		{
			if (Vec2(otherBullets[i].GetPosition() - pos).GetLengthSq() <= radiusSq )
			{
				alive = false;
				otherBullets[i].Destroy();
			}
		}
	}
This avoids having to do the square root each iteration of the loop.
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: C++ Progress ish

Post by albinopapa » June 24th, 2017, 7:26 pm

Instead of using hex codes for char keys, I would suggest using the literals; 'W', 'S', 'A', 'D'. The reason being it is way easier to tell at a glance those are the keys you are meant to push.

Code: Select all

	if (kbd.KeyIsPressed('W'))
	{
		delta.y = -1.0f;
		movementHappened = true;
	}
	else if (kbd.KeyIsPressed('S'))
	{
		delta.y = 1.0f;
		movementHappened = true;
	}
	if (kbd.KeyIsPressed('A'))
	{
		delta.x = -1.0f;
		movementHappened = true;
	}
	else if (kbd.KeyIsPressed('D'))
	{
		delta.x = 1.0f;
		movementHappened = true;
	}
This way, you or anyone else won't have to look up char codes to know which letter/number/symbol you are trying to use. If I got the order wrong or incorrect keys here, it's because I didn't want to look the hex codes up.

I like the code layout, it's pretty clean, keep up the good work.
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

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

Re: C++ Progress ish

Post by chili » July 1st, 2017, 5:01 am

Yeah, definitely use the char literals when you can.
Chili

ceofil
Posts: 39
Joined: April 13th, 2017, 8:35 pm

Re: C++ Progress ish

Post by ceofil » July 18th, 2017, 7:56 pm

Well, well, well...
What happened in the past few weeks? Not that much...at least for me.

Changed the level selection menu in the super hotline miami game.
Edit: found these http://imgur.com/a/G8eJu

Watched the old B19 tutorial for loading sprites but then I watched a few more. Nothing much, just tryna make it work. Added a little something something. Functions to make a sprite black&whie, threshhold, invert...just for fun. Maybe I'll use them later when a character dies draw him black and white, or when it takes damage draw it with threshhold.
Spoiler:

Code: Select all

	void Desaturate() 
	{
		int newValue = ( GetR() + GetG() + GetB() ) / 3;
		*this = Color(newValue, newValue, newValue);
	}
	void ThreshHold(int value)
	{
		assert( value >= 0 && value <= 255 );
		int average = (GetR() + GetG() + GetB()) / 3;
		if ( average < value )
		{
			*this = Color(0,0,0);
		}
		else
		{
			*this = Color(255,255,255);
		}
	}
	void Invert()
	{
		int r = 255 - GetR();
		int g = 255 - GetG();
		int b = 255 - GetB();
		*this = Color( r,g,b ); 
	}
And then do that for every pixel in the surface except the key.

Then continued with the old series ( B19 - I6 ). Great stuff. I4 was a very good watch even tho I might not have understood everything, it gives a pretty good idea about how things works.
Made the chaos game. It's still a very simple version of it with hard coded numbers and the points can't be moved.
Spoiler:
Image
Homework for current I6.

Good times, good times.

Post Reply