-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIBatteries.cs
More file actions
64 lines (52 loc) · 1.79 KB
/
UIBatteries.cs
File metadata and controls
64 lines (52 loc) · 1.79 KB
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
using System;
using System.Collections;
using GXPEngine;
using GXPEngine.Core;
using TiledMapParser;
using System.Drawing;
public class UIBatteries : GameObject
{
private Sprite batteryImage;
private Sprite[] batteriesList;
private float batteriesCoordinate;
private int currentLives;
private LifeCounter lifecounter;
public UIBatteries(LifeCounter pLifeCounter)
{
lifecounter = pLifeCounter;
batteriesList = new Sprite[3];
currentLives = lifecounter.lifeAmount;
createBatteries();
}
void Update()
{
if (lifecounter.lifeAmount < currentLives || lifecounter.lifeAmount > currentLives)
{
for (int i = 0; i < batteriesList.Length; i++)
{
batteriesList[i].Destroy();
}
currentLives = lifecounter.lifeAmount;
createBatteries();
}
}
private void createBatteries()
{
for (int i = 0; i < batteriesList.Length; i++)
{
if (i+1 <= lifecounter.lifeAmount)
{
batteryImage = new Sprite("sprites/battery.png", false, false);
}
else
{
batteryImage = new Sprite("sprites/battery_empty.png", false, false);
}
batteryImage.scale = 2f;
batteriesCoordinate = game.width*9 / 10 - batteryImage.width * 1.5f;
batteryImage.SetXY(batteriesCoordinate + batteryImage.width*i, 0);
batteriesList[i] = batteryImage;
AddChild(batteriesList[i]);
}
}
}