-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6cbf7e3
Showing
14 changed files
with
1,336 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# AllPaulinek | ||
|
||
## About | ||
|
||
This is a little library (based on Allegro 5 library) written in C++ by Paulina Kalicka (PAULINEK) | ||
|
||
## [Download](https://github.com/Paulinek-13/AllPaulinek/releases) | ||
|
||
## Credits | ||
|
||
- Used library: [Allegro 5](https://liballeg.org/) | ||
|
||
## Notes | ||
|
||
* [Open an issue](https://github.com/Paulinek-13/AllPaulinek/issues) : | ||
- if you have noticed bugs or errors | ||
- if you have ideas or suggestions about new features and improvements | ||
- if you want to discuss something related to the project | ||
|
||
## ![paulinek_logo](https://raw.githubusercontent.com/Paulinek-13/Paulinek-13.github.io/master/PAULINEK.ico) | ||
|
||
# Changelog | ||
|
||
## _v1.0_ *(2020-07-09)* | ||
|
||
#### First release 👏 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// ================================================== | ||
// file: PK13_AllPaulinek.h | ||
// project: AllPaulinek | ||
// author: Paulina Kalicka | ||
// ================================================== | ||
|
||
///////////////////////////////////////////////////// | ||
/* | ||
This is the main header file of the | ||
AllPaulinek library. | ||
*/ | ||
///////////////////////////////////////////////////// | ||
|
||
#ifndef PK13_ALLPAULINEK_H | ||
#define PK13_ALLPAULINEK_H | ||
|
||
///////////////////////////////////////////////////// | ||
// < USEFUL MACROS | ||
|
||
#define PK13_INIT_ALLEGRO \ | ||
if(!al_init()) return -1 | ||
#define PK13_INIT_ACODEC_ADDON \ | ||
if(!al_init_acodec_addon()) return -1 | ||
#define PK13_INIT_FONT_ADDON \ | ||
if(!al_init_font_addon()) return -1 | ||
#define PK13_INIT_IMAGE_ADDON \ | ||
if(!al_init_image_addon()) return -1 | ||
#define PK13_INIT_NATIVE_DIALOG_ADDON \ | ||
if(!al_init_native_dialog_addon()) return -1 | ||
#define PK13_INIT_PRIMITIVES_ADDON \ | ||
if(!al_init_primitives_addon()) return -1 | ||
#define PK13_INIT_TTF_ADDON \ | ||
if(!al_init_ttf_addon()) return -1 | ||
#define PK13_INIT_VIDEO_ADDON \ | ||
if(!al_init_video_addon()) return -1 | ||
|
||
#define PK13_INSTALL_AUDIO \ | ||
if(!al_install_audio()) return -1 | ||
#define PK13_INSTALL_JOYSTICK \ | ||
if(!al_install_joystick()) return -1 | ||
#define PK13_INSTALL_KEYBOARD \ | ||
if(!al_install_keyboard()) return -1 | ||
#define PK13_INSTALL_MOUSE \ | ||
if(!al_install_mouse()) return -1 | ||
#define PK13_INSTALL_TOUCH_INPUT \ | ||
if(!al_install_touch_input()) return -1 | ||
|
||
// > USEFUL MACROS | ||
///////////////////////////////////////////////////// | ||
|
||
#include "PK13_App.h" | ||
#include "PK13_AppState.h" | ||
|
||
#include <allegro5/allegro.h> | ||
|
||
#endif // !PK13_ALLPAULINEK_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ================================================== | ||
// file: PK13_App.h | ||
// project: AllPaulinek | ||
// author: Paulina Kalicka | ||
// ================================================== | ||
|
||
#ifndef PK13_APP_H | ||
#define PK13_APP_H | ||
|
||
#include "PK13_Camera.h" | ||
|
||
#include <allegro5/allegro5.h> | ||
#include <allegro5/allegro_font.h> | ||
|
||
// respresents instance of an app and | ||
// holds information that is shared | ||
// between all appp states; | ||
// should be one per application; | ||
// every derived struct/class has to have: | ||
// Init() method which calls PK13_App::Init(...) and | ||
// Clean() method which calls PK13_App::Clean(); | ||
struct PK13_App | ||
{ | ||
ALLEGRO_DISPLAY* _display = 0; // the main window | ||
ALLEGRO_TIMER* _timer = 0; // indicates speed for drawing and updating logic | ||
ALLEGRO_EVENT_QUEUE* _event_queue = 0; // for all events | ||
ALLEGRO_FONT* _font = 0; // the default font | ||
ALLEGRO_BITMAP* _icon = 0; // the display icon | ||
ALLEGRO_BITMAP* _prev_state = 0; // bitmap with a previous state on it (used mainly for transitions) | ||
ALLEGRO_BITMAP* _dest_state = 0; // bitmap with a destination state on it (used mainly for transitions) | ||
|
||
PK13_Camera _camera; // the main camera | ||
|
||
int _w = 800; // width of the app content (it should be set once and should not change during execution) | ||
int _h = 600; // height of the app content (it should be set once and should not change during execution) | ||
int _hw = 400; // half of the width | ||
int _hh = 300; // half of the height | ||
|
||
// creates the app base and initializes important fields | ||
// call it only once at the beginning and remember to call Clean() | ||
// returns false if failed | ||
bool _Init(int app_width, int app_height, | ||
const char* app_name, const char* font_path, const char* icon_path, | ||
double timer_speed, int display_flags); | ||
|
||
// destroys everything that was created in Init() method | ||
// call it only once at the end (if Init() was called) | ||
// returns false if failed | ||
void _Clean(); | ||
}; | ||
|
||
#endif // !PK13_APP_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// ================================================== | ||
// file: PK13_AppState.h | ||
// project: AllPaulinek | ||
// author: Paulina Kalicka | ||
// ================================================== | ||
|
||
#ifndef PK13_APP_STATE_H | ||
#define PK13_APP_STATE_H | ||
|
||
#include "PK13_App.h" | ||
#include "PK13_Transition.h" | ||
|
||
#include <allegro5/allegro5.h> | ||
#include <allegro5/allegro_font.h> | ||
#include <memory> | ||
|
||
#define PK13_EXIT_STATE (-1) | ||
|
||
// represents single app state | ||
// (ex.menu, settings, playing scene, etc.); | ||
// by default handles basic events like | ||
// closing display, resizing display and | ||
// transforms camera and mouse positions when needed; | ||
// indicates when to draw app state content | ||
// and update logic based on timer speed; | ||
struct PK13_AppState | ||
{ | ||
bool _end = false; // if end app state | ||
bool _draw = false; // if draw app state content | ||
bool _pressed = false; // if at least one key is pressed | ||
bool _clicked = false; // if at least one mouse button is clicked | ||
|
||
float _mx = 0.f; // mouse position x (depends on camera x position) | ||
float _my = 0.f; // mouse position y (depends on camera y position) | ||
float _mx_gui = 0.f; // mouse GUI position x (camera independent) | ||
float _my_gui = 0.f; // mouse GUI position y (camera independent) | ||
|
||
int _next_state = PK13_EXIT_STATE; // which state goes after this one (it should be changed in state loop) | ||
|
||
std::unique_ptr<PK13_Transition> _transition = 0; // unique pointer to a transition struct | ||
|
||
ALLEGRO_TRANSFORM _trans_resize = {0}; // transformation after resizing display | ||
ALLEGRO_TRANSFORM _trans_camera = {0}; // transformation after camera change | ||
|
||
// inits some variables | ||
// for example it can make a uniue pointer for a transition | ||
// returns false if failed | ||
virtual bool Init(); | ||
|
||
// cleans everything that was allocated in Init() | ||
// returns false if failed | ||
virtual void Clean(); | ||
|
||
// draws app state content | ||
virtual void Draw(); | ||
|
||
// handles app state events and app logic | ||
virtual void Events(ALLEGRO_EVENT event); | ||
|
||
// loops through the state loop | ||
// at first it calls Init() and loops through transition loop | ||
// then it calls Draw() and Events() methods in loop | ||
// at the end it calls Clean() method | ||
// returns next app state | ||
int _Loop(PK13_App* app); | ||
|
||
// ends the current state and starts the next state | ||
void _EndTheState(int next_state); | ||
|
||
// call it before drawing GUI content (only if camera can be changed in app state otherwise there is no need) | ||
void _StartDrawingGUI(); | ||
|
||
// call it after drawing GUI (only if StartDrawingGUI() was called before) | ||
void _StopDrawingGUI(); | ||
|
||
private: | ||
// resizes display properly and makes app content responsive to that changes | ||
void _TransformDisplay(PK13_App* app); | ||
|
||
// transforms mouse coordinates | ||
void _TransformMouse(ALLEGRO_EVENT& event); | ||
|
||
// transforms mouse coordinates based on mouse state | ||
void _TransformMouse(); | ||
}; | ||
|
||
#endif // !PK13_APP_STATE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// ================================================== | ||
// file: PK13_Camera.h | ||
// project: AllPaulinek | ||
// author: Paulina Kalicka | ||
// ================================================== | ||
|
||
#ifndef PK13_CAMERA_H | ||
#define PK13_CAMERA_H | ||
|
||
// represents just a camera object; | ||
// it has its positions, width, | ||
// height and scale; | ||
struct PK13_Camera | ||
{ | ||
int cx = 0; // center x position | ||
int cy = 0; // center y position | ||
int x1 = 0; // most left x position | ||
int y1 = 0; // most up y position | ||
int x2 = 0; // most right x position | ||
int y2 = 0; // most down x position | ||
int vx = 0; // velocity x | ||
int vy = 0; // velocity y | ||
float scale = 1.f; // zoom | ||
|
||
bool update = false; // if needed to update camera transformation | ||
|
||
// back to normal position and scale | ||
void Reset(int w, int h); | ||
|
||
// move right with set velocity vx | ||
void MoveR(); | ||
|
||
// move left with set velocity vx | ||
void MoveL(); | ||
|
||
// move up with set velocity vy | ||
void MoveU(); | ||
|
||
// move down with set velocity vy | ||
void MoveD(); | ||
|
||
// move horizontally with given velocity | ||
void MoveX(short velx); | ||
|
||
// move vertically with given velocity | ||
void MoveY(short vely); | ||
|
||
// bigger scale (more detailed) | ||
void ZoomIn(int w, int h); | ||
|
||
// smaller scale (less detailed) | ||
void ZoomOut(int w, int h); | ||
}; | ||
|
||
#endif // !PK13_CAMERA_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// ================================================== | ||
// file: PK13_Colors.h | ||
// project: AllPaulinek | ||
// author: Paulina Kalicka | ||
// ================================================== | ||
|
||
#ifndef PK13_COLORS_H | ||
#define PK13_COLORS_H | ||
|
||
///////////////////////////////////////////////////// | ||
/* | ||
Color names from https://rgbcolorcode.com/ | ||
*/ | ||
///////////////////////////////////////////////////// | ||
|
||
#define PK13_BLACK al_map_rgb(0, 0, 0) | ||
#define PK13_GRAY al_map_rgb(128, 128, 128) | ||
#define PK13_WHITE al_map_rgb(255, 255, 255) | ||
|
||
#define PK13_RED al_map_rgb(255, 0, 0) | ||
#define PK13_ELECTRIC_GREEN al_map_rgb(0, 255, 0) | ||
#define PK13_BLUE al_map_rgb(0, 0, 255) | ||
#define PK13_ELECTRIC_YELLOW al_map_rgb(255, 255, 0) | ||
#define PK13_FUCHSIA al_map_rgb(255, 0, 255) | ||
#define PK13_AQUA al_map_rgb(0, 255, 255) | ||
|
||
#define PK13_MAROON al_map_rgb(128, 0, 0) | ||
#define PK13_AO al_map_rgb(0, 128, 0) | ||
#define PK13_NAVY_BLUE al_map_rgb(0, 0, 128) | ||
#define PK13_HEART_GOLD al_map_rgb(128, 128, 0) | ||
#define PK13_PATRIATCH al_map_rgb(128, 0, 128) | ||
#define PK13_TEAL al_map_rgb(0, 128, 128) | ||
|
||
#define PK13_COLAR_PINK al_map_rgb(255, 128, 128) | ||
#define PK13_SCREAMIN_GREEN al_map_rgb(128, 255, 128) | ||
#define PK13_MEDIUM_SLATE_BLUE al_map_rgb(128, 128, 255) | ||
#define PK13_PASTEL_YELLOW al_map_rgb(255, 255, 128) | ||
#define PK13_FUCHSIA_PINK al_map_rgb(255, 128, 255) | ||
#define PK13_ELECTRIC_BLUE al_map_rgb(128, 255, 255) | ||
|
||
#endif // !PK13_COLORS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ================================================== | ||
// file: PK13_Text.h | ||
// project: AllPaulinek | ||
// author: Paulina Kalicka | ||
// ================================================== | ||
|
||
#ifndef PK13_TEXT_H | ||
#define PK13_TEXT_H | ||
|
||
#include <allegro5/allegro_font.h> | ||
|
||
struct PK13_TextInfo | ||
{ | ||
int x1 = 0.f; // most left actual text x position | ||
int y1 = 0.f; // most up actual text y position | ||
int x2 = 0.f; // most right actual text x position | ||
int y2 = 0.f; // most down actual text y position | ||
int aw = 0.f; // actual text width | ||
int ah = 0.f; // actual text height | ||
}; | ||
|
||
// draws string with accurate scale based on given width and height | ||
// returns structure with some information about text after transformation | ||
PK13_TextInfo pk13_draw_string(ALLEGRO_FONT* font, int width, int height, int cx, int cy, ALLEGRO_COLOR color, const char* string); | ||
|
||
// draws integer number with accurate scale based on given width and height | ||
// length of buffer has a limit | ||
// returns structure with some information about text after transformation | ||
PK13_TextInfo pk13_draw_integer_number(ALLEGRO_FONT* font, int width, int height, int cx, int cy, ALLEGRO_COLOR color, int number); | ||
|
||
// draws floating-point number with accurate scale based on given width and height | ||
// length of buffer has a limit | ||
// precision is set to two digits | ||
// returns structure with some information about text after transformation | ||
PK13_TextInfo pk13_draw_float_number(ALLEGRO_FONT* font, int width, int height, int cx, int cy, ALLEGRO_COLOR color, float number); | ||
|
||
#endif // !PK13_TEXT_H |
Oops, something went wrong.