-
Notifications
You must be signed in to change notification settings - Fork 0
/
basicgameparameters.cs
142 lines (121 loc) · 4.06 KB
/
basicgameparameters.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace Frogger
{
class Frogger
{
/********************* Private variables *******************/
//4 Private Variables
private Texture2D frogTexture;
private Rectangle frogPosition;
private bool isVisible;
private Rectangle Screen;
/********************* Constructor ********************** */
/// <summary>
/// Creates a frog
/// </summary>
/// <param name="theImage">The frog image. </param>
/// <param name="thePosition">The frog's position. </param>
/// <param name="isVisible">Whether to draw the frog or not. </param>
/// <param name="theScreen">The bounds within which the frog must remain.</param>
public Frogger(Texture2D theImage, Rectangle thePosition, bool isVisible, Rectangle theScreen)
{
frogTexture = theImage;
frogPosition = thePosition;
Screen = theScreen;
isVisible = true;
}
/********************* Property methods ********************/
public Texture2D theImage
{
get { return frogTexture; }
set { frogTexture = value; }
}
public Rectangle thePosition
{
get { return frogPosition; }
set
{
frogPosition = value;
}
}
public bool Visible
{
get { return isVisible; }
set { isVisible = value; }
}
/********************** Methods ****************************/
/// <summary>
/// Move in the given direction, WITHOUT going off of the screen.
/// </summary>
public void Jump(Direction frogJump)
{
//Move Up
if (frogJump == Direction.North)
{
frogPosition.Y = frogPosition.Y - frogPosition.Height;
}
//Keep Frog From Moving Past the Top
if (frogPosition.Top < Screen.Top)
{
frogPosition.Y = Screen.Top;
}
//Move Down
if (frogJump == Direction.South)
{
frogPosition.Y = frogPosition.Y + frogPosition.Height;
}
//Keep Frog From Moving Past the Bottom
if (frogPosition.Bottom > Screen.Bottom)
{
frogPosition.Y = Screen.Bottom - frogPosition.Height;
}
//Move Right
if (frogJump == Direction.East)
{
frogPosition.X = frogPosition.X + frogPosition.Width;
}
//Keep Frog From Moving Past the Right
if (frogPosition.Right > Screen.Right)
{
frogPosition.X = Screen.Right - frogPosition.Width;
}
//Move Left
if (frogJump == Direction.West)
{
frogPosition.X = frogPosition.X - frogPosition.Width;
}
//Keep Frog From Moving Past the Left
if (frogPosition.X < Screen.Left)
{
frogPosition.X = Screen.Left;
}
}
/// <summary>
/// Return true if the frog is in the top row of the screen.
/// </summary>
/// <returns></returns>
//public bool OnTopRow()
//{
// if (frogPosition.Y == Screen.Top)
// return true;
//}
/// <summary>
/// Draw the frog using the spriteBatch, IF the frog is visible.
/// </summary>
/// <param name="spriteBatch"></param>
// Pass in the spriteBatch object so the sprite can draw itself.
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(frogTexture, frogPosition, Color.White);
}
}
}