Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhanovr committed Dec 27, 2013
0 parents commit 72a4dd1
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 0 deletions.
96 changes: 96 additions & 0 deletions Bullet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include "hge.h"
#include "hgesprite.h"
#include <iostream>
using namespace std;
extern HGE *hge;

class Bullet
{
private:
hgeSprite* sprite;
HTEXTURE tex;
float x, y;
float dx;
float dy;
float speed;
double friction;
enum direction {LEFT, RIGHT, UP};
direction d;
bool state;
public:
Bullet()
{
x = 0; y = 0;
d = RIGHT;
dx = 0; dy = 0;
speed = 200;
friction = 0.7;
sprite = new hgeSprite(0, 7, 7, 7, 7);
state = false;
}
void shoot(float x, float y, int d)
{
this->x = x; this->y = y; this->d = (direction)d;
this->state = true;
cout << "bang!\n";
}
void Update()
{
float dt=hge->Timer_GetDelta();
switch(d)
{
case LEFT:
dx-=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
break;
case RIGHT:
dx+=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
break;
case UP:
dy-=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx; y+=dy;
break;
}
}
void Render()
{
sprite->Render(x, y);
}
bool GetState()
{
return state;
}
void Reload()
{
state = false;
}
float GetX()
{
return x;
}
float GetY()
{
return y;
}
void LoadTexture()
{
tex = hge->Texture_Load("Bullet1.png");
if(!tex)
{
MessageBoxA(NULL, "Can't load one of the following files:\n Bullet.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
}
sprite->SetTexture(tex);
}
void Kill()
{
state = false;
}

};

Empty file added Enemy.cpp
Empty file.
237 changes: 237 additions & 0 deletions Player.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#include "hge.h"
#include "hgesprite.h"
#include <deque>
#include <time.h>
#include "Bullet.cpp"
using namespace std;

extern HGE *hge;

class Player
{
private:
hgeSprite* sprite;
HTEXTURE tex;
float x, y;
float dx, dy;
float speed, friction;
int life;
public:
deque <Bullet> B;
Player()
{
x = 400; y = 530;
dx = 0; dy = 0;
speed = 180;
friction = 0.7;
sprite = new hgeSprite(0, 32, 64, 32, 64);
for(int i = 0; i <9; i++){
Bullet b;
B.push_back(b);
}
life = 10;
}
void shooting()
{
if (hge->Input_GetKeyState(HGEK_LEFT) && hge->Input_KeyDown(HGEK_CTRL)){
for(int i = 0; i < 9; i++){
if(!B[i].GetState()){
B[i].shoot(x, y+13, 0);
break;
}
}
}
if (hge->Input_GetKeyState(HGEK_RIGHT) && hge->Input_KeyDown(HGEK_CTRL)){
for(int i = 0; i < 9; i++){
if(!B[i].GetState()){
B[i].shoot(x, y+13, 1);
break;
}
}
}
if (hge->Input_GetKeyState(HGEK_UP) && hge->Input_KeyDown(HGEK_CTRL)){
for(int i = 0; i < 9; i++){
if(!B[i].GetState()){
B[i].shoot(x, y+13, 2);
break;
}
}
}
}
void reload()
{
if (hge->Input_GetKeyState(HGEK_SHIFT)){
for(int i = 0; i < 9; i++)
B[i].Reload();
}
}
void Render()
{
if(life>0){
for(int i = 0; i < 9; i++){
if(B[i].GetState())
B[i].Render();
}
sprite->Render(x, y);
}
}
void Update()
{
float dt=hge->Timer_GetDelta();
float t = hge->Timer_GetTime();
// Process keys
if (hge->Input_GetKeyState(HGEK_LEFT) && !hge->Input_GetKeyState(HGEK_CTRL))
dx-=speed*dt;
if (hge->Input_GetKeyState(HGEK_RIGHT) && !hge->Input_GetKeyState(HGEK_CTRL))
dx+=speed*dt;
// Do some movement calculations and collision detection
dx*=friction; dy*=friction; x+=dx;
if(x>800) {x=800;dx=0;}
if(x<0) {x=0;dx=0;}
shooting();
reload();
for(int i = 0; i < 9; i++){
if(B[i].GetState())
B[i].Update();
}
if(life<0) { x = 0; y = 0;}
}
void LoadTexture()
{

tex = hge->Texture_Load("man1.png");
if(!tex)
{
MessageBoxA(NULL, "Can't load one of the following files:\n Man1.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
}
sprite->SetTexture(tex);
for(int i = 0; i < 9; i++)
B[i].LoadTexture();
}
float GetX()
{
return x;
}
float GetY()
{
return y;
}
void Kill()
{
life--;
}
};

class Enemy
{
private:
hgeSprite* sprite;
HTEXTURE tex;
float x, y;
bool state;
public:
deque <Bullet> B;
Enemy()
{
x = 0; y = 0;
sprite = new hgeSprite(0, 32, 64, 32, 64);
for(int i = 0; i <9; i++){
Bullet b;
B.push_back(b);
}
state = true;
}
Enemy(float x, float y)
{
this->x = x; this->y = y;
sprite = new hgeSprite(0, 32, 64, 32, 64);
for(int i = 0; i <9;i++){
Bullet b;
B.push_back(b);
}
state = true;
}
void LoadTexture()
{
tex = hge->Texture_Load("enemy.png");
if(!tex)
{
MessageBoxA(NULL, "Can't load one of the following files:\n enemy.png", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
hge->System_Shutdown();
hge->Release();
}
sprite->SetTexture(tex);
for(int i = 0; i < 9; i++)
B[i].LoadTexture();
}
void shooting()
{
int t = hge->Timer_GetTime();
if (t%3 == 0){
for(int i = 0; i < 9; i++){
if(!B[i].GetState()){
B[i].shoot(x, y+13, 0);
break;
}
}
}
/*if (hge->Input_GetKeyState(HGEK_RIGHT) && hge->Input_KeyDown(HGEK_CTRL)){
for(int i = 0; i < 9; i++){
if(!B[i].GetState()){
B[i].shoot(x, y, 1);
break;
}
}
}
if (hge->Input_GetKeyState(HGEK_UP) && hge->Input_KeyDown(HGEK_CTRL)){
for(int i = 0; i < 9; i++){
if(!B[i].GetState()){
B[i].shoot(x, y, 2);
break;
}
}
}*/
}
void reload()
{
if (hge->Input_GetKeyState(HGEK_SHIFT)){
for(int i = 0; i < 9; i++)
B[i].Reload();
}
}
void Render()
{
if(state){
for(int i = 0; i < 9; i++){
if(B[i].GetState())
B[i].Render();
}
sprite->Render(x, y);
}
}
void Update()
{
shooting();
reload();
for(int i = 0; i < 9; i++){
if(B[i].GetState())
B[i].Update();
}
}
float GetX()
{
return x;
}
float GetY()
{
return y;
}
void kill()
{
state = false;
x = 0;
y = 0;
}
};
Loading

0 comments on commit 72a4dd1

Please sign in to comment.