Untitled
unknown
c_cpp
a year ago
1.9 kB
6
Indexable
#include <raylib.h>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int mapSX, mapSY;
int mapPointer = 0;
int map[1000000];
void loadMap();
void drawMap();
Image empty_grid_img;
Texture2D empty_grid;
Image tester_img;
Texture2D tester;
int main() {
InitWindow(1920, 1080, "Electrical");
Image empty_grid_img = LoadImage("assets/empty-grid.png");
Texture2D empty_grid = LoadTextureFromImage(empty_grid_img);
UnloadImage(empty_grid_img);
Image tester_img = LoadImage("assets/tester.png");
Texture2D tester = LoadTextureFromImage(tester_img);
UnloadImage(tester_img);
loadMap();
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
drawMap();
EndDrawing();
}
UnloadTexture(empty_grid);
UnloadTexture(tester);
CloseWindow();
return 0;
}
void loadMap(){
fstream mapFile;
mapFile.open("map.txt", ios::in);
string currentLineContent;
int currentLineNumber = 1;
for (int i = 0; i < 1000001; i++) {
map[i] = 0;
}
while (getline(mapFile, currentLineContent)) {
if (currentLineNumber == 1) {
mapSX = std::stoi(currentLineContent);
}
if (currentLineNumber == 2) {
mapSY = std::stoi(currentLineContent);
}
if (currentLineNumber >= 5 && currentLineNumber < 95) {
for(int i = 0; i<mapSX; i++){
map[mapPointer++] = currentLineContent.at(i*2);
}
}
currentLineNumber++;
}
}
void drawMap(){
for(int i = 0; i < 1; i++){
if(map[i] == 48){
//DrawTexture(empty_grid, (i-(i/mapSX))*32, (i/mapSX)*32, WHITE);
DrawTexture(empty_grid, 100, 60, WHITE);
}
if(map[i] == 49){
DrawTexture(empty_grid, 100, 60, WHITE);
}
}
}Editor is loading...
Leave a Comment