-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSnakeGame.Renderer.cs
72 lines (52 loc) · 1.66 KB
/
SnakeGame.Renderer.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
using Meadow;
using Meadow.Foundation.Graphics;
using System;
using System.Threading;
namespace Snake;
public partial class SnakeGame
{
MicroGraphics graphics;
int topOffset;
int pixelScale;
public void Init(MicroGraphics gl)
{
graphics = gl;
gl.CurrentFont = new Font8x12();
topOffset = 12; //pixels
pixelScale = 5;
gl.Clear();
gl.DrawText(0, 0, "Meadow Snake");
gl.DrawText(0, 10, "v0.2.0");
gl.Show();
Thread.Sleep(1000);
BoardWidth = gl.Width / pixelScale;
BoardHeight = (gl.Height - topOffset) / pixelScale;
Reset();
}
public void Update()
{
graphics.Clear();
UpdateGameState();
//draw score and level
graphics.DrawText(0, 0, $"Score: {Level}");
//draw border
graphics.DrawRectangle(0, topOffset, graphics.Width, graphics.Height - topOffset);
//draw food
graphics.DrawRectangle(FoodPosition.X * pixelScale + 1,
FoodPosition.Y * pixelScale + topOffset + 1,
pixelScale, pixelScale, Color.Red);
//draw snake
for (int i = 0; i < SnakePosition.Count; i++)
{
var point = (Point)SnakePosition[i];
graphics.DrawRectangle(point.X * pixelScale + 1,
point.Y * pixelScale + topOffset + 1,
pixelScale, pixelScale, Color.HotPink, true);
}
// if (PlaySound)
// speaker.PlayTone(440, 25);
//show
graphics.Show();
Thread.Sleep(Math.Max(250 - Level * 10, 0));
}
}