Compare commits
1 commit
| Author | SHA1 | Date | |
|---|---|---|---|
| 32e50969b4 |
45 changed files with 38346 additions and 38306 deletions
|
|
@ -5,7 +5,7 @@ set(CMAKE_CXX_STANDARD 14)
|
|||
|
||||
include_directories("D:/Program Files/mingw-w64/mingw64/x86_64-w64-mingw32/include")
|
||||
|
||||
add_executable(SFML_Template main.cpp Game.cpp Game.h GameSprite.cpp GameSprite.h Ship.cpp Ship.h System.cpp System.h Planet.cpp Planet.h Collision.cpp Collision.h Menu.cpp Menu.h GameSound.h)
|
||||
add_executable(SFML_Template main.cpp Game.cpp Game.h GameSprite.cpp GameSprite.h Ship.cpp Ship.h System.cpp System.h Planet.cpp Planet.h Collision.cpp Collision.h Menu.cpp Menu.h Rider.h)
|
||||
|
||||
target_link_directories(SFML_Template PUBLIC "D:/Program Files/mingw-w64/mingw64/x86_64-w64-mingw32/lib")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* File: collision.cpp
|
||||
* Author: Nick (original version), ahnonay (SFML2 compatibility)
|
||||
* Author: Nick (original version), ahnonay (SFML2 compatibility), bmorgan1 (collsion point return)
|
||||
*/
|
||||
|
||||
#include <map>
|
||||
|
|
@ -57,7 +57,7 @@ namespace Collision
|
|||
|
||||
BitmaskManager Bitmasks;
|
||||
|
||||
bool PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit) {
|
||||
bool PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit, sf::Vector2f &point) {
|
||||
sf::FloatRect Intersection;
|
||||
if (Object1.getGlobalBounds().intersects(Object2.getGlobalBounds(), Intersection)) {
|
||||
sf::IntRect O1SubRect = Object1.getTextureRect();
|
||||
|
|
@ -79,9 +79,10 @@ namespace Collision
|
|||
o2v.x < O2SubRect.width && o2v.y < O2SubRect.height) {
|
||||
|
||||
if (Bitmasks.GetPixel(mask1, Object1.getTexture(), (int)(o1v.x)+O1SubRect.left, (int)(o1v.y)+O1SubRect.top) > AlphaLimit &&
|
||||
Bitmasks.GetPixel(mask2, Object2.getTexture(), (int)(o2v.x)+O2SubRect.left, (int)(o2v.y)+O2SubRect.top) > AlphaLimit)
|
||||
Bitmasks.GetPixel(mask2, Object2.getTexture(), (int)(o2v.x)+O2SubRect.left, (int)(o2v.y)+O2SubRect.top) > AlphaLimit) {
|
||||
point = sf::Vector2f(i, j);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* File: collision.h
|
||||
* Authors: Nick Koirala (original version), ahnonay (SFML2 compatibility)
|
||||
* Authors: Nick Koirala (original version), ahnonay (SFML2 compatibility), bmorgan1 (collsion point return)
|
||||
*
|
||||
* Collision Detection and handling class
|
||||
* For SFML2.
|
||||
|
|
@ -49,7 +49,7 @@ namespace Collision {
|
|||
/// downloading the textures from the graphics card to memory -> SLOW!
|
||||
/// You can avoid this by using the "CreateTextureAndBitmask" function
|
||||
//////
|
||||
bool PixelPerfectTest(const sf::Sprite& Object1 ,const sf::Sprite& Object2, sf::Uint8 AlphaLimit = 0);
|
||||
bool PixelPerfectTest(const sf::Sprite& Object1 ,const sf::Sprite& Object2, sf::Uint8 AlphaLimit, sf::Vector2f &point);
|
||||
|
||||
//////
|
||||
/// Replaces Texture::loadFromFile
|
||||
|
|
|
|||
11
Game.cpp
11
Game.cpp
|
|
@ -17,6 +17,7 @@
|
|||
#include "ProjectileWeapon.h"
|
||||
#include "Collision.h"
|
||||
#include "BeamWeapon.h"
|
||||
#include "Rider.h"
|
||||
|
||||
std::vector<std::string> open(const std::string &path) {
|
||||
std::vector<std::string> files;
|
||||
|
|
@ -899,9 +900,13 @@ void Game::init() {
|
|||
p->update();
|
||||
|
||||
for (Ship *s : ships) {
|
||||
if (p->getShooter()->getTarget() == s && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(s->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *s))) {
|
||||
sf::Vector2f collisionPoint;
|
||||
if (p->getShooter()->getTarget() == s && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(s->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *s, 10, collisionPoint))) {
|
||||
s->setHull(s->getHullRemaining() - p->getDamage());
|
||||
|
||||
if (collisionPoint != sf::Vector2f(0, 0)) objects.push_back(new Rider(laser, 5, s, collisionPoint));
|
||||
else objects.push_back(new Rider(laser, 5, s, s->getPosition()));
|
||||
|
||||
for (COMShip *s : ships) {
|
||||
s->setPlayerRep(s->isFriendly() || s->isNeutral() ? -1 : s->getPlayerRep());
|
||||
}
|
||||
|
|
@ -930,7 +935,8 @@ void Game::init() {
|
|||
|
||||
if (deleted) break;
|
||||
|
||||
if (p->getShooter()->getTarget() == player && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(player->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *player))) {
|
||||
sf::Vector2f collisionPoint;
|
||||
if (p->getShooter()->getTarget() == player && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(player->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *player, 10, collisionPoint))) {
|
||||
player->setHull(player->getHullRemaining() - p->getDamage());
|
||||
hullLevel.setTextureRect(sf::IntRect(origGaugeRect.left, origGaugeRect.top,
|
||||
origGaugeRect.width / (float) player->getHullCap() *
|
||||
|
|
@ -1311,6 +1317,7 @@ void Game::init() {
|
|||
window.draw(*s);
|
||||
}
|
||||
|
||||
std::cout << objects.size() << std::endl;
|
||||
for (GameSprite *s : objects) {
|
||||
window.draw(*s);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public:
|
|||
/**
|
||||
* Updates sprite's position, direction, velocities, etc. every tick based on its Physics struct
|
||||
*/
|
||||
void update();
|
||||
virtual void update();
|
||||
void updateAnimation(bool override = false);
|
||||
|
||||
/*
|
||||
|
|
|
|||
29
Rider.h
Normal file
29
Rider.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Created by Benjamin on 4/29/2021.
|
||||
//
|
||||
|
||||
#ifndef SFML_TEMPLATE_RIDER_H
|
||||
#define SFML_TEMPLATE_RIDER_H
|
||||
|
||||
|
||||
class Rider : public GameSprite {
|
||||
private:
|
||||
GameSprite *mount;
|
||||
sf::Vector2f relativeLoc;
|
||||
public:
|
||||
Rider(const sf::Texture &texture, float scale, GameSprite *_mount, sf::Vector2f worldCoord) : GameSprite(texture, scale) {
|
||||
mount = _mount;
|
||||
relativeLoc = sf::Vector2f(worldCoord.x - mount->getPosition().x, worldCoord.y - mount->getPosition().y);
|
||||
relativeLoc = mount->getInverseTransform().transformPoint(relativeLoc);
|
||||
}
|
||||
|
||||
void update() override {
|
||||
sf::Vector2f newLoc = mount->getTransform().transformPoint(relativeLoc);
|
||||
setPosition(newLoc);
|
||||
|
||||
GameSprite::update();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif //SFML_TEMPLATE_RIDER_H
|
||||
BIN
data/Misc. Sprites/explosions.png
Normal file
BIN
data/Misc. Sprites/explosions.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 MiB |
|
|
@ -18,5 +18,8 @@ Images: https://commons.wikimedia.org/wiki/File:Dunajec_Gorge_-_Limestone_Rocks_
|
|||
Sounds: https://freesound.org/people/PhreaKsAccount/sounds/46492/
|
||||
https://freesound.org/people/NenadSimic/sounds/268108/
|
||||
https://freesound.org/people/plasterbrain/sounds/423166/
|
||||
https://freesound.org/people/chipfork71/sounds/72239/
|
||||
|
||||
Ship Name Components: https://github.com/endless-sky/endless-sky/blob/master/data/human/names.txt
|
||||
|
||||
Explosions: https://www.deviantart.com/joesalotofthings/art/Explosion-w-Smoke-Earth-Magic-Special-Effect-869413004
|
||||
Loading…
Add table
Add a link
Reference in a new issue