View Full Version: DOS Shooting game

C++ Learning Community > C++ Creations > DOS Shooting game

Pages: [1] 2

Title: DOS Shooting game
Description: very easy programming, 503 lines of code


DOOM - February 25, 2005 01:00 AM (GMT)
CODE
// Author: Kev J.


#include <stdlib.h>
#include <windows.h>
#include <iostream>
using namespace std;

#define VK_A 0x41
#define VK_B 0x42
#define VK_C 0x43
#define VK_D 0x44
#define VK_E 0x45
#define VK_F 0x46
#define VK_G 0x47
#define VK_H 0x48
#define VK_I 0x49
#define VK_J 0x4A
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_M 0x4D
#define VK_N 0x4E
#define VK_O 0x4F
#define VK_P 0x50
#define VK_Q 0x51
#define VK_R 0x52
#define VK_S 0x53
#define VK_T 0x54
#define VK_U 0x55
#define VK_V 0x56
#define VK_W 0x57
#define VK_X 0x58
#define VK_Y 0x59
#define VK_Z 0x5A

struct GAMEINFO {
COORD PlayerOnePosition;
COORD PlayerTwoPosition;
COORD PlayerOneBullet;
COORD PlayerTwoBullet;
COORD PlayerOneBullet2;
COORD PlayerTwoBullet2;
COORD ZeroZero;
};

HANDLE hInput, hOutput;
GAMEINFO GameInfo;

void Movement(GAMEINFO &GameInfo);
void Draw(GAMEINFO);
void Erase(GAMEINFO);
int LaunchBullet(GAMEINFO &GameInfo, int);
void LaunchBullet2(GAMEINFO &GameInfo, int);
int Wait();


int main()
{
GAMEINFO GameInfo;



hInput = GetStdHandle(STD_INPUT_HANDLE);
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);



SetConsoleMode(hOutput, ENABLE_PROCESSED_INPUT);

GameInfo.PlayerOnePosition.X = 19;
GameInfo.PlayerOnePosition.Y = 12;
GameInfo.PlayerTwoPosition.X = 61;
GameInfo.PlayerTwoPosition.Y = 12;
GameInfo.PlayerOneBullet.X = 0;
GameInfo.PlayerOneBullet.Y = 0;
GameInfo.PlayerTwoBullet.X = 79;
GameInfo.PlayerTwoBullet.Y = 0;
GameInfo.PlayerOneBullet2.X = 1;
GameInfo.PlayerOneBullet2.Y = 0;
GameInfo.PlayerTwoBullet2.X = 78;
GameInfo.PlayerTwoBullet2.Y = 0;
GameInfo.ZeroZero.X = 0;
GameInfo.ZeroZero.Y = 0;

int i;
GameInfo.ZeroZero.Y = 24;
for(i = 0; i < 79; i++){
 SetConsoleCursorPosition(hOutput, GameInfo.ZeroZero);
 cout << ".";
 GameInfo.ZeroZero.X++;
}

Draw(GameInfo);

while(1){
 Movement(GameInfo);
}

return 0;
}

void Movement(GAMEINFO &GameInfo)
{
INPUT_RECORD InputRecord;
DWORD Events = 0;

ReadConsoleInput(hInput, &InputRecord, 1, &Events);

if(InputRecord.EventType == KEY_EVENT){
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_Q && InputRecord.Event.KeyEvent.bKeyDown == 1){
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y--;
  if(GameInfo.PlayerOnePosition.Y < 0)
   GameInfo.PlayerOnePosition.Y++;
  Draw(GameInfo);
 }
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_A && InputRecord.Event.KeyEvent.bKeyDown == 1){
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y++;
  if(GameInfo.PlayerOnePosition.Y > 24)
   GameInfo.PlayerOnePosition.Y--;
  Draw(GameInfo);
 }

 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_S && InputRecord.Event.KeyEvent.bKeyDown == 1){
  LaunchBullet(GameInfo, 1);
 }
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_O && InputRecord.Event.KeyEvent.bKeyDown == 1){
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y--;
  if(GameInfo.PlayerTwoPosition.Y < 0)
   GameInfo.PlayerTwoPosition.Y++;
  Draw(GameInfo);
 }

 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_L && InputRecord.Event.KeyEvent.bKeyDown == 1){
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y++;
  if(GameInfo.PlayerTwoPosition.Y > 24)
   GameInfo.PlayerTwoPosition.Y--;
  Draw(GameInfo);
 }

 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_K && InputRecord.Event.KeyEvent.bKeyDown == 1){
  LaunchBullet(GameInfo, 2);
 }

 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
  exit(0);

}
FlushConsoleInputBuffer(hInput);
}

void Draw(GAMEINFO GameInfo)
{
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << "|";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoPosition);
cout << "|";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet);
cout << ".";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet);
cout << ".";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet2);
cout << ".";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet2);
cout << ".";

GameInfo.ZeroZero.X = 0;
GameInfo.ZeroZero.Y = 0;

int i;
for(i = 0; i < 79; i++){
 SetConsoleCursorPosition(hOutput, GameInfo.ZeroZero);
 cout << ".";
 GameInfo.ZeroZero.X++;
}

}

void Erase(GAMEINFO GameInfo)
{
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << " ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoPosition);
cout << " ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet);
cout << " ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet);
cout << " ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet2);
cout << " ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet2);
cout << " ";
}

int LaunchBullet(GAMEINFO &GameInfo, int PlayerNumber)
{
int i;
if(PlayerNumber == 1){
 GameInfo.PlayerOneBullet.Y = GameInfo.PlayerOnePosition.Y;
 GameInfo.PlayerOneBullet.X = GameInfo.PlayerOnePosition.X + 1;
 Draw(GameInfo);
 Erase(GameInfo);
 for(i = 0; i < 77; i++){
  GameInfo.PlayerOneBullet.X += 1;
  Draw(GameInfo);

  int move;
  move = Wait();
  switch(move){
  case 1:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y--;
   if(GameInfo.PlayerOnePosition.Y < 0)
    GameInfo.PlayerOnePosition.Y++;
   break;
  case 2:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y++;
   if(GameInfo.PlayerOnePosition.Y > 24)
    GameInfo.PlayerOnePosition.Y--;
   break;
  case 3:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y--;
   if(GameInfo.PlayerTwoPosition.Y < 0)
    GameInfo.PlayerTwoPosition.Y++;
   break;
  case 4:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y++;
   if(GameInfo.PlayerTwoPosition.Y > 24)
    GameInfo.PlayerTwoPosition.Y--;
   break;
  case 5:
   LaunchBullet2(GameInfo, 1);
   return 0;
   break;
  case 6:
   LaunchBullet2(GameInfo, 2);
   return 0;
   break;
  }

  Draw(GameInfo);
  Erase(GameInfo);
  if(GameInfo.PlayerOneBullet.X == GameInfo.PlayerTwoPosition.X)
   if(GameInfo.PlayerOneBullet.Y == GameInfo.PlayerTwoPosition.Y){
    system("cls");
    cout << "\aPlayer 1 Wins" << endl;
    system("pause");
    exit(0);
   }
 }
 GameInfo.PlayerOneBullet.Y = 0;
 GameInfo.PlayerOneBullet.X = 0;
 Draw(GameInfo);
}
if(PlayerNumber == 2){
 GameInfo.PlayerTwoBullet.Y = GameInfo.PlayerTwoPosition.Y;
 GameInfo.PlayerTwoBullet.X = GameInfo.PlayerTwoPosition.X - 1;
 Draw(GameInfo);
 Erase(GameInfo);
 for(i = 0; i < 77; i++){
  GameInfo.PlayerTwoBullet.X -= 1;
  Draw(GameInfo);
 
  int move;
  move = Wait();
  switch(move){
  case 1:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y--;
   if(GameInfo.PlayerOnePosition.Y < 0)
    GameInfo.PlayerOnePosition.Y++;
   break;
  case 2:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y++;
   if(GameInfo.PlayerOnePosition.Y > 24)
    GameInfo.PlayerOnePosition.Y--;
   break;
  case 3:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y--;
   if(GameInfo.PlayerTwoPosition.Y < 0)
    GameInfo.PlayerTwoPosition.Y++;
   break;
  case 4:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y++;
   if(GameInfo.PlayerTwoPosition.Y > 24)
    GameInfo.PlayerTwoPosition.Y--;
   break;
  case 5:
   LaunchBullet2(GameInfo, 1);
   return 0;
   break;
  case 6:
   LaunchBullet2(GameInfo, 2);
   return 0;
   break;
  }
 
  Draw(GameInfo);
  Erase(GameInfo);
  if(GameInfo.PlayerTwoBullet.X == GameInfo.PlayerOnePosition.X)
   if(GameInfo.PlayerTwoBullet.Y == GameInfo.PlayerOnePosition.Y){
    system("cls");
    cout << "\aPlayer 2 Wins" << endl;
    system("pause");
    exit(0);
  }
 }
 GameInfo.PlayerTwoBullet.Y = 0;
 GameInfo.PlayerTwoBullet.X = 79;
 Draw(GameInfo);
}
return 0;
}

int Wait()
{
INPUT_RECORD InputRecord;
DWORD Events = 0;

if(WAIT_TIMEOUT == WaitForSingleObject(hInput,1))
   return 0;
ReadConsoleInput(hInput, &InputRecord, 1, &Events);

if(InputRecord.EventType == KEY_EVENT){
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_Q && InputRecord.Event.KeyEvent.bKeyDown == 1)
  return 1;
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_A && InputRecord.Event.KeyEvent.bKeyDown == 1)
  return 2;
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_O && InputRecord.Event.KeyEvent.bKeyDown == 1)
  return 3;
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_L && InputRecord.Event.KeyEvent.bKeyDown == 1)
  return 4;
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_S && InputRecord.Event.KeyEvent.bKeyDown == 1)
  return 5;
 
 if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_K && InputRecord.Event.KeyEvent.bKeyDown == 1)
  return 6;
}
FlushConsoleInputBuffer(hInput);
return 0;
}

void LaunchBullet2(GAMEINFO &GameInfo, int PlayerNumber)
{
if(PlayerNumber == 1){
 GameInfo.PlayerOneBullet2.X = GameInfo.PlayerOnePosition.X + 1;
 GameInfo.PlayerOneBullet2.Y = GameInfo.PlayerOnePosition.Y;

 Draw(GameInfo);
 Erase(GameInfo);
 int i;
 for(i = 0; i < 77; i++){
  GameInfo.PlayerOneBullet.X += 1;
  GameInfo.PlayerOneBullet2.X += 1;
  GameInfo.PlayerTwoBullet.X -= 1;
  GameInfo.PlayerTwoBullet2.X -= 1;
  Draw(GameInfo);

  int move;
  move = Wait();
  switch(move){
  case 1:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y--;
   if(GameInfo.PlayerOnePosition.Y < 0)
    GameInfo.PlayerOnePosition.Y++;
   break;
  case 2:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y++;
   if(GameInfo.PlayerOnePosition.Y > 24)
    GameInfo.PlayerOnePosition.Y--;
   break;
  case 3:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y--;
   if(GameInfo.PlayerTwoPosition.Y < 0)
    GameInfo.PlayerTwoPosition.Y++;
   break;
  case 4:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y++;
   if(GameInfo.PlayerTwoPosition.Y > 24)
    GameInfo.PlayerTwoPosition.Y--;
   break;
  }

  Draw(GameInfo);
  Erase(GameInfo);
  if(GameInfo.PlayerOneBullet.X == GameInfo.PlayerTwoPosition.X)
   if(GameInfo.PlayerOneBullet.Y == GameInfo.PlayerTwoPosition.Y){
    system("cls");
    cout << "\aPlayer 1 Wins" << endl;
    system("pause");
    exit(0);
   }
  if(GameInfo.PlayerOneBullet2.X == GameInfo.PlayerTwoPosition.X)
   if(GameInfo.PlayerOneBullet2.Y == GameInfo.PlayerTwoPosition.Y){
    system("cls");
    cout << "\aPlayer 1 Wins" << endl;
    system("pause");
    exit(0);
   }
 }
 GameInfo.PlayerOneBullet.Y = 0;
 GameInfo.PlayerOneBullet.X = 0;
 GameInfo.PlayerOneBullet2.Y = 0;
 GameInfo.PlayerOneBullet2.X = 1;
 Draw(GameInfo);
}

if(PlayerNumber == 2){
 GameInfo.PlayerTwoBullet2.Y = GameInfo.PlayerTwoPosition.Y;
 GameInfo.PlayerTwoBullet2.X = GameInfo.PlayerTwoPosition.X - 1;
 Draw(GameInfo);
 Erase(GameInfo);
 int i;
 for(i = 0; i < 77; i++){
  GameInfo.PlayerTwoBullet.X -= 1;
  GameInfo.PlayerTwoBullet2.X -= 1;
  GameInfo.PlayerOneBullet.X += 1;
  GameInfo.PlayerOneBullet2.X += 1;
  Draw(GameInfo);
 
  int move;
  move = Wait();
  switch(move){
  case 1:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y--;
   if(GameInfo.PlayerOnePosition.Y < 0)
    GameInfo.PlayerOnePosition.Y++;
   break;
  case 2:
   Erase(GameInfo);
   GameInfo.PlayerOnePosition.Y++;
   if(GameInfo.PlayerOnePosition.Y > 24)
    GameInfo.PlayerOnePosition.Y--;
   break;
  case 3:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y--;
   if(GameInfo.PlayerTwoPosition.Y < 0)
    GameInfo.PlayerTwoPosition.Y++;
   break;
  case 4:
   Erase(GameInfo);
   GameInfo.PlayerTwoPosition.Y++;
   if(GameInfo.PlayerTwoPosition.Y > 24)
    GameInfo.PlayerTwoPosition.Y--;
   break;
  }

  Draw(GameInfo);
  Erase(GameInfo);
  if(GameInfo.PlayerTwoBullet.X == GameInfo.PlayerOnePosition.X)
   if(GameInfo.PlayerTwoBullet.Y == GameInfo.PlayerOnePosition.Y){
    system("cls");
    cout << "\aPlayer 2 Wins" << endl;
    system("pause");
    exit(0);
  }
  if(GameInfo.PlayerTwoBullet2.X == GameInfo.PlayerOnePosition.X)
   if(GameInfo.PlayerTwoBullet2.Y == GameInfo.PlayerOnePosition.Y){
    system("cls");
    cout << "\aPlayer 2 Wins" << endl;
    system("pause");
    exit(0);
  }
 }
 GameInfo.PlayerOneBullet.Y = 0;
 GameInfo.PlayerOneBullet.X = 0;
 GameInfo.PlayerOneBullet2.Y = 0;
 GameInfo.PlayerOneBullet2.X = 1;
 Draw(GameInfo);
}
}

Dah Vid - February 25, 2005 01:05 AM (GMT)
Nice, took me a minute on how to operate the game.

Shackleb0lt - February 25, 2005 01:07 AM (GMT)
wtf.... 503 lines of code for such a simple game? I can't believe that the first video game was something as simple as this.

Viper - February 25, 2005 07:29 AM (GMT)
Good programming. Yes simple DOS programs can fill more than simple Win32 progs..

DeAs91 - February 25, 2005 02:28 PM (GMT)
Nice dos game :)

C-Man - February 25, 2005 02:41 PM (GMT)
PLEASE DO NOT COMFUSE DOS WITH CONSOLE PROGRAMS THEYR NOT THE SAME THING !!!!!
thank your for reading and have a nice day ^_^

Shackleb0lt - February 25, 2005 03:31 PM (GMT)
so, is this a console program?

C-Man - February 25, 2005 05:23 PM (GMT)
yes it is ^_^

donprogc++ - February 25, 2005 05:53 PM (GMT)
Console != DOS

DOS: disk operating system

DeAs91 - February 25, 2005 06:14 PM (GMT)
Okay, then I reform it to:

Nice console game :)

C-Man - February 25, 2005 06:31 PM (GMT)
thats better ^_^

Nintendofreak88 - February 25, 2005 09:53 PM (GMT)
Heh, it's a nice game. :) You should add single player with ai :P

Shackleb0lt - February 26, 2005 01:43 AM (GMT)
AI, huh? it'd be interesting to see how he programs that.

MonkeyMan - February 26, 2005 01:50 AM (GMT)
I like I like... a bit glitchy...kinda... i guess but it still is cool.

donprogc++ - February 26, 2005 03:34 AM (GMT)
it would be better if he can make a seperate thread for the 2nd player B)
but its a nice play

DOOM - February 26, 2005 05:06 AM (GMT)
thanks and sorry for mixing DOS with CONSOLE
i'm such an idiot :P

tubapro12 - March 8, 2005 04:21 AM (GMT)
nice game. took a bit figure out (maybe its instructions?) but also discover running .exe instead of the Borland in-IDE version helps a lot. lol

User Name - March 9, 2005 04:09 AM (GMT)
how do you exactly make the bullets in a console?

Shackleb0lt - March 9, 2005 04:11 AM (GMT)
lol I didn't realize I hadn't logged out from that account... (just trying the bug, you know, like when programing ^_^). That was my question, anyways.

donprogc++ - March 9, 2005 06:13 PM (GMT)
cout << "-";
and then you use the win32 function to first set the position then move it on the console screen

DOOM - March 31, 2005 03:05 AM (GMT)
i am working on making one for beginner CONSOLE C++ programmers, and it will use a lot of:
CODE
cout<<"-";

then clear screens,
but hey!

DOOM - April 20, 2005 02:20 AM (GMT)
i'm gonna make a new one, easier for beginners at c++.

_se7en - April 20, 2005 11:23 AM (GMT)
Nice. But kinda pointless when playing with only one player, lol.

DOOM - April 27, 2005 01:59 AM (GMT)
thank you

aaron7215 - May 20, 2005 05:29 PM (GMT)
Cool Game. I have only been learning c++ for 3 days, but I was an expert with gamemaker, so this is easier to understand, and I am currently working on a game like this, only you are an "O", and you press WASD to move and you run into the "o"'s to get points. I have the moving down.

moi - June 13, 2005 12:25 PM (GMT)
Hi DOOM!

Thank you for your sample game! Helped me a lot to understand how moving a ASCII-Charcter works... I took the freedom to modify the game a little bit:

CODE

#include <stdlib.h>
#include <windows.h>
#include <iostream>
//moi:
#include <time.h>

using namespace std;

#define VK_A 0x41
#define VK_B 0x42
#define VK_C 0x43
#define VK_D 0x44
#define VK_E 0x45
#define VK_F 0x46
#define VK_G 0x47
#define VK_H 0x48
#define VK_I 0x49
#define VK_J 0x4A
#define VK_K 0x4B
#define VK_L 0x4C
#define VK_M 0x4D
#define VK_N 0x4E
#define VK_O 0x4F
#define VK_P 0x50
#define VK_Q 0x51
#define VK_R 0x52
#define VK_S 0x53
#define VK_T 0x54
#define VK_U 0x55
#define VK_V 0x56
#define VK_W 0x57
#define VK_X 0x58
#define VK_Y 0x59
#define VK_Z 0x5A

struct GAMEINFO {
COORD PlayerOnePosition;
COORD PlayerTwoPosition;
COORD PlayerOneBullet;
COORD PlayerTwoBullet;
COORD PlayerOneBullet2;
COORD PlayerTwoBullet2;
COORD ZeroZero;
};

HANDLE hInput, hOutput;
GAMEINFO GameInfo;

void Movement(GAMEINFO &GameInfo);
void Draw(GAMEINFO);
void Erase(GAMEINFO);
int LaunchBullet(GAMEINFO &GameInfo, int);
void LaunchBullet2(GAMEINFO &GameInfo, int);
int Wait();
short lastmovement;

int main()
{

GAMEINFO GameInfo;



hInput = GetStdHandle(STD_INPUT_HANDLE);
hOutput = GetStdHandle(STD_OUTPUT_HANDLE);


//Moi
#define POSMAX 21
SetConsoleMode(hOutput, ENABLE_PROCESSED_INPUT);

GameInfo.PlayerOnePosition.X = 19;
GameInfo.PlayerOnePosition.Y = POSMAX-5; //moi

//Moi: RAndom
srand((unsigned) time(NULL));
int p2=rand()%78+1;
GameInfo.PlayerTwoPosition.Y = POSMAX-5;
/*GameInfo.PlayerTwoPosition.X = 61; */
GameInfo.PlayerTwoPosition.X = p2; //now Player2 appears at a random X-position


GameInfo.PlayerOneBullet.X = 0;
GameInfo.PlayerOneBullet.Y = 0;
GameInfo.PlayerTwoBullet.X = 79;
GameInfo.PlayerTwoBullet.Y = 0;
GameInfo.PlayerOneBullet2.X = 1;
GameInfo.PlayerOneBullet2.Y = 0;
GameInfo.PlayerTwoBullet2.X = 78;
GameInfo.PlayerTwoBullet2.Y = 0;
GameInfo.ZeroZero.X = 0;
GameInfo.ZeroZero.Y = 0;

int i;
GameInfo.ZeroZero.Y = 24;
for(i = 0; i < 79; i++){
SetConsoleCursorPosition(hOutput, GameInfo.ZeroZero);
cout << ".";
GameInfo.ZeroZero.X++;
}

Draw(GameInfo);

while(1){
Movement(GameInfo);
}

return 0;
}

void Movement(GAMEINFO &GameInfo)
{
INPUT_RECORD InputRecord;
DWORD Events = 0;

ReadConsoleInput(hInput, &InputRecord, 1, &Events);

if(InputRecord.EventType == KEY_EVENT){
//Moving up lm=0
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_Q && InputRecord.Event.KeyEvent.bKeyDown == 1){
 Erase(GameInfo);
 GameInfo.PlayerOnePosition.Y--;
lastmovement=0; //Moi notice last movement
 if(GameInfo.PlayerOnePosition.Y < 1) //check if the border is passed
  GameInfo.PlayerOnePosition.Y++;
 Draw(GameInfo);
}

//moving down  lm=1
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_A && InputRecord.Event.KeyEvent.bKeyDown == 1){
 Erase(GameInfo);
 GameInfo.PlayerOnePosition.Y++;
lastmovement=1; //Moi notice last movement
 if(GameInfo.PlayerOnePosition.Y > 23)
  GameInfo.PlayerOnePosition.Y--;
 Draw(GameInfo);
}

//moi: Player1 X-Movement - right
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_X && InputRecord.Event.KeyEvent.bKeyDown == 1){
 Erase(GameInfo);
 GameInfo.PlayerOnePosition.X++;
  lastmovement=2; //Moi notice last movement
 if(GameInfo.PlayerOnePosition.X > 78 )
  GameInfo.PlayerOnePosition.X--;
 Draw(GameInfo);
}
//moi movement left
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_Y && InputRecord.Event.KeyEvent.bKeyDown == 1){
 Erase(GameInfo);
 GameInfo.PlayerOnePosition.X--;
  lastmovement=3; //Moi notice last movement
 if(GameInfo.PlayerOnePosition.X < 0)
  GameInfo.PlayerOnePosition.X++;
 Draw(GameInfo);
}
//Moi-end

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_S && InputRecord.Event.KeyEvent.bKeyDown == 1){
 LaunchBullet(GameInfo, 1);
}

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_O && InputRecord.Event.KeyEvent.bKeyDown == 1){
 Erase(GameInfo);
 GameInfo.PlayerTwoPosition.Y--;
 if(GameInfo.PlayerTwoPosition.Y < 0)
  GameInfo.PlayerTwoPosition.Y++;
 Draw(GameInfo);
}

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_L && InputRecord.Event.KeyEvent.bKeyDown == 1){
 Erase(GameInfo);
 GameInfo.PlayerTwoPosition.Y++;
 if(GameInfo.PlayerTwoPosition.Y > 24)
  GameInfo.PlayerTwoPosition.Y--;
 Draw(GameInfo);
}

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_K && InputRecord.Event.KeyEvent.bKeyDown == 1){
 LaunchBullet(GameInfo, 2);
}

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
 exit(0);

}
FlushConsoleInputBuffer(hInput);
}

void Draw(GAMEINFO GameInfo)
{
//Moi: Rotating incase y++
//if moving y++, rotate
if (lastmovement==0){
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << "^^";}
else
if (lastmovement==1){
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << "vv"; }
else
if (lastmovement==2){
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << ">>"; }
else
if (lastmovement==3){
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << "<<"; }
//Moi end



SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoPosition);
cout << "|";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet);
cout << ".";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet);
cout << ".";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet2);
cout << ".";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet2);
cout << ".";

GameInfo.ZeroZero.X = 0;
GameInfo.ZeroZero.Y = 0;

int i;
for(i = 0; i < 79; i++){
SetConsoleCursorPosition(hOutput, GameInfo.ZeroZero);
cout << ".";
GameInfo.ZeroZero.X++;
}

}

void Erase(GAMEINFO GameInfo)
{
SetConsoleCursorPosition(hOutput, GameInfo.PlayerOnePosition);
cout << "  ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoPosition);
cout << "  ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet);
cout << "  ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet);
cout << "  ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerOneBullet2);
cout << "  ";

SetConsoleCursorPosition(hOutput, GameInfo.PlayerTwoBullet2);
cout << "  ";
}

int LaunchBullet(GAMEINFO &GameInfo, int PlayerNumber)
{
int i;
if(PlayerNumber == 1){
GameInfo.PlayerOneBullet.Y = GameInfo.PlayerOnePosition.Y;
GameInfo.PlayerOneBullet.X = GameInfo.PlayerOnePosition.X + 1;
Draw(GameInfo);
Erase(GameInfo);
for(i = 0; i < 77; i++){
 GameInfo.PlayerOneBullet.X += 1;
 Draw(GameInfo);

 int move;
 move = Wait();
 switch(move){
 case 1:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y--;
  if(GameInfo.PlayerOnePosition.Y < 0)
   GameInfo.PlayerOnePosition.Y++;
  break;
 case 2:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y++;
  if(GameInfo.PlayerOnePosition.Y > 24)
   GameInfo.PlayerOnePosition.Y--;
  break;
 case 3:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y--;
  if(GameInfo.PlayerTwoPosition.Y < 0)
   GameInfo.PlayerTwoPosition.Y++;
  break;
 case 4:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y++;
  if(GameInfo.PlayerTwoPosition.Y > 24)
   GameInfo.PlayerTwoPosition.Y--;
  break;
 case 5:
  LaunchBullet2(GameInfo, 1);
  return 0;
  break;
 case 6:
  LaunchBullet2(GameInfo, 2);
  return 0;
  break;
 }

 Draw(GameInfo);
 Erase(GameInfo);
 if(GameInfo.PlayerOneBullet.X == GameInfo.PlayerTwoPosition.X)
  if(GameInfo.PlayerOneBullet.Y == GameInfo.PlayerTwoPosition.Y){
   system("cls");
   cout << "\aPlayer 1 Wins" << endl;
   system("pause");
   exit(0);
  }
}
GameInfo.PlayerOneBullet.Y = 0;
GameInfo.PlayerOneBullet.X = 0;
Draw(GameInfo);
}


if(PlayerNumber == 2){
GameInfo.PlayerTwoBullet.Y = GameInfo.PlayerTwoPosition.Y;
GameInfo.PlayerTwoBullet.X = GameInfo.PlayerTwoPosition.X - 1;
Draw(GameInfo);
Erase(GameInfo);
for(i = 0; i < 77; i++){
 GameInfo.PlayerTwoBullet.X -= 1;
 Draw(GameInfo);

 int move;
 move = Wait();
 switch(move){
 case 1:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y--;
  if(GameInfo.PlayerOnePosition.Y < 0)
   GameInfo.PlayerOnePosition.Y++;
  break;
 case 2:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y++;
  if(GameInfo.PlayerOnePosition.Y > 24)
   GameInfo.PlayerOnePosition.Y--;
  break;
 case 3:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y--;
  if(GameInfo.PlayerTwoPosition.Y < 0)
   GameInfo.PlayerTwoPosition.Y++;
  break;
 case 4:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y++;
  if(GameInfo.PlayerTwoPosition.Y > 24)
   GameInfo.PlayerTwoPosition.Y--;
  break;
 case 5:
  LaunchBullet2(GameInfo, 1);
  return 0;
  break;
 case 6:
  LaunchBullet2(GameInfo, 2);
  return 0;
  break;
 }
 
 Draw(GameInfo);
 Erase(GameInfo);
 if(GameInfo.PlayerTwoBullet.X == GameInfo.PlayerOnePosition.X)
  if(GameInfo.PlayerTwoBullet.Y == GameInfo.PlayerOnePosition.Y){
   system("cls");
   cout << "\aPlayer 2 Wins" << endl;
   system("pause");
   exit(0);
 }
}
GameInfo.PlayerTwoBullet.Y = 0;
GameInfo.PlayerTwoBullet.X = 79;
Draw(GameInfo);
}
return 0;
}

int Wait()
{
INPUT_RECORD InputRecord;
DWORD Events = 0;

if(WAIT_TIMEOUT == WaitForSingleObject(hInput,1))
  return 0;
ReadConsoleInput(hInput, &InputRecord, 1, &Events);

if(InputRecord.EventType == KEY_EVENT){
if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_Q && InputRecord.Event.KeyEvent.bKeyDown == 1)
 return 1;

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_A && InputRecord.Event.KeyEvent.bKeyDown == 1)
 return 2;

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_O && InputRecord.Event.KeyEvent.bKeyDown == 1)
 return 3;

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_L && InputRecord.Event.KeyEvent.bKeyDown == 1)
 return 4;

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_S && InputRecord.Event.KeyEvent.bKeyDown == 1)
 return 5;

if(InputRecord.Event.KeyEvent.wVirtualKeyCode == VK_K && InputRecord.Event.KeyEvent.bKeyDown == 1)
 return 6;
}
FlushConsoleInputBuffer(hInput);
return 0;
}

void LaunchBullet2(GAMEINFO &GameInfo, int PlayerNumber)
{
if(PlayerNumber == 1){
GameInfo.PlayerOneBullet2.X = GameInfo.PlayerOnePosition.X + 1;
GameInfo.PlayerOneBullet2.Y = GameInfo.PlayerOnePosition.Y;

Draw(GameInfo);
Erase(GameInfo);
int i;
for(i = 0; i < 77; i++){
 GameInfo.PlayerOneBullet.X += 1;
 GameInfo.PlayerOneBullet2.X += 1;
 GameInfo.PlayerTwoBullet.X -= 1;
 GameInfo.PlayerTwoBullet2.X -= 1;
 Draw(GameInfo);

 int move;
 move = Wait();
 switch(move){
 case 1:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y--;
  if(GameInfo.PlayerOnePosition.Y < 0)
   GameInfo.PlayerOnePosition.Y++;
  break;
 case 2:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y++;
  if(GameInfo.PlayerOnePosition.Y > 24)
   GameInfo.PlayerOnePosition.Y--;
  break;
 case 3:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y--;
  if(GameInfo.PlayerTwoPosition.Y < 0)
   GameInfo.PlayerTwoPosition.Y++;
  break;
 case 4:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y++;
  if(GameInfo.PlayerTwoPosition.Y > 24)
   GameInfo.PlayerTwoPosition.Y--;
  break;
 }

 Draw(GameInfo);
 Erase(GameInfo);
 if(GameInfo.PlayerOneBullet.X == GameInfo.PlayerTwoPosition.X)
  if(GameInfo.PlayerOneBullet.Y == GameInfo.PlayerTwoPosition.Y){
   system("cls");
   cout << "\aPlayer 1 Wins" << endl;
   system("pause");
   exit(0);
  }
 if(GameInfo.PlayerOneBullet2.X == GameInfo.PlayerTwoPosition.X)
  if(GameInfo.PlayerOneBullet2.Y == GameInfo.PlayerTwoPosition.Y){
   system("cls");
   cout << "\aPlayer 1 Wins" << endl;
   system("pause");
   exit(0);
  }
}
GameInfo.PlayerOneBullet.Y = 0;
GameInfo.PlayerOneBullet.X = 0;
GameInfo.PlayerOneBullet2.Y = 0;
GameInfo.PlayerOneBullet2.X = 1;
Draw(GameInfo);
}

if(PlayerNumber == 2){
GameInfo.PlayerTwoBullet2.Y = GameInfo.PlayerTwoPosition.Y;
GameInfo.PlayerTwoBullet2.X = GameInfo.PlayerTwoPosition.X - 1;
Draw(GameInfo);
Erase(GameInfo);
int i;
for(i = 0; i < 77; i++){
 GameInfo.PlayerTwoBullet.X -= 1;
 GameInfo.PlayerTwoBullet2.X -= 1;
 GameInfo.PlayerOneBullet.X += 1;
 GameInfo.PlayerOneBullet2.X += 1;
 Draw(GameInfo);

 int move;
 move = Wait();
 switch(move){
 case 1:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y--;
  if(GameInfo.PlayerOnePosition.Y < 0)
   GameInfo.PlayerOnePosition.Y++;
  break;
 case 2:
  Erase(GameInfo);
  GameInfo.PlayerOnePosition.Y++;
  if(GameInfo.PlayerOnePosition.Y > 24)
   GameInfo.PlayerOnePosition.Y--;
  break;
 case 3:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y--;
  if(GameInfo.PlayerTwoPosition.Y < 0)
   GameInfo.PlayerTwoPosition.Y++;
  break;
 case 4:
  Erase(GameInfo);
  GameInfo.PlayerTwoPosition.Y++;
  if(GameInfo.PlayerTwoPosition.Y > 24)
   GameInfo.PlayerTwoPosition.Y--;
  break;
 }

 Draw(GameInfo);
 Erase(GameInfo);
 if(GameInfo.PlayerTwoBullet.X == GameInfo.PlayerOnePosition.X)
  if(GameInfo.PlayerTwoBullet.Y == GameInfo.PlayerOnePosition.Y){
   system("cls");
   cout << "\aPlayer 2 Wins" << endl;
   system("pause");
   exit(0);
 }
 if(GameInfo.PlayerTwoBullet2.X == GameInfo.PlayerOnePosition.X)
  if(GameInfo.PlayerTwoBullet2.Y == GameInfo.PlayerOnePosition.Y){
   system("cls");
   cout << "\aPlayer 2 Wins" << endl;
   system("pause");
   exit(0);
 }
}
GameInfo.PlayerOneBullet.Y = 0;
GameInfo.PlayerOneBullet.X = 0;
GameInfo.PlayerOneBullet2.Y = 0;
GameInfo.PlayerOneBullet2.X = 1;
Draw(GameInfo);
}
}

KTC - June 17, 2005 05:07 PM (GMT)
:codeblks: :codeblks: :codeblks:

moi - June 23, 2005 12:44 PM (GMT)
QUOTE (KTC @ Jun 17 2005, 05:07 PM)
:codeblks: :codeblks: :codeblks:

A nice way of greeting n00bs ;) :)

SatanInja - July 9, 2005 09:49 AM (GMT)
ctime > time.h

Viper - July 9, 2005 05:19 PM (GMT)
CODE
#include <cstdlib>
#include <windows.h>
#include <iostream>
#include <ctime>

k?

C00L - July 9, 2005 09:39 PM (GMT)
QUOTE (moi @ Jun 23 2005, 12:44 PM)
A nice way of greeting n00bs ;) :)

well it gets the point across to people, and it does say please :)

Whispher - July 11, 2005 05:15 PM (GMT)
um...ok, what do i put this in? Im using bloodshed or Dev 5 or somethin like that, i needs some help, i wanna play the game! and do i add anything to the code?

Viper - July 12, 2005 08:07 AM (GMT)
You just compile it. Don't add anything.

nontitle - July 12, 2005 05:37 PM (GMT)
i dont have access to any "good" dos compilers, i have to use gcc and g++ in cygwin... it's ok but it doesnt know what cls is...

DOOM - July 19, 2005 12:25 AM (GMT)
mingw

Viper - July 19, 2005 07:06 AM (GMT)
It's not DOS :D

tubapro12 - July 20, 2005 06:15 AM (GMT)
its command prompt on windows. the best excuse for a microsoft program microsoft has ever made... [i know that made no/little sense. i just installed a hdd and fried my brain on a jumper in the process. okay i didn't, i did install a new hdd though. now i'll go play battlefield.]

Harry - July 20, 2005 11:12 AM (GMT)
How do you play? :unsure:

Iam complete newb to c++, i opend dev c++ and made a new windows application then copyied all the code into it and then compiled and run it. i pressed every key and nothing moved?

EDIT: Ok now i have compiled it to the desktop and i doeble clicked on it and nothing happend? Then i tried to delete it and it said "acces is denied" :o now i cant delete it!

Viper - July 21, 2005 07:16 AM (GMT)
You have to compile it as a console program...
Also, the access denied is a Windows©®™ error. There's special programs to delete it before Windows©®™ gets it's services started.

DOOM - December 29, 2006 08:07 PM (GMT)
Thank you all for liking this game.

Wow, its been over a year since I replied here..




Hosted for free by InvisionFree