Noob learns to code in 3 months

The Partridge Family were neither partridges nor a family. Discuss.
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 » June 20th, 2017, 5:45 am

Chili

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 » June 20th, 2017, 10:51 am

funny you mentioned qix btw. Never heard of Qix, but Volfied was on my list of games to maybe cover :)

https://www.youtube.com/watch?v=H4xWmdaApoY
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 » June 20th, 2017, 12:11 pm

Thanks guys!
I'm liking codingame. Signed up and will use for extra practice when I'm bored :)

Is qix the same as xonix? Seems to be many similar versions. I've actually never played it or heard of it either. A friend from the poker world asked me to try making it because it used to be his favorite game.

never heard of volfied either but looks dope :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 » June 20th, 2017, 3:10 pm

Almost done with xonix, but wanted to make everything smaller. This makes the grid 80 by 60 instead of 40 by 30 and I get stack overflow. I think there's too much recursion for the drop function.
The game works in release but not in debug

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 » June 20th, 2017, 8:21 pm

Phew, today didn't go quite as planned.
Ended up coding in xonix a lot more than planned.
Ran into problems here and there but really wanted to finish the game.

I'm not 100% happy with everything in the code, but the game is pretty similar to the original now so I'm still kinda pleased and am gonna call it a game and be done with it now :)

Have some stuff to do tomorrow and my brain could use some rest, so probably taking to whole day off from programming. Then returning to tutorials on thursday.

Here's the finished game if you wanna try and play it. Branch: shipithollaballa
https://github.com/Yumtard/xonix/tree/shipithollaballa

There's a tiny bug that makes the outside enemy sometimes stick to the black field instead of bouncing off, not sure why. If anyone has an idea I'd like to hear it. It's one of the few things I'd consider working more on if i could figure out the issue :p

Code: Select all

void OutsideEnemy::Move(Board::Type(&grid)[60][80], float dt)
{
	x += vx * dt;
	const int right = int(x) + size;
	if (grid[int(y) / size][int(x) / size] == Board::Type::empty ||
		grid[int(y) / size][right / size] == Board::Type::empty ||
		x < 0 || right > Graphics::ScreenWidth)
	{
		x -= vx * dt; //Thought I took care of the issue by adding this
		vx = -vx;
		x += vx * dt;
	}
	y += vy * dt;
	const int bottom = int(y) + size;
	if (grid[int(y) / size][int(x) / size] == Board::Type::empty ||
		grid[bottom / size][int(x) / size] == Board::Type::empty ||
		y < 0 || bottom > Graphics::ScreenHeight)
	{
		y -= vy * dt;
		vy = -vy;
		y += vy * dt;
	}
}
here's the code that makes it bounce


edit: actually that line miiiight have taken care of it.... not sure anymore lol

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

Re: Noob learns to code in 3 months

Post by albinopapa » June 21st, 2017, 7:35 am

Hey Yumtard, I got bored and decided to check out your balls. :)

Nah, I really did get bored and wanted to mess around with polymorphism some and I chose your project to do so. It works for the most part. There are some areas I'm not sure why it acts different, but I changed so much of the code.

I know you said you were done with the project, but I figure why not share it with you and see what you think. The game is exactly the same, but handled differently. Instead of switch statements using Game::State enums, I created some GameState derived classes that handle each state as the switch statement would have.

Might have to change the SDK and Build versions to Win8.1 and v140, but should build fine in VS2015. I edited it in VS2017.
Attachments
polymorphism.zip
(5.89 MiB) Downloaded 133 times
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
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 » June 21st, 2017, 10:41 am

This is great :D Thanks

First of all I really like the idea of putting your files into a game folder in the project. Not having to look for your h files is great.

I also like get tile type and set tile type, passing board as reference to enemy move function. Because passign that 2d array was one of the things with the game I wasn't happy with.

Code: Select all

const auto ix = static_cast< int >( x );
		const auto iy = static_cast< int >( y );
		const auto curTileX = ix / TileSize;
		const auto curTileY = iy / TileSize;
		const auto nextTileX = curTileX + 1;

		if( Brd.GetTileType( curTileX, curTileY ) == Board::Type::filled ||
			Brd.GetTileType( nextTileX, curTileY ) == Board::Type::filled )

This part was cool too.

When I got to the polymorphism I got a bit more confuzzled though.
Mainly because in GamStateManager I see an include for GameState but I can't find the file for GameState anywhere. Same thing with PlayingState. I can see it on include list but can't find the h file.

Will look into this code morre tomorow since today was supposed to be a day off :)
Thanks Albinipapa!

Btw, what parts act different than they do in my version?
The only thing I've noticed is that your version starts in game over while mine starts in newgame



I might change my study plan a little bit. Was planning on going through the book while waiting for more intermediate videos once I reach the latest one.
but I think instead I will watch slide fucker series and after that try and build a minesweeper solver.

Then read the book/watch 3d fundamentals as the last thing I do this summer

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

Re: Noob learns to code in 3 months

Post by albinopapa » June 21st, 2017, 7:05 pm

Ah, maybe that's where I messed up. I started with PlayingState, but because the tile you start in is labeled tail, you get a game over immediately. I'll have to switch to the NewLevel for the beginning and see how that turns out.

The GameState.h/cpp, PlayingState.h/cpp, GameOver.h/cpp and NewLevel.h/cpp files should be under the States filter.

I prefer the easy path, so instead of passing an array with that god awful signature make some utility functions and pass a reference to the class object, glad you liked it.

As stated, the game plays exactly like yours, the difference is instead of having switch/case statements in Game::UpdateModel AND Game::ComposeFrame to determine which state you're in, each State class handles all the code for that state. I'd think it's more efficient since it doesn't have to use the switch statements and just processes the code for that state. There is less repetition in the code, no multiple switch statements to write. I'd like to say it also makes the code cleaner and makes it easier to debug, but honestly sometimes it can make it harder to debug. Egizz has a project that uses a lot of polymorphism in his UI code. It's a nightmare to debug because you can't know which type you are dealing with without drilling down in the Locals window and looking up each type. I think that's more because in his case, the objects aren't executing code, but just storing different values. At least with this approach, if there is an error, it's in the state class and not in some manager that just gets data from that state.
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: Noob learns to code in 3 months

Post by albinopapa » June 21st, 2017, 7:12 pm

Code: Select all

      const auto ix = static_cast< int >( x );
      const auto iy = static_cast< int >( y );
      const auto curTileX = ix / TileSize;
      const auto curTileY = iy / TileSize;
      const auto nextTileX = curTileX + 1;

      if( Brd.GetTileType( curTileX, curTileY ) == Board::Type::filled ||
         Brd.GetTileType( nextTileX, curTileY ) == Board::Type::filled )
The reason I did the ix and iy is to remove redundant casts and made it reduce the number of division operations. Sometimes though, this can have the opposite effect of making things slower. The curTileX and curTileY divisions can be done at the same time or pipelined at least, but the nextTileX has to wait for the curTileX to be calculated before it can be calculated so reducing the number of divisions may be slower in this case because the CPU has to fully complete a task before moving on to the next. The way you had it, may have been faster as the CPU wouldn't have to wait for one calculation to end before starting the next. I just like seeing less repetitious code, so it's more of a readability thing for me.

EDIT: Same thing with the ix, iy. The curTileX and curTileY have to wait for ix and iy to exist before they can be calculated, so again, may not be the best approach.

In case you are wondering look up pipelining. Almost all CPUs use it to be as fast as possible. The idea is to stagger out the stages ( load, process, store, etc...) so there is less wasted CPU cycles. There are way more stages than just those three, but that's the gist of it.
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
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 » June 22nd, 2017, 2:34 pm

Study update

Rewatched part 3. Didn't code along with the video. Instead I wanted to just take minimal notes and see if afterwards I was able to do the red, print and str2int functions on my own.
I was! but it was still fresh in my memory. Might try to do them tomorrow too. This was the only notes I took while watching

//print with const char*
//read input from user until he hits return (13), char* buf
//Str2Int, const char*
//scan to start point

Now I'm gonna move on to the home work and see if I do better than the first time

Post Reply