Skip to content

Commit b7dc710

Browse files
authored
Merge pull request #11 from LManaslu/devel
Release 0.3
2 parents 05028c2 + 15eb5fe commit b7dc710

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2938
-0
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,10 @@
3030

3131
# Vagrant path
3232
.vagrant/
33+
34+
# Build paths
35+
bin
36+
obj
37+
38+
*.swp
39+
*.swo

.travis.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sudo: required
2+
dist: trusty
3+
language: cpp
4+
5+
install:
6+
- sudo apt-get update
7+
- sudo apt-get install libsdl2-2.0-0 libsdl2-dev libsdl2-image-2.0-0 libsdl2-image-dev libsdl2-ttf-2.0-0 libsdl2-ttf-dev libsdl2-mixer-2.0-0 libsdl2-mixer-dev -y
8+
compiler:
9+
- g++
10+
script:
11+
- make

Makefile

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
NAME = game
2+
SRC_DIR = src
3+
INC_DIR = include
4+
OBJ_DIR = obj
5+
BIN_DIR = bin
6+
7+
TARGET = $(BIN_DIR)/$(NAME)
8+
9+
CC = g++
10+
CFLAGS = -pedantic -std=c++11 -MMD -g3 -g -fPIC\
11+
-W -Wall -Wextra -Wshadow -Wcast-align -Wcast-qual -Wctor-dtor-privacy\
12+
-Wdisabled-optimization -Wformat=2 -Wlogical-op -Wmissing-declarations\
13+
-Wmissing-include-dirs -Wnoexcept -Woverloaded-virtual -Wredundant-decls\
14+
-Wsign-promo -Wstrict-null-sentinel -Wundef\
15+
-Wzero-as-null-pointer-constant -Wuseless-cast -Wnon-virtual-dtor
16+
INCLUDES = -I$(INC_DIR) `sdl2-config --cflags`
17+
LIBS = `sdl2-config --libs` -lSDL2_image -lSDL2_ttf -lSDL2_mixer -ldl
18+
19+
SRC = ${wildcard $(SRC_DIR)/*.cpp}
20+
OBJ = ${addprefix $(OBJ_DIR)/, ${notdir ${SRC:.cpp=.o}}}
21+
22+
RMDIR = rm -rf
23+
24+
#--------------------------------------------------------------
25+
ifeq ($(OS), Windows_NT)
26+
27+
SDL_PATH = C:\SDL-2.0.5
28+
29+
INCLUDES = -Iinclude/ -I$(SDL_PATH)\include
30+
31+
LIBS = -L $(SDL_PATH)\lib -lSDL2main\
32+
-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm
33+
34+
NAME := $(NAME).exe
35+
#--------------------------------------------------------------
36+
else
37+
38+
UNAME_S := $(shell uname -s)
39+
40+
ifeq ($(UNAME_S), Darwin)
41+
42+
LIBS = -lm -framework SDL2 -framework SDL2_image -framework SDL2_mixer\
43+
-framework SDL_TTF
44+
45+
#-------------------------------------------------------------
46+
47+
endif
48+
endif
49+
50+
.PHONY: clean depend dist-clean dist
51+
52+
all:
53+
#-------------------------------------------------------------
54+
@mkdir -p $(OBJ_DIR) $(BIN_DIR)
55+
$(MAKE) $(TARGET)
56+
#-------------------------------------------------------------
57+
58+
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
59+
@echo Building $@
60+
@$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@
61+
62+
$(TARGET): $(OBJ)
63+
@echo Building $@
64+
$(CC) $(CFLAGS) $(INCLUDES) $(OBJ) -o $@ $(LIBS)
65+
@echo Done.
66+
67+
run:
68+
$(TARGET)
69+
70+
reset:
71+
make dist-clean
72+
make -j
73+
74+
crun:
75+
make dist-clean
76+
make -j
77+
make run
78+
79+
arun:
80+
make -j
81+
make run
82+
83+
clean:
84+
@echo Cleaning...
85+
@$(RMDIR) *~ *.o
86+
87+
dist-clean: clean
88+
@$(RMDIR) $(TARGET)/$(NAME)
89+
@$(RMDIR) *.tar.gz $(OBJ_DIR) $(BIN_DIR)
90+
91+
print-%:
92+
@echo $* = $($*)

include/Animation.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef ANIMATION_H
2+
#define ANIMATION_H
3+
4+
#include "GameObject.h"
5+
#include "Timer.h"
6+
#include "Sprite.h"
7+
8+
class Animation : public GameObject{
9+
private:
10+
Timer end_timer;
11+
float time_limit;
12+
bool one_time_only;
13+
Sprite sprite;
14+
15+
public:
16+
Animation(float x, float y, float crotation, string csprite, int frame_count, float frame_time, bool ends);
17+
void update(float delta);
18+
void render();
19+
20+
bool is_dead();
21+
22+
void notify_collision(GameObject & object);
23+
bool is(string type);
24+
};
25+
26+
#endif

include/BattleState.h

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef BATTLESTATE_H
2+
#define BATTLESTATE_H
3+
4+
#include "State.h"
5+
#include "Sprite.h"
6+
#include "Text.h"
7+
#include "Timer.h"
8+
#include "Music.h"
9+
#include "Fighter.h"
10+
11+
#include <vector>
12+
13+
class BattleState : public State{
14+
private:
15+
Sprite background[3];
16+
vector <Fighter *> fighters;
17+
Music music;
18+
void read_level_design(string stage);
19+
20+
public:
21+
BattleState(string stage, string cmusic);
22+
~BattleState();
23+
24+
void update(float delta);
25+
void render();
26+
27+
void pause();
28+
void resume();
29+
};
30+
31+
#endif

include/Camera.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef CAMERA_H
2+
#define CAMERA_H
3+
4+
#include "GameObject.h"
5+
#include "Vector.h"
6+
7+
#define LAYERS 4
8+
9+
class Camera{
10+
private:
11+
static GameObject * focus;
12+
13+
public:
14+
static Vector pos[LAYERS];
15+
static float layer_speed[LAYERS];
16+
static Vector speed;
17+
18+
static void follow(GameObject * new_focus);
19+
static void unfollow();
20+
static void update(float delta);
21+
};
22+
23+
#endif

include/Collision.h

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#ifndef COLLISION_H
2+
#define COLLISION_H
3+
4+
#include <cmath>
5+
#include <algorithm>
6+
7+
#include "Rectangle.h"
8+
#include "Vector.h"
9+
10+
class Collision {
11+
public:
12+
static inline bool is_colliding(Rectangle& a, Rectangle& b, float angleOfA, float angleOfB){
13+
Vector A[] = { Vector( a.get_draw_x(), a.get_draw_y() + a.get_height() ),
14+
Vector( a.get_draw_x() + a.get_width(), a.get_draw_y() + a.get_height() ),
15+
Vector( a.get_draw_x() + a.get_width(), a.get_draw_y() ),
16+
Vector( a.get_draw_x(), a.get_draw_y() )
17+
};
18+
Vector B[] = { Vector( b.get_draw_x(), b.get_draw_y() + b.get_height() ),
19+
Vector( b.get_draw_x() + b.get_width(), b.get_draw_y() + b.get_height() ),
20+
Vector( b.get_draw_x() + b.get_width(), b.get_draw_y() ),
21+
Vector( b.get_draw_x(), b.get_draw_y() )
22+
};
23+
24+
for (auto& v : A) {
25+
v = rotate(v - a.get_center(), angleOfA) + a.get_center();
26+
}
27+
28+
for (auto& v : B) {
29+
v = rotate(v - b.get_center(), angleOfB) + b.get_center();
30+
}
31+
32+
Vector axes[] = { norm(A[0] - A[1]), norm(A[1] - A[2]), norm(B[0] - B[1]), norm(B[1] - B[2]) };
33+
34+
for (auto& axis : axes) {
35+
float P[4];
36+
37+
for (int i = 0; i < 4; ++i) P[i] = dot(A[i], axis);
38+
39+
float minA = *std::min_element(P, P + 4);
40+
float maxA = *std::max_element(P, P + 4);
41+
42+
for (int i = 0; i < 4; ++i) P[i] = dot(B[i], axis);
43+
44+
float minB = *std::min_element(P, P + 4);
45+
float maxB = *std::max_element(P, P + 4);
46+
47+
if (maxA < minB || minA > maxB)
48+
return false;
49+
}
50+
51+
return true;
52+
}
53+
54+
private:
55+
static inline float mag(const Vector& p){
56+
return std::sqrt(p.x * p.x + p.y * p.y);
57+
}
58+
static inline Vector norm(const Vector& p){
59+
return p * (1.f / mag(p));
60+
}
61+
static inline float dot(const Vector& a, const Vector& b){
62+
return a.x * b.x + a.y * b.y;
63+
}
64+
static inline Vector rotate(const Vector& p, float angle){
65+
float cs = std::cos(angle), sn = std::sin(angle);
66+
return Vector ( p.x * cs - p.y * sn, p.x * sn + p.y * cs );
67+
}
68+
};
69+
70+
#endif

include/EditState.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef EDITSTATE_H
2+
#define EDITSTATE_H
3+
4+
#include "State.h"
5+
#include "Sprite.h"
6+
#include "Text.h"
7+
#include "Timer.h"
8+
#include "Fighter.h"
9+
10+
class EditState : public State{
11+
private:
12+
Sprite background[3];
13+
Fighter * test_fighter;
14+
string stage;
15+
16+
void read_level_design();
17+
void update_level_design();
18+
19+
public:
20+
EditState(string stage);
21+
22+
void update(float delta);
23+
void render();
24+
25+
void pause();
26+
void resume();
27+
};
28+
29+
#endif

include/EditableFloor.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifndef EDITABLEFLOOR_H
2+
#define EDITABLEFLOOR_H
3+
4+
#include "Floor.h"
5+
#include "Sprite.h"
6+
7+
class EditableFloor : public Floor{
8+
private:
9+
enum FloorState{SELECTED, NOT_SELECTED};
10+
Sprite normal_sprite, platform_sprite, selected_sprite;
11+
FloorState state;
12+
bool deleted;
13+
bool selected;
14+
15+
public:
16+
17+
EditableFloor(float x, float y, float crotation, bool cplatform);
18+
EditableFloor(float x, float y, float width, float crotation, bool cplatform);
19+
20+
~EditableFloor();
21+
22+
void update(float delta);
23+
void render();
24+
bool is_dead();
25+
26+
void notify_collision(GameObject & object);
27+
28+
string get_information();
29+
void set_selected(bool cselected);
30+
};
31+
32+
#endif

include/Fighter.h

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef FIGHTER_H
2+
#define FIGHTER_H
3+
4+
#include "GameObject.h"
5+
#include "Sprite.h"
6+
#include "Vector.h"
7+
#include "Timer.h"
8+
9+
class Fighter : public GameObject{
10+
private:
11+
enum FighterState {IDLE, RUNNING, JUMPING, FALLING, CROUCH};
12+
enum Orientation {LEFT, RIGHT};
13+
Sprite sprite[10];
14+
FighterState state;
15+
Orientation orientation;
16+
Vector speed;
17+
Vector acceleration;
18+
float vertical_speed;
19+
bool on_floor, pass_through;
20+
int last_collided_floor;
21+
float max_speed;
22+
int remaining_life;
23+
void test_limits();
24+
int special;
25+
Timer crouch_timer;
26+
27+
public:
28+
Fighter(string name, float x, float y);
29+
~Fighter();
30+
31+
void update(float delta);
32+
void post_collision_update(float delta);
33+
void render();
34+
bool is_dead();
35+
36+
int get_remaining_life();
37+
int get_special();
38+
39+
void notify_collision(GameObject & object);
40+
bool is(string type);
41+
42+
void change_state(FighterState cstate);
43+
void reset_position(float x, float y);
44+
45+
static const int MAX_LIFE = 500;
46+
47+
static const int MAX_SPECIAL = 400;
48+
};
49+
50+
#endif

0 commit comments

Comments
 (0)