-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnakeFood.cs
49 lines (42 loc) · 1.2 KB
/
SnakeFood.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
using System.Linq;
using Definitions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
namespace Client
{
public class SnakeFood
{
public List<Vector2> FoodList { get; set; }
public const int FoodSize = BaseSnake.SnakeBodySize;
public SnakeFood()
{
this.Init();
}
public void Init()
{
FoodList = new List<Vector2>();
}
public void Draw(SpriteBatch spriteBatch)
{
foreach (var food in FoodList)
{
var rect = new Rectangle();
rect.Width = FoodSize;
rect.Height = FoodSize;
rect.X = (int)food.X * FoodSize;
rect.Y = (int)food.Y * FoodSize;
Color foodColor = Color.FromNonPremultiplied(75, 0, 130, 255);
RectangleGraphicsHelper.DrawRectangle(spriteBatch, rect, foodColor);
}
}
public bool TryPickFoodAtPosition(Vector2 position)
{
if (FoodList.Any(s => s.Equals(position)))
{
return true;
}
return false;
}
}
}