Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <BasicTerm.h>
- BasicTerm term(&Serial);
- #define VRy A0 //VRx
- #define VRx A1 //VRy
- #define SW 2
- #define LEN(arr) ((unsigned) (sizeof (arr) / sizeof (arr)[0]))
- /* a map consists of its map data ("tiles") and its dimensions*/
- struct Map {
- unsigned width;
- unsigned height;
- const char* data; // in PROGMEM
- const char lvlname[20]; //optional meta info, whatever you need
- };
- /* load data pointer at x,y */
- /* reference a 1D array like a 2D array */
- #define GET_MAPDATA(map,x,y) pgm_read_byte((unsigned short)(&map->data[x + map->width*y]))
- const char Level1[] PROGMEM =
- "###############"
- "# #"
- "# #"
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- " # # "
- "# #"
- "# #"
- "###############";
- Map allMaps[] = {
- {
- .width = 15, // can't be computed at compile time anymore, needs constant data
- .height = 17,
- .data = Level1,
- {"LVL 1"}
- }
- };
- Map* currentMap;
- int mapY;
- int mapX;
- void MapSetup(Map* pMap) {
- // just repoint the pionter
- currentMap = pMap;
- mapY = currentMap->height;
- mapX = currentMap->width;
- }
- void drawMap() {
- term.cls();
- for (uint8_t y = 0; y < mapY; y++)
- {
- for(uint8_t x = 0; x < mapX; x++) {
- // load character at given X,Y coordinate from PROGMEM
- char c = GET_MAPDATA(currentMap, 0, y);
- term.print(c);
- }
- term.println(); // new line
- }
- }
- void setup() {
- // put your setup code here, to run once:
- pinMode(VRx,INPUT);
- pinMode(VRy,INPUT);
- pinMode(SW,INPUT_PULLUP);
- Serial.begin(115200);
- term.show_cursor(false); //disable the cursor
- Serial.println((String)"C++: " + __cplusplus + "\r\nPinovi:\r\nVRx = " + VRy + "\r\nVRy = " + VRx + "\r\nSW = " + SW + "\r\nPritisni joystick kada si spreman."); //windows: \r\n | linux: \n | mac: \r
- while (digitalRead(SW) == 1)
- {
- //literally nothing just wait
- }
- term.init();
- term.cls();
- MapSetup(&allMaps[0]);
- Serial.println("Map dimensions" + String(mapX) + " x " + String(mapY));
- // print the whole map at once, since its one continous string
- // but will do so without line breaks
- Serial.println((const __FlashStringHelper*) currentMap->data);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement