major cleanup of csv loading, now supports import straight from tiled!! Also moved game loop into its own file
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
SRC = src/main.c src/player.c src/window.c src/camera.c src/tilemap.c src/csvparser.c src/world.c
|
||||
SRC = src/main.c src/player.c src/window.c src/camera.c src/tilemap.c src/csvparser.c src/world.c src/game.c
|
||||
TARGET = target
|
||||
LIB = -lraylib -lm -lpthread -ldl -lrt -lX11
|
||||
all: $(TARGET)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
1,2,2,2,2,2,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,3,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,10,10,10,10,10,0,0,0,0,0,9,10,10,11,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,10,10,10,10,0,0,17,18,18,19,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,10,10,10,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,12,0,0,0,0,0,0,0,0,0,0,0,0,0,10,10,10,0,0,0,0,0,0,
|
||||
,17,5,10,10,10,10,10,10,12,2,2,2,2,2,2,2,2,2,2,3,0,0,0,10,10,0,0,0,0,0,
|
||||
,0,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,3,0,0,0,10,0,0,0,0,0,
|
||||
,1,13,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,3,0,0,0,10,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,0,0,0,10,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,0,0,0,10,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,10,4,18,18,18,18,18,18,5,10,10,10,10,10,11,0,0,0,10,0,0,0,0,
|
||||
,9,10,4,5,10,10,10,4,19,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,10,0,0,0,0,
|
||||
,9,10,12,13,10,10,4,19,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,4,19,0,0,0,10,10,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,17,18,18,18,18,19,0,0,10,10,10,10,10,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,0,0,0,0,0,0,0,0,0,10,10,10,10,0,1,13,10,10,10,10,10,11,0,0,0,0,1,2,3,0,
|
||||
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,5,4,18,18,18,18,19,0,0,0,0,9,10,11,0,
|
||||
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,19,0,0,0,0,0,0,0,0,0,17,18,19,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,0,0,0,
|
||||
|
@@ -1,25 +0,0 @@
|
||||
import sys
|
||||
|
||||
def add_commas_to_lines(input_file, output_file):
|
||||
try:
|
||||
with open(input_file, 'r') as infile:
|
||||
with open(output_file, 'w') as outfile:
|
||||
line_num = 0
|
||||
for line in infile:
|
||||
if not line_num:
|
||||
modified_line = f'{line.strip()},\n'
|
||||
else:
|
||||
modified_line = f',{line.strip()},\n'
|
||||
outfile.write(modified_line)
|
||||
line_num += 1
|
||||
print("File processed successfully!")
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
|
||||
# Check if the correct number of command-line arguments is provided
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python script.py <input_file_path> <output_file_path>")
|
||||
else:
|
||||
input_file_path = sys.argv[1]
|
||||
output_file_path = sys.argv[2]
|
||||
add_commas_to_lines(input_file_path, output_file_path)
|
||||
+20
-20
@@ -1,20 +1,20 @@
|
||||
1,2,2,2,2,2,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,3,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,10,10,11,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,18,18,19,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
,17,5,10,10,10,10,10,10,12,2,2,2,2,2,2,2,2,2,2,3,0,0,0,0,0,0,0,0,0,0,
|
||||
,0,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,3,0,0,0,0,0,0,0,0,0,
|
||||
,1,13,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,3,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,10,10,10,4,18,18,18,18,18,18,5,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,9,10,4,5,10,10,10,4,19,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,9,10,12,13,10,10,4,19,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,9,10,10,10,10,4,19,0,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,17,18,18,18,18,19,0,0,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0,
|
||||
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,13,10,10,10,10,10,11,0,0,0,0,1,2,3,0,
|
||||
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,5,4,18,18,18,18,19,0,0,0,0,9,10,11,0,
|
||||
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,19,0,0,0,0,0,0,0,0,0,17,18,19,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,0,0,0,
|
||||
1,2,2,2,2,2,2,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,2,3,0,0,0,0
|
||||
9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9,10,10,11,0,0,0,0
|
||||
9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,18,18,19,0,0,0,0
|
||||
9,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
9,10,10,10,10,10,10,12,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
17,5,10,10,10,10,10,10,12,2,2,2,2,2,2,2,2,2,2,3,0,0,0,0,0,0,0,0,0,0
|
||||
0,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,3,0,0,0,0,0,0,0,0,0
|
||||
1,13,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,12,3,0,0,0,0,0,0,0,0
|
||||
9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
9,10,10,10,10,10,10,10,4,18,18,18,18,18,18,5,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
9,10,4,5,10,10,10,4,19,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
9,10,12,13,10,10,4,19,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
9,10,10,10,10,4,19,0,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
17,18,18,18,18,19,0,0,0,0,0,0,0,0,0,9,10,10,10,10,10,11,0,0,0,0,0,0,0,0
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,13,10,10,10,10,10,11,0,0,0,0,1,2,3,0
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,5,4,18,18,18,18,19,0,0,0,0,9,10,11,0
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,17,19,0,0,0,0,0,0,0,0,0,17,18,19,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,0,0,0
|
||||
|
||||
|
@@ -1,40 +0,0 @@
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,1,1,1,1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-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
|
@@ -1,40 +0,0 @@
|
||||
66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,192,66,134,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,132,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,129,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,129,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,473,473,473,473,473,473,537,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,129,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,471,470,470,470,470,470,470,472,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,475,470,470,470,470,470,470,470,470,472,473,473,473,473,473,473,66,66,66,66,66,66,66,66,134,192,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,475,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,472,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,475,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,536,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,475,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,536,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,129,66,475,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,536,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,475,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,536,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,475,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,470,536,66,66,132,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,474,470,470,470,470,470,470,470,470,470,470,470,470,470,470,534,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,474,470,470,470,470,470,470,470,470,470,470,470,470,470,536,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,474,470,470,470,470,470,470,470,470,470,470,534,538,66,66,66,66,66,66,66,66,129,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,538,538,538,538,538,538,538,538,538,538,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,132,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,134,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,192,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,129,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,132,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,66,
|
||||
|
@@ -1,40 +0,0 @@
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,117,118,119,120,121,122,123,124,125,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,106,169,169,169,105,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,181,182,183,184,185,186,187,188,189,-1,-1,-1,
|
||||
,-1,-1,-1,-1,106,167,167,167,167,167,102,1256,1257,-1,296,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,245,246,247,248,249,250,251,252,253,-1,-1,-1,
|
||||
,-1,-1,-1,-1,232,-1,-1,-1,-1,-1,-1,1320,1321,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,309,310,311,312,313,312,313,312,252,123,124,125,
|
||||
,-1,-1,-1,-1,232,-1,-1,-1,-1,-1,-1,1384,1385,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,373,374,375,376,377,376,377,376,249,252,188,189,
|
||||
,-1,-1,-1,-1,232,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,437,438,439,505,313,314,313,249,313,314,252,253,
|
||||
,-1,-1,-1,-1,232,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,501,502,503,313,314,376,377,313,314,315,316,317,
|
||||
,-1,-1,-1,-1,296,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,565,566,567,505,313,314,376,377,378,379,380,381,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,629,630,631,437,438,439,440,441,442,443,444,445,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,369,370,-1,-1,-1,-1,-1,-1,-1,-1,-1,501,502,503,504,505,506,507,508,509,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,433,434,-1,-1,-1,-1,-1,-1,-1,-1,-1,565,566,567,568,569,570,571,572,573,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,629,630,631,632,633,634,635,636,637,
|
||||
,-1,244,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1196,1197,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,308,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1260,1261,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,-1,372,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1324,1325,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,435,436,-1,244,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1388,1389,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,499,500,-1,308,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
|
||||
,563,564,-1,372,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-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1,
|
||||
,-1,177,178,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,241,242,-1,-1,-1,-1,1793,1794,1794,1795,560,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,307,-1,-1,-1,-1,-1,-1,-1,-1,305,306,-1,-1,-1,1793,1858,1858,1858,1859,560,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,2208,2209,2210,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1793,1858,1858,1858,1922,1923,560,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,2272,2273,2274,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1857,1858,1858,1859,1986,1987,560,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,2336,2337,2338,-1,2720,2721,2722,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1921,1922,1922,1923,2050,2051,560,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,2400,2401,2402,-1,2784,2785,2786,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1985,1986,1986,1987,-1,-1,560,-1,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2848,2849,2850,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2049,2050,2050,2051,-1,-1,493,494,-1,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2912,2913,2914,-1,-1,945,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,493,494,-1,-1,-1,
|
||||
,-1,-1,-1,-1,1138,-1,-1,2405,2406,2407,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,557,495,495,495,495,495,495,495,558,495,495,495,
|
||||
,-1,-1,-1,-1,-1,-1,-1,2469,2470,2471,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,560,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,560,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,560,-1,-1,-1,
|
||||
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,493,495,496,-1,
|
||||
|
@@ -3,7 +3,7 @@
|
||||
"height": 4300,
|
||||
"width": 2
|
||||
},
|
||||
"activeFile": "sunny_map.tmx",
|
||||
"activeFile": "",
|
||||
"expandedProjectPaths": [
|
||||
".",
|
||||
"tilesets"
|
||||
@@ -26,7 +26,7 @@
|
||||
"selectedLayer": 1,
|
||||
"viewCenter": {
|
||||
"x": 348.419540229885,
|
||||
"y": 343.03160919540227
|
||||
"y": 173.01245210727967
|
||||
}
|
||||
},
|
||||
"sunnyside_world.tsx": {
|
||||
@@ -52,7 +52,6 @@
|
||||
"map.tileWidth": 16,
|
||||
"map.width": 40,
|
||||
"openFiles": [
|
||||
"sunny_map.tmx"
|
||||
],
|
||||
"project": "test.tiled-project",
|
||||
"recentFiles": [
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"activeFile": "simple_map.tmx",
|
||||
"expandedProjectPaths": [
|
||||
"."
|
||||
],
|
||||
"fileStates": {
|
||||
"simple_map.tmx": {
|
||||
"scale": 3.2539,
|
||||
"selectedLayer": 0,
|
||||
"viewCenter": {
|
||||
"x": 57.776821660161644,
|
||||
"y": 37.33980761547682
|
||||
}
|
||||
},
|
||||
"simple_tileset.tsx": {
|
||||
"scaleInDock": 6.1126,
|
||||
"scaleInEditor": 1
|
||||
}
|
||||
},
|
||||
"openFiles": [
|
||||
"simple_map.tmx"
|
||||
],
|
||||
"recentFiles": [
|
||||
"simple_map.tmx",
|
||||
"simple_tileset.tsx"
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
tilemap_t* csv_to_tilemap(char* csv);
|
||||
|
||||
int count_chars(char c, char* input_str);
|
||||
int** allocate_2d_array(int max_row, int max_column);
|
||||
|
||||
void read_csv_into_array(char* csv, int** array, int columns);
|
||||
void count_rows_columns(char* csv, int* num_rows, int* num_columns);
|
||||
void print_array2d(int** array, int rows, int columns);
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
# pragma once
|
||||
|
||||
int start_game();
|
||||
+107
-83
@@ -6,93 +6,117 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
tilemap_t* csv_to_tilemap(char* csv) {
|
||||
char* text = strdup(csv);
|
||||
|
||||
const char* delimiter = ",";
|
||||
int r, c; // number of rows and columns
|
||||
count_rows_columns(csv, &r, &c);
|
||||
|
||||
// FIRST PASS (calc token amount)
|
||||
// allocate memory
|
||||
int** array = allocate_2d_array(r, c);
|
||||
|
||||
char *token_c;
|
||||
// read csv into array
|
||||
read_csv_into_array(csv, array, c);
|
||||
|
||||
// Get the first token
|
||||
token_c = strtok(text, delimiter);
|
||||
|
||||
// Walk through other tokens
|
||||
int max_row = 0;
|
||||
int column = 0;
|
||||
int max_column = 0;
|
||||
while (token_c != NULL) {
|
||||
if (token_c[0]=='\n') {
|
||||
max_row++;
|
||||
max_column = column > max_column ? column : max_column;
|
||||
column=0;
|
||||
}
|
||||
else {
|
||||
column++;
|
||||
}
|
||||
token_c = strtok(NULL, delimiter);
|
||||
}
|
||||
|
||||
printf("NUM_COLMN: [%d]\n", max_column);
|
||||
printf("NUM_ROWS : [%d]\n", max_row);
|
||||
|
||||
// ALLOCATE MEMORY
|
||||
int** map_array = calloc((size_t)max_row, sizeof(int*));
|
||||
if (!map_array) { printf("[!] malloc failed"); exit(1); }
|
||||
for (int r = 0; r < max_row; r++) {
|
||||
map_array[r] = (int*)calloc(max_column, sizeof(int));
|
||||
if (!map_array[r]) { printf("[!] malloc failed"); exit(1); }
|
||||
}
|
||||
|
||||
// SECOND PASS (parse tokens)
|
||||
char* text_2 = strdup(csv);
|
||||
|
||||
char *token;
|
||||
|
||||
// Get the first token
|
||||
token = strtok(text_2, delimiter);
|
||||
|
||||
// Walk through other tokens
|
||||
int row_i = 0;
|
||||
int column_i = 0;
|
||||
|
||||
while (token != NULL) {
|
||||
if (token[0]=='\n') {
|
||||
// printf("LINE (%d)\n", row_i);
|
||||
row_i++;
|
||||
column_i=0;
|
||||
}
|
||||
else {
|
||||
char *endptr;
|
||||
int num = (int)strtol(token, &endptr, 10); // base 10
|
||||
|
||||
if (endptr == token) {
|
||||
// printf("ERROR");
|
||||
} else {
|
||||
if (column_i < max_column) {
|
||||
map_array[row_i][column_i] = num;
|
||||
// printf("(%d)'%d', ", column_i, num);
|
||||
}
|
||||
}
|
||||
|
||||
column_i++;
|
||||
}
|
||||
|
||||
token = strtok(NULL, delimiter);
|
||||
}
|
||||
|
||||
// print result
|
||||
printf("\n\nPARSED DATA:\n\n");
|
||||
for (int r = 0; r < max_row; r++) {
|
||||
for (int x = 0; x < max_column; x++) {
|
||||
printf("%d ", map_array[r][x]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
// print_array2d(array, r, c);
|
||||
|
||||
// Create, populate and return tilemap object
|
||||
tilemap_t* tm = malloc(sizeof(tilemap_t));
|
||||
tm->tmap = map_array;
|
||||
tm->rows = max_row;
|
||||
tm->columns = max_column;
|
||||
tm->tmap = array;
|
||||
tm->rows = r;
|
||||
tm->columns = c;
|
||||
return tm;
|
||||
}
|
||||
|
||||
void print_array2d(int** array, int rows, int columns) {
|
||||
printf("\n\nPARSED DATA:\n ");
|
||||
|
||||
for (int r = 0; r < rows; r++) {
|
||||
for (int x = 0; x < columns; x++) {
|
||||
printf("%d ", array[r][x]);
|
||||
}
|
||||
if (!(r == rows-1)) {
|
||||
printf(" \n ");
|
||||
}
|
||||
}
|
||||
printf("\nROW: [%d] COL: [%d]\n", rows, columns);
|
||||
|
||||
}
|
||||
|
||||
void read_csv_into_array(char* csv, int** array, int columns) {
|
||||
char* text = strdup(csv);
|
||||
|
||||
const char* delimiters = ",\n";
|
||||
|
||||
char* token;
|
||||
|
||||
token = strtok(text, delimiters);
|
||||
|
||||
int index = 0;
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
|
||||
while (token != NULL) {
|
||||
// calculate 2d position from token index
|
||||
row = index / columns;
|
||||
column = index % columns;
|
||||
|
||||
// populate 2d array
|
||||
int value = (int)strtol(token, NULL, 10); // base 10
|
||||
array[row][column] = value;
|
||||
|
||||
// next token
|
||||
index++;
|
||||
token = strtok(NULL, delimiters);
|
||||
}
|
||||
free(text);
|
||||
}
|
||||
|
||||
int** allocate_2d_array(int max_row, int max_column) {
|
||||
// ALLOCATE BASE ARRAY
|
||||
int** array_2d = calloc((size_t)max_row, sizeof(int*));
|
||||
if (!array_2d) { printf("[!] malloc failed"); exit(1); }
|
||||
|
||||
// ALLOCATE EACH ROW ARRAY
|
||||
for (int r = 0; r < max_row; r++) {
|
||||
array_2d[r] = (int*)calloc(max_column, sizeof(int));
|
||||
if (!array_2d[r]) { printf("[!] malloc failed"); exit(1); }
|
||||
}
|
||||
|
||||
return array_2d;
|
||||
}
|
||||
|
||||
void count_rows_columns(char* csv, int* num_rows, int* num_columns) {
|
||||
char* text = strdup(csv);
|
||||
|
||||
const char* newline = "\n";
|
||||
char* token;
|
||||
|
||||
token = strtok(text, newline);
|
||||
|
||||
// Walk through other tokens
|
||||
int row = 0;
|
||||
int columns = 0;
|
||||
while (token != NULL) {
|
||||
if (!row) {
|
||||
columns = count_chars(',', token) + 1;
|
||||
}
|
||||
row++;
|
||||
token = strtok(NULL, newline);
|
||||
}
|
||||
free(text);
|
||||
|
||||
*num_rows = row;
|
||||
*num_columns = columns;
|
||||
}
|
||||
|
||||
int count_chars(char c, char* input_str) {
|
||||
char* str = input_str;
|
||||
int count = 0;
|
||||
|
||||
while (*str != '\0') {
|
||||
if (*str == c) {
|
||||
count++;
|
||||
}
|
||||
str++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../include/window.h"
|
||||
#include "../include/player.h"
|
||||
#include "../include/camera.h"
|
||||
#include "../include/tilemap.h"
|
||||
#include "../include/world.h"
|
||||
|
||||
int start_game() {
|
||||
unsigned long time_us = 0; // time in µs
|
||||
|
||||
// create_tile
|
||||
|
||||
player_t player;
|
||||
camera_t camera;
|
||||
world_t world;
|
||||
|
||||
// Initialize components
|
||||
init_window("Game", /*RESOLUTION:*/1920/2, 1200/2, /*FPS:*/600);
|
||||
init_player(&player);
|
||||
init_camera(&camera, /*ZOOM*/ 3.0);
|
||||
init_world(&world, "assets/levels/test_collision.csv");
|
||||
printf("[!] Initialized successfully!\n\n");
|
||||
|
||||
tileset_t* tileset_sunnyside = load_tileset(16, "assets/tilesheets/sunnyside.png");
|
||||
tileset_t* tileset_collision = load_tileset(16, "assets/tilesheets/collision_tilesheet.png");
|
||||
printf("[!] Loaded tilesets successfully!\n\n");
|
||||
|
||||
tilemap_t* tilemap_objects = load_tilemap("assets/levels/test_object.csv");
|
||||
tilemap_t* tilemap_ground = load_tilemap("assets/levels/test_ground.csv");
|
||||
printf("\n[!] Loaded tilemaps successfully!\n\n");
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
// UPDATE
|
||||
update_player(&player, &world);
|
||||
update_camera(&camera, &player);
|
||||
|
||||
// RENDER
|
||||
start_render(&camera);
|
||||
render_tilemap(tilemap_ground, tileset_sunnyside);
|
||||
render_tilemap(tilemap_objects, tileset_sunnyside);
|
||||
|
||||
render_player(&player, (int)time_us/1000);
|
||||
|
||||
render_to_window(&camera);
|
||||
|
||||
time_us += GetFrameTime() * 1000000;
|
||||
}
|
||||
|
||||
// cleanup_window(&window);
|
||||
return 0;
|
||||
}
|
||||
+2
-78
@@ -1,83 +1,7 @@
|
||||
#include <raylib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../include/window.h"
|
||||
#include "../include/player.h"
|
||||
#include "../include/camera.h"
|
||||
#include "../include/tilemap.h"
|
||||
#include "../include/world.h"
|
||||
|
||||
int game();
|
||||
int test_tilemap();
|
||||
#include "../include/game.h"
|
||||
|
||||
int main() {
|
||||
game();
|
||||
// test_tilemap();
|
||||
start_game();
|
||||
}
|
||||
|
||||
int test_tilemap() {
|
||||
InitWindow(640, 400, "My Game");
|
||||
printf("\n--- GAME RUNNING ---\n");
|
||||
|
||||
// test tile
|
||||
tile_t* tile = create_tile(16, 32, 64);
|
||||
printf("test tile: Pos(%f, %f)\n", tile->rect.x, tile->rect.y);
|
||||
|
||||
// test tileset
|
||||
tileset_t* ts = load_tileset(16, "assets/test_tileset.png");
|
||||
|
||||
for (int x = 0; x < ts->num_tiles; x++) {
|
||||
printf("Tile at pos (%.1f|%.1f) with size (%.1f)\n",
|
||||
ts->tiles[x]->rect.x,
|
||||
ts->tiles[x]->rect.y,
|
||||
ts->tiles[x]->rect.width,
|
||||
ts->tiles[x]->rect.height
|
||||
);
|
||||
}
|
||||
|
||||
// test tilemap
|
||||
tilemap_t* tmap = load_tilemap("assets/map01.txt");
|
||||
}
|
||||
|
||||
int game() {
|
||||
unsigned long time_us = 0; // time in µs
|
||||
|
||||
// create_tile
|
||||
|
||||
player_t player;
|
||||
camera_t camera;
|
||||
world_t world;
|
||||
|
||||
// Initialize components
|
||||
init_window("Game", /*RESOLUTION:*/1920/2, 1200/2, /*FPS:*/600);
|
||||
init_player(&player);
|
||||
init_camera(&camera, /*ZOOM*/ 3.0);
|
||||
init_world(&world, "assets/levels/maps/test_collision.csv");
|
||||
|
||||
|
||||
tileset_t* tileset_sunnyside = load_tileset(16, "assets/tilesheets/sunnyside.png");
|
||||
tileset_t* tileset_collision = load_tileset(16, "assets/tilesheets/collision_tilesheet.png");
|
||||
|
||||
tilemap_t* tilemap_objects = load_tilemap("assets/levels/maps/test_object.csv");
|
||||
tilemap_t* tilemap_ground = load_tilemap("assets/levels/maps/test_ground.csv");
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
// UPDATE
|
||||
update_player(&player, &world);
|
||||
update_camera(&camera, &player);
|
||||
|
||||
// RENDER
|
||||
start_render(&camera);
|
||||
render_tilemap(tilemap_ground, tileset_sunnyside);
|
||||
render_tilemap(tilemap_objects, tileset_sunnyside);
|
||||
|
||||
render_player(&player, (int)time_us/1000);
|
||||
|
||||
render_to_window(&camera);
|
||||
|
||||
time_us += GetFrameTime() * 1000000;
|
||||
}
|
||||
|
||||
// cleanup_window(&window);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
|
|
+2
-1
@@ -58,7 +58,7 @@ tileset_t* load_tileset(int tile_size, char* tile_sheet_path) {
|
||||
}
|
||||
}
|
||||
|
||||
printf("Tileset with (%d) tiles created!\n", total_tiles);
|
||||
printf("Tileset with (%d) tiles created!\n\n", total_tiles);
|
||||
|
||||
return tileset_p;
|
||||
}
|
||||
@@ -68,6 +68,7 @@ tilemap_t* load_tilemap(char* map_path) {
|
||||
|
||||
tilemap_t* tm = (tilemap_t*)csv_to_tilemap(raw_file);
|
||||
|
||||
printf("[!] Tilemap [%s] loaded successfully!\n", map_path);
|
||||
return tm;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
void init_window(char* title, int width, int height, int maxFps) {
|
||||
InitWindow(width, height, title);
|
||||
SetWindowState(FLAG_WINDOW_RESIZABLE);
|
||||
SetTargetFPS(600);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -4,5 +4,5 @@
|
||||
#include "../include/world.h"
|
||||
|
||||
void init_world(world_t* world, char* collision_map) {
|
||||
world->col_map = load_tilemap(collision_map);
|
||||
world->col_map = load_tilemap(collision_map);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user