Before I brick my Arduboy, could you make sure with me I’m not gonna screw it up? (meaning I don’t want to brick my Arduboy). I’m 99% sure I have to use the PROGMEM keyword otherwise it loads in the 2500 bytes or so instead of the big old 28000 something bytes of storage
Here’s my code:
World.h
#pragma once
constexpr uint8_t TOTAL_WORLD_WIDTH = 48;
constexpr uint8_t TOTAL_WORLD_HEIGHT = 32;
extern uint8_t world[TOTAL_WORLD_WIDTH*TOTAL_WORLD_HEIGHT];
constexpr uint8_t WORLD_SECTION_WIDTH = 16;
constexpr uint8_t WORLD_SECTION_HEIGHT = 8;
extern uint8_t loaded_world_section[WORLD_SECTION_WIDTH*WORLD_SECTION_HEIGHT];
int8_t x_on_grid(int16_t x);
int8_t y_on_grid(int16_t y);
uint8_t get_tile(uint8_t xIndex, uint8_t yIndex);
bool is_tile_solid(int16_t x, int16_t y);
void draw_world();
bool detect_wall(int8_t x, int8_t y);
World.cpp
#include <Arduboy2.h>
#include "World.h"
#include "Images.h"
extern Arduboy2 arduboy;
constexpr uint8_t TILE_WIDTH = 8;
uint8_t world[TOTAL_WORLD_WIDTH*TOTAL_WORLD_HEIGHT] {
0,1,1,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,11,11,11,11,11,11,11,11,11,11,0,0,0,0,0,0,0,0,0,
1,12,13,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,12,13,0,0,0,0,0,1,1,1,1,0,11,11,11,11,11,11,11,0,0,0,0,0,0,0,0,0,0,0,
1,14,15,0,0,0,1,1,1,12,13,0,0,0,0,1,1,1,14,15,0,0,0,0,0,1,5,5,5,0,0,11,11,11,11,0,0,0,0,0,0,0,12,13,0,0,0,0,
0,1,0,0,0,1,1,1,1,14,15,0,0,0,11,0,1,1,1,1,1,0,0,0,0,0,5,5,5,1,0,11,11,11,0,0,1,1,0,0,1,1,14,15,0,0,0,0,
0,0,0,0,0,1,12,13,1,1,1,0,0,1,11,11,0,1,1,0,0,0,1,1,1,1,6,7,6,1,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,0,0,0,0,0,0,0,0,1,0,1,0,
0,0,1,14,15,0,0,12,13,1,14,15,0,0,0,0,0,12,13,0,0,1,0,0,1,1,1,1,14,15,1,0,0,1,0,0,0,0,0,0,1,0,0,1,1,1,0,0,
0,0,0,1,1,1,1,14,15,1,1,0,0,1,1,1,1,14,15,0,0,0,0,0,1,12,13,1,1,1,1,0,0,1,1,0,0,1,1,1,1,0,1,1,0,0,0,0,
0,0,1,0,0,1,1,1,0,0,0,0,0,12,13,1,1,1,0,0,0,0,0,0,1,14,15,1,1,1,1,0,1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
0,1,12,13,1,1,0,0,0,0,0,0,0,14,15,1,0,0,0,1,1,0,0,0,0,1,1,1,1,1,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,
0,0,14,15,0,0,0,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,1,1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
//9928 - 9796 = 132
uint8_t loaded_world_section[WORLD_SECTION_WIDTH*WORLD_SECTION_HEIGHT] = {
1,1,0,0,0,2,0,0,0,0,0,12,13,1,1,1,
0,5,5,5,0,2,1,12,13,4,4,4,15,0,11,1,
0,5,5,5,5,2,1,14,15,4,4,4,1,0,11,11,
1,6,5,5,5,2,1,1,0,6,7,6,1,1,1,0,
1,1,6,7,6,2,2,2,2,2,2,2,2,2,2,2,
2,2,2,2,2,2,1,1,1,11,0,1,1,1,0,0,
1,1,1,1,1,1,0,11,11,11,11,0,0,0,0,1,
1,1,1,0,0,0,0,0,11,11,1,1,1,1,1,1,
};
int8_t x_on_grid(int16_t x) {
x = (x / TILE_WIDTH);
x = max(x, 0);
x = min(x, WORLD_SECTION_WIDTH-1);
return x;
}
int8_t y_on_grid(int16_t y) {
y = (y / TILE_WIDTH);
y = max(y, 0);
y = min(y, WORLD_SECTION_HEIGHT-1);
return y;
}
uint8_t get_tile(uint8_t xIndex, uint8_t yIndex) {
return loaded_world_section[WORLD_SECTION_WIDTH * yIndex + xIndex];
}
bool is_tile_solid(int16_t x, int16_t y) {
return (4 <= get_tile(x, y));
}
bool detect_wall(int8_t x, int8_t y) {
int8_t x1 = x_on_grid(x);
int8_t x2 = x_on_grid(x+TILE_WIDTH-1);
int8_t y1 = y_on_grid(y);
int8_t y2 = y_on_grid(y+TILE_WIDTH-1);
return ((is_tile_solid(x1, y1) || is_tile_solid(x2, y1) || is_tile_solid(x2, y2) || is_tile_solid(x1, y2)));
}
void draw_world() {
for(uint8_t x = 0; x < WORLD_SECTION_WIDTH; x++) {
for(uint8_t y = 0; y < WORLD_SECTION_HEIGHT; y++) {
uint8_t frame = get_tile(x, y);
//Sprites::drawOverwrite(x*8, y*8, spr_world, frame);
Sprites::drawSelfMasked(x*8, y*8, spr_world, frame);
}
}
}