Click here to Skip to main content
15,884,686 members
Articles / Mobile Apps / Windows Phone 7

Use Pinup and PinupManager to Create pinups in XNA, WPXNA (17)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
29 Jul 2013CPOL1 min read 6.5K   4  
Use Pinup and PinupManager to create pinups in XNA, WPXNA (17)

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.

C#
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.

C#
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.

C#
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.

C#
private PinupManager pinupManager;

private bool is1Hit = false;

Field is1Hit is used to indicate whether the bird is hit for the first time.

C#
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.

C#
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --