Need source code from Beginner Game Programming Ep. 6

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Jeyes
Posts: 1
Joined: September 21st, 2018, 2:57 pm

Need source code from Beginner Game Programming Ep. 6

Post by Jeyes » September 21st, 2018, 3:06 pm

So I got lost in the programming videos and cant seem to find my way back. I tried copying the code from the videos but it's hard to read. This is specifically the Game.cpp file I'm talking about. What I have now is:

Code: Select all

#include "MainWindow.h"
#include "Game.h"

Game::Game( MainWindow& wnd )
	:
	wnd( wnd ),
	gfx( wnd )
{
}

void Game::Go()
{
	gfx.BeginFrame();	
	UpdateModel();
	ComposeFrame();
	gfx.EndFrame();
}

void Game::UpdateModel()
{
	bool condNull = true;
	if (wnd.kbd.KeyIsPressed(VK_UP)) 
	{
		if (inhibitUp)
		{
		}
		else
		{
			vy = vy -1;
			inhibitUp = true;
		}
	}
	else
	{
		inhibitUp = false;
	}


	if (wnd.kbd.KeyIsPressed(VK_DOWN)) 
	{
		if (inhibitDown)
		{
		}
		else
		{
			vy = vy +1;
			inhibitDown = true;
		}
	}
	else
	{
		inhibitDown = false;
	}

	if (wnd.kbd.KeyIsPressed(VK_LEFT)) 
	{
		if (inhibitLeft)
		{
		}
		else
		{
			vx = vx -1;
			inhibitLeft = true;
		}
	}
	else
	{
		inhibitLeft = false;
	}

	if (wnd.kbd.KeyIsPressed(VK_RIGHT)) 
	{
		if (inhibitRight)
		{
		}
		else
		{
			vx = vx +1;
			inhibitRight = true;
		}
	}
	else
	{
		inhibitRight = false;
	}

	x = x + vx;
	y = y + vy;

	if (x + 10 >= gfx.ScreenWidth)
	{
		x = gfx.ScreenWidth - 10;
		vx = 0;
	}
	if (x - 10 < 0)
	{
		x = 10;
		vx = 0;
	}
	if (y + 10 >= gfx.ScreenHeight)
	{
		y = gfx.ScreenHeight - 10;
		vy = 0;
	}
	if (y - 10 < 0)
	{
		y =  10;
		vy = 0;
	}

	
	x(x > 200)
	{
	if (x < 300)
	{
	}
	}

	if (wnd.kbd.KeyIsPressed(VK_CONTROL)) {
		g = 0;
		b = 0;
	}
	else
	{
		g = 255;
		b = 255;
	}

	shapeIsChanged = wnd.kbd.KeyIsPressed(VK_SHIFT);
}

void Game::ComposeFrame()
{
	const int r_fixed = 0;
	const int g_fixed = 255;
	const int b_fixed = 0;

	gfx.PutPixel(-5 + x_fixed, -5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-5 + x_fixed, -4 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-5 + x_fixed, -3 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-4 + x_fixed, -5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-3 + x_fixed, -5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-5 + x_fixed, 5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-5 + x_fixed, 4 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-5 + x_fixed, 3 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-4 + x_fixed, 5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(-3 + x_fixed, 5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(5 + x_fixed, -5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(5 + x_fixed, -4 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(5 + x_fixed, -3 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(4 + x_fixed, -5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(3 + x_fixed, -5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(5 + x_fixed, 5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(5 + x_fixed, 4 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(5 + x_fixed, 3 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(4 + x_fixed, 5 + y_fixed, r_fixed, g_fixed, b_fixed);
	gfx.PutPixel(3 + x_fixed, 5 + y_fixed, r_fixed, g_fixed, b_fixed);

	if (colliding)
	{
		r_mobile = 255;
		g_mobile = 0;
		b_mobile = 0;
	}
	else
	{
		r_mobile = 255;
		g_mobile = 255;
		b_mobile = 255;
	}



	}
	gfx.PutPixel( -5 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -5 + x_mobile,  -4 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -5 + x_mobile,  -3 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -4 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -3 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -5 + x_mobile,   5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -5 + x_mobile,   4 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -5 + x_mobile,   3 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -4 + x_mobile,   5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel( -3 + x_mobile,   5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  5 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  5 + x_mobile,  -4 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  5 + x_mobile,  -3 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  4 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  3 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  5 + x_mobile,   5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  5 + x_mobile,   4 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  5 + x_mobile,   3 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  4 + x_mobile,   5 + y_mobile, r_mobile, g_mobile, b_mobile);
	gfx.PutPixel(  3 + x_mobile,   5 + y_mobile, r_mobile, g_mobile, b_mobile);
}
As you can see I tried copying a bit from the video but that's when I got lost

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

Re: Need source code from Beginner Game Programming Ep. 6

Post by albinopapa » September 22nd, 2018, 9:43 am

looks like you have an extra curly brace there...

Code: Select all

...

   }
   gfx.PutPixel( -5 + x_mobile,  -5 + y_mobile, r_mobile, g_mobile, b_mobile);
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

Post Reply