Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved code formatting #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/res
.vscode
/res/
/.idea/
/.vscode/
.project
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# doom-nano
A 3d raycast engine for Arduino

A 3d raycast engine for Arduino.

![](/images/screen-1.jpg?raw=true)

Expand All @@ -23,17 +24,17 @@ Hardware I used:

Resources:
- Sprites from https://www.spriters-resource.com
- Much thanks to https://lodev.org/cgtutor for so wonderful resource about raycasting engines
- Many thanks to https://lodev.org/cgtutor for so wonderful resource about raycasting engines

Current status:
- The map rendering is working nicely. Even I was able to add a depth effect by using different dithering patterns, depending on the distance to the view.
- Sprites are working too, though has some issues hiding them behind walls because memory limitations (the z-buffer precision has been limited a lot to make it smaller).
- You can move through the map, collide with walls, collect items and interact with enemies. I could also add the jogging effect, like Doom´s one.
- The enemies AI, despite is very simple, I think works very well and it´s enough for the purpose of the game. Looks very similar to Imp enemy from original Doom.
- For the HUD, I realized that the native `print` from Adafruit's library uses too much memory. So I've implemented my custom text rendering methods and a custom font which includes only needed characters and some icons.
- ~~Currently I´m using 99% of program memory, which doesn´t let me adds more code. I need to research how to optimize it to make it smaller.~~
- FPS and memory consumption has been improved using a slim and customized version of the SSD1306 lib from Adafruit. Thanks [@miracoly](https://github.com/miracoli)
- Now it has a basic sound support through Pin 9. Thanks again [@miracoly](https://github.com/miracoli)!
- ~~Currently, I´m using 99% of program memory, which doesn´t let me adds more code. I need to research how to optimize it to make it smaller.~~
- FPS and memory consumption has been improved using a slim and customized version of the SSD1306 lib from Adafruit. Thanks, [@miracoly](https://github.com/miracoli).
- Now it has a basic sound support through Pin 9. Thanks again, [@miracoly](https://github.com/miracoli)!

(I'd like) To do:
- ~~Make possible kill enemies.~~
Expand Down
6 changes: 3 additions & 3 deletions constants.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _constants_h
#define _constants_h
#ifndef CONSTANTS_H
#define CONSTANTS_H

// Key pinout
#define USE_INPUT_PULLUP
Expand Down Expand Up @@ -78,4 +78,4 @@ constexpr uint8_t HALF_WIDTH = SCREEN_WIDTH/2;
constexpr uint8_t RENDER_HEIGHT = 56; // raycaster working height (the rest is for the hud)
constexpr uint8_t HALF_HEIGHT = SCREEN_HEIGHT/2;

#endif
#endif /* CONSTANTS_H */
9 changes: 7 additions & 2 deletions display.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/*
#ifndef DISPLAY_H
#define DISPLAY_H

/*
todo: Moving this to CPP looks like it takes more Flash storage. Figure out why.
*/
#include "SSD1306.h"
#include "constants.h"
#include "SSD1306.h"

// Reads a char from an F() string
#define F_char(ifsh, ch) pgm_read_byte(reinterpret_cast<PGM_P>(ifsh) + ch)
Expand Down Expand Up @@ -274,3 +277,5 @@ void drawText(uint8_t x, uint8_t y, uint8_t num) {
itoa(num, buf, 10);
drawText(x, y, buf);
}

#endif /* DISPLAY_H */
10 changes: 5 additions & 5 deletions doom-nano.ino
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "constants.h"
#include "display.h"
#include "entities.h"
#include "input.h"
#include "level.h"
#include "sound.h"
#include "sprites.h"
#include "input.h"
#include "entities.h"
#include "types.h"
#include "display.h"
#include "sound.h"

// Useful macros
#define swap(a, b) do { typeof(a) temp = a; a = b; b = temp; } while (0)
#define sign(a, b) (double) (a > b ? 1 : (b > a ? -1 : 0))
#define sign(a, b) (double) ((a) > (b) ? 1 : ((b) > (a) ? -1 : 0))

// general
uint8_t scene = INTRO;
Expand Down
3 changes: 2 additions & 1 deletion entities.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include <stdint.h>

#include "constants.h"
#include "entities.h"
#include "types.h"
#include "constants.h"

Entity create_entity(uint8_t type, uint8_t x, uint8_t y, uint8_t initialState, uint8_t initialHealth) {
UID uid = create_uid(type, x, y);
Expand Down
7 changes: 3 additions & 4 deletions entities.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _entities_h
#define _entities_h
#ifndef ENTITIES_H
#define ENTITIES_H

#include "types.h"

Expand Down Expand Up @@ -56,5 +56,4 @@ struct StaticEntity {
Entity create_entity(uint8_t type, uint8_t x, uint8_t y, uint8_t initialState, uint8_t initialHealth);
StaticEntity create_static_entity(UID uid, uint8_t x, uint8_t y, bool active);

#endif

#endif /* ENTITIES_H */
4 changes: 3 additions & 1 deletion input.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <Arduino.h>
#include "input.h"

#include <Arduino.h>

#include "constants.h"

#ifdef USE_INPUT_PULLUP
Expand Down
6 changes: 3 additions & 3 deletions input.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _input_h
#define _input_h
#ifndef INPUT_H
#define INPUT_H

enum BUTTONS {
B = 0x0001,
Expand Down Expand Up @@ -28,4 +28,4 @@ bool input_start();
void getControllerData(void);
#endif

#endif
#endif /* INPUT_H */
7 changes: 3 additions & 4 deletions level.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _level_h
#define _level_h
#ifndef LEVEL_H
#define LEVEL_H

#include <avr/pgmspace.h>
#include "constants.h"
Expand Down Expand Up @@ -129,5 +129,4 @@ const static uint8_t sto_level_1[LEVEL_SIZE] PROGMEM = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
};

#endif

#endif /* LEVEL_H */
7 changes: 4 additions & 3 deletions sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
http://www.shikadi.net/moddingwiki/AudioT_Format
*/

#ifndef _sound_h
#define _sound_h
#ifndef SOUND_H
#define SOUND_H

#include <avr/pgmspace.h>

#include "constants.h"

constexpr uint8_t GET_KEY_SND_LEN = 90;
Expand Down Expand Up @@ -93,4 +94,4 @@ ISR(TIMER2_COMPA_vect) {
}
}

#endif
#endif /* SOUND_H */
10 changes: 5 additions & 5 deletions sprites.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef _sprites_h
#define _sprites_h
#ifndef SPRITES_H
#define SPRITES_H

#include <avr/pgmspace.h>
#include <stdint.h>

#include <avr/pgmspace.h>

#define bmp_font_width 24 // in bytes
#define bmp_font_height 6
#define CHAR_MAP " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-_(){}[]#"
Expand Down Expand Up @@ -716,5 +717,4 @@ const static uint8_t gradient[] PROGMEM = {
0xff, 0xff,
};

#endif

#endif /* SPRITES_H */
8 changes: 5 additions & 3 deletions types.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <stdint.h>
#include <math.h>
#include "types.h"

#include <math.h>
#include <stdint.h>

#include "constants.h"

template <class T>
Expand All @@ -20,6 +22,6 @@ UID create_uid(uint8_t type, uint8_t x, uint8_t y) {
return ((y << LEVEL_WIDTH_BASE) | x) << 4 | type;
}

uint8_t uid_get_type(UID uid) {
EType uid_get_type(UID uid) {
return uid & 0x0F;
}
7 changes: 3 additions & 4 deletions types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef _types_h
#define _types_h
#ifndef TYPES_H
#define TYPES_H

#define UID_null 0

Expand Down Expand Up @@ -30,5 +30,4 @@ EType uid_get_type(UID uid);
Coords create_coords(double x, double y);
uint8_t coords_distance(Coords* a, Coords* b);

#endif

#endif /* TYPES_H */