Added laser collision on aliens

This commit is contained in:
2024-01-30 16:22:43 +01:00
parent d67394aaec
commit 0bc7a96c32
9 changed files with 499 additions and 409 deletions
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
class Alien
{
public:
Alien(Vector2f& position);
RectangleShape& getShape() { return _shape; };
private:
RectangleShape _shape;
};
+36 -32
View File
@@ -1,32 +1,36 @@
#pragma once
#include <cstdlib>
#include <SFML/Graphics.hpp>
#include "Player.h"
#include "Laser.h"
#include "Shield.h"
using namespace std;
using namespace sf;
class GameManager
{
public:
GameManager();
void run();
void handleInputs();
void handleLasersCollision();
private:
Clock _clock;
//RenderWindow _window{ VideoMode::getFullscreenModes()[0], "Space Invader", Style::Fullscreen };
RenderWindow _window{ VideoMode(1024, 800), "Space Invader", Style::Close | Style::Titlebar};
Player _player = { _window.getSize() };
vector<Laser*> _lasers;
vector<Shield*> _shields;
};
#pragma once
#include <cstdlib>
#include <SFML/Graphics.hpp>
#include "Player.h"
#include "Laser.h"
#include "Shield.h"
#include "Alien.h"
using namespace std;
using namespace sf;
class GameManager
{
public:
GameManager();
void run();
void handleInputs();
void handleLasersCollision();
private:
Clock _clock;
const int alienScreenMargin = 50;
//RenderWindow _window{ VideoMode::getFullscreenModes()[0], "Space Invader", Style::Fullscreen };
RenderWindow _window{ VideoMode(1024, 800), "Space Invader", Style::Close | Style::Titlebar};
Player _player = { _window.getSize() };
vector<Laser*> _lasers;
vector<Shield*> _shields;
vector<Alien*> _aliens;
};
+21 -22
View File
@@ -1,22 +1,21 @@
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
class Laser
{
public:
Laser() {};
Laser(Window& window);
RectangleShape& getShape() { return _laser; }
void setInitialPosition(Vector2f position);
private:
RectangleShape _laser;
};
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
class Laser
{
public:
Laser(Window& window);
RectangleShape& getShape() { return _laser; }
void setInitialPosition(Vector2f position);
private:
RectangleShape _laser;
};
+24 -25
View File
@@ -1,26 +1,25 @@
#pragma once
#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
using namespace sf;
using namespace std;
class Shield
{
public:
Shield() {};
Shield(Window& window);
void setPosition(Vector2f position);
RectangleShape& getShape() { return _shape; };
int getLife() const { return _life; };
void decreaseLife() { _life -= 1; };
private:
int _life = 10;
RectangleShape _shape;
#pragma once
#include <iostream>
#include <string>
#include <SFML/Graphics.hpp>
using namespace sf;
using namespace std;
class Shield
{
public:
Shield(Window& window);
void setPosition(Vector2f position);
RectangleShape& getShape() { return _shape; };
int getLife() const { return _life; };
void decreaseLife() { _life -= 1; };
private:
int _life = 10;
RectangleShape _shape;
};