SAU-trade
27-02-2013, 00:51
Здравствуйте... Пытаюсь написать игру типа Космической дуэли... Застопарился на стрельбе... Точнее как заставить свой объект стрелять... Подскажите как можно организовать данный процесс. Или где можно про это почитать?
#pragma once
#include <iostream>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
class GameObject
{
public:
int x, y; // Координаты расположения объекта
int size; // Размер объекта
char image; //Изображение объекта
GameObject(void);
GameObject(int x, int y, char img);
GameObject(int x, int y, int s, char img);
virtual void Draw();
~GameObject(void);
};
#include "GameObject.h"
GameObject::GameObject(void)
{
}
GameObject::GameObject(int x, int y, int s, char img)
{
this-> x = x;
this-> y = y;
size = s;
image = img;
}
GameObject::GameObject(int x, int y, char img)
{
this-> x = x;
this-> y = y;
image = img;
}
void GameObject::Draw()
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); //Дескриптор устройства стандартного вывода.
COORD coord = {x, y}; //структура для опред позиции на плосости
SetConsoleTextAttribute(h, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
SetConsoleCursorPosition(h, coord);
cout << image;
}
GameObject::~GameObject(void)
{
}
#pragma once
#include "GameObject.h"
class Spacecraft : public GameObject
{
int speedx;
int speedy;
public:
Spacecraft(void);
Spacecraft(int, int, char);
void Move();
~Spacecraft(void);
};
#include "Spacecraft.h"
Spacecraft::Spacecraft(void)
{
}
Spacecraft::Spacecraft(int x, int y, char img):GameObject(x, y, img)
{
}
Spacecraft::~Spacecraft(void)
{
}
#pragma once
#include "Spacecraft.h"
class Player_SC : public Spacecraft
{
public:
Player_SC(void);
Player_SC(int, int, char);
void Draw();
void Move();
~Player_SC(void);
};
#include "Player_SC.h"
Player_SC::Player_SC(void)
{
}
Player_SC::~Player_SC(void)
{
}
Player_SC::Player_SC(int x, int y, char img):Spacecraft(x, y, img)
{
}
void Player_SC::Draw()
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {x, y};
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);
SetConsoleCursorPosition(h, coord);
cout << image;
}
void Player_SC::Move()
{
if(GetAsyncKeyState(VK_UP))
{
if(y>0)
y--;
}
if(GetAsyncKeyState(VK_LEFT))
{
if(x>0)
x--;
}
if(GetAsyncKeyState(VK_RIGHT))
{
if(x<79)
x++;
}
if(GetAsyncKeyState(VK_DOWN))
{
if(y<24)
y++;
}
}
#pragma once
#include <iostream>
#include <stdlib.h>
#include <Windows.h>
using namespace std;
class GameObject
{
public:
int x, y; // Координаты расположения объекта
int size; // Размер объекта
char image; //Изображение объекта
GameObject(void);
GameObject(int x, int y, char img);
GameObject(int x, int y, int s, char img);
virtual void Draw();
~GameObject(void);
};
#include "GameObject.h"
GameObject::GameObject(void)
{
}
GameObject::GameObject(int x, int y, int s, char img)
{
this-> x = x;
this-> y = y;
size = s;
image = img;
}
GameObject::GameObject(int x, int y, char img)
{
this-> x = x;
this-> y = y;
image = img;
}
void GameObject::Draw()
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); //Дескриптор устройства стандартного вывода.
COORD coord = {x, y}; //структура для опред позиции на плосости
SetConsoleTextAttribute(h, FOREGROUND_BLUE | FOREGROUND_INTENSITY);
SetConsoleCursorPosition(h, coord);
cout << image;
}
GameObject::~GameObject(void)
{
}
#pragma once
#include "GameObject.h"
class Spacecraft : public GameObject
{
int speedx;
int speedy;
public:
Spacecraft(void);
Spacecraft(int, int, char);
void Move();
~Spacecraft(void);
};
#include "Spacecraft.h"
Spacecraft::Spacecraft(void)
{
}
Spacecraft::Spacecraft(int x, int y, char img):GameObject(x, y, img)
{
}
Spacecraft::~Spacecraft(void)
{
}
#pragma once
#include "Spacecraft.h"
class Player_SC : public Spacecraft
{
public:
Player_SC(void);
Player_SC(int, int, char);
void Draw();
void Move();
~Player_SC(void);
};
#include "Player_SC.h"
Player_SC::Player_SC(void)
{
}
Player_SC::~Player_SC(void)
{
}
Player_SC::Player_SC(int x, int y, char img):Spacecraft(x, y, img)
{
}
void Player_SC::Draw()
{
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = {x, y};
SetConsoleTextAttribute(h, FOREGROUND_RED | FOREGROUND_INTENSITY);
SetConsoleCursorPosition(h, coord);
cout << image;
}
void Player_SC::Move()
{
if(GetAsyncKeyState(VK_UP))
{
if(y>0)
y--;
}
if(GetAsyncKeyState(VK_LEFT))
{
if(x>0)
x--;
}
if(GetAsyncKeyState(VK_RIGHT))
{
if(x<79)
x++;
}
if(GetAsyncKeyState(VK_DOWN))
{
if(y<24)
y++;
}
}