Noob learns to code in 3 months

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

Noob learns to code in 3 months

Post by Yumtard » January 26th, 2017, 2:46 am

Hey guys!

First of all, if this forum is not intended to be used this way please feel free to delete this thread :)

About me
26 years old. Plays poker for a living, enjoys bjj, mma and skateboarding

Why A journal?
I just started programming, well, I've done some superbasic shit before like helloWorld() etc but nothing with games.
I need to improve as much as I can fairly fast.
In 3.5 months I'm supposed to show some game projects in order to try and get accepted to a school for game programming.
I thought it would be a good idea to make a thread where I can post progress, what I've been working on in order to improve and maybe get some feedback.

Why programming?
I've found programming intriguing for a long time but never felt like I had the time to get balls deep in it.
I've been saying stuff like "when I'm no longer playing poker I'm gonna learn programming". Well, for a while now I've been wanting to step away from poker and get an education, recently I found out that my gf is pregnant which made me decide that now is the time.

Goals
I want to get to a level where I understand and am able to apply all the concepts taught in tutorial 14 (snek game) and make games of similar complexity on my own.
And I want to have something not too retarded to show in 3.5 months

Today
Watched the tutorials for the snek game and went into monkey see monkey do mode. Tons of stuff I didn't understand.
Afterwards I decided that rather than moving on to the next thing, best thing is probably to try and add stuff to the snek game, this way I get to mess around with the code and eventually some stuff might start making more sense.
First task was to add the obstacles.

Image

Aaaaaaaaand After 3 hours of confusion, fails, copy pasta of older functions and general button clicking I made it work the way I wanted it to. The code is prob a train wreck but it works :D
next on the list:
1. add counter for score
2. Make it so you don't die if you try to move backwards
3. Add special goals that show up for limited time and give a higher score
4. Restart the game

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 » January 26th, 2017, 4:14 am

Dude, this thread already looks golden. 3.5 months is a reasonable goal to make a neat little portfolio piece that will get people's attention... IF you dedicate more than just a few hours a week to it. The beginner tutorials are gonna give you a solid grounding in C++ and basics graphics / game concepts. When you get past a certain point, I'm gonna guide you switching over to SFML for making your portfolio piece(s).

First things first: 2 suggestions

1) Do tutorial 15 right now. It's gonna teach you nothing about C++ or programming. It will give you tools to better organize your code and collaborate. It will enable you to better...

2) Share your code! I wanna see what crazy shit you crap out, and others will too. Once you learn about Git, and git into using it, sharing your code will be easy as motherficking Euler's number.
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 » January 26th, 2017, 2:01 pm

Having issues today. Realized that while the obstacles wont spawn on top of the goal, the goal may spawn on top of the obstacles. I've messed around with it for an hour or so but can't figure out how to solve this one.
chili wrote:Dude, this thread already looks golden. 3.5 months is a reasonable goal to make a neat little portfolio piece that will get people's attention... IF you dedicate more than just a few hours a week to it. The beginner tutorials are gonna give you a solid grounding in C++ and basics graphics / game concepts. When you get past a certain point, I'm gonna guide you switching over to SFML for making your portfolio piece(s).

First things first: 2 suggestions

1) Do tutorial 15 right now. It's gonna teach you nothing about C++ or programming. It will give you tools to better organize your code and collaborate. It will enable you to better...

2) Share your code! I wanna see what crazy shit you crap out, and others will too. Once you learn about Git, and git into using it, sharing your code will be easy as motherficking Euler's number.
Awesome! What is SFML and why is it better for portfolio pieces?
Would you recommend after I've gone throught the beginners series to maybe go throught the old beginners series and the intermediate series?

Alright tutorial 15 is next thing on the menu then I'll post my current snek mess and see if I can get some help with the issue of goals spawning on top of obstacles.

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 » January 26th, 2017, 2:53 pm

You need some code that says:

// Pseudo code
make a random number for X
make a random number for Y
while random X and Y are equal to any obstacle's X and Y
make a new random number for X
make a new random number for Y

I'm pretty sure chili has covered arrays by the time the Snek game, so the obstacle X and Y referred to in the pseudo code would be each obstacle in your obstacle array if that is the route you went.
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 » January 26th, 2017, 3:31 pm

^ thanks :)

After flexing the brain mucles for another hour or so I THINK I manged to solve the issue in not very neat looking way :D

Code: Select all

const bool eating = next == goal.GetLocation();
				if (eating)
				{
					snake.Grow();					
					bool isOverlapping = false;
					goal.Respawn(rng, brd, snake);
					do
					{
						for (int i = 0; i < nObstacles; i++)
						{
							isOverlapping = isOverlapping && obstacles[i].GetLocation() == goal.GetLocation();
							if (isOverlapping)
							{
								goal.Respawn(rng, brd, snake);
								break;
							}
						}
					} while (isOverlapping);
				}
So basically it respawns the goal then loops through the obstacle array. if the location of goal is equal to the location of the obstacle then isOverlapping will change to true. And if it changes to true then the goal will respawn to a new location and break out of the for loop.
Since isOverlapping is now true the do while loop will repeat and check if the new location of goal is also colliding with any of the obstacles. If it isn't then happy days, move along.

Think this should work but again, I'm sure there's more neat ways to get this done :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 » January 26th, 2017, 3:54 pm


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 » January 26th, 2017, 7:04 pm

Code: Select all

const bool eating = ( next == goal.GetLocation() );
if (eating)
{
	snake.Grow();
	bool isOverlapping = false;
	do
	{
		goal.Respawn(rng, brd, snake);
		for (int i = 0; i < nObstacles; i++)
		{
			isOverlapping = isOverlapping && ( obstacles[i].GetLocation() == goal.GetLocation() );
			if (isOverlapping)
			{
				break;
			}
		}
	} while (isOverlapping);
}
Moving the goal.Respawn call inside the 'do' loop is the only change I would have made. Since the do loop does at least one iteration before checking the condition, you can move the respawn function inside the loop and don't need it in the for loop.

Because of order of operations in C++, you don't need parentheses around your comparisons, but it might make it a little clearer and avoid misunderstandings later on if you used them, just a personal opinion though.

For isntance,
isOverlapping = isOverlapping && obstacles.GetLocation() == goal.GetLocation();
does the compiler evaluate isOverlapping && obstacles.GetLocation() first? OR
does the compiler evaluate obstacles.GetLocation() == goal.GetLocation() first?

I believe in this instance, it evaluates isOverlapping first and if it is false, the rest doesn't even matter, it just returns false and doesn't evaluate the ==.
If the operator&& was overloaded like the operator== has been, then it would evaluate both sides before determining true or false.

Just some food for thought, I want to say it's been awhile, but I have had unexpected results from not knowing in which order the conditions were evaluated.
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 » January 27th, 2017, 12:24 am

Today

So here's what I did too improve today

1. Fucked around with snek game until I came up with a way to solve
the issue of the goal spawning on top of obstacles

2. watched the tutorial on github. Understood the gist of it but will
take some practice getting used to for sure. A couple things were
unclear to me.
If I make a branch and work in it until that branch is better than
the master branch, do I now somehow promote my new branch to master?
can I make tons of branches which are all different games starting
from an empty chili framework and branch out into a bunch of games
from that one?

Tried doing the homework. Got to the point of having cloned the repo
but wasn't able to figure out how to run it.

Then I watched episode 16, finally a whole episode where everything
made sense to me!
Image

alright then on to homework. Let's see what we gotz here.
I'll need the radius, then just make a function like the
DrawSquare function but add an if statement and if the point
I'm trying to draw is too far away from the radius then it wont get
drawn.
Image

90 minutes later I've managed to come up with over 9000 ways to
write the same thing, drawing a square each time
Image

BUT WAIT! Chili left a hint about pythagoras which is a^2 + b^2 = c^2
so let's see what we can do....triangles...cirlces .... mathz....
Spoiler:
Image
So ended up cheating in the end and watched the solution.
Safe to say I wouldn't have gotten there on my own
albinopapa wrote:

Code: Select all

const bool eating = ( next == goal.GetLocation() );
if (eating)
{
	snake.Grow();
	bool isOverlapping = false;
	do
	{
		goal.Respawn(rng, brd, snake);
		for (int i = 0; i < nObstacles; i++)
		{
			isOverlapping = isOverlapping && ( obstacles[i].GetLocation() == goal.GetLocation() );
			if (isOverlapping)
			{
				break;
			}
		}
	} while (isOverlapping);
}
Moving the goal.Respawn call inside the 'do' loop is the only change I would have made. Since the do loop does at least one iteration before checking the condition, you can move the respawn function inside the loop and don't need it in the for loop.

Because of order of operations in C++, you don't need parentheses around your comparisons, but it might make it a little clearer and avoid misunderstandings later on if you used them, just a personal opinion though.

For isntance,
isOverlapping = isOverlapping && obstacles.GetLocation() == goal.GetLocation();
does the compiler evaluate isOverlapping && obstacles.GetLocation() first? OR
does the compiler evaluate obstacles.GetLocation() == goal.GetLocation() first?

I believe in this instance, it evaluates isOverlapping first and if it is false, the rest doesn't even matter, it just returns false and doesn't evaluate the ==.
If the operator&& was overloaded like the operator== has been, then it would evaluate both sides before determining true or false.

Just some food for thought, I want to say it's been awhile, but I have had unexpected results from not knowing in which order the conditions were evaluated.


Thanks for the help :) Order of operation seems like a mindfuck

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 » January 27th, 2017, 12:50 am

On a brighter note the explanation in the homework made complete sense and I don't think I'll forget how to draw circles. Also I quickly figured out a way to draw the donut.

Image

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 » January 27th, 2017, 5:41 pm

Today I took a break from tutorials and tried to make a dumb game on my own.
The code feels like a hot mess and I've spent many confusing hours of buttonclicking.

I cannot figure out how to make my ship shoot bullets the way I want it to.
Right now the bullets are connected to the ships position so if the ship moves to the left so does the bullet even though it's already been fired and I'd like it to continue straight.
I also can't figure out how to make it so the bullet continues all the way of screen without the playet having to hold down space bar. Just one click on the space bar should fire of a bullet and not have it disappear when the player let's go of space bar.

Would be happy to get some input on how to get this done and/or input on anything that looks dumb
https://github.com/Yumtard/Spaceballs

Post Reply