-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamePlayer.cs
78 lines (72 loc) · 2.39 KB
/
gamePlayer.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
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace CastleOfPain
{
//subclass of moving game item
class gamePlayer : generalGameItem
{
//constructor
public gamePlayer(Rectangle aPlayerRect, Texture2D aPlayerImage, Color aPlayerColor)
: base(aPlayerImage, aPlayerRect, aPlayerColor)
{}
//move method
public void movePlayer()
{
//if the right arrow key is pressed
if (Keyboard.GetState().IsKeyDown(Keys.D))
{
//move the game item right
rect.X+=2;
}
//if the left arrow key is pressed
if (Keyboard.GetState().IsKeyDown(Keys.A))
{
//move the game item left
rect.X-=2;
}
}
//method to keep player rectangle within bounds
public void outOfBounds()
{
//if the player rectangle is trying to go left off screen
if (rect.X <= 0)
//keep it within bounds
rect.X = 0;
//if the player rectangle is trying to go right off screen
if (rect.X >= 800-rect.Width)
//keep it within bounds
rect.X = 800-rect.Width;
//if the player rectangle is trying to go up off screen
if (rect.Y <= 0)
//keep it within bounds
rect.Y = 0;
//if the player rectangle is trying to go down off screen
if (rect.Y >= 480-rect.Height)
//keep it within bounds
rect.Y = 480-rect.Height;
}
}
}
//code graveyard
/*
//if the up arrow key is pressed
if (Keyboard.GetState().IsKeyDown(Keys.W))
{
//move the game item up
rect.Y-=3;
}
//if the down arrow key is pressed
if (Keyboard.GetState().IsKeyDown(Keys.S))
{
//move the game item down
rect.Y+=3;
}
*/