趁着这段时间有空,把之前整理开发的一款手机游戏记录一下。之前是用微软的winphone系统开发,开发工具vs2010。和以往一样,先发一下效果图。整理总结不易,如需全部代码,请联系我15098950589(微信同号)。
核心代码如下
此模块主要 包括 三个部分:用户信息的显示:
hpmp.Draw();
GameMain.spriteBatch.Draw(nowfubenShow, new Vector2(10, 250), null, Color.White, 0, Vector2.Zero, 2f, SpriteEffects.None, 0);
GameMain.spriteBatch.DrawString(mapFont, "*" + dangqian.Split('/')[1], new Vector2(120, 240), Color.Bisque, 0f, Vector2.Zero, 2f, SpriteEffects.None, 1f);
GameMain.spriteBatch.DrawString(mapFont, dqzdsx.hp + "\\" + dqzdsx.ap, new Vector2(10, 0), Color.Bisque, 0f, Vector2.Zero, 2f, SpriteEffects.None, 1f);
GameMain.spriteBatch.DrawString(mapFont, "LV:" + user.dengji, new Vector2(20, 50), Color.Bisque, 0f, Vector2.Zero, 2f, SpriteEffects.None, 1f);
GameMain.spriteBatch.DrawString(mapFont, "ATT:" + dqzdsx.gongji, new Vector2(20, 100), Color.Bisque, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 1f);
GameMain.spriteBatch.DrawString(mapFont, "SPD:" + dqzdsx.sudu, new Vector2(20, 130), Color.Bisque, 0f, Vector2.Zero, 1.5f, SpriteEffects.None, 1f);
游戏的操作:
TouchCollection touCollection = TouchPanel.GetState();
foreach (TouchLocation touchlocation in touCollection)
{
foreach (directionButtonNode node in directionNodes)
{
switch (node.whetherClick(touchlocation))
{
case Motion.Click:
case Motion.Drag:
switch (node.GetDirection())
{
case Direction.Up:
dongzuo.dong(ref yuanfx, Direction.Up,ref donghua);
break;
case Direction.Down:
dongzuo.dong(ref yuanfx, Direction.Down,ref donghua);
break;
case Direction.Left:
dongzuo.dong(ref yuanfx, Direction.Left,ref donghua);
break;
case Direction.Right:
dongzuo.dong(ref yuanfx, Direction.Right,ref donghua);
break;
}
break;
case Motion.Stop:
dqyd = false;
break;
}
}
foreach (functionButtonNode node in nodes)
{
switch (node.whetherClick(touchlocation))
{
case Motion.Click:
case Motion.Drag:
if (juqi >= 50 && dqzdsx.ap>=100)
{
user.chuzhan.Tankmode = TankMode.Fire;
juqi = 0;
dqzdsx.ap -= 100;
if (dqyd == false)
{
donghua = new donghuaweituo(RunAndFire.RunFire);
}
jiazaifure.jfires.Add(user .chuzhan .Jdz ());
}
juqi++;
break;
case Motion.Stop:
switch (node.GetFunction())
{
case "fire":
if (jiazaifure.jfires.Count <= 0)
{
user.chuzhan.Tankmode = TankMode.Fire;
if (dqyd==false)
{
donghua = new donghuaweituo(RunAndFire.RunFire);
}
jiazaifure.jfires.Add(user.chuzhan.JfoundFire());
juqi = 0;
}
break;
}
break;
}
}
}
showTank = tank;
GetNum(tank.dr);
SpriteEffects effects = DrawT(tank.dr);
showTank.Time += timeC;
if (showTank.Time > 30)
{
if (showTank.Texturechange + showTank.RunBegin < showTank.RunEnd)
{
showTank.Texturechange++;
}
else
{
showTank.Texturechange = 0;
tank.Tankmode = TankMode.Run;
showTank.zt = true;
}
showTank.Time = 0;
}
return effects;