I've been trying to make a space invader game day and night for three days straight having little to no sleep but I just can't do it. I'm at my wit's end and I don't know anyone who's willing to help me out on this.
#include <iostream>
#include <conio.h>
#include <windows.h>
usingnamespace std;
bool gameOver;
constint width = 40;
constint height = 10;
int x, y, enemyX, enemyY, bulletx[100], bullety[100];
enum eDirecton { STOP = 0, LEFT, RIGHT, UP, DOWN, ATTACK};
eDirecton dir;
void Setup()
{
gameOver = false;
dir = STOP;
x = width / 2; // so that the player starts on the middle
y = height / 2;
}
void Draw()
{
system("cls"); //system("clear");
for (int i = 0; i < width+2; i++) // top cover
cout << "1";
cout << endl;
for (int i = 0; i < height; i++) // system print of what you see
{
for (int j = 0; j < width; j++)
{
if (j == 0) //left side of the map
cout << "2";
if (i == y && j == x)
cout << "O";
else
{
bool print = false;
if (!print)
cout << " ";
}
if (j == width - 1) //right side of the map
cout << "3";
}
cout << endl;
}
for (int i = 0; i < width+2; i++) // bottom cover
cout << "4";
cout << endl;
}
void Input()
{
if (_kbhit()) // how the program knows which key to input and what direction it will go
{
switch (_getch())
{
case'a':
dir = LEFT;
break;
case'd':
dir = RIGHT;
break;
case'w':
dir = UP;
break;
case's':
dir = DOWN;
case'l':
dir = ATTACK;
break;
case'x':
gameOver = true;
break;
}
}
}
void Logic()
{
switch (dir)// how the program knows what the directions are
{
case LEFT:
x-=1;
break;
case RIGHT:
x+=1;
break;
case UP:
y-=1;
break;
case DOWN:
y+=1;
break;
case ATTACK:
// can't figure this part out
break;
default:
break;
}
if (x >= width) x = 0;
elseif (x < 0) x = width - 1;// pass through walls horizontal
if (y >= height) y = 0;
elseif (y < 0) y = height - 1; // pass through walls vertical
if (x == enemyX && y == enemyY)
{
enemyX = rand() % width;
enemyY = rand() % height;
}
}
int main()
{
Setup();
while (!gameOver)
{
Draw();
Input();
Logic();
Sleep(30); //sleep(10);
}
return 0;
}
What the end product should be like:
A. The player must be able to shoot
B. Enemies going down from the map
C. When the player hits the enemies they die and the player gains a point
D. The enemy shoots back and when hit the player loses health (health and damage can be of any amount)
E. There is a score system
note: for some reason the player can't move down form the map
Hi gameguy8888, you can use my simple shotgame as basic implementation for a space invader games. https://processing8.wordpress.com/2016/02/28/einfaches-ballerspiel/
the source is written in simple java code. the main class is the turtle-class based on the language TURTLE. it is very easy to think in circles and lines.
some commands of the turtle class:
lf : turn left
rt : turn right
fw : forward
bw : backward
dc : draw circle
ic : is point in circle (collision detection)
la : look at point or turtle
The idea of the turtle class is : you have a turtle with a pen on the white paper and you can give him commands like "go forward 10 pixels", "turn left 45 degree", "look at a turtle" or "look at a point x/y". It's like using a circle and a ruler to create your scetches on paper.