Skip to content

Commit

Permalink
Initial Import
Browse files Browse the repository at this point in the history
  • Loading branch information
firas-assaad committed Oct 24, 2014
0 parents commit 4b85c5d
Show file tree
Hide file tree
Showing 132 changed files with 15,490 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
*~

19 changes: 19 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The license below does not apply to the following files:
- win/data/player.png and win/data/test_tileset.gif by Francis Coulombe (cc-by http://www.frankiesmileshow.com/)
- win/data/music.ogg by HorrorPen (cc-by https://soundcloud.com/horrorpen/spirit-waltz)
- win/data/Unibody 8-Italic.otf by Underware (http://underware.nl/fonts/unibody/)
- src/base64.cpp by Ren� Nyffenegger (zlib http://www.adp-gmbh.ch/cpp/common/base64.html)
- include/rapidxml.hpp by Marcin Kalicinski (MIT http://rapidxml.sourceforge.net/)

For all other files, the following license applies:

Copyright (c) 2014, Firas Assaad
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Octopus Engine
-----------

A cross-platform 2D game engine used in [Octopus City Blues](http://octopuscityblues.com). Octopus Engine is an OpenGL engine written in C++11 and based on the [XD framework](https://github.com/firas-assaad/xd). It was developed to meet the needs of Octopus City Blues in particular, but it might be useful for other adventure games or RPGs.

### Features

* Partial support for [TMX](https://github.com/bjorn/tiled/wiki/TMX-Map-Format) maps ([Custom Properties](https://docs.google.com/document/d/1Y_l-yU-Zg7KF5-RJbVpVyhJKy6W4WEt6V1TbZNigI7Y/edit?usp=sharing)).
* Lua scripting features ([Reference](https://docs.google.com/document/d/1GTJ0rVu4J4hg0B49IqWwUqUE9--KCmZ0tMyc6UBsYsE/edit?usp=sharing)).
* A flexible XML sprite format. See [SpriteEditor](https://bitbucket.org/firas_assaad/spriteeditor).
* Octopus City Blues-specific features such as NPC scheduling and game time.
* Tile-based collision detection.
* Player movement and interaction with various object types.
* Support for custom GLSL shaders.

### License

See LICENSE.text file.

### Building

** Dependencies **

* [XD](https://github.com/firas-assaad/xd) - Should be placed in vendor/ directory
* [FreeType](http://www.freetype.org/index.html)
* [Lua 5.2](http://www.lua.org/)
* [Luabind](https://bitbucket.org/uso/luabind) - with Lua 5.2 support
* [Boost](http://www.boost.org/) - Regex (Required), Unit Test Framework (Optional)
* [FMOD Studio Programmer's API](http://www.fmod.org/download/)
* [DevIL](http://openil.sourceforge.net/)
* [GLFW3](http://www.glfw.org/)
* [GLEW](http://glew.sourceforge.net/)

Start by cloning my XD fork into the vendor/ directory. There are project files for Visual Studio 2012 and Xcode, although I never tested them on another machine. There's a basic Makefile in the linux/ directory for GCC. You can test the executable by placing it in the win/ directory or try it with the [Octopus City Blues](http://ghost-in-a-bottle.itch.io/octopus-city-blues) demo.

9 changes: 9 additions & 0 deletions doc/todo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Better management of sound files (track them per map?)
- New camera movement command that centers on an object.
- Allow running a script while game is paused.
- Overload text command to show at specific position without needing an object.
- Automatic text command mode that optionally doesn't restrict player movement.
- Saving and loading game data (including engine and Lua state).
- Proper Linux distributables (.deb files? autopackage?)
- Fix pathfinding bugs (empty path, accuracy problems, etc.)
- Move more Octopus City Blues-specific code to Lua.
9 changes: 9 additions & 0 deletions include/base64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef HPP_BASE64
#define HPP_BASE64

#include <string>

std::string base64_encode(unsigned char const* , unsigned int len);
std::string base64_decode(std::string const& s);

#endif
95 changes: 95 additions & 0 deletions include/camera.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#ifndef HPP_CAMERA
#define HPP_CAMERA

#include <xd/system.hpp>
#include <xd/graphics/types.hpp>
#include <xd/entity.hpp>

class Game;
class Map_Object;
class Screen_Shaker;

class Camera : public xd::entity<Camera> {
public:
Camera(Game& game);
// Setup viewport for rendering
void update_viewport(float shake_offset = 0.0f);
// Center camera at position
void center_at(float x, float y);
// Update position within map bounds
void set_position(float x, float y);
// Start shaking screen
void start_shaking(float strength, float speed);
// Cease shaking screen
void cease_shaking();
// Getters and setters
xd::vec2 get_position() const {
return position;
}
xd::rect get_viewport() const {
return viewport;
}
xd::vec4 get_tint_color() const {
return tint_color;
}
void set_tint_color(xd::vec4 color) {
tint_color = color;
}
const Map_Object* get_object() const {
return object;
}
void set_object(Map_Object* obj) {
object = obj;
}
// Is the camera shaking?
bool is_shaking() const {
return shaker != nullptr;
}
// Get current shake offset
float shake_offset() const;
private:
// Game instance
Game& game;
// Camera position
xd::vec2 position;
// Viewport rectangle
xd::rect viewport;
// Screen tint color
xd::vec4 tint_color;
// Tracked map object
Map_Object* object;
// Screen shaker component
Screen_Shaker* shaker;
};

class Camera_Renderer : public xd::render_component<Camera> {
public:
Camera_Renderer(Game& game) : game(game) {}
void render(Camera& camera);
private:
Game& game;
};

class Object_Tracker : public xd::logic_component<Camera> {
public:
void update(Camera& camera);
};

class Screen_Shaker : public xd::logic_component<Camera> {
public:
Screen_Shaker(float str, float spd)
: strength(str), speed(spd), direction(1), offset(0) {}
float shake_offset() { return offset; }
void update(Camera& camera);
private:
// Shake strength
float strength;
// Shake speed
float speed;
// Shake direction (-1 left, 1 right)
float direction;
// Shake offset
float offset;
};

#endif
132 changes: 132 additions & 0 deletions include/canvas.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#ifndef HPP_CANVAS
#define HPP_CANVAS

#include <string>
#include <vector>
#include <xd/graphics/types.hpp>
#include <xd/graphics/texture.hpp>
#include "sprite_holder.hpp"

class Game;
namespace xd {
class simple_text_renderer;
}

class Canvas : public Sprite_Holder {
public:
// Create a canvas from a sprite
Canvas(Game& game, const std::string& sprite, const std::string& pose_name, xd::vec2 position);
// Create a canvas from an image file name
Canvas(const std::string& filename, xd::vec2 position);
// Create a canvas with a transparent color
Canvas(const std::string& filename, xd::vec2 position, xd::vec4 trans);
// Create a canvas with some text
Canvas(Game& game, xd::vec2 position, const std::string& text);
// Update the image
void set_image(const std::string& filename);
void set_transparent_image(const std::string& filename, xd::vec4 trans);
// Update the sprite
void set_sprite(Game& game, xd::asset_manager& manager, const std::string& filename, const std::string& pose_name = "");
// Update the text for a text canvas
void set_text(const std::string& text);
// Get the current canvas text
std::string get_text() const { return text; }
// Render canvas text
void render_text(const std::string& text , float x, float y);
// Get the sprite, if any
Sprite* get_sprite() { return sprite.get(); }
// Get canvas width
int get_width() const {
if (image_texture)
return image_texture->width();
return 0;
}
// Get canvas height
int get_height() const {
if (image_texture)
return image_texture->height();
return 0;
}
// Getters and setters
xd::vec2 get_position() const {
return position;
}
void set_position(xd::vec2 position) {
this->position = position;
}
xd::vec2 get_origin() const {
return origin;
}
void set_origin(xd::vec2 origin) {
this->origin = origin;
}
xd::vec2 get_magnification() const {
return magnification;
}
void set_magnification(xd::vec2 magnification) {
this->magnification = magnification;
}
float get_angle() const {
return angle;
}
void set_angle(float angle) {
this->angle = angle;
}
float get_opacity() const {
return opacity;
}
void set_opacity(float opacity) {
this->opacity = opacity;
}
bool is_visible() const {
return visible;
}
void set_visible(bool visible) {
this->visible = visible;
}
std::string get_filename() const {
return filename;
}
xd::texture* get_texture() {
return image_texture.get();
}
std::vector<std::string>& get_text_lines() {
return text_lines;
}
xd::font_style* get_style() const {
return style.get();
}
private:
// Canvas position
xd::vec2 position;
// Drawing origin
xd::vec2 origin;
// X and Y magnification
xd::vec2 magnification;
// Rotation angle in degrees
float angle;
// Opacity (0 transparent, 1 opaque)
float opacity;
// Is the canvas visible?
bool visible;
// Image filename
std::string filename;
// Image texture
xd::texture::ptr image_texture;
// Optional sprite
Sprite::ptr sprite;
// Text to print
std::string text;
// Text lines
std::vector<std::string> text_lines;
// Font to use
xd::font* font;
// Text renderer
xd::simple_text_renderer* text_renderer;
// Text style
std::unique_ptr<xd::font_style> style;
// Text formatter
xd::text_formatter::ptr formatter;
};

#endif
16 changes: 16 additions & 0 deletions include/canvas_renderer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef HPP_CANVAS_RENDERER
#define HPP_CANVAS_RENDERER

#include <xd/config.hpp>
#include <xd/entity.hpp>
#include <xd/graphics/sprite_batch.hpp>
#include "map.hpp"

class Canvas_Renderer : public xd::render_component<Map> {
public:
void render(Map& map);
private:
xd::sprite_batch batch;
};

#endif
13 changes: 13 additions & 0 deletions include/canvas_updater.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef HPP_CANVAS_UPDATER
#define HPP_CANVAS_UPDATER

#include <xd/config.hpp>
#include <xd/entity.hpp>
#include "map.hpp"

class Canvas_Updater : public xd::logic_component<Map> {
public:
void update(Map& map);
};

#endif
34 changes: 34 additions & 0 deletions include/clock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef HPP_CLOCK
#define HPP_CLOCK

class Game;

class Clock {
public:
Clock(Game& game);
// Get game ticks
int ticks() const;
// Check if game time is stopped
bool stopped() const { return time_stop; }
// Stop game time
void stop_time();
// Resume game time
void resume_time();
// Get total time in seconds without applying a multipler
int actual_seconds() const;
// Get total time in seconds after applying multiplier
int total_seconds() const {
return static_cast<int>(actual_seconds() * time_multiplier);
}
void add_seconds(int seconds);
private:
Game& game;
int start_time;
bool time_stop;
int stop_start_time;
int total_stopped_time;
int added_time;
float time_multiplier;
};

#endif
Loading

0 comments on commit 4b85c5d

Please sign in to comment.