Skip to content

Commit

Permalink
Midterm time
Browse files Browse the repository at this point in the history
  • Loading branch information
Fontbane committed Mar 23, 2022
1 parent 975309e commit 57e5b09
Show file tree
Hide file tree
Showing 41 changed files with 879 additions and 145 deletions.
34 changes: 6 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
# gameframework2d (GF2D)
a collection of utlitity functions designed to facilitate creating 2D games with SDL2
This project is specifically intended to function as an educational tool for my students taking 2D Game Programming.
# Keystone

Currently the project is in a WIP state, however it is functional with sample projects showcasing rudimentary scrolling shooters,
platformers, and adventure games.
Pokemon-like RPG

The master branch is kept deliberately minimal to allow students to build out systems as they are learning.
Other branches have more complete system: Collisions, menus, input abstraction.

# Build Process

Before you can build the example code we are providing for you, you will need to obtain the libraries required
by the source code
- SDL2
- SDL2_image
- SDL2_mixer
- SDL2_ttf
There are additional sub modules that are needed for this project to work as well, but they can be pulled right from within the project.
Performable from the following steps from the root of the cloned git repository within a terminal.

Make sure you fetch submodules: `git submodule update --init --recursive`
Go into each submodule's src directory and type:
`make`
`make static`

Once each submodule has been made you can go into the base project src folder anre simply type:
`make`

You should now have a `gf2d` binary within the root of your git repository. Executing this will start your game.
- WASD to move
- You can't move through trees or other people
- Press enter to interact with people
- Be careful you might start sliding weeee
7 changes: 7 additions & 0 deletions config/catalog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sappurr":
{
"entry1":"It taps into trees with its root-like fangs, drinking the sap from within.",
"entry2":"If you invite one in your home, expect to find holes in your furniture soon."
}
}
5 changes: 5 additions & 0 deletions config/texts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hatkid_show_egglet" : {
"english":"Hey, can you show me an Egglet?"
}
}
2 changes: 1 addition & 1 deletion gfc
Submodule gfc updated 1 files
+1 −1 simple_json
Binary file added images/battlers/Egglet/front.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 images/battlers/Mukchuk/front.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 images/battlers/Pyruff/front.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 modified images/battlers/Sappurr/front.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 modified images/battlers/Squoink/front.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 modified images/objects/HatKid.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 modified images/tiles/kt01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion include/k_battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ typedef struct BattleRender {
}BattleRender;

typedef struct {
u8 fieldsize;
u8 fieldsizex;
u8 fieldsizey;
u8 fieldtype;
u8 battleType;
u8 numMons;
Expand Down
18 changes: 15 additions & 3 deletions include/k_entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ typedef struct EDICT_S{
u16 moving : 1;

void (*Think)(struct EDICT_S* self);
void (*Move)(Direction dir);
void (*OnTalk)(Direction dir);
void (*OnCollide)(Direction dir);
void (*Move)(struct EDICT_S* self, Direction dir);
void (*OnTalk)(struct EDICT_S* self, Direction dir);
void (*OnCollide)(struct EDICT_S* self, Direction dir);
} Edict;

Edict *player;
Expand All @@ -133,6 +133,16 @@ void ent_manager_init(u32 maxEnts);
void ent_manager_clear();

void ent_think_generic(Edict* ent);
void ent_collide_generic(Edict* ent, Direction dir);

void coll_mukchuk(Edict* ent, Direction dir);
void coll_tree(Edict* ent, Direction dir);

void talk_showme_egglet(Edict* ent, Direction dir);
void talk_treehugger(Edict* ent, Direction dir);
void talk_find_mukchuk(Edict* ent, Direction dir);
void talk_riddler(Edict* ent, Direction dir);
void talk_give_restorade(Edict* ent, Direction dir);

void ent_think(Edict* ent);
void ent_manager_think_all();
Expand All @@ -150,4 +160,6 @@ extern CropPlant PlantFruit(u8 fruitID);
extern void WaterFruit(CropPlant* plant);
extern void PickFruit(CropPlant* plant);

u16 CheckEntCollision(Point8 pt, Direction dir);

#endif
17 changes: 8 additions & 9 deletions include/k_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,16 @@ void tileset_load(char* filename);
void tileset_free(Tileset tileset);
void tileset_draw(Tileset tileset, u16 tile, Vector2D position);

typedef struct MapTile_s{
u16 blockID:12;
u16 collision:4;
} MapTile;
typedef u16 MapTile;

typedef struct MapConnection {
u16 id;
Point8 offset;
} MapConnection;

typedef struct Encounter {
u16 species : 9;
u16 level : 7;
u8 species;
u8 level;
} Encounter;


Expand All @@ -83,7 +80,7 @@ typedef struct Chunk {
typedef struct Map{
u16 id;
char* name;
u16 outdoors : 1;
u8 outdoors : 1;
Tileset tileset;
MapConnection north;
MapConnection south;
Expand All @@ -92,14 +89,16 @@ typedef struct Map{
u8 height;
u8 width;
Block* border;
Chunk* chunks;
Encounter encounters[12]; //Array of 12 random encounters with odds
//20% 20% 10% 10% 10% 10% 5% 5% 4% 4% 1% 1%
Edict* entities;
MapTile* layout;
MapTile* layout;
MapTile* layer2;
TileCollision* collision;
} Map;

extern void RenderMap(Map* map);
extern void RenderMapLayer2(Map* map);
Map* LoadMap(const char* jsonfile);

TileCollision GetCollisionAt(Map *map, Point8 position);
Expand Down
11 changes: 8 additions & 3 deletions include/k_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "k_crop.h"
#include "k_global.h"
#include "gfc_text.h"

typedef enum {
POCKET_MISC,
Expand All @@ -16,16 +17,20 @@ typedef enum {

typedef struct ITEM_S {
u16 id;
TextWord name;
Pocket pocket;
Fruit crop;
CropType cropType;
u16 price;//times 10
u8 useOnField : 1;
u8 useInBattle : 1;
void(*Use)(u16 args);
u16 useargs;
void (*Use)(struct ITEM_S* item);
}Item;

void GiveItem(u16 id);
Item GetItemFromJson(u16 id);
int RemoveItem(char *name);
void GiveItem(char* name);
Item GetItemFromJson(char* name);
Item* gItems;

#endif // !__K_ITEM_H__
8 changes: 8 additions & 0 deletions include/k_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ typedef struct GameLocal {
Edict* camera;
Edict* player;
u32 steps;
int camera_offset_x;
int camera_offset_y;

GameState state;
Bool lockall;

u64 randomSeed;
u64 random;
Expand All @@ -20,8 +25,11 @@ typedef struct GameLocal {


extern u64 Random(u64 min, u64 max);
extern u32 Random32();
extern void SeedRNG();

void game_init();

GameLocal game;
Map level;

Expand Down
9 changes: 9 additions & 0 deletions include/k_menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef __K_MENU_H__
#define __K_MENU_H__

#include "gfc_text.h"
#include "gf2d_sprite.h"

void DrawHUD();

#endif
15 changes: 8 additions & 7 deletions include/k_monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,17 @@ typedef struct MonDict {

} MonDict;//Size: 0x2A 44 bytes

struct BaseStats {
typedef struct BaseStats {
const char* name;
const char* spritefile;

u8 hp; /*0x00*/
u8 attack; /*0x01*/
u8 defense; /*0x02*/
u8 m_attack; /*0x03*/
u8 m_defense; /*0x04*/
u8 agility; /*0x05*/

u8 type1;/*0x06*/
u8 type2;/*0x07*/

Expand Down Expand Up @@ -134,7 +138,7 @@ struct BaseStats {
u8 forms;/*0x1C*/
u8 flags;/*0x1D*/
u16 statsToInherit;/*0x1E*/
};//Size: 0x20, 32 bytes
} BaseStats;//Size: 0x20, 32 bytes

#define GROWTH_SLOW 0
#define GROWTH_MEDIUM 1
Expand Down Expand Up @@ -196,11 +200,7 @@ extern const u32 LvToXP_Medium[101];

extern const int gTypeMatchupTable[16][16];

extern const struct BaseStats *gBaseStats;

extern const char* gBattlerSprites[NUM_SPECIES];

const char* gMonsterNames[NUM_SPECIES];
extern const BaseStats gBaseStats[NUM_SPECIES];

void ExtractBaseStats(char* filename);

Expand All @@ -213,5 +213,6 @@ MonDict* monster_set_dict(PersonalDict* pers);
PersonalDict* MonsterRead(char* filename);
PersonalDict* MonsterSave(char* filename);
void monster_manager_init();
void GiveDemoParty();

#endif
3 changes: 3 additions & 0 deletions include/k_save.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "simple_json.h"

#include "k_field.h"
#include "k_item.h"
#include "k_monster.h"

typedef struct TheBalls {
Expand All @@ -9,6 +10,7 @@ typedef struct TheBalls {
Player client;
time_t playTime;
u64 quests;
Item inventory[8];
} SaveBlock1;

typedef struct SaveBlock2 {
Expand All @@ -24,6 +26,7 @@ typedef struct Options {
}Options;

SaveBlock1 save1;
SaveBlock2 party;

extern SaveBlock1 *LoadSave(char* filename);
extern void WriteSave(char* filename);
Expand Down
2 changes: 1 addition & 1 deletion include/k_species.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum Species {
SPECIES_SQUOINK,
SPECIES_WOGHASH,
SPECIES_SOLUBOAR,
SPECIES_EGLET,
SPECIES_EGGLET,
SPECIES_REAGLE,
SPECIES_REAGALIA,
SPECIES_MUKCHUK,
Expand Down
Binary file removed maps/map1.bin.bak
Binary file not shown.
Loading

0 comments on commit 57e5b09

Please sign in to comment.