Game Development Reference
In-Depth Information
using Microsoft.Xna.Framework;
1
using Microsoft.Xna.Framework.Content;
2
using Microsoft.Xna.Framework.Graphics;
3
4
5
class Ball : ThreeColorGameObject
{
6
bool shooting;
7
8
9
public Ball(ContentManager Content)
: base (Content.Load<Texture2D>("spr_ball_red"),
10
Content.Load<Texture2D>("spr_ball_green"),
11
Content.Load<Texture2D>("spr_ball_blue"))
12
{
13
}
14
15
16
public override void HandleInput(InputHelper inputHelper)
{
17
if (inputHelper.MouseLeftButtonPressed() && !shooting)
18
{
19
shooting = true ;
20
velocity = (inputHelper.MousePosition
position)
1.2f;
21
}
22
}
23
24
25
public override void Update(GameTime gameTime)
{
26
if (shooting)
27
{
28
velocity.X
= 0.99f;
29
velocity.Y += 6;
30
}
31
else
32
{
33
Color = Painter.GameWorld.Cannon.Color;
34
position = Painter.GameWorld.Cannon.BallPosition
Center;
35
}
36
if (Painter.GameWorld.IsOutsideWorld(position))
37
Reset();
38
base .Update(gameTime);
39
}
40
41
42
public override void Reset()
{
43
base .Reset();
44
position = new Vector2(65, 390);
45
velocity = Vector2.Zero;
46
shooting = false ;
47
}
48
}
49
Listing 10.2
The final Ball class
Search WWH ::




Custom Search