/
Game1.cs
156 lines (136 loc) · 6.31 KB
/
Game1.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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.Input.Touch;
using Microsoft.Xna.Framework.Media;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
namespace ReduceReuseRecycle
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
private Rectangle _gameBoundaries;
private Boolean _windowIsSnapped;
private gameObjects _gameObjects;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
_graphics.IsFullScreen = true;
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
IsMouseVisible = true;
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
_gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
// Abstract to Level Defined Method or some ish.....
var random = new Random();
var trashItem1Texture = Content.Load<Texture2D>("trash1");
var trashItemLocation = new Vector2(_gameBoundaries.Width / 2 - random.Next(-800, 1000), 0f);
var trashItem1 = new trashItem(trashItem1Texture, trashItemLocation, _gameBoundaries);
trashItem1.setTrashType(TrashType.Trash);
var recycleItem1Texture = Content.Load<Texture2D>("recycle1");
var recylceItemLocation = new Vector2(_gameBoundaries.Width / 2 - random.Next(-1000, 800), 0f);
var recycleItem1 = new trashItem(recycleItem1Texture, recylceItemLocation, _gameBoundaries);
recycleItem1.setTrashType(TrashType.Recycle);
//Abstract to Level Defined Method or some ish.....
var trashBinTexture = Content.Load<Texture2D>("trashBin");
var trashBinLocation = new Vector2(_gameBoundaries.Width/2 + 50f, _gameBoundaries.Height - 100f);
var trashBin = new playerBin(trashBinTexture, trashBinLocation, _gameBoundaries);
trashBin.setBinType(TrashType.Trash);
var recycleBinTexture = Content.Load<Texture2D>("recycleBin");
var recycleBinLocation = new Vector2(_gameBoundaries.Width/2 - 50f, _gameBoundaries.Height - 100f);
var recycleBin = new playerBin(recycleBinTexture, recycleBinLocation, _gameBoundaries);
recycleBin.setBinType(TrashType.Recycle);
var iconTexture = new Texture2D(GraphicsDevice, 100, 100);
iconTexture = Content.Load<Texture2D>("RecyCloneIcon");
var icon = new Icon(iconTexture, Vector2.Zero, _gameBoundaries);
// Score Creation
var spriteFontTexture = Content.Load<SpriteFont>("font");
var score = new Score(spriteFontTexture, _gameBoundaries);
_gameObjects = new gameObjects();
_gameObjects.TrashBin = trashBin;
_gameObjects.RecycleBin = recycleBin;
_gameObjects.Score = score;
_gameObjects.Icon = icon;
_gameObjects.trashItem1 = trashItem1;
_gameObjects.recycleItem1 = recycleItem1;
_gameObjects.Score = score;
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
_windowIsSnapped = checkGameWindow();
if (Keyboard.GetState().IsKeyDown(Keys.R) || ((_gameObjects.Score.gameOver == true) && (Mouse.GetState().LeftButton == ButtonState.Pressed || TouchPanel.GetState().FirstOrDefault().State != TouchLocationState.Invalid)))
{
}
else if (_gameObjects.Score.gameOver == false)
{
_gameObjects.TrashBin.Update(gameTime, _gameObjects);
_gameObjects.RecycleBin.Update(gameTime, _gameObjects);
_gameObjects.Score.Update(gameTime, _gameObjects);
_gameObjects.recycleItem1.Update(gameTime, _gameObjects);
_gameObjects.trashItem1.Update(gameTime, _gameObjects);
_gameObjects.Score.Update(gameTime, _gameObjects);
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(new Color(43,85,5));
_spriteBatch.Begin();
//MustBegin
if (_windowIsSnapped)
{
var IconLocation = new Vector2((_gameBoundaries.Width - _gameObjects.Icon.Width) / 2, (_gameBoundaries.Height - _gameObjects.Icon.Height) / 2);
_gameObjects.Icon.Location = IconLocation;
_gameObjects.Icon.Draw(_spriteBatch);
}
else
{
_gameObjects.TrashBin.Draw(_spriteBatch);
_gameObjects.RecycleBin.Draw(_spriteBatch);
_gameObjects.trashItem1.Draw(_spriteBatch);
_gameObjects.recycleItem1.Draw(_spriteBatch);
_gameObjects.Score.Draw(_spriteBatch);
}
//MustEnd
_spriteBatch.End();
base.Draw(gameTime);
}
private Boolean checkGameWindow()
{
Boolean lSnapped = false;
if (ApplicationView.Value == ApplicationViewState.Snapped)
{
lSnapped = true;
_gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
}
else if (ApplicationView.Value == ApplicationViewState.Filled)
{
lSnapped = true;
_gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
}
else if (ApplicationView.Value == ApplicationViewState.FullScreenLandscape)
{
lSnapped = false;
_gameBoundaries = new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
}
return lSnapped;
}
}
}