Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Cleaning up API Examples and refactoring Print/Log logic to work bett…
Browse files Browse the repository at this point in the history
…er in Lua and C#.
  • Loading branch information
jessefreeman committed Mar 17, 2021
1 parent 937b713 commit df2f256
Show file tree
Hide file tree
Showing 17 changed files with 373 additions and 488 deletions.
7 changes: 6 additions & 1 deletion Disks/APIExamples/AddScript/code.lua
Expand Up @@ -11,14 +11,19 @@
local textFile =
[===[
function test()
DrawText("Hello World", 1, 1, DrawMode.Tile, "large", 15)
DrawText("Hello World", 1, 8, DrawMode.Tile, "large", 15)
end
]===]

-- Register the text file as a script
AddScript("textFile", textFile)

function Init()

-- Example Title
DrawText("AddScript()", 1, 1, DrawMode.Tile, "large", 15)
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4)

-- Call the text method
test()
end
Expand Down
Binary file removed Disks/APIExamples/AddScript/colors.png
Binary file not shown.
57 changes: 0 additions & 57 deletions Disks/APIExamples/AddScript/data.json

This file was deleted.

60 changes: 0 additions & 60 deletions Disks/APIExamples/BackgroundColor/data.json

This file was deleted.

6 changes: 4 additions & 2 deletions Disks/APIExamples/Button/code.cs
Expand Up @@ -32,8 +32,9 @@ class ExampleGameChip : GameChip

public override void Init()
{
// Example Title
DrawText("Button()", 1, 1, DrawMode.Tile, "large", 15);
DrawText("C Sharp Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
DrawText("C Sharp Example - Press a direction or action button", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
}

public override void Update(int timeDelta)
Expand Down Expand Up @@ -63,8 +64,9 @@ public override void Draw()

// Convert the pressedButtons into a string and draw to the display
var message = string.Join(", ", pressedButtons.ToArray()).ToUpper();

// DrawText("Buttons Down:", 8, 8, DrawMode.Sprite, "large", 15);
DrawText(message.Substring(0, message.Length), 8, 24, DrawMode.Sprite, "medium", 14, -4);
DrawText(message.Substring(0, message.Length), 8, 32, DrawMode.Sprite, "medium", 14, -4);

}
}
Expand Down
9 changes: 7 additions & 2 deletions Disks/APIExamples/Button/code.lua
Expand Up @@ -23,8 +23,11 @@ local buttons = {
}

function Init()

-- Example Title
DrawText("Button()", 1, 1, DrawMode.Tile, "large", 15);
DrawText("Lua Example", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);
DrawText("Lua Example - Press a direction or action button", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);

end

function Update(timeDelta)
Expand All @@ -39,6 +42,7 @@ function Update(timeDelta)
if(Button(buttons[i], InputState.Down, 0)) then
table.insert(pressedButtons, tostring(buttons[i]))
end

end

end
Expand All @@ -50,7 +54,8 @@ function Draw()

-- Convert the pressedButtons into a string and draw to the display
local message = table.concat(pressedButtons, ", "):upper()

-- DrawText("Buttons Down:", 8, 8, DrawMode.Sprite, "large", 15)
DrawText(message:sub(0, #message), 8, 24, DrawMode.Sprite, "medium", 14, - 4)
DrawText(message:sub(0, #message), 8, 32, DrawMode.Sprite, "medium", 14, - 4)

end
60 changes: 0 additions & 60 deletions Disks/APIExamples/Button/data.json

This file was deleted.

14 changes: 10 additions & 4 deletions Disks/APIExamples/CalculateDistance/code.cs
Expand Up @@ -26,8 +26,12 @@ class ExampleGameChip : GameChip
public override void Init()
{

// Example Title
DrawText("CalculateDistance()", 1, 1, DrawMode.Tile, "large", 15);
DrawText("C Sharp Example - Drag the mouse to measure the distance", 8, 16, DrawMode.TilemapCache, "medium", 15, -4);

// Create a new canvas and pass this GameChip into the constructor
canvas = new Canvas(256, 240, this);
canvas = new Canvas(256, 240-32, this);

// Set the canvas stroke to a white 1x1 pixel brush
canvas.SetStroke(15, 1);
Expand All @@ -40,9 +44,11 @@ public override void Update(int timeDelta)
// // Update position B with the MousePosition
pointB = MousePosition();

// // Calculate the distance between pointA and pointB
// Calculate the distance between pointA and pointB
distance = CalculateDistance(pointA.X, pointA.Y, pointB.X, pointB.X);

Print(distance);

}

public override void Draw()
Expand All @@ -52,7 +58,7 @@ public override void Draw()
RedrawDisplay();

// // Clear the canvas with the background color
canvas.Clear(0);
canvas.Clear(5);

// // Draw 2 circles around each point
canvas.DrawEllipse(pointA.X - 4, pointA.Y - 4, 10, 10);
Expand All @@ -65,7 +71,7 @@ public override void Draw()
canvas.DrawText(distance.ToString(), pointB.X, pointB.Y - 12, "small", 15, -4);

// Draw the canvas to the display
canvas.DrawPixels();
canvas.DrawPixels(0, 32);

}
}
Expand Down
1 change: 1 addition & 0 deletions Disks/APIExamples/CalculateDistance/code.lua
Expand Up @@ -55,6 +55,7 @@ function Draw()
-- Draw the canvas to the display
canvas:DrawPixels()

--
DrawText("CalculateDistance()", 8, 8, DrawMode.Sprite, "large", 15);
DrawText("Lua Example", 8, 16, DrawMode.Sprite, "medium", 15, -4);

Expand Down

0 comments on commit df2f256

Please sign in to comment.