diff --git a/README.md b/README.md index f886f0c..2d3cb1a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ # flasim +FlaSim is a mini game I did as a birthday party gag. It lets you manually control an anti-aircraft cannon with your joystick. Five jets are then randomly spawned (one after the other) as targets to be engaged by the player. + +## Controls + +You'll need a joystick to play the game. The game starts out with no enemies so you can get used to steering the cannons. Joystick button 1 fires, button 2 reloads the guns (15 seconds penalty). Pressing F9 activates the game mode which spawns a plane every 45 secs (so scan your horizon!), F10 quits game mode (same as when 'aircraft remain' is zero), F12 quits the game. +Successfully engaging a plane rewards you with 1000 points plus bonus for the distance (the further out the more points). Relevant info is shown in the top-left corner. + +## About the game + +The game uses the irrlicht graphics engine for the eye and cAudio for the ear. It's quite of simple complexity and might hence serve as a good example for someone learning about game and/or graphics programming. +About the visual content shown in the game: I did some parts myself (cannon model, crosshairs, terrain), all other stuff is from free content websites. + +## Building flasim + +Currently only Linux works, should have a windows buildability in a couple of days. +The game is written in QtCreator and hence uses the qmake build system. You should have gcc, qmake, irrlicht and cAudio installed and handy. +cd to the 'prj' folder and run qmake to get a Makefile out of flasim.pro. Build the game using 'make'. Done. + +Questions? Reach me at otto@socialnerds.org diff --git a/res/heightmap2.png b/res/heightmap2.png deleted file mode 100644 index 55f1f49..0000000 Binary files a/res/heightmap2.png and /dev/null differ diff --git a/res/smoke.png b/res/smoke.png new file mode 100644 index 0000000..98d42ef Binary files /dev/null and b/res/smoke.png differ diff --git a/res/smoke1.png b/res/smoke1.png new file mode 100644 index 0000000..873fd5b Binary files /dev/null and b/res/smoke1.png differ diff --git a/src/Aircraft.cpp b/src/Aircraft.cpp index 7fb4673..da56105 100644 --- a/src/Aircraft.cpp +++ b/src/Aircraft.cpp @@ -57,7 +57,13 @@ bool Aircraft::evalShot(const irr::core::line3df &shotline) { // got hit for the first time: do smokey? auto pman = Globals::getSceneManager()->addParticleSystemSceneNode(true, model); + pman->getEmitter()->setMinStartSize(dimension2df(80.f, 80.f)); + pman->getEmitter()->setMaxStartSize(dimension2df(120.f, 120.f)); pman->getEmitter()->setDirection(vector3df(0.f, 0.f, 0.f)); + pman->setMaterialTexture(0, Globals::getVideoDriver()->getTexture("../res/smoke.png")); + pman->setMaterialTexture(1, Globals::getVideoDriver()->getTexture("../res/smoke1.png")); + pman->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF); + pman->setMaterialFlag(video::EMF_LIGHTING, false); } healthy = false; diff --git a/src/Aircraft.hpp b/src/Aircraft.hpp index 381b4f7..aa2fbaf 100644 --- a/src/Aircraft.hpp +++ b/src/Aircraft.hpp @@ -5,6 +5,7 @@ namespace cAudio class IAudioSource; } +//! Sends an aircraft along a line in a given time. Handles hits and smoke - that all class Aircraft { public: diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index b0f5eaa..b114da4 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -20,7 +20,7 @@ Dispatcher::~Dispatcher() void Dispatcher::start() { - lastDispatchMS = Globals::getDevice()->getTimer()->getRealTime(); + lastDispatchMS = Globals::getDevice()->getTimer()->getRealTime() - 40000; active = true; aircraftsRemaining = 5; points = 0; @@ -112,5 +112,5 @@ void Dispatcher::dispatchAircraft() line3df l; l.start = vector3df(start.X, alt, start.Y); l.end = vector3df(end.X, alt, end.Y); - aircrafts.push_back(std::make_shared(l, 30000 + static_cast(rand->frand() * 30000.f))); + aircrafts.push_back(std::make_shared(l, 30000 + static_cast(rand->frand() * 15000.f))); } diff --git a/src/Dispatcher.hpp b/src/Dispatcher.hpp index 1814d82..d7691cf 100644 --- a/src/Dispatcher.hpp +++ b/src/Dispatcher.hpp @@ -3,6 +3,7 @@ #include +//! Spawns aircraft, conducts hit-testing and points counting class Dispatcher { public: diff --git a/src/FireUnit.cpp b/src/FireUnit.cpp index d2dd30e..5c50f97 100644 --- a/src/FireUnit.cpp +++ b/src/FireUnit.cpp @@ -42,7 +42,7 @@ FireUnit::FireUnit() mflashR->setVisible(false); fireSound = Globals::getAudioManager()->create("fireSound", "../res/gunburst.wav", false); - + screenSize = Globals::getVideoDriver()->getScreenSize(); } FireUnit::~FireUnit() @@ -143,6 +143,11 @@ void FireUnit::draw() { auto drv = Globals::getVideoDriver(); auto& res = drv->getScreenSize(); + if (screenSize != res) + { + screenSize = res; + cam->setAspectRatio(static_cast(res.Width) / static_cast(res.Height)); + } drv->draw2DImage(crosshair, position2di(res.Width / 2 - 128, res.Height / 2 - 128), recti(0, 0, 256, 256), nullptr, video::SColor(255,255,255,255), true ); @@ -182,6 +187,4 @@ void FireUnit::draw() stripsRemaining = 5; } } - //drv->draw3DLine(shotline.start, shotline.end); - //cout << tgt.X << ' ' << tgt.Y << ' ' << tgt.Z << endl; } diff --git a/src/FireUnit.hpp b/src/FireUnit.hpp index 063c22f..49336a6 100644 --- a/src/FireUnit.hpp +++ b/src/FireUnit.hpp @@ -8,6 +8,7 @@ namespace cAudio class IAudioSource; } +//! Cannon control, input handling class FireUnit : public irr::IEventReceiver { public: @@ -35,6 +36,7 @@ private: irr::u32 reloadUntil; class cAudio::IAudioSource* fireSound; + irr::core::dimension2du screenSize; }; #endif // FIREUNIT_HPP diff --git a/src/FlaSimApp.cpp b/src/FlaSimApp.cpp index f56fb31..e8c61a8 100644 --- a/src/FlaSimApp.cpp +++ b/src/FlaSimApp.cpp @@ -42,8 +42,6 @@ FlaSimApp::FlaSimApp() { cout << "Joystick support is enabled and " << joystickInfo.size() << " joystick(s) are present." << endl; } - - } FlaSimApp::~FlaSimApp() diff --git a/src/FlaSimApp.hpp b/src/FlaSimApp.hpp index e8462d9..8bd433f 100644 --- a/src/FlaSimApp.hpp +++ b/src/FlaSimApp.hpp @@ -1,5 +1,6 @@ #include "FireUnit.hpp" +//! Main app class class FlaSimApp : public irr::IEventReceiver { public: diff --git a/src/Globals.cpp b/src/Globals.cpp index 11cac7a..099b5cc 100644 --- a/src/Globals.cpp +++ b/src/Globals.cpp @@ -10,7 +10,8 @@ Globals* Globals::instance = nullptr; Globals::Globals() { - dev = createDevice(video::EDT_OPENGL, core::dimension2du(1600, 900), 32, false, false, true); + dev = createDevice(video::EDT_OPENGL, core::dimension2du(1366, 768), 32, false, false, true); + dev->setResizable(true); drv = dev->getVideoDriver(); sman = dev->getSceneManager(); dispatcher = new Dispatcher(); diff --git a/src/Globals.hpp b/src/Globals.hpp index 95979c7..c973681 100644 --- a/src/Globals.hpp +++ b/src/Globals.hpp @@ -24,7 +24,7 @@ namespace irr } } - +//! Globally used stuff (mostly irrlicht-related) packed in a singleton class Globals { public: diff --git a/src/TurretCamAnimator.hpp b/src/TurretCamAnimator.hpp index c9b091f..2885257 100644 --- a/src/TurretCamAnimator.hpp +++ b/src/TurretCamAnimator.hpp @@ -1,5 +1,6 @@ #include +//! Super simple scene node animator that makes the camera look along the cannon class TurretCamAnimator : public irr::scene::ISceneNodeAnimator { public: