Sei sulla pagina 1di 4

/

***********************************************************************************
*******
* Chili DirectX Framework Version 16.07.20
*
* Game.cpp
*
* Copyright 2016 PlanetChili.net <http://www.planetchili.net>
*
*
*
* This file is part of The Chili DirectX Framework.
*
*
*
* The Chili DirectX Framework is free software: you can redistribute it and/or
modify *
* it under the terms of the GNU General Public License as published by
*
* the Free Software Foundation, either version 3 of the License, or
*
* (at your option) any later version.
*
*
*
* The Chili DirectX Framework is distributed in the hope that it will be
useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of
*
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*
* GNU General Public License for more details.
*
*
*
* You should have received a copy of the GNU General Public License
*
* along with The Chili DirectX Framework. If not, see
<http://www.gnu.org/licenses/>. *

***********************************************************************************
*******/
#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()
{
if (wnd.kbd.KeyIsPressed(VK_CONTROL)) {
gColor = 0;
bColor = 0;
}
if (!wnd.kbd.KeyIsPressed(VK_CONTROL)) {
gColor = 255;
bColor = 255;
}

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

}
else {
inhibitRight = false;
}

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

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

if (wnd.kbd.KeyIsPressed(VK_UP)) {
if (!inhibitUp) {
vy -= 1;
inhibitUp = true;
}
}
else {
inhibitUp = false;
}

x += vx;
y += vy;

if (x + 5 >= gfx.ScreenWidth) {
x = gfx.ScreenWidth - 6;
vx = 0;
}
if (x - 5 <= 0) {
x += 5;
vx = 0;
}
if (y + 5 >= gfx.ScreenHeight) {
y = gfx.ScreenHeight - 6;
vy = 0;
}
if (y - 5 <= 0) {
y += 5;
vy = 0;
}
/*if (x > 100 && x < 200) {
gColor = 0;
bColor = 0;
}*/
/*if (wnd.kbd.KeyIsPressed(VK_SHIFT)) {
shapeIsChanged = true;
}
else {
shapeIsChanged = false;
}*/
if (x - 5 <= newx+5 && x+5>=newx-5 && y - 5 <= newy + 5 && y + 5 >=
newy - 5) {
bColor = 0;
gColor = 0;
}

void Game::ComposeFrame()
{
//x+=390,y+=290
//int x = 400;
//int y = 300;

//bool cond=wnd.kbd.KeyIsPressed(VK_UP);

if (!shapeIsChanged) {
gfx.PutPixel(x - 5, y, rColor, gColor, bColor);
gfx.PutPixel(x - 4, y, rColor, gColor, bColor);
gfx.PutPixel(x - 3, y, rColor, gColor, bColor);
gfx.PutPixel(x + 3, y, rColor, gColor, bColor);
gfx.PutPixel(x + 4, y, rColor, gColor, bColor);
gfx.PutPixel(x + 5, y, rColor, gColor, bColor);

gfx.PutPixel(x, y - 5, rColor, gColor, bColor);


gfx.PutPixel(x, y - 4, rColor, gColor, bColor);
gfx.PutPixel(x, y - 3, rColor, gColor, bColor);
gfx.PutPixel(x, y + 3, rColor, gColor, bColor);
gfx.PutPixel(x, y + 4, rColor, gColor, bColor);
gfx.PutPixel(x, y + 5, rColor, gColor, bColor);
}
else {
gfx.PutPixel(x + 5, y - 5, rColor, gColor, bColor);
gfx.PutPixel(x + 5, y - 4, rColor, gColor, bColor);
gfx.PutPixel(x + 4, y - 5, rColor, gColor, bColor);

gfx.PutPixel(x + 5, y + 5, rColor, gColor, bColor);


gfx.PutPixel(x + 5, y + 4, rColor, gColor, bColor);
gfx.PutPixel(x + 4, y + 5, rColor, gColor, bColor);

gfx.PutPixel(x - 5, y + 5, rColor, gColor, bColor);


gfx.PutPixel(x - 5, y + 4, rColor, gColor, bColor);
gfx.PutPixel(x - 4, y + 5, rColor, gColor, bColor);

gfx.PutPixel(x - 5, y - 5, rColor, gColor, bColor);


gfx.PutPixel(x - 5, y - 4, rColor, gColor, bColor);
gfx.PutPixel(x - 4, y - 5, rColor, gColor, bColor);
}

gfx.PutPixel(newx + 5, newy - 5, 0, 0, 255);


gfx.PutPixel(newx + 5, newy - 4, 0, 0, 255);
gfx.PutPixel(newx + 4, newy - 5, 0, 0, 255);

gfx.PutPixel(newx + 5, newy + 5, 0, 0, 255);


gfx.PutPixel(newx + 5, newy + 4, 0, 0, 255);
gfx.PutPixel(newx + 4, newy + 5, 0, 0, 255);

gfx.PutPixel(newx - 5, newy + 5, 0, 0, 255);


gfx.PutPixel(newx - 5, newy + 4, 0, 0, 255);
gfx.PutPixel(newx - 4, newy + 5, 0, 0, 255);

gfx.PutPixel(newx - 5, newy - 5, 0, 0, 255);


gfx.PutPixel(newx - 5, newy - 4, 0, 0, 255);
gfx.PutPixel(newx - 4, newy - 5, 0, 0, 255);

Potrebbero piacerti anche