Here's the SFML version's code:
to make things easier you could just comment out everything other than show world, or show player, it will be just the same.
//#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
//#include <SFML/System.hpp>
#include <string>
#include <vector>
#include <time.h>
#include <list>
//#include <algorithm> // remove and remove_if
using namespace std;
//forward declare
class Enemy;
class Player;
class World;
class Particle;
//
//Screen attributes
const int SCREEN_WIDTH = 1280;
const int SCREEN_HEIGHT = 600;
const int SCREEN_BPP = 32;
// Create the main window
sf::RenderWindow App(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP), "Rectangle Wars");
sf::Image background_IMG;
sf::Sprite background;
sf::Image bullet_IMG;
sf::Sprite bullet;
sf::Image player_IMG;
sf::Sprite player;
sf::Image star_bright_s_IMG;
sf::Sprite star_bright_s;
sf::Image star_bright_m_IMG;
sf::Sprite star_bright_m;
sf::Image star_bright_l_IMG;
sf::Sprite star_bright_l;
sf::Image star_medium_s_IMG;
sf::Sprite star_medium_s;
sf::Image star_medium_m_IMG;
sf::Sprite star_medium_m;
sf::Image star_medium_l_IMG;
sf::Sprite star_medium_l;
sf::Image star_dark_s_IMG;
sf::Sprite star_dark_s;
sf::Image star_dark_m_IMG;
sf::Sprite star_dark_m;
sf::Image star_dark_l_IMG;
sf::Sprite star_dark_l;
sf::Image star_shooting_IMG;
sf::Sprite star_shooting;
sf::Image p1_IMG;
sf::Sprite p1;
sf::Image p2_IMG;
sf::Sprite p2;
sf::Image p3_IMG;
sf::Sprite p3;
sf::Image p4_IMG;
sf::Sprite p4;
sf::Image bparticle_IMG;
sf::Sprite bparticle;
sf::Image shimmer_IMG;
sf::Sprite shimmer;
sf::Image enemy_IMG;
sf::Sprite enemy;
sf::Image gameover_IMG;
sf::Sprite gameover;
//The frame rate
const int FRAMES_PER_SECOND = 60;
const int TOTAL_PARTICLES = 100 *20;
//handle input relies on these
const int DOT_WIDTH = 30;
const int DOT_HEIGHT = 30;
//The event structure
//SDL_Event event;
class Particle
{
private:
//Offsets
int x, y, xVel, yVel, type, life; //type 1 to 4 fire, 5 laser, 6 explosion
//Current frame of animation
//int frame;
//Type of particle
sf::Sprite part;
bool initialized;
public:
//Constructor
Particle( int X, int Y, int Type );
//Shows the particle
void show();
//Checks if particle is dead
bool alive;
bool vel_set;
//bool dead();
};
class Bullet
{
private:
friend void Collision_Detection(Player &p, World &w);
int x, y, type, life, erase_cooldown; //type 0 == player, 1 == enemy
vector<Particle> v_particles;
vector<Particle>::iterator v_particles_it;
public:
Bullet(int x, int y, int type);
bool alive;
bool to_erase;
void show();
void show_particles();
};
class Player
{
private:
friend void Collision_Detection(Player &p, World &w);
int x, y;
int recharge;
int xVel, yVel;
bool fire_on;
vector<Particle> v_particles;
vector<Particle>::iterator v_particles_it;
vector<Bullet> v_bullets;
vector<Bullet>::iterator v_bullets_it;
public:
Player();
//~Player();
void handle_input();
void move();
void show();
void fire();
void show_bullets();
void show_particles();
int x_coord();
int y_coord();
bool alive;
int killcount_1;
};
class Enemy
{
private:
friend void Collision_Detection(Player &p, World &w);
int x, y;
int recharge;
int xVel, yVel;
int type;
vector<Particle> v_particles;
vector<Particle>::iterator v_particles_it;
vector<Bullet> v_bullets;
vector<Bullet>::iterator v_bullets_it;
public:
Enemy(int Y);
bool alive;
void move(Player &p);
void show();
void fire();
void show_bullets();
void show_particles();
};
Enemy::Enemy(int Y)
{
alive = true;
y = Y;
x = SCREEN_WIDTH;
xVel = 2;
yVel = 0;
recharge =0;
}
void Enemy::move(Player &p)
{
//Move the dot left or right
x -= xVel;
//If the dot went too far to the left or right
if( ( x < 0 ) || ( x + DOT_WIDTH > SCREEN_WIDTH ) )
{
//move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down
if( ( y < 0 ) || ( y + DOT_HEIGHT > SCREEN_HEIGHT ) )
{
//move back
y -= yVel;
}
if (p.y_coord() > y)
yVel = +2;
if (p.y_coord() < y)
yVel = -2;
if (abs(p.y_coord() - y)< 5)
yVel = 0;
if (abs(p.y_coord() - y) < 50)
fire();
}
void Enemy::fire()
{
if (recharge > 25) {
Bullet a(x, y, 1);
v_bullets.push_back (a);
recharge = 0;
}
}
bool dead_b(Bullet b){
if (b.to_erase)
return true;
else
return false;
}
void Enemy::show_bullets()
{
v_bullets.erase(remove_if(v_bullets.begin(), v_bullets.end(), dead_b), v_bullets.end());
//Show bullets
for (v_bullets_it = v_bullets.begin(); v_bullets_it != v_bullets.end(); v_bullets_it++){
v_bullets_it->show();
}
}
bool dead_p(Particle p){
if (p.alive==false)
return true;
else
return false;
}
void Enemy::show_particles()
{
v_particles.erase(remove_if(v_particles.begin(), v_particles.end(), dead_p), v_particles.end());
//Show particles
for (v_particles_it = v_particles.begin(); v_particles_it != v_particles.end(); v_particles_it++){
v_particles_it->show();
}
}
Particle::Particle( int X, int Y, int Type){
type = Type;
x=X;
y=Y;
xVel=0;
yVel=0;
life = 0;
alive = true;
//part = NULL;
vel_set = false;
initialized = false;
}
class Star
{
private:
int type; //1=dark 2=medium 3=bright 4=shooting
int size; //1=small 2=medium 3=large
int x;
int y;
int xVel;
bool initialized;
sf::Sprite star;
public:
Star(int x, int y, int type, int size, int xVel);
void show();
bool alive;
};
Bullet::Bullet(int ix, int iy, int itype)
{
type = itype;
if (type == 0){
x = ix+30;
y = iy+15;
}
if (type == 1){
x = ix-30;
y = iy+15;
}
life =0;
to_erase = false;
erase_cooldown = 0;
alive = true;
Particle a(x, y, 5);
//v_particles.push_back(a);
}
class World
{
private:
friend void Collision_Detection(Player &p, World &w);
vector<Star> v_stars;
vector<Star>::iterator v_stars_it;
vector<Enemy> v_enemies;
vector<Enemy>::iterator v_enemies_it;
vector<Particle> v_particles;
vector<Particle>::iterator v_particles_it;
int frame;
public:
World();
void show();
void add_star();
void add_bullet(int x, int y);
void show_stars();
void show_enemies();
Player myPlayer;
void show_player();
void enemy_move();
// void show_bullets();
void show_particles();
void explosion(int x, int y);
};
World::World()
{
// X should not be a factor of screen_width, more like screen height
for (int i=0; i < (SCREEN_WIDTH/6) ; i++){
int randmX = rand() %SCREEN_WIDTH + 1;
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 1;
int randmSize = rand() %2 + 1;
Star a(randmX, randmY, randmType, 1, 1);
v_stars.push_back (a);
}
//mid layer xVel 4
for (int i=0; i < (SCREEN_WIDTH/15) ; i++){
int randmX = rand() %SCREEN_WIDTH + 1;
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 1;
int randmSize = rand() %2 + 1;
Star a(randmX, randmY, randmType, randmSize, 2);
v_stars.push_back (a);
}
//front layer xVel 8
for (int i=0; i < (SCREEN_WIDTH/30) ; i++){
int randmX = rand() %SCREEN_WIDTH + 1;
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 2;
int randmSize = rand() %2 + 2;
Star a(randmX, randmY, randmType, randmSize, 4);
v_stars.push_back (a);
}
//front front layer xVel 8
for (int i=0; i < (SCREEN_WIDTH/50) ; i++){
int randmX = rand() %SCREEN_WIDTH + 1;
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 2;
int randmSize = rand() %2 + 2;
Star a(randmX, randmY, randmType, randmSize, 8);
v_stars.push_back (a);
}
//foreground line star layer Xvel 15, Type 4
for (int i=0; i < (SCREEN_WIDTH/300) ; i++){
int randmX = rand() %SCREEN_WIDTH + 1;
int randmY = rand() %599 + 1;
Star a(randmX, randmY, 4, 1, 15);
v_stars.push_back (a);
}
}
void World::show(){
show_stars();
show_enemies();
show_player();
show_particles();
frame++;
}
void World::explosion(int x, int y){
for (int i=0, r=((rand() % 100) -80); i < 120 + r ; i++){
int xx = x + rand() % 10 - 5;
int yy = y + rand() % 10 - 5;
Particle a(xx, yy, 6);
v_particles.push_back(a);
}
}
void World::show_particles()
{
//remove/erase idiom
v_particles.erase(remove_if(v_particles.begin(), v_particles.end(), dead_p), v_particles.end());
for (v_particles_it = v_particles.begin(); v_particles_it != v_particles.end(); v_particles_it++){
v_particles_it->show();
}
}
void World::enemy_move() //commands all the enemies to take their move and gives them reference to the player object
{
for (v_enemies_it = v_enemies.begin(); v_enemies_it != v_enemies.end(); v_enemies_it++){
v_enemies_it->move(myPlayer);
}
}
void World::show_player(){
myPlayer.show();
}
void Player::show_bullets()
{
v_bullets.erase(remove_if(v_bullets.begin(), v_bullets.end(), dead_b), v_bullets.end());
//Show bullets
for (v_bullets_it = v_bullets.begin(); v_bullets_it != v_bullets.end(); v_bullets_it++){
v_bullets_it->show();
}
}
void Player::show_particles()
{
v_particles.erase(remove_if(v_particles.begin(), v_particles.end(), dead_p), v_particles.end());
for( int p = 0; p < TOTAL_PARTICLES/4 ; p++ )
{
int randmX = x - (rand() % 11) +2;
int randmY = y +14 + (rand() % 29) - 14;
const Particle a(randmX, randmY, 1);
v_particles.push_back(a);
}
for( int p = 0; p < TOTAL_PARTICLES/4 ; p++ )
{
int randmX = x - (rand() % 11) - 5 ;
int randmY = y + 14 + (rand() % 12);
int negm = rand() %2;
if (negm == 1)
randmY = randmY - (2*(randmY - (y+15)));
const Particle a(randmX, randmY, 2);
v_particles.push_back(a);
}
for( int p = 0; p < TOTAL_PARTICLES/4 ; p++ )
{
int randmX = x - (rand() % 11) - 11 ;
int randmY = y + 14 +(rand() % 7);
int negm = rand() %2;
if (negm == 1)
randmY = randmY - (2*(randmY - (y+15)));
const Particle a(randmX, randmY, 3);
v_particles.push_back(a);
}
for( int p = 0; p < TOTAL_PARTICLES/8 ; p++ )
{
int randmX = x - (rand() % 11) - 21 ;
int randmY = y + 14 +(rand() % 2);
int negm = rand() %2;
if (negm == 1)
randmY = randmY - (2*(randmY - (y+15)));
const Particle a(randmX, randmY, 4);
v_particles.push_back(a);
}
//Show particles
for (v_particles_it = v_particles.begin(); v_particles_it != v_particles.end(); v_particles_it++){
v_particles_it->show();
}
}
bool dead_e(Enemy e){
if (e.alive==false)
return true;
else
return false;
}
void World::show_enemies()
{
v_enemies.erase(remove_if(v_enemies.begin(), v_enemies.end(), dead_e), v_enemies.end());
if (rand() % 50 == 0){
int randmY = rand() %(SCREEN_HEIGHT - DOT_HEIGHT) +1;
Enemy a(randmY);
v_enemies.push_back (a);
}
for (v_enemies_it = v_enemies.begin(); v_enemies_it != v_enemies.end(); v_enemies_it++){
v_enemies_it->show();
}
}
bool dead_s (Star s){
if (s.alive==false)
return true;
else
return false;
}
void World::show_stars()
{
v_stars.erase(remove_if(v_stars.begin(), v_stars.end(), dead_s), v_stars.end());
//adding stars to the right of screen
//furthest, slowest layer xVel 1 dark or medium, small or medium
if (frame % 6 == 0){
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 1;
int randmSize = rand() %2 + 1;
Star a(SCREEN_WIDTH, randmY, randmType, 1, 1);
v_stars.push_back (a);
}
//mid layer xVel 2
if (frame % 15 == 0){
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 1;
int randmSize = rand() %2 + 1;
Star a(SCREEN_WIDTH, randmY, randmType, randmSize, 2);
v_stars.push_back (a);
}
//front layer xVel 4
if (frame % 30 == 0){
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 2;
int randmSize = rand() %2 + 2;
Star a(SCREEN_WIDTH, randmY, randmType, randmSize, ((rand() % 4) +3));
v_stars.push_back (a);
}
//front front layer xVel 8
if (frame % 50 == 0){
int randmY = rand() %599 + 1;
int randmType = rand() %2 + 2;
int randmSize = rand() %2 + 2;
Star a(SCREEN_WIDTH, randmY, randmType, randmSize, ((rand() % 6) + 7));
v_stars.push_back (a);
}
//foreground line star layer Xvel 15, Type 4
if (frame % 30 == 0){
int randmY = rand() %599 + 1;
Star a(SCREEN_WIDTH, randmY, 4, 1, ((rand() % 15) + 10));
v_stars.push_back (a);
}
for (v_stars_it = v_stars.begin(); v_stars_it != v_stars.end(); v_stars_it++){
v_stars_it->show();
}
}
Star::Star(int ix, int iy, int itype, int isize, int ixVel)
{
x = ix;
y = iy;
type = itype;
size = isize;
xVel = ixVel;
initialized = false;
//star = NULL;
}
bool init()
{
// Create the main window
sf::Window App(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP), "Rectangle Wars");
// Get a reference to the input manager associated to our window, and store it for later use
const sf::Input& Input = App.GetInput();
//sf::Clock Clock;
return true;
}
bool load_files()
{
//Load the dot image
//dot = load_image( "ship.png" );
//Load the background
if (!background_IMG.LoadFromFile("recwar/black.png"))
{
// Error...
}
background.SetImage(background_IMG);
if (!bullet_IMG.LoadFromFile("recwar/bullet.png"))
{
// Error...
}
bullet.SetImage(bullet_IMG);
if (!player_IMG.LoadFromFile("recwar/player.png"))
{
// Error...
}
player.SetImage(player_IMG);
if (!star_bright_s_IMG.LoadFromFile("recwar/starbright_s.png"))
{
// Error...
}
star_bright_s.SetImage(star_bright_s_IMG);
if (!star_bright_m_IMG.LoadFromFile("recwar/starbright.png"))
{
// Error...
}
star_bright_m.SetImage(star_bright_m_IMG);
if (!star_bright_l_IMG.LoadFromFile("recwar/starbright_l.png"))
{
// Error...
}
star_bright_l.SetImage(star_bright_l_IMG);
if (!star_medium_s_IMG.LoadFromFile("recwar/starmedium_s.png"))
{
// Error...
}
star_medium_s.SetImage(star_medium_s_IMG);
if (!star_medium_m_IMG.LoadFromFile("recwar/starmedium.png"))
{
// Error...
}
star_medium_m.SetImage(star_medium_m_IMG);
if (!star_medium_l_IMG.LoadFromFile("recwar/starmedium_l.png"))
{
// Error...
}
star_medium_l.SetImage(star_medium_l_IMG);
if (!star_dark_s_IMG.LoadFromFile("recwar/stardark_s.png"))
{
// Error...
}
star_dark_s.SetImage(star_dark_s_IMG);
if (!star_dark_m_IMG.LoadFromFile("recwar/stardark.png"))
{
// Error...
}
star_dark_m.SetImage(star_dark_m_IMG);
if (!star_dark_l_IMG.LoadFromFile("recwar/stardark_l.png"))
{
// Error...
}
star_dark_l.SetImage(star_dark_l_IMG);
//if (!star_shooting_IMG.LoadFromFile("recwar/star_shooting.png"))
{
// Error...
}
star_shooting.SetImage(star_shooting_IMG);
if (!p1_IMG.LoadFromFile("recwar/particle1.png"))
{
// Error...
}
p1.SetImage(p1_IMG);
if (!p2_IMG.LoadFromFile("recwar/particle2.png"))
{
// Error...
}
p2.SetImage(p2_IMG);
if (!p3_IMG.LoadFromFile("recwar/particle3.png"))
{
// Error...
}
p3.SetImage(p3_IMG);
if (!p4_IMG.LoadFromFile("recwar/particle4.png"))
{
// Error...
}
p4.SetImage(p4_IMG);
if (!bparticle_IMG.LoadFromFile("recwar/bparticle.png"))
{
// Error...
}
bparticle.SetImage(bparticle_IMG);
if (!shimmer_IMG.LoadFromFile("recwar/shimmer.png"))
{
// Error...
}
shimmer.SetImage(shimmer_IMG);
if (!enemy_IMG.LoadFromFile("recwar/enemy.png"))
{
// Error...
}
enemy.SetImage(enemy_IMG);
if (!gameover_IMG.LoadFromFile("recwar/gameover.png"))
{
// Error...
}
gameover.SetImage(gameover_IMG);
//If everything loaded fine
return true;
}
void Star::show(){
//determine type and size of star (only the first time)
//add bool for first init check
if (initialized == false){
if ((type == 1) && (size == 1)) star = star_dark_s;
if ((type == 1) && (size == 2)) star = star_dark_m;
if ((type == 1) && (size == 3)) star = star_dark_l;
if ((type == 2) && (size == 1)) star = star_medium_s;
if ((type == 2) && (size == 2)) star = star_medium_m;
if ((type == 2) && (size == 3)) star = star_medium_l;
if ((type == 3) && (size == 1)) star = star_bright_s;
if ((type == 3) && (size == 2)) star = star_bright_m;
if ((type == 3) && (size == 3)) star = star_bright_l;
if ((type == 4)) {star = star_shooting; xVel = 30;}
initialized = true;
}
star.SetPosition(x,y);
App.Draw(star);
//apply_surface( x, y, star);
x -= xVel;
if (x<0)
alive = false;
}
void Particle::show()
{
//Show image
if (initialized == false){
if (type == 1) part = p1;
else if (type == 2) part = p2;
else if (type == 3) part = p3;
else if (type == 4) part = p4;
else if (type == 5) part = bparticle;
else if (type == 6){
if ((rand() % 4) == 0)
part = p1;
else if ((rand() % 4) == 1)
part = p2;
else if ((rand() % 4) == 2)
part = p3;
else if ((rand() % 4) == 1)
part = p4;}
initialized = true;
}
if(alive)
{
//part.SetPosition(x,y);
//App.Draw(part);
//apply_surface( x, y, part, screen );
}
//Animate
life++;
if (type <= 4 && vel_set == false){
xVel = ((rand() % 10) +10) * (-1);
vel_set = true;}
if (type <= 4 && life>(2 + rand() % 5))
alive=false;
if (type == 5 && life> (20 + rand() % 11))
alive = false;
if (type == 5 && vel_set == false){
xVel = (rand() % 5) -2;
yVel = (rand() % 5) -2;
vel_set=true;
}
if (type == 6 && life> (20 + rand () % 11))
alive = false;
if (type == 6 && vel_set == false){
int randmX = rand() % 6;
int randmY = rand() % 6;
if ((rand() %2) == 0)
randmX = -randmX;
if ((rand() %2) == 0)
randmY = -randmY;
xVel = randmX;
yVel = randmY;
vel_set = true;
}
if (type == 6 && vel_set == true && xVel > 0 && (life % 5 == 0)){
xVel -= 1;
}
if (type == 6 && vel_set == true && xVel < 0 && (life % 5 == 0)){
xVel += 1;
}
if (type == 6 && vel_set == true && yVel > 0 && (life % 5 == 0)){
yVel -= 1;
}
if (type == 6 && vel_set == true && yVel < 0 && (life % 5 == 0)){
yVel += 1;
}
x = x+xVel;
y = y+yVel;
}
Player::Player()
{
//Initialize the offsets
recharge = 0;
x = 100;
y = 100;
fire_on = false;
alive = true;
killcount_1 = 0;
//v_particles.reserve(10000);
//Initialize the velocity
xVel = 0;
yVel = 0;
//Initialize particles
for( int p = 0; p < TOTAL_PARTICLES/4; p++ )
{
int randmX = x - (rand() % 11);
int randmY = y + (rand() % 31) - 15;
Particle a(randmX, randmY, 1);
v_particles.push_back(a);
}
for( int p = 0; p < TOTAL_PARTICLES/4; p++ )
{
int randmX = x - (rand() % 11) - 5 ;
int randmY = y + (rand() % 12);
if ((rand() % 2) == 1) randmY = randmY * -1;
Particle a(randmX, randmY, 2);
v_particles.push_back(a);
}
for( int p = 0; p < TOTAL_PARTICLES/4; p++ )
{
int randmX = x - (rand() % 11) - 11 ;
int randmY = y + (rand() % 7);
if ((rand() % 2) == 1) randmY = randmY * -1;
Particle a(randmX, randmY, 3);
v_particles.push_back(a);
}
for( int p = 0; p < TOTAL_PARTICLES/4; p++ )
{
int randmX = x - (rand() % 11) - 21 ;
int randmY = y + (rand() % 5);
if ((rand() % 2) == 1) randmY = randmY * -1;
Particle a(randmX, randmY, 4);
v_particles.push_back(a);
}
}
void Player::move()
{
//Move the dot left or right
x += xVel;
//If the dot went too far to the left or right
if( ( x < 0 ) || ( x + DOT_WIDTH > SCREEN_WIDTH ) )
{
//move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down
if( ( y < 0 ) || ( y + DOT_HEIGHT > SCREEN_HEIGHT ) )
{
//move back
y -= yVel;
}
}
void Player::fire(){
if (recharge > 10) {
Bullet a(x, y, 0);
v_bullets.push_back (a);
recharge = 0;
}
}
void Player::show(){
if (alive){
player.SetPosition(x,y);
App.Draw(player);
show_bullets();
show_particles();
}
recharge++;
if (fire_on)
fire();
}
int Player::x_coord()
{
return x;
}
int Player::y_coord()
{
return y;
}
void Enemy::show(){
//x -= 1;
//move();
if (alive){
enemy.SetPosition(x,y);
App.Draw(enemy);
show_bullets();
show_particles();
recharge++;
if (x<(-30))
alive = false;
}
//if (fire_on)
//fire();
}
void Bullet::show(){
if (alive){
bullet.SetPosition(x,y);
App.Draw(bullet);
if (type==0){
x += 25;
if (x>SCREEN_WIDTH)
alive = false;
}
else if (type == 1){
x -=15;
if (x<0)
alive = false;
}
}
else{
if (erase_cooldown >= 40){
to_erase = true;
}
erase_cooldown++;
}
show_particles();
}
void Bullet::show_particles(){
if (alive){
if (rand() % 10 == 0){
int randmX = x - ( rand() % 50);
int randmY = y + (rand() % 7) - 3;
Particle a(randmX, randmY, 5);
v_particles.push_back(a);
}
}
//Show particles
for (v_particles_it = v_particles.begin(); v_particles_it != v_particles.end(); v_particles_it++){
v_particles_it->show();
}
}
void Collision_Detection(Player &p, World &w)
{
//player's bullet and enemy collision
//player: 30 x 30
//bullet: 32 x 4
for (p.v_bullets_it = p.v_bullets.begin(); p.v_bullets_it != p.v_bullets.end(); p.v_bullets_it++){
int leftB, rightB, topB, bottomB;
leftB = p.v_bullets_it->x;
rightB = p.v_bullets_it->x + 32;
topB = p.v_bullets_it->y;
bottomB = p.v_bullets_it->y + 4;
for (w.v_enemies_it = w.v_enemies.begin(); w.v_enemies_it != w.v_enemies.end(); w.v_enemies_it++){
int leftE, rightE, topE, bottomE;
leftE = w.v_enemies_it->x;
rightE = w.v_enemies_it->x + 30;
topE = w.v_enemies_it->y;
bottomE = w.v_enemies_it->y + 30;
if(( bottomB <= topE ) || ( topB >= bottomE ) || ( rightB <= leftE ) || ( leftB >= rightE )){
//int a = 1;
}
else
{
p.v_bullets_it->alive = false;
w.v_enemies_it->alive = false;
w.explosion(w.v_enemies_it->x + 15, w.v_enemies_it->y + 15);
p.killcount_1++;
}
}
}
int leftP, rightP, topP, bottomP;
leftP = p.x;
rightP = p.x + 30;
topP = p.y;
bottomP = p.y + 30;
for (w.v_enemies_it = w.v_enemies.begin(); w.v_enemies_it != w.v_enemies.end(); w.v_enemies_it++){
for (w.v_enemies_it->v_bullets_it = w.v_enemies_it->v_bullets.begin();
w.v_enemies_it->v_bullets_it != w.v_enemies_it->v_bullets.end();
w.v_enemies_it->v_bullets_it++){
int leftB, rightB, topB, bottomB;
leftB = w.v_enemies_it->v_bullets_it->x;
rightB = w.v_enemies_it->v_bullets_it->x + 32;
topB = w.v_enemies_it->v_bullets_it->y;
bottomB = w.v_enemies_it->v_bullets_it->y + 4;
if(( bottomP <= topB ) || ( topP >= bottomB ) || ( rightP <= leftB ) || ( leftP >= rightB )){
//int a = 1;
}
else
{
p.alive = false;
w.v_enemies_it->v_bullets_it->alive = false;
w.explosion(p.x + 15, p.y + 15);
//w.v_enemies.erase(w.v_enemies_it++);
}}
}
}
int main( int argc, char* args[] )
{
bool quit = false;
bool running = true;
srand( time(NULL) );
//App.SetFramerateLimit(60);
//App.UseVerticalSync(true);
while (quit == false && running == true)
{
if( load_files() == false )
{
return 1;
}
bool player_dead = false;
World myWorld;
//While the user hasn't quit
while( player_dead == false )
{
if (myWorld.myPlayer.alive == false)
player_dead = true;
App.Clear();
myWorld.myPlayer.move();
myWorld.enemy_move();
myWorld.show();
Collision_Detection(myWorld.myPlayer, myWorld);
/*for( int p = 0; p < 1 ; p++ )
{
int randmX = (rand() % 11) - 21 ;
int randmY = (rand() % 2);
int negm = rand() %2;
if (negm == 1)
randmY = randmY - (2*(randmY - 15));
vector<int> vint;
vint.push_back(randmX);
}*/
//Update the screen
App.Display();
}
}
return 0;
}