-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame1.cs
151 lines (115 loc) · 4.49 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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Recycle_game.States;
using Recycle_game.Interaction;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Audio;
using Recycle_game;
namespace Recycle_game
{
/// <summary>
/// This is the main type for your game.
/// </summary>
///
public partial class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
private State _currentState;
private State _nextState;
ConstVar.LEVEL LEVEL1;
ConstVar.LEVEL LEVEL2;
public ConstVar.LEVEL LEVEL3;
public List<ConstVar.LEVEL> LEVELS;
public ConstVar.LEVEL GameLevel;
private int _score;
private SoundEffect effectLevelUp;
public int Score
{
get => _score;
set
{
if(_score < GameLevel.POINT_TARGET)
{
_score = value;
}
}
}
public void ChangeState(State state)
{
_nextState = state;
}
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
graphics.PreferredBackBufferWidth = (int)ConstVar.displayDim.X;
graphics.PreferredBackBufferHeight = (int)ConstVar.displayDim.Y;
graphics.IsFullScreen = false;
IsMouseVisible = true;
graphics.ApplyChanges();
LEVEL3 = new ConstVar.LEVEL(200000, 2000, 20000, "Livello3", 30, new List<Item.Type>() { Item.Type.CENTRORACCOLTA }, null, LEVEL2);
LEVEL2 = new ConstVar.LEVEL(20000, 200, 2000, "Livello2", 20, new List<Item.Type>() { Item.Type.ABITI, Item.Type.OLIOSPECIFICO, Item.Type.TONER, Item.Type.FARMACI, Item.Type.BATTERIE }, LEVEL3, LEVEL1);
LEVEL1 = new ConstVar.LEVEL(2000, 20, 200, "Livello1", 10, new List<Item.Type>() { Item.Type.ORGANICO, Item.Type.SECCO, Item.Type.VETRO, Item.Type.PLASTICA_MET, Item.Type.CARTA }, LEVEL2);
LEVELS = new List<ConstVar.LEVEL>();
LEVELS.Add(LEVEL1);
LEVELS.Add(LEVEL2);
LEVELS.Add(LEVEL3);
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
loadTMX("content/maps/mondo.tmx", ConstVar.layers);
loadAdvices();
loadNarratorText();
effectLevelUp = Content.Load<SoundEffect>("soundEffect/effectLevelUp");
GameLevel = LEVEL1;
ConstVar.sb = spriteBatch;
ConstVar.font = Content.Load<SpriteFont>("Fonts/font");
ConstVar.menu = new MenuState(this, graphics, Content, 0);
ConstVar.main = new MainState(this, graphics, Content, 1);
ConstVar.chooseBucket = new ChooseBucket(this, graphics, Content, 2);
ConstVar.tutorialState = new TutorialState(this, graphics, Content, 3);
ConstVar.UI = new UI(this, graphics, Content);
ConstVar.vocabulary = new Vocabulary(this, graphics, Content);
ConstVar.tutorial = new Tutorial(this, graphics, Content);
_currentState = ConstVar.menu;
}
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
protected override void Update(GameTime gameTime)
{
if (_nextState != null)
{
_currentState = _nextState;
_nextState = null;
}
KeyboardState kbState = Keyboard.GetState();
_currentState.Update(gameTime, kbState);
HandleLevel();
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
//GraphicsDevice.Clear(Color.CornflowerBlue);
_currentState.Draw(gameTime, spriteBatch);
base.Draw(gameTime);
}
void HandleLevel()
{
if (Score >= GameLevel.POINT_TARGET && GameLevel.NEXT_LEVEL != null)
{
GameLevel = GameLevel.NEXT_LEVEL;
effectLevelUp.Play();
}
}
}
}