Skip to content

Commit

Permalink
Done
Browse files Browse the repository at this point in the history
  • Loading branch information
imerr committed Apr 19, 2015
1 parent b922ed7 commit 3a464ae
Show file tree
Hide file tree
Showing 41 changed files with 1,451 additions and 23 deletions.
5 changes: 3 additions & 2 deletions Bat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <iostream>

Bat::Bat(engine::Scene* scene): Damagable(scene), m_targetPoint(0,0) {

m_deathSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/bat_death.wav");
m_hurtSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/bat_hurt.wav");
}

Bat::~Bat() {
Expand All @@ -38,7 +39,7 @@ void Bat::OnUpdate(sf::Time interval) {
}
auto delta = m_targetPoint-GetGlobalPosition();
float dist = sqrtf(delta.x*delta.x+delta.y*delta.y);
if (dist < 700) {
if (dist < 700 && abs(delta.y) < 300) {
float angle = atan2(delta.y, delta.x);

const float v = 3 * interval.asSeconds() ;
Expand Down
38 changes: 38 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,45 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
add_subdirectory(Engine ${CMAKE_CURRENT_BINARY_DIR}/engine)
include("Engine/includes.cmake")
include_directories(.)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "/Zm256 /Gy /GR- /W2 /wd4275 /wd4530 /wd4566 /FS")
set(CMAKE_CXX_FLAGS_DEBUG "/MDd /DDEBUG /RTCsu /Od /Zi")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/GL /GS- /O2 /MD /fp:fast /DNDEBUG /Zi")
set(CMAKE_CXX_FLAGS_RELEASE "/GL /GS- /O2 /MD /fp:fast /DNDEBUG")

set(CMAKE_C_FLAGS "/Zm256 /Gy /W2 /wd4566 /FS")
set(CMAKE_C_FLAGS_DEBUG "/MDd /DDEBUG /RTCsu /Od /Zi /D_SECURE_SCL=0 /D_HAS_ITERATOR_DEBUGGING=0")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/GL /GS- /O2 /MD /fp:fast /DNDEBUG /Zi")
set(CMAKE_C_FLAGS_RELEASE "/GL /GS- /O2 /MD /fp:fast /DNDEBUG")

#
# Workaround for "LINK : fatal error LNK1104: cannot open file 'XXX.map'" issue
# see http://social.msdn.microsoft.com/Forums/en-US/vcprerelease/thread/19804537-05ba-4adf-8273-68d2450401e0
#

set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /MAP /OPT:ICF /OPT:REF /INCREMENTAL:NO")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /MAP /DEBUG /OPT:ICF /OPT:REF /LTCG /INCREMENTAL:NO")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /MAP /OPT:ICF /OPT:REF /LTCG /INCREMENTAL:NO")

set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /MAP /OPT:ICF /OPT:REF /INCREMENTAL:NO")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /MAP /OPT:ICF /OPT:REF /LTCG /INCREMENTAL:NO")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /MAP /OPT:ICF /OPT:REF /LTCG /INCREMENTAL:NO")
else ()
set(CMAKE_CXX_FLAGS "-Wall -march=pentium4 -mmmx -msse -msse2 -std=c++11 -fno-exceptions -fno-rtti")
set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Ofast -g")
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast")

set(CMAKE_C_FLAGS "-Wall -march=pentium4 -mmmx -msse -msse2")
set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpmath=sse")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpmath=sse")
endif ()
endif ()
set(SOURCE_FILES main.cpp
LD32.cpp
SplashMessage.cpp
Expand Down
6 changes: 6 additions & 0 deletions Damagable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ bool Damagable::initialize(Json::Value& root) {
void Damagable::Damage(float damage){
if (m_invulnTime > 0) return;
m_health-=damage;

if (damage > 0.1 || m_health < 0) {
m_hit = true;
}
if (m_health < 0 && !m_dead) {
m_deathSound->play();
} else {
m_hurtSound->play();
}
m_invulnTime = 0.1;
static_cast<Level*>(m_scene)->ChangeScore(damage/4);
UpdateHealthbar();
Expand Down
3 changes: 3 additions & 0 deletions Damagable.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef LD32_ENEMY_HPP
#define LD32_ENEMY_HPP
#include <Engine/SpriteNode.hpp>
#include <SFML/Audio.hpp>

#include "misc.hpp"
class Damagable: public engine::SpriteNode {
Expand All @@ -21,6 +22,8 @@ class Damagable: public engine::SpriteNode {
bool m_hit;
ContactHandler m_preCH;
float m_invulnTime;
sf::Sound* m_deathSound;
sf::Sound* m_hurtSound;
public:
Damagable(engine::Scene* scene);
virtual ~Damagable();
Expand Down
2 changes: 1 addition & 1 deletion Engine
2 changes: 1 addition & 1 deletion LD32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LD32::~LD32() {
}

void LD32::StartGame() {
SwitchScene(engine::Factory::create<Level>("assets/scripts/level_1.json", this));
SwitchScene(engine::Factory::create<Level>("assets/scripts/level_2.json", this));
}
void LD32::Unlock(WeaponType wt){
m_unlocks[wt] = true;
Expand Down
1 change: 1 addition & 0 deletions Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@ bool Level::initialize(Json::Value& root) {
if (!engine::Scene::initialize(root)) return false;
m_respawnPoint = sf::Vector2f(root["respawn"].get(0u, 100.0f).asFloat(), root["respawn"].get(1u, 100.0f).asFloat());
m_next = root.get("next", "").asString();
return true;
}
19 changes: 15 additions & 4 deletions Slayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Level.hpp"
#include "LD32.hpp"
#include "Engine/Factory.hpp"
#include "Engine/ResourceManager.hpp"
#include <SFML/Window.hpp>
#include <Engine/Game.hpp>
#include <iostream>
Expand All @@ -11,17 +12,22 @@
Slayer::Slayer(engine::Scene* scene): Damagable(scene), m_maxVelocity(20, 1),
m_velocityIncrease(6, 10), m_contactHandler(this), m_state(STANDING),
m_weaponType(WT_NONE), m_weapon(nullptr), m_shootTime{},
m_respawnTimer(10.0f) {
m_respawnTimer(10.0f), m_jumpCooldown(0) {
m_scene->OnContact.AddHandler(&m_contactHandler);
static_cast<Level*>(scene)->SetSlayer(this);
static_cast<Level*>(scene)->DecEnemies();
// Remove damagable enemy hit handler
m_scene->OnContactPreSolve.RemoveHandler(&m_preCH);
m_health = m_maxHealth = 100;

m_deathSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/death.wav");
m_hurtSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/hurt.wav");
m_shootSound[WT_CROSSBOW] = engine::ResourceManager::instance()->MakeSound("assets/sounds/crossbow_shoot.wav");
m_shootSound[WT_LAUNCHER] = engine::ResourceManager::instance()->MakeSound("assets/sounds/launcher_shoot.wav");
m_shootSound[WT_SUNCANNON] = engine::ResourceManager::instance()->MakeSound("assets/sounds/suncannon_shoot.wav");
}

Slayer::~Slayer() {
static_cast<Level*>(m_scene)->IncEnemies();
m_scene->OnContact.RemoveHandler(&m_contactHandler);
// Add it back in so it can be properly removed by damagable destructor
m_scene->OnContactPreSolve.AddHandler(&m_preCH);
Expand Down Expand Up @@ -94,6 +100,7 @@ void Slayer::OnUpdate(sf::Time interval) {
// Shooting
m_shootTime[m_weaponType] -= interval.asSeconds();
if (m_shootTime[m_weaponType] < 0 && (sf::Keyboard::isKeyPressed(sf::Keyboard::Space) || sf::Mouse::isButtonPressed(sf::Mouse::Left))) {
m_shootSound[m_weaponType]->play();
m_shootTime[m_weaponType] = weapons[m_weaponType].shootDelay;
auto projectile = engine::Factory::CreateChildFromFile(weapons[m_weaponType].projectileFile, m_scene);
auto pos = GetGlobalPosition();
Expand Down Expand Up @@ -152,12 +159,13 @@ void Slayer::Damage(float damage) {
if (m_health < 0) {
if (!m_dead) {
static_cast<Level*>(m_scene)->ChangeScore(-m_maxHealth);
// TODO DEATHSOUND
m_deathSound->play();
PlayAnimation("death");
m_dead=true;
}
} else {
static_cast<Level*>(m_scene)->ChangeScore(-damage);
// TODO HITSOUND
m_hurtSound->play();
}
UpdateHealthbar();
}
Expand Down Expand Up @@ -185,12 +193,15 @@ void Slayer::ContactHandler::handle(b2Contact* contact, bool begin) {
if (other->GetIdentifier() == "upgrade_crossbow") {
static_cast<LD32*>(m_slayer->GetScene()->GetGame())->Unlock(WT_CROSSBOW);
other->Delete();
m_upgradeSound->play();
}else if (other->GetIdentifier() == "upgrade_launcher") {
static_cast<LD32*>(m_slayer->GetScene()->GetGame())->Unlock(WT_LAUNCHER);
other->Delete();
m_upgradeSound->play();
}else if (other->GetIdentifier() == "upgrade_suncannon") {
static_cast<LD32*>(m_slayer->GetScene()->GetGame())->Unlock(WT_SUNCANNON);
other->Delete();
m_upgradeSound->play();
}
}
}
8 changes: 7 additions & 1 deletion Slayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@

#include "Damagable.hpp"
#include "misc.hpp"
#include "Engine/include/Engine/ResourceManager.hpp"


class Slayer: public Damagable {
class ContactHandler: public engine::util::EventHandler<b2Contact*, bool> {
protected:
Slayer* m_slayer;
size_t m_count;
sf::Sound* m_upgradeSound;
public:
ContactHandler(Slayer* slayer): m_slayer(slayer), m_count(0) {}
ContactHandler(Slayer* slayer): m_slayer(slayer), m_count(0) {
m_upgradeSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/upgrade.wav");
}
void handle(b2Contact*, bool);

size_t GetCount() const {
Expand All @@ -32,6 +36,8 @@ class Slayer: public Damagable {
ContactHandler m_contactHandler;
float m_shootTime[WT_MAX];
float m_respawnTimer;

sf::Sound* m_shootSound[WT_MAX];
public:
Slayer(engine::Scene* scene);
virtual ~Slayer();
Expand Down
7 changes: 4 additions & 3 deletions Vampire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
#include "Engine/util/Random.hpp"
#include <iostream>

Vampire::Vampire(engine::Scene* scene): Damagable(scene), m_targetPoint(0,0) {

Vampire::Vampire(engine::Scene* scene): Damagable(scene), m_targetPoint(0,0), m_targetTime(0) {
m_deathSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/vampire_death.wav");
m_hurtSound = engine::ResourceManager::instance()->MakeSound("assets/sounds/vampire_hurt.wav");
}

Vampire::~Vampire() {
Expand All @@ -28,7 +29,7 @@ void Vampire::OnUpdate(sf::Time interval) {
m_targetPoint = (slayer->GetGlobalPosition());
}
auto delta = m_targetPoint-GetGlobalPosition();
if (abs(delta.x) < 500 && abs(delta.x) > 10) {
if (abs(delta.y) < 300 && abs(delta.x) < 500 && abs(delta.x) > 10) {
const float v = 2 * interval.asSeconds() ;
m_body->ApplyLinearImpulse(b2Vec2(v * (delta.x > 0?1:-1), r() < 0.005?-5:0), m_body->GetWorldCenter(), true);
}
Expand Down
1 change: 0 additions & 1 deletion WeaponSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ WeaponSelector::WeaponSelector(engine::Scene* scene): Node(scene), m_current(WT_
}

WeaponSelector::~WeaponSelector() {
std::cout << "~WeaponSelector" << std::endl;
m_scene->GetGame()->OnKeyDown.RemoveHandler(&m_keyListener);
delete m_disabledSound;
}
Expand Down
Binary file added assets/images/level2.pdn
Binary file not shown.
Binary file added assets/images/level2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/level3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/misc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/images/slayer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/scripts/blood_particle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"size": [6, 6],
"origin": "center",
"damage": 0,
"despawn": 5,
"sprite": {
"sheet": {
"texture": "assets/images/particle.png",
Expand Down
65 changes: 65 additions & 0 deletions assets/scripts/end.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"size": [1024, 576],
"pixelToMeter": 60.0,
"gravity": [0, 5],
"respawn": [100, 100],
"debug": false,
"light": {
"enabled": true,
"ambient": [100, 100, 100]
},
"next": "assets/scripts/level_1.json",
"ui": [

{
"type": "text",
"position": [512, 290],
"text": {
"align": "center",
"font": "assets/lcd_solid.ttf",
"size": 30,
"text": "Thanks for playing! :)"
}
},
{
"type": "text",
"position": [512, 250],
"identifier": "score",
"text": {
"align": "center",
"font": "assets/lcd_solid.ttf",
"size": 30,
"text": "Score: 0"
}
},
{
"type": "text",
"position": [512, 260],
"identifier": "next",
"active": false,
"text": {
"align": "center",
"font": "assets/lcd_solid.ttf",
"size": 20,
"text": "You slayed all vampires! Press ENTER to proceed to the next level"
}
},
{
"childData": "assets/scripts/ui_paused.json"
}
],
"children": [
{
"type": "sprite",
"size": [1024, 576],
"sprite": {
"texture": "assets/images/title_screen_bg.png"
}
},
{
"childData": "assets/scripts/enemy_bat.json",
"position": [889, 104],
"active": false
}
]
}
2 changes: 1 addition & 1 deletion assets/scripts/lantern.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"children": [
{
"type":"light",
"radius":150,
"radius":250,
"color": [255, 163, 45],
"position": [25, 11]
}
Expand Down
2 changes: 1 addition & 1 deletion assets/scripts/level_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"enabled": true,
"ambient": [150, 150, 150]
},
"next": "assets/scripts/level_1.json",
"next": "assets/scripts/level_2.json",
"ui": [
{
"childData": "assets/scripts/selector.json"
Expand Down
Loading

0 comments on commit 3a464ae

Please sign in to comment.