-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cs
76 lines (67 loc) · 1.67 KB
/
Player.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
using System;
using SplashKitSDK;
public class Player : GamePiece
{
public int speed = 3;
public Bitmap bitmap {get; set;}
public double x {get; set;}
public double y {get; set;}
public bool movingLeft;
public bool movingRight;
public bool movingUp;
public bool movingDown;
public Player(Window window)
{
bitmap = new Bitmap("HeroLeft", "HeroLeft.png");
x = (window.Width / 2) - (bitmap.Width / 2);
y = window.Height - bitmap.Height;
}
public Circle SafetyCircle()
{
return SplashKit.CircleAt(x + bitmap.Width / 2, y + bitmap.Height / 2, 150);
}
public bool CircleCollision(GamePiece gamePiece)
{
return SplashKit.BitmapCircleCollision(gamePiece.bitmap, gamePiece.x, gamePiece.y, SafetyCircle());
}
public bool CollidesWith(GamePiece gamePiece)
{
return SplashKit.BitmapCollision(this.bitmap, x, y, gamePiece.bitmap, gamePiece.x, gamePiece.y);
}
public void Draw()
{
if (movingLeft)
{
bitmap = new Bitmap("HeroLeft", "HeroLeft.png");
}
if (movingRight)
{
bitmap = new Bitmap("HeroRight", "HeroRight.png");
}
bitmap.Draw(x, y);
}
public void MoveUp()
{
y -= speed;
movingUp = true;
movingDown = false;
}
public void MoveDown()
{
y += speed;
movingDown = true;
movingUp = false;
}
public void MoveLeft()
{
x -= speed;
movingLeft = true;
movingRight = false;
}
public void MoveRight()
{
x += speed;
movingRight = true;
movingLeft = false;
}
}