-
Notifications
You must be signed in to change notification settings - Fork 0
/
NumberBlock.cs
168 lines (147 loc) · 4.82 KB
/
NumberBlock.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
157
158
159
160
161
162
163
164
165
166
167
168
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.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace numBlock
{
/// <summary>
/// This is a game component that implements IUpdateable.
/// </summary>
public class NumberBlock : Microsoft.Xna.Framework.GameComponent
{
public Guid guid;
public int blockNumber = 0;
public int lockCount = 0;
public int column = 0;
public bool beingRemoved = false;
private static float ACCELERATION = 2500.0f;
public Vector2 position;
public Vector2 velocity;
public bool dropping = false;
public bool floating = false;
public int destination_y = 0;
public NumberBlock(Game game)
: base(game)
{
position = new Vector2(0, 0);
velocity = new Vector2(0, 0);
guid = System.Guid.NewGuid();
}
public void MoveLeft()
{
position.X -= 50;
}
public void MoveRight()
{
position.X += 50;
}
/// <summary>
/// Allows the game component to perform any initialization it needs to before starting
/// to run. This is where it can query for any required services and load content.
/// </summary>
public override void Initialize()
{
base.Initialize();
}
/// <summary>
/// Allows the game component to update itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(GameTime gameTime)
{
if (dropping)
{
if (position.Y >= destination_y)
{
dropping = false;
velocity.Y = 0;
position.Y = destination_y;
((NumBlockGame)this.Game).StopDrop();
}
else
{
velocity.Y += ACCELERATION * (float)gameTime.ElapsedGameTime.TotalSeconds;
position.Y += velocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
}
else if (floating)
{
if (position.Y <= destination_y)
{
this.floating = false;
velocity.Y = 0;
position.Y = destination_y;
((NumBlockGame)this.Game).dropBlockCount--;
}
else
{
velocity.Y += -500.0f * (float)gameTime.ElapsedGameTime.TotalSeconds;//-2500.0f *(float)gameTime.ElapsedGameTime.TotalSeconds;
position.Y += velocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
}
base.Update(gameTime);
}
public bool BoostDrop()
{
this.velocity.Y = -200.0f;
return this.Drop();
}
public bool Float()
{
this.floating = true;
return true;
}
public bool Drop()
{
this.dropping = true;
//TODO determine actual drop position
List<NumberBlock> col = ((NumBlockGame)this.Game).gameBoard[this.column];
int index = (col.Count()-1) - col.IndexOf(this);
//TODO finish
this.destination_y = NumBlockGame.BOARD_OFFSET_Y + (7-index)*48 + (7-index)*2;
if (this.destination_y == this.position.Y)
{
this.dropping = false;
}
return this.dropping;
}
public override String ToString()
{
String returnVal = "[" + blockNumber + "]";
return returnVal;
}
public override bool Equals(object obj)
{
return (obj is NumberBlock && this.guid.Equals(((NumberBlock)obj).guid));
}
public override int GetHashCode()
{
return this.guid.GetHashCode();
}
public void checkLock()
{
if (this.lockCount > 0)
{
((NumBlockGame)this.Game).unlock.Play();
this.lockCount--;
if (this.lockCount == 0)
{
this.blockNumber = NumBlockGame.rand.Next(1, 8);
}
else
{
//Go to semi-unlocked sprite
this.blockNumber = 9;
}
}
}
}
}