Compare commits

..

No commits in common. "develop" and "master" have entirely different histories.

45 changed files with 38306 additions and 38346 deletions

View file

@ -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 Rider.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 GameSound.h)
target_link_directories(SFML_Template PUBLIC "D:/Program Files/mingw-w64/mingw64/x86_64-w64-mingw32/lib")

View file

@ -1,6 +1,6 @@
/*
* File: collision.cpp
* Author: Nick (original version), ahnonay (SFML2 compatibility), bmorgan1 (collsion point return)
* Author: Nick (original version), ahnonay (SFML2 compatibility)
*/
#include <map>
@ -57,7 +57,7 @@ namespace Collision
BitmaskManager Bitmasks;
bool PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit, sf::Vector2f &point) {
bool PixelPerfectTest(const sf::Sprite& Object1, const sf::Sprite& Object2, sf::Uint8 AlphaLimit) {
sf::FloatRect Intersection;
if (Object1.getGlobalBounds().intersects(Object2.getGlobalBounds(), Intersection)) {
sf::IntRect O1SubRect = Object1.getTextureRect();
@ -79,10 +79,9 @@ 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) {
point = sf::Vector2f(i, j);
Bitmasks.GetPixel(mask2, Object2.getTexture(), (int)(o2v.x)+O2SubRect.left, (int)(o2v.y)+O2SubRect.top) > AlphaLimit)
return true;
}
}
}
}

View file

@ -1,6 +1,6 @@
/*
* File: collision.h
* Authors: Nick Koirala (original version), ahnonay (SFML2 compatibility), bmorgan1 (collsion point return)
* Authors: Nick Koirala (original version), ahnonay (SFML2 compatibility)
*
* 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, sf::Vector2f &point);
bool PixelPerfectTest(const sf::Sprite& Object1 ,const sf::Sprite& Object2, sf::Uint8 AlphaLimit = 0);
//////
/// Replaces Texture::loadFromFile

View file

@ -17,7 +17,6 @@
#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;
@ -900,13 +899,9 @@ void Game::init() {
p->update();
for (Ship *s : ships) {
sf::Vector2f collisionPoint;
if (p->getShooter()->getTarget() == s && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(s->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *s, 10, collisionPoint))) {
if (p->getShooter()->getTarget() == s && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(s->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *s))) {
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());
}
@ -935,8 +930,7 @@ void Game::init() {
if (deleted) break;
sf::Vector2f collisionPoint;
if (p->getShooter()->getTarget() == player && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(player->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *player, 10, collisionPoint))) {
if (p->getShooter()->getTarget() == player && ((p->getLifetime() == 1 && p->getGlobalBounds().intersects(player->getGlobalBounds())) || Collision::PixelPerfectTest(*p, *player))) {
player->setHull(player->getHullRemaining() - p->getDamage());
hullLevel.setTextureRect(sf::IntRect(origGaugeRect.left, origGaugeRect.top,
origGaugeRect.width / (float) player->getHullCap() *
@ -1317,7 +1311,6 @@ void Game::init() {
window.draw(*s);
}
std::cout << objects.size() << std::endl;
for (GameSprite *s : objects) {
window.draw(*s);
}

View file

@ -61,7 +61,7 @@ public:
/**
* Updates sprite's position, direction, velocities, etc. every tick based on its Physics struct
*/
virtual void update();
void update();
void updateAnimation(bool override = false);
/*

29
Rider.h
View file

@ -1,29 +0,0 @@
//
// 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

View file

@ -18,8 +18,5 @@ 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