-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathray-gfx.ino
More file actions
89 lines (73 loc) · 1.7 KB
/
Copy pathray-gfx.ino
File metadata and controls
89 lines (73 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <TimerOne.h>
#include "game.h"
#include "gfx_engine.h"
#define D(x) x
#define I2C_ADDRESS 0x3C
#define OLED_RESET 3 //not used but needed by lib
Adafruit_SSD1306 display(OLED_RESET);
void timer_IRQ();
void drawFrame(Enemy *enemy, Player *player);
void resetEnemys(Enemy *enemy);
volatile uint8_t timer_flag = 0;
void setup() {
D(Serial.begin(9600));
pinMode(SHOOT_BUTTON, INPUT_PULLUP);
pinMode(SHOOT_BUTTON2, INPUT_PULLUP);
Timer1.initialize(50000);
Timer1.attachInterrupt(timer_IRQ);
display.begin(SSD1306_SWITCHCAPVCC, I2C_ADDRESS); // initialize with the I2C addr 0x3C (for the 128x64)
display.clearDisplay();
display.display(); //init display
}
void drawFrame(Enemy *enemy, Player *player) {
display.clearDisplay();
resetEnemys(enemy);
doRayCasting(player, enemy);
drawSprite(player, enemy);
drawHUD(player);
if (player->points == NBR_OF_ENEMIES) {
theEnd();
}
display.display();
}
void resetEnemys(Enemy *enemy) {
for (uint8_t i = 0; i < NBR_OF_ENEMIES; i++) {
enemy[i].visible = 0;
}
}
void loop() {
//New player
Player player;
player.x = 2;
player.y = 3;
player.dirX = 1;
player.dirY = 0;
player.planeX = 0;
player.planeY = 0.66;
player.shooting = 0;
player.points = 0;
Enemy enemy[NBR_OF_ENEMIES] {
{2, 7, 0, 0},
{6, 3, 0, 0},
{2, 11, 0, 0},
{11, 22, 0, 0},
{21, 17, 0, 0},
{32, 32, 0, 0}
};
while (1) {
if (timer_flag) {
movePlayer(&player);
playerShoot(&player);
drawFrame(&enemy[0], &player);
player.shooting = 0;
timer_flag = 0;
}
}
}
void timer_IRQ(){
timer_flag = 1;
}