Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 58 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,62 @@
{
"files.associations": {
"*.mdx": "markdown"
}
},
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wcast-align",
"-Wconversion",
"-Wsign-conversion",
"-Wnull-dereference"
],
"C_Cpp_Runner.msvcWarnings": [
"/W4",
"/permissive-",
"/w14242",
"/w14287",
"/w14296",
"/w14311",
"/w14826",
"/w44062",
"/w44242",
"/w14905",
"/w14906",
"/w14263",
"/w44265",
"/w14928"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
],
"C_Cpp_Runner.useAddressSanitizer": false,
"C_Cpp_Runner.useUndefinedSanitizer": false,
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
}
79 changes: 79 additions & 0 deletions public/usage-examples/json/data_driven_dungeon-1-example-oop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

namespace DataDrivenDungeon
{
public class DungeonManager
{
private Json _levelData;

public DungeonManager(string fileName)
{
_levelData = JsonFromFile(fileName);
}

public string LevelName => JsonReadString(_levelData, "level_name");
public int Difficulty => JsonReadInteger(_levelData, "difficulty");
public string Theme => JsonReadString(_levelData, "theme");

public void Draw()
{
ClearScreen(ColorBlack());
DrawText($"Level: {LevelName}", ColorWhite(), 20, 20);
DrawText($"Difficulty: {Difficulty}", ColorWhite(), 20, 40);
DrawText($"Theme: {Theme}", ColorWhite(), 20, 60);

// Accessing the 'spawn_points' array and looping through objects
Json spawnPoints = JsonReadArray(_levelData, "spawn_points");
for (int i = 0; i < JsonArraySize(spawnPoints); i++)
{
Json entry = JsonReadObjectAtIndex(spawnPoints, i);
string entryType = JsonReadString(entry, "type");
double x = JsonReadNumber(entry, "x");
double y = JsonReadNumber(entry, "y");

Color drawColor = (entryType == "Player") ? ColorGreen() : ColorRed();
FillRectangle(drawColor, x, y, 32, 32);
DrawText(entryType, ColorWhite(), (float)x, (float)y - 15);
}

// Accessing the 'loot' array
Json lootPoints = JsonReadArray(_levelData, "loot");
for (int i = 0; i < JsonArraySize(lootPoints); i++)
{
Json item = JsonReadObjectAtIndex(lootPoints, i);
string lootName = JsonReadString(item, "item");
double x = JsonReadNumber(item, "x");
double y = JsonReadNumber(item, "y");

FillCircle(ColorGold(), (float)x, (float)y, 8);
DrawText(lootName, ColorGold(), (float)x - 20, (float)y - 20);
}
}

public void Cleanup()
{
FreeJson(_levelData);
}
}

public class Program
{
public static void Main()
{
DungeonManager dungeon = new DungeonManager("level_data.json");
OpenWindow($"Dungeon Navigator: {dungeon.LevelName}", 800, 600);

while (!QuitRequested())
{
ProcessEvents();
dungeon.Draw();
RefreshScreen(60);
}

dungeon.Cleanup();
CloseAllWindows();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using SplashKitSDK;
using static SplashKitSDK.SplashKit;

// Data-Driven dungeon loading logic
Json levelInfo = JsonFromFile("level_data.json");

// Access strings and ints
string levelName = JsonReadString(levelInfo, "level_name");
int difficulty = JsonReadInteger(levelInfo, "difficulty");
string theme = JsonReadString(levelInfo, "theme");

OpenWindow($"Dungeon: {levelName}", 800, 600);

while (!QuitRequested())
{
ProcessEvents();
ClearScreen(ColorBlack());

DrawText($"Level Name: {levelName}", ColorWhite(), 20, 20);
DrawText($"Difficulty: {difficulty}", ColorWhite(), 20, 40);
DrawText($"Theme: {theme}", ColorWhite(), 20, 60);

// Reading nested objects from an array
Json spawnPoints = JsonReadArray(levelInfo, "spawn_points");
for (int i = 0; i < JsonArraySize(spawnPoints); i++)
{
Json entry = JsonReadObjectAtIndex(spawnPoints, i);
string type = JsonReadString(entry, "type");
double x = JsonReadNumber(entry, "x");
double y = JsonReadNumber(entry, "y");

Color drawColor = (type == "Player") ? ColorGreen() : ColorRed();
FillRectangle(drawColor, x, y, 32, 32);
DrawText(type, ColorWhite(), (float)x, (float)y - 15);
}

// Reading loot points
Json lootItems = JsonReadArray(levelInfo, "loot");
for (int i = 0; i < JsonArraySize(lootItems); i++)
{
Json item = JsonReadObjectAtIndex(lootItems, i);
string itemName = JsonReadString(item, "item");
double x = JsonReadNumber(item, "x");
double y = JsonReadNumber(item, "y");

FillCircle(ColorGold(), (float)x, (float)y, 8);
DrawText(itemName, ColorGold(), (float)x - 20, (float)y - 20);
}

RefreshScreen(60);
}

FreeJson(levelInfo);
CloseAllWindows();
62 changes: 62 additions & 0 deletions public/usage-examples/json/data_driven_dungeon-1-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "splashkit.h"

int main()
{
// Load the dungeon room data from the JSON file
json level_info = json_from_file("level_data.json");

// Reading top-level strings and integers
string level_name = json_read_string(level_info, "level_name");
int difficulty = json_read_number_as_int(level_info, "difficulty");
string theme = json_read_string(level_info, "theme");

open_window("Data-Driven Dungeon: " + level_name, 800, 600);

while (!quit_requested())
{
process_events();
clear_screen(color_black());

// Display Dungeon metadata
draw_text("Level: " + level_name, color_white(), 20, 20);
draw_text("Difficulty: " + std::to_string(difficulty), color_white(), 20, 40);
draw_text("Theme: " + theme, color_white(), 20, 60);

// Accessing the 'spawn_points' array and looping through objects
vector<json> spawn_points;
json_read_array(level_info, "spawn_points", spawn_points);
for (int i = 0; i < spawn_points.size(); i++)
{
json entry = spawn_points[i];
string entity_type = json_read_string(entry, "type");
double x = json_read_number(entry, "x");
double y = json_read_number(entry, "y");

color draw_color = (entity_type == "Player") ? color_green() : color_red();
fill_rectangle(draw_color, x, y, 32, 32);
draw_text(entity_type, color_white(), x, y - 15);
}

// Create loot sprites based on the loot array in the JSON
vector<json> loot_list;
json_read_array(level_info, "loot", loot_list);
for (int i = 0; i < loot_list.size(); i++)
{
json item = loot_list[i];
string item_name = json_read_string(item, "item");
double x = json_read_number(item, "x");
double y = json_read_number(item, "y");

fill_circle(color_gold(), x, y, 8);
draw_text(item_name, color_gold(), x - 20, y - 20);
}

refresh_screen(60);
}

// Clean up
free_json(level_info);
close_all_windows();

return 0;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions public/usage-examples/json/data_driven_dungeon-1-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from splashkit import *

def main():
# Load the JSON file
level_info = json_from_file("level_data.json")

# Read basic data fields
level_name = json_read_string(level_info, "level_name")
difficulty = json_read_integer(level_info, "difficulty")
theme = json_read_string(level_info, "theme")

open_window(f"Data-Driven Dungeon: {level_name}", 800, 600)

while not quit_requested():
process_events()
clear_screen(color_black())

# Display metadata on screen
draw_text(f"Level Name: {level_name}", color_white(), 20, 20)
draw_text(f"Difficulty Score: {difficulty}", color_white(), 20, 40)
draw_text(f"Dungeon Theme: {theme}", color_white(), 20, 60)

# Access arrays and objects nested inside the JSON
spawn_points = json_read_array(level_info, "spawn_points")
for i in range(json_array_size(spawn_points)):
entry = json_read_object_at_index(spawn_points, i)
entity_type = json_read_string(entry, "type")
x = json_read_number(entry, "x")
y = json_read_number(entry, "y")

draw_color = color_green() if entity_type == "Player" else color_red()
fill_rectangle(draw_color, x, y, 32, 32)
draw_text(entity_type, color_white(), x, y - 15)

# Iterate through loot array
loot_items = json_read_array(level_info, "loot")
for i in range(json_array_size(loot_items)):
item = json_read_object_at_index(loot_items, i)
item_name = json_read_string(item, "item")
x = json_read_number(item, "x")
y = json_read_number(item, "y")

fill_circle(color_gold(), x, y, 8)
draw_text(item_name, color_gold(), x - 20, y - 20)

refresh_screen_with_target_fps(60)

# Note: free_json(level_info) is implicitly handled in splashkit-python wrapper but explicit cleanup is good practice
close_all_windows()

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Data-Driven Dungeon Integration Example
16 changes: 16 additions & 0 deletions public/usage-examples/json/level_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"level_name": "Skeleton Crypt",
"difficulty": 2,
"theme": "Gothic",
"dungeon_width": 800,
"dungeon_height": 600,
"spawn_points": [
{"type": "Player", "x": 100, "y": 100},
{"type": "Skeleton", "x": 400, "y": 300},
{"type": "Skeleton", "x": 600, "y": 450}
],
"loot": [
{"item": "Health Potion", "x": 150, "y": 120},
{"item": "Rusty Key", "x": 750, "y": 50}
]
}
Loading