-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameScreen.cs
84 lines (72 loc) · 2.39 KB
/
GameScreen.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;
namespace ActionGame
{
class GameScreen:Screen
{
World world;
public progressBar HP;
public TextObject scoreLabel;
public int Status=PAUSE;
public const int READY = 0;
public const int RUNNING = 1;
public const int PAUSE = 2;
public int score = 0;
public GameScreen(Game1 game, ContentManager Content) : base(game, Content)
{
world = new World(game,this);
HP = new progressBar(game, new Rectangle(0, 0, 500,50),game.assets.black,game.assets.barBack,game.assets.bar);
HP.MaxValue = 10;
HP.Value = 10;
HP.animationSpeed = 0.5f;
HP.showSplit = true;
scoreLabel = new TextObject(game, game.assets.font, "score : 0",Color.White);
scoreLabel.setLocation(1000, 0);
game.FloatScreen.Add(new readyScreen(game,Content,this));
}
public override void update(float deltaTime)
{
if (game.input.onKeyDown(Keys.Escape))
{
if (Status == RUNNING) { Status = PAUSE; game.FloatScreen.Add(new pauseScreen(game, Content)); }
else if (Status == PAUSE) { Status = RUNNING; game.FloatScreen.Clear(); }
}
if (game.input.onKeyDown(Keys.U)) HP.setValue(10);
if (Status == RUNNING)
{
updateObject(deltaTime);
updateUI(deltaTime);
}
}
public override void Draw(SpriteBatch batch)
{
DrawObject(batch);
DrawUI(batch);
}
public void updateUI(float deltaTime)
{
HP.update(deltaTime);
scoreLabel.text = "score : " + score;
}
public void updateObject(float deltaTime)
{
world.update(deltaTime);
}
public void DrawUI(SpriteBatch batch)
{
HP.Draw(batch, 1);
scoreLabel.Draw(batch, 1);
}
public void DrawObject(SpriteBatch batch)
{
world.draw(batch);
}
}
}