Skip to content

Commit

Permalink
Added src
Browse files Browse the repository at this point in the history
  • Loading branch information
pyroceper committed Oct 31, 2022
1 parent 4b4cf6e commit 8bf2179
Show file tree
Hide file tree
Showing 38 changed files with 1,011 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
*.exe
*.out
*.app
*.elf
*.sav
*.gba

.vscode/*
58 changes: 58 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#---------------------------------------------------------------------------------------------------------------------
# TARGET is the name of the output.
# BUILD is the directory where object files & intermediate files will be placed.
# LIBBUTANO is the main directory of butano library (https://github.com/GValiente/butano).
# PYTHON is the path to the python interpreter.
# SOURCES is a list of directories containing source code.
# INCLUDES is a list of directories containing extra header files.
# DATA is a list of directories containing binary data.
# GRAPHICS is a list of directories containing files to be processed by grit.
# AUDIO is a list of directories containing files to be processed by mmutil.
# DMGAUDIO is a list of directories containing files to be processed by mod2gbt and s3m2gbt.
# ROMTITLE is a uppercase ASCII, max 12 characters text string containing the output ROM title.
# ROMCODE is a uppercase ASCII, max 4 characters text string containing the output ROM code.
# USERFLAGS is a list of additional compiler flags:
# Pass -flto to enable link-time optimization.
# Pass -O0 to improve debugging.
# USERASFLAGS is a list of additional assembler flags.
# USERLDFLAGS is a list of additional linker flags:
# Pass -flto=auto -save-temps to enable parallel link-time optimization.
# USERLIBDIRS is a list of additional directories containing libraries.
# Each libraries directory must contains include and lib subdirectories.
# USERLIBS is a list of additional libraries to link with the project.
# USERBUILD is a list of additional directories to remove when cleaning the project.
# EXTTOOL is an optional command executed before processing audio, graphics and code files.
#
# All directories are specified relative to the project directory where the makefile is found.
#---------------------------------------------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
LIBBUTANO := ../../butano
PYTHON := python
SOURCES := src ../../common/src
INCLUDES := include ../../common/include
DATA :=
GRAPHICS := graphics ../../common/graphics
AUDIO := audio ../../common/audio
DMGAUDIO := dmg_audio ../../common/dmg_audio
ROMTITLE := ROCK_PAPER_SHOTGUN
ROMCODE := SBTP
USERFLAGS :=
USERASFLAGS :=
USERLDFLAGS :=
USERLIBDIRS :=
USERLIBS :=
USERBUILD :=
EXTTOOL :=

#---------------------------------------------------------------------------------------------------------------------
# Export absolute butano path:
#---------------------------------------------------------------------------------------------------------------------
ifndef LIBBUTANOABS
export LIBBUTANOABS := $(realpath $(LIBBUTANO))
endif

#---------------------------------------------------------------------------------------------------------------------
# Include main makefile:
#---------------------------------------------------------------------------------------------------------------------
include $(LIBBUTANOABS)/butano.mak
Empty file added audio/.gitignore
Empty file.
Empty file added dmg_audio/.gitignore
Empty file.
Binary file added graphics/assault_class_.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/assault_class_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added graphics/board.bmp
Binary file not shown.
3 changes: 3 additions & 0 deletions graphics/board.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "regular_bg"
}
Binary file added graphics/d_red.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/d_red.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added graphics/dst_cursor.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/dst_cursor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added graphics/g_arrow.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/g_arrow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added graphics/selection_cursor.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/selection_cursor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added graphics/tiles.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/tiles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added graphics/wasp.bmp
Binary file not shown.
4 changes: 4 additions & 0 deletions graphics/wasp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "sprite",
"height": 16
}
Binary file added img/pathfinding-0.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 img/pathfinding-1.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 img/pathfinding-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added include/.gitignore
Empty file.
30 changes: 30 additions & 0 deletions include/pathfinder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef PATHFINDER_H
#define PATHFINDER_H

#include "queue.h"
#include "stack.h"
#include "bn_log.h"

#define ROW 9
#define COL 9

class Pathfinder
{
public:
Pathfinder();
void reset();
bool is_valid(int row, int col);
bool found;
int game[ROW][COL] = {0};
void search(int row, int col);
void add_obstacle(int row, int col);
bool check_obstacle(int row, int col);
private:
Queue<int> queue_r {};
Queue<int> queue_c {};
Queue<int> queue_count {};
bool visited[ROW*COL] = {false};
bool obstacles[ROW*COL] = {false};
};

#endif
76 changes: 76 additions & 0 deletions include/queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#ifndef QUEUE_H
#define QUEUE_H

template<class T>
class Queue
{
public:
bool empty();
bool is_full();
T front();
T rear();
void push(T element);
void pop();
void clear();
private:
T _queue[1000];
int _capacity = 1000;
int _size = 0;
int _front = 0;
int _rear = _capacity - 1;
};

template<class T>
void Queue<T>::clear()
{
_size = _front = 0;
_rear = _capacity - 1;
}

template<class T>
bool Queue<T>::empty()
{
return _size == 0;
}

template<class T>
bool Queue<T>::is_full()
{
return _capacity == _size;
}

template<class T>
T Queue<T>::front()
{
return _queue[_front];
}

template<class T>
T Queue<T>::rear()
{
return _rear;
}

template<class T>
void Queue<T>::push(T element)
{
if(!is_full())
{
_rear = (_rear + 1) % _capacity;
_queue[_rear] = element;
_size++;
}
}

template<class T>
void Queue<T>::pop()
{
if(!empty())
{
_front = (_front + 1) % _capacity;
_size--;
}
}


#endif
18 changes: 18 additions & 0 deletions include/scene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef SCENE_H
#define SCENE_H

enum SceneType
{
MENU,
LVL1
};

class Scene
{
public:
virtual void init() = 0;
virtual void update() = 0;
virtual ~Scene() = 0;
};

#endif
57 changes: 57 additions & 0 deletions include/stack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef STACK_H
#define STACK_H

template<class T>
class Stack
{
public:
void push(T element);
void pop(T& element);
bool empty();
bool is_full();
void clear();
private:
T _stack[1000];
int _top = -1;
int capacity = 1000;
};

template<class T>
void Stack<T>::push(T element)
{
if(!is_full())
{
_top++;
_stack[_top] = element;
}
}

template<class T>
void Stack<T>::pop(T& element)
{
if(!empty())
{
element = _stack[_top];
_top--;
}
}

template<class T>
bool Stack<T>::empty()
{
return _top == -1;
}

template<class T>
bool Stack<T>::is_full()
{
return _top == capacity;
}

template<class T>
void Stack<T>::clear()
{
_top = -1;
}

#endif
12 changes: 12 additions & 0 deletions include/tiles.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef TILES_H
#define TILES_H

#include "bn_sprite_ptr.h"
#include "bn_sprite_items_tiles.h"

struct Tile
{
bn::sprite_ptr tile = bn::sprite_items::tiles.create_sprite(0, 0);
};

#endif
19 changes: 19 additions & 0 deletions include/turn_controller.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef TURN_CONTROLLER_H
#define TURN_CONTROLLER_H

class TurnController
{
public:
TurnController();
TurnController(int player_u, int npc_u, int total_player_u, int total_npc_u);
bool is_player_turn = false;
int turn_timer = 20;
private:
int player_units;
int npc_units;
int total_player_units;
int total_npc_units;
};


#endif
26 changes: 26 additions & 0 deletions include/unit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef UNIT_H
#define UNIT_H

enum UnitType { Player, NPC};

class Unit
{
public:
Unit(int r, int c, int X, int Y, UnitType unit_type_);
Unit();

int row;
int col;

int x;
int y;

int movement_counter;
int movement_radius;
bool is_moving;

UnitType unit_type;
};


#endif
26 changes: 26 additions & 0 deletions include/util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef UTIL_H
#define UTIL_H

#include "bn_sprite_ptr.h"

#include "unit.h"
#include "pathfinder.h"
#include "turn_controller.h"

namespace Util
{
void move_unit(Unit& curr_unit, bn::sprite_ptr& curr_sprite, Pathfinder& pf, int& movement_counter);
void vaild_moves(Pathfinder& pf, int row, int col, int count);
void paint_moves_1(Unit& curr_unit,Pathfinder& pf, bn::sprite_ptr& v_tile_1, bn::sprite_ptr& v_tile_2,
bn::sprite_ptr& v_tile_3, bn::sprite_ptr& v_tile_4);
void paint_moves_2(Unit& curr_unit,Pathfinder& pf, bn::sprite_ptr& v_tile_5, bn::sprite_ptr& v_tile_6,
bn::sprite_ptr& v_tile_7, bn::sprite_ptr& v_tile_8);
void paint_moves_3(Unit& curr_unit,Pathfinder& pf, bn::sprite_ptr& v_tile_9, bn::sprite_ptr& v_tile_10,
bn::sprite_ptr& v_tile_11, bn::sprite_ptr& v_tile_12);
void hide_tiles(bn::sprite_ptr& v_tile_1, bn::sprite_ptr& v_tile_2,
bn::sprite_ptr& v_tile_3, bn::sprite_ptr& v_tile_4, bn::sprite_ptr& v_tile_5, bn::sprite_ptr& v_tile_6,
bn::sprite_ptr& v_tile_7, bn::sprite_ptr& v_tile_8, bn::sprite_ptr& v_tile_9, bn::sprite_ptr& v_tile_10,
bn::sprite_ptr& v_tile_11, bn::sprite_ptr& v_tile_12);
};

#endif
Loading

0 comments on commit 8bf2179

Please sign in to comment.