This repository has been archived by the owner on Jan 4, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
code.cs
78 lines (56 loc) · 2.32 KB
/
code.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
Pixel Vision 8 - CalculateDistance Example
Copyright(C) 2017, Pixel Vision 8 (http://pixelvision8.com)
Created by Jesse Freeman(@jessefreeman)
This project was designed to display some basic instructions when you create
a new game.Simply delete the following code and implement your own Init(),
Update() and Draw() logic.
Learn more about making Pixel Vision 8 games at
https://www.pixelvision8.com/getting-started
**/
using Microsoft.Xna.Framework;
using PixelVision8.Player;
namespace PixelVision8.Examples
{
class ExampleGameChip : GameChip
{
private Point pointA = new Point(8, 8);
private Point pointB = new Point(248, 232);
private Canvas canvas;
private int distance;
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-32, this);
// Set the canvas stroke to a white 1x1 pixel brush
canvas.SetStroke(15, 1);
}
public override void Update(int timeDelta)
{
// // Update position B with the MousePosition
pointB = MousePosition();
// Calculate the distance between pointA and pointB
distance = CalculateDistance(pointA.X, pointA.Y, pointB.X, pointB.X);
Print(distance);
}
public override void Draw()
{
// Redraw the display
RedrawDisplay();
// // Clear the canvas with the background color
canvas.Clear(5);
// // Draw 2 circles around each point
canvas.DrawEllipse(pointA.X - 4, pointA.Y - 4, 10, 10);
canvas.DrawEllipse(pointB.X - 4, pointB.Y - 4, 10, 10);
// // Draw a line between the two points
canvas.DrawLine(pointA.X, pointA.Y, pointB.X, pointB.Y);
// // Draw the distance value above pointB
canvas.DrawText(distance.ToString(), pointB.X, pointB.Y - 12, "small", 15, -4);
// Draw the canvas to the display
canvas.DrawPixels(0, 32);
}
}
}