Updated game new features: two structures; 1. immobile and other mobile 2. Change of color when collide

in #programming6 years ago

Program

 A program is set of instruction given by user to computer to perform a specific task.computer program, in depth intend or else process in lieu of solving a riddle by means of a computer; supplementary specifically, an unambiguous, well thought-out string of computational advice indispensable near attain such a solution.    

Program Body

#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()
{
	ctrl = false;
	if (wnd.kbd.KeyIsPressed(VK_UP)) {
		if (iup) {

		}
		else {
			vy = vy - 1;
			iup = true;
		}
	}
	else {
		iup = false;
	}	if (wnd.kbd.KeyIsPressed(VK_DOWN)) {
		if (idown) {

		}
		else {
			vy = vy + 1;
			idown = true;
		}
	} else{
		idown = false;
}
	if (wnd.kbd.KeyIsPressed(VK_LEFT)) {
		if (ileft) {

		}
		else {
			vx = vx - 1;
			ileft = true;
		}
	}
	else {
		ileft = false;
	}
if (wnd.kbd.KeyIsPressed(VK_RIGHT)) {
		if (iright) {

		}
		else {
			vx = vx + 1;
			iright = true;
		}
	}
	else {
		iright = false;
	}
	shift = wnd.kbd.KeyIsPressed(VK_SHIFT);
	x = x + vx;
	y = y + vy;
	if (x + 10  >= gfx.ScreenWidth) {
		x = gfx.ScreenWidth - 11;
		vx = 0;
	}
	if (x - 10 < 0) {
		x = 11;
		vx = 0;
	}
	if (y + 10 > gfx.ScreenHeight) {
		y = gfx.ScreenHeight - 11;
		vy = 0;
	}
	if (y - 10 < 0) {
		y = 11;
		vy = 0;
	}
	if (x > 300) {
		if (x < 400) {
			ctrl = true;
		}
	}
	const int xl = x - 4;
	const int xr = x + 4;
	const int yu = y - 4;
	const int yd = y + 4;
	const int x1l = x1 - 3;
	const int x1r = x1 + 3;
	const int y1u = y1 - 4;
	const int y1d = y1 + 4;
	if (xl<x1r&&
		xr>x1l&&
		yu<y1d&&
		yd>y1u
		) {
		colide = true;
	}
	else {
		colide = false;
	}
	if (colide) {
		color = 100;
	}
	else  {
		color = 500;
	}
};


void Game::ComposeFrame()
{
	gfx.PutPixel(x1,     y1, 0, 500, 600);
	gfx.PutPixel(x1 + 1, y1, 0, 500, 600);
	gfx.PutPixel(x1 + 2, y1, 0, 500, 600);
	gfx.PutPixel(x1 + 3, y1, 0, 500, 600);
	gfx.PutPixel(x1, y1 + 1, 0, 500, 600);
	gfx.PutPixel(x1, y1 + 2, 0, 500, 600);
	gfx.PutPixel(x1, y1 + 3, 0, 500, 600);
	gfx.PutPixel(x1, y1, 0, 500, 600);
	gfx.PutPixel(x1 + 1, y1 + 1, 0, 500, 600);
	gfx.PutPixel(x1 + 2, y1 + 2, 0, 500, 600);
	gfx.PutPixel(x1 + 3, y1 + 3, 0, 500, 600);
	gfx.PutPixel(x1 + 4, y1 + 4, 0, 500, 600);
	gfx.PutPixel(x1 + 4, y1 + 1, 0, 500, 600);
	gfx.PutPixel(x1 + 3, y1 + 2, 0, 500, 600);
	gfx.PutPixel(x1 + 2, y1 + 3, 0, 500, 600);
		if (shift) {
			gfx.PutPixel(x, y, 400, 0, color);
			gfx.PutPixel(x + 1, y, 400, 0, color);
			gfx.PutPixel(x + 2, y, 400, 0, color);
			gfx.PutPixel(x + 8, y, 0, 400, color);
			gfx.PutPixel(x + 9, y, 400, 0, color);
			gfx.PutPixel(x + 10, y, 400, 0, color);
			gfx.PutPixel(x - 3, y, 400, 0, color);
			gfx.PutPixel(x - 3, y - 5, 400, 0, color);
			gfx.PutPixel(x - 3, y - 5, 400, 0, color);
			gfx.PutPixel(x, y, 0, 400, color);
			gfx.PutPixel(x, y + 9, 400, 0, color);
			gfx.PutPixel(x, y + 10, 400, 0, color);

		} if (ctrl) {
			gfx.PutPixel(x, y, color, 500, 0);
			gfx.PutPixel(x + 1, y, color, 500, 0);
			gfx.PutPixel(x + 2, y, color, 500, 0);
			gfx.PutPixel(x + 3, y, color, 500, 0);
			gfx.PutPixel(x, y + 1, color, 500, 0);
			gfx.PutPixel(x, y + 2, color, 500, 0);
			gfx.PutPixel(x, y + 3, color, 500, 0);
			gfx.PutPixel(x, y, color, 500, 0);
			gfx.PutPixel(x + 1, y + 1, color, 500, 0);
			gfx.PutPixel(x + 2, y + 2, color, 500, 0);
			gfx.PutPixel(x + 3, y + 3, color, 500, 0);
			gfx.PutPixel(x + 4, y + 4, color, 500, 0);
			gfx.PutPixel(x + 4, y + 1, color, 500, 0);
			gfx.PutPixel(x + 3, y + 2, color, 500, 0);
			gfx.PutPixel(x + 2, y + 3, color, 500, 0);
		}else {
			gfx.PutPixel(x, y, color, 400, 300);
			gfx.PutPixel(x, y + 1, color, 400, 300);
			gfx.PutPixel(x, y + 2, color, 400, 300);
			gfx.PutPixel(x, y + 3, color, 400, 300);
			gfx.PutPixel(x, y + 4, color, 400, 300);
			gfx.PutPixel(x + 1, y, color, 400, 300);
			gfx.PutPixel(x + 1, y + 1, color, 400, 300);
			gfx.PutPixel(x + 1, y + 2, color, 400, 300);
			gfx.PutPixel(x + 1, y + 3, color, 400, 300);
			gfx.PutPixel(x + 1, y + 4, color, 400, 300);

			gfx.PutPixel(x + 2, y, color, 400, 300);
			gfx.PutPixel(x + 2, y + 1, color, 400, 300);
			gfx.PutPixel(x + 2, y + 2, color, 400, 300);
			gfx.PutPixel(x + 2, y + 3, color, 400, 300);
			gfx.PutPixel(x + 2, y + 4, color, 400, 300);
			gfx.PutPixel(x + 3, y, color, 400, 300);
			gfx.PutPixel(x + 3, y + 1, color, 400, 300);
			gfx.PutPixel(x + 3, y + 2, color, 400, 300);
			gfx.PutPixel(x + 3, y + 3, color, 400, 300);
			gfx.PutPixel(x + 3, y + 4, color, 400, 300);

			gfx.PutPixel(x - 1, y, color, 400, 300);
			gfx.PutPixel(x - 1, y + 1, color, 400, 300);
			gfx.PutPixel(x - 1, y + 2, color, 400, 300);
			gfx.PutPixel(x - 1, y + 3, color, 400, 300);
			gfx.PutPixel(x - 1, y + 4, color, 400, 300);
			gfx.PutPixel(x - 2, y, color, 400, 300);
			gfx.PutPixel(x - 2, y + 1, color, 400, 300);
			gfx.PutPixel(x - 2, y + 2, color, 400, 300);
			gfx.PutPixel(x - 2, y + 3, color, 400, 300);
			gfx.PutPixel(x - 2, y + 4, color, 400, 300);
		}

};

 

Written in C++

Source

Made in Visual C++ IDE

Source

 I hope it was helpful and you learned something from it, Thanks

Sort:  

great post

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.027
BTC 60654.57
ETH 2343.25
USDT 1.00
SBD 2.48