Introduction/Catalog
I have developed some games on Windows Phone. Here, I'll share my experiences and gradually upload some classes, no good name, I just call it WPXNA. (Some example code may not be stringent enough.)
Pinup
PinupManager
- Example
Pinup
In the game, pinup
can be used to display content such as text or a picture. For example: display "good", "amazing", it can also be used to show HP.
We define the Pinup
class to represent the pinup, it is a very simple class.
internal abstract class Pinup
: Spirit
{
protected Pinup ( IPlayScene scene, int type, Vector2 location,
string movieName, float speed, int angle, int width,
int height, double destroySecond )
: base ( scene, type, location, movieName,
null,
speed,
angle,
null,
width, height, destroySecond,
true,
false,
false,
0
)
{ }
protected override Vector2 getMovieLocation ( )
{ return this.Location - this.halfSize; }
protected override void updateSpeed ( )
{
this.xSpeed = Calculator.Cos ( this.angle ) * this.speed;
this.ySpeed = Calculator.Sin ( this.angle ) * this.speed;
base.updateSpeed ( );
}
protected override void move ( )
{
this.Location.X += this.xSpeed;
this.Location.Y += this.ySpeed;
}
}
As members of this class have no special, so you can reference the Spirit
class.
PinupManager
PinupManager
class is derived from class SpiritManager<T>
, the default order is 4000
.
internal class PinupManager
: SpiritManager<Pinup>
{
internal PinupManager ( )
: base ( 4000 )
{ }
}
Example
SceneT18
is an extension of SceneT17
, in addition to the functions of SceneT17
, it will also display a pinup.
We have defined a class MyHit
which represents a pinup
, we will show MyHit
after the first shot.
internal class MyHit
: Pinup
{
internal MyHit ( IPlayScene scene, Vector2 location )
: base ( scene, 1, location, "mypinup", 0, 0,
30, 30,
1
)
{ }
}
Then, we define some fields.
private PinupManager pinupManager;
private bool is1Hit = false;
Field is1Hit
is used to indicate whether the bird
is hit for the first time.
internal SceneT18 ( )
: base ( Vector2.Zero, GestureType.None, "background1",
new Resource[] {
new Resource ( "bird2.image", ResourceType.Image, @"image\bird2" ),
new Resource ( "bullet.image", ResourceType.Image, @"image\bullet" ),
new Resource ( "item.image", ResourceType.Image, @"image\item" ),
new Resource ( "pinup.image", ResourceType.Image, @"image\pinup1" ),
new Resource ( "go.image", ResourceType.Image, @"image\button1" ),
},
new Making[] {
new Movie ( "bird", "bird2.image", 80, 80, 5, "live",
new MovieSequence ( "live", true, new Point ( 1, 1 ), new Point ( 2, 1 ) )
),
new Movie ( "mybutton", "bullet.image", 10, 10, 0, "b",
new MovieSequence ( "b", new Point ( 1, 1 ) )
),
new Movie ( "myitem", "item.image", 30, 30, 0, "i",
new MovieSequence ( "i", new Point ( 1, 1 ) )
),
new Movie ( "mypinup", "pinup.image", 100, 50, 0, "p",
new MovieSequence ( "p", new Point ( 1, 1 ) )
),
new Button ( "b.go", "go.image", "GO",
new Vector2 ( 10, 690 ), 100, 50, new Point ( 1, 1 ) ),
}
)
{
this.pinupManager = new PinupManager ( );
this.pinupManager.Scene = this;
}
In the SceneT18
constructor, we'll create a new PinupManager
.
private void bulletHitTesting ( object sender, BulletHitAreaEventArgs e )
{
if ( !this.bird.IsDied && e.HitArea.HitTest ( this.bird.HitArea ) )
{
e.IsHit = true;
e.Targets = new IAssailable[] { this.bird };
if ( !this.is1Hit )
{
this.is1Hit = true;
this.pinupManager.Append ( new MyHit ( this, new Vector2 ( 0, 400 ) ) );
}
}
}
We use field is1Hit
to decide whether to display the pinup
, and display time is 1 second.
Get the code here, for more contents, please visit WPXNA.