Skip to content

Commit

Permalink
Merge pull request #2 from Gualor/dev
Browse files Browse the repository at this point in the history
Doom Nano Brutality integration
  • Loading branch information
Gualor authored Jul 30, 2023
2 parents d3cbf42 + c857f11 commit 2cc4d3e
Show file tree
Hide file tree
Showing 18 changed files with 2,066 additions and 893 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
bin
lib
raylib
doom_pico*
.vscode
36 changes: 24 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,51 @@ TARGET_EXEC := doom_pico

CC := gcc
RM := rm -rf
MKDIR := mkdir -p

SRC_DIR := src
INC_DIR := inc
LIB_DIR := lib
BIN_DIR := bin
RAYLIB_DIR := raylib

SRCS := $(shell find $(SRC_DIR) -name '*.c' -or -name '*.s')
OBJS := $(SRCS:%=$(BIN_DIR)/%.o)
SRCS := $(shell find $(SRC_DIR) -name "*.c")
OBJS := $(patsubst $(SRC_DIR)/%,$(BIN_DIR)/%.o,$(SRCS))
DEPS := $(OBJS:.o=.d)

CFLAGS := -Iinc -Ilib -MMD -MP -g
CFLAGS := -I$(INC_DIR) -MMD -MP -g
LDFLAGS := -lm

ifeq ($(USE_RAYLIB), 1)
CFLAGS += -DUSE_RAYLIB
LDFLAGS += -lraylib
CFLAGS += -I$(RAYLIB_DIR)/include -DUSE_RAYLIB
LDFLAGS += -L$(RAYLIB_DIR)/lib -lraylib
ifeq ($(OS), Windows_NT)
LDFLAGS += -lopengl32 -lgdi32 -lwinmm
else ifeq ($(shell uname -s), Linux)
LDFLAGS += -lGL -lpthread -ldl -lrt -lX11
else
$(error Platform $(OS) currently not supported for make "run" target)
endif
endif

$(BIN_DIR)/$(TARGET_EXEC): $(OBJS)
$(TARGET_EXEC): $(OBJS)
$(CC) $(OBJS) -o $@ $(LDFLAGS)

$(BIN_DIR)/%.c.o: %.c
mkdir -p $(dir $@)
$(BIN_DIR)/%.c.o: $(SRC_DIR)/%.c
$(MKDIR) $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@

$(RAYLIB_DIR):
./install_raylib.sh

.PHONY: run
run:
$(MAKE) clean
run: $(RAYLIB_DIR)
$(MAKE) USE_RAYLIB=1
./$(BIN_DIR)/$(TARGET_EXEC)
./$(TARGET_EXEC)

.PHONY: clean
clean:
ifneq (,$(wildcard $(BIN_DIR)))
$(RM) $(BIN_DIR)
endif

-include $(DEPS)
105 changes: 68 additions & 37 deletions inc/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,81 @@
* precision taking care of keep numbers inside the type range.
* Max is 256 / MAX_RENDER_DEPTH */
#define DISTANCE_MULTIPLIER 20
#define MAX_RENDER_DEPTH 12
#define MAX_SPRITE_DEPTH 8
#define MAX_RENDER_DEPTH 12
#define MAX_SPRITE_DEPTH 8

/* Faster rendering of vertical lines */
#define OPTIMIZE_RAYCASTING 1

/* Depth buffer for sprites */
#define ZBUFFER_SIZE ((SCREEN_WIDTH / Z_RES_DIVIDER) + 4)

/* Display */
#define SCREEN_WIDTH 128
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define HALF_WIDTH (SCREEN_WIDTH / 2)
#define HALF_HEIGHT (SCREEN_HEIGHT / 2)
#define RENDER_HEIGHT 58 // Raycaster working height
#define HUD_HEIGHT 6 // HUD working height
#define RENDER_HEIGHT 58
#define HUD_HEIGHT 6

/* Level */
#define LEVEL_WIDTH_BASE 6
#define LEVEL_WIDTH (1 << LEVEL_WIDTH_BASE)
#define LEVEL_HEIGHT 57
#define LEVEL_SIZE (LEVEL_WIDTH / 2 * LEVEL_HEIGHT)
/* Display colors */
#define COLOR_BLACK 0
#define COLOR_WHITE 1

/* Game */
#define GUN_TARGET_POS 18
#define GUN_SHOT_POS (GUN_TARGET_POS + 4)

#define ROT_SPEED 0.12f
#define MOV_SPEED 0.2f
#define MOV_SPEED_INV (1.0f / MOV_SPEED)

#define JOGGING_SPEED 0.005f
#define ENEMY_SPEED 0.02f
#define FIREBALL_SPEED 0.2f
#define FIREBALL_ANGLES 45 // Num of angles per PI

#define MAX_ENTITIES 10 // Max num of active entities
#define MAX_STATIC_ENTITIES 28 // Max num of entities in sleep mode

#define MAX_ENTITY_DISTANCE 200 // * DISTANCE_MULTIPLIER
#define MAX_ENEMY_VIEW 80 // * DISTANCE_MULTIPLIER
#define ITEM_COLLIDER_DIST 6 // * DISTANCE_MULTIPLIER
#define ENEMY_COLLIDER_DIST 4 // * DISTANCE_MULTIPLIER
#define FIREBALL_COLLIDER_DIST 2 // * DISTANCE_MULTIPLIER
#define ENEMY_MELEE_DIST 6 // * DISTANCE_MULTIPLIER
#define WALL_COLLIDER_DIST 0.2f

#define ENEMY_MELEE_DAMAGE 8
#define ENEMY_FIREBALL_DAMAGE 20
#define GUN_MAX_DAMAGE 15
#define GUN_SHOT_POS (GUN_TARGET_POS + 8)

#define ROT_SPEED 0.05f
#define MOV_SPEED 0.1f
#define GUN_SPEED 2.5f
#define JOGGING_SPEED 0.005f
#define ENEMY_SPEED 0.04f
#define FIREBALL_SPEED 0.2f
#define FIREBALL_ANGLES 45.0f

#define MAX_ENTITIES 12
#define MAX_STATIC_ENTITIES 24
#define MAX_ENTITY_DISTANCE 200
#define MAX_ENEMY_VIEW 90
#define ITEM_COLLIDER_DIST 6
#define ENEMY_COLLIDER_DIST 4
#define FIREBALL_COLLIDER_DIST 3
#define ENEMY_MELEE_DIST 9
#define WALL_COLLIDER_DIST 0.2f

#define ENEMY_MELEE_DAMAGE_EASY 20
#define ENEMY_MELEE_DAMAGE_NORMAL 30
#define ENEMY_MELEE_DAMAGE_HARD 40
#define ENEMY_MELEE_DAMAGE_VERY_HARD 50

#define ENEMY_FIREBALL_DAMAGE_EASY 25
#define ENEMY_FIREBALL_DAMAGE_NORMAL 40
#define ENEMY_FIREBALL_DAMAGE_HARD 60
#define ENEMY_FIREBALL_DAMAGE_VERY_HARD 80

#define GUN_MAX_DAMAGE_EASY 80
#define GUN_MAX_DAMAGE_NORMAL 60
#define GUN_MAX_DAMAGE_HARD 40
#define GUN_MAX_DAMAGE_VERY_HARD 20

#define PLAYER_MAX_HEALTH 100
#define MEDKIT_HEAL_EASY 100
#define MEDKIT_HEAL_NORMAL 80
#define MEDKIT_HEAL_HARD 50
#define MEDKIT_HEAL_VERY_HARD 30

#define PLAYER_MAX_AMMO 255
#define AMMO_PICKUP_EASY 13
#define AMMO_PICKUP_NORMAL 10
#define AMMO_PICKUP_HARD 9
#define AMMO_PICKUP_VERY_HARD 5

#define ENEMY_KILL_GOAL1 20
#define ENEMY_KILL_GOAL2 8

#define SCORE_SECRET_ENDING 200

/* Settings */
#define BUTTON_PRESS_WAIT 200

#endif /* CONSTANTS_H */

Expand Down
4 changes: 1 addition & 3 deletions inc/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

/* Definitions -------------------------------------------------------------- */

#define OPTIMIZE_DISPLAY
#define ZBUFFER_SIZE (SCREEN_WIDTH / Z_RES_DIVIDER)
#define DISPLAY_BUF_SIZE (SCREEN_WIDTH * ((SCREEN_HEIGHT + 7) / 8))

/* Function prototypes ------------------------------------------------------ */
Expand Down Expand Up @@ -163,7 +161,7 @@ void display_draw_vline(uint8_t x, int8_t start_y, int8_t end_y, uint8_t i);
* @param color Color value
*/
void display_draw_bitmap(int16_t x, int16_t y, const uint8_t bitmap[],
int16_t w, int16_t h, uint16_t color);
int16_t w, int16_t h, bool color);

/**
* @brief DISPLAY draw sprite to display buffer.
Expand Down
83 changes: 48 additions & 35 deletions inc/entities.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,31 @@ typedef uint16_t EntityUID;

typedef enum
{
E_FLOOR = 0x0, // . (also null)
E_WALL = 0xF, // #
E_PLAYER = 0x1, // P
E_ENEMY = 0x2, // E
E_DOOR = 0x4, // D
E_LOCKEDDOOR = 0x5, // L
E_EXIT = 0x7, // X
E_MEDKIT = 0x8, // M
E_KEY = 0x9, // K
E_FIREBALL = 0xa, // not in map
E_FLOOR = 0x0,
E_WALL = 0xF,
E_DOOR = 0xD,
E_DOOR2 = 0xA,
E_DOOR3 = 0xB,
E_COLL = 0xC,
E_PLAYER = 0x1,
E_ENEMY = 0x2,
E_EXIT = 0x7,
E_MEDKIT = 0x8,
E_AMMO = 0x9,
E_FIREBALL = 0xA
} EntityType;

typedef enum
{
S_STAND = 0,
S_ALERT = 1,
S_FIRING = 2,
S_MELEE = 3,
S_HIT = 4,
S_DEAD = 5,
S_HIDDEN = 6,
S_OPEN = 7,
S_CLOSE = 8,
S_STAND,
S_ALERT,
S_FIRING,
S_MELEE,
S_HIT,
S_DEAD,
S_HIDDEN,
S_OPEN,
S_CLOSE
} EntityStatus;

typedef struct
Expand All @@ -52,17 +54,21 @@ typedef struct
Coords plane;
float velocity;
uint8_t health;
uint8_t keys;
uint8_t ammo;
bool secret;
bool secret2;
bool secret3;
} Player;

typedef struct
{
EntityUID uid;
Coords pos;
uint8_t state;
uint8_t health; // angle for fireballs
uint8_t health;
uint8_t distance;
uint8_t timer;
bool drop_item;
} Entity;

typedef struct
Expand All @@ -77,7 +83,7 @@ typedef struct

/**
* @brief ENTITIES get UID from entity type and location.
*
*
* @param type Entity type
* @param x X coordinate
* @param y Y coordinate
Expand All @@ -87,7 +93,7 @@ EntityUID entities_get_uid(EntityType type, uint8_t x, uint8_t y);

/**
* @brief ENTITIES get entity type from UID.
*
*
* @param uid Entity UID
* @return EntityType Entity type
*/
Expand All @@ -97,7 +103,7 @@ EntityType entities_get_type(EntityUID uid);

/**
* @brief ENTITIES create player entity struct.
*
*
* @param x X coordinate
* @param y Y coordinate
* @return Player Player entity instance
Expand All @@ -110,12 +116,15 @@ static inline Player entities_create_player(uint8_t x, uint8_t y)
.plane = {0.0f, -0.66f},
.velocity = 0.0f,
.health = 100,
.keys = 0};
.ammo = 10,
.secret = false,
.secret2 = false,
.secret3 = false};
}

/**
* @brief ENTITIES create enemy entity struct.
*
*
* @param x X coordinate
* @param y Y coordinate
* @return Entity Enemy entity instance
Expand All @@ -128,12 +137,13 @@ static inline Entity entities_create_enemy(uint8_t x, uint8_t y)
.state = S_STAND,
.health = 100,
.distance = 0,
.timer = 0};
.timer = 0,
.drop_item = true};
}

/**
* @brief ENTITIES create medkit entity struct.
*
*
* @param x X coordinate
* @param y Y coordinate
* @return Entity Medkit entity instance
Expand All @@ -146,30 +156,32 @@ static inline Entity entities_create_medkit(uint8_t x, uint8_t y)
.state = S_STAND,
.health = 100,
.distance = 0,
.timer = 0};
.timer = 0,
.drop_item = true};
}

/**
* @brief ENTITIES create key entity struct.
*
*
* @param x X coordinate
* @param y Y coordinate
* @return Entity Key entity instance
*/
static inline Entity entities_create_key(uint8_t x, uint8_t y)
{
return (Entity){
.uid = entities_get_uid(E_KEY, x, y),
.uid = entities_get_uid(E_AMMO, x, y),
.pos = {x + 0.5f, y + 0.5f},
.state = S_STAND,
.health = 100,
.distance = 0,
.timer = 0};
.timer = 0,
.drop_item = true};
}

/**
* @brief ENTITIES create fireball entity struct.
*
*
* @param x X coordinate
* @param y Y coordinate
* @param dir Angle
Expand All @@ -178,12 +190,13 @@ static inline Entity entities_create_key(uint8_t x, uint8_t y)
static inline Entity entities_create_fireball(uint8_t x, uint8_t y, uint8_t dir)
{
return (Entity){
.uid = entities_get_uid(E_KEY, x, y),
.uid = entities_get_uid(E_AMMO, x, y),
.pos = {x + 0.5f, y + 0.5f},
.state = S_STAND,
.health = dir,
.distance = 0,
.timer = 0};
.timer = 0,
.drop_item = true};
}

#endif /* ENTITIES_H */
Expand Down
Loading

0 comments on commit 2cc4d3e

Please sign in to comment.