控制精灵和碰撞检测
[csharp]
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;
namespace WindowsGame6
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Texture2D ringtexture; //三环动画的相关变量
Point ringframeSize = new Point(75, 75);
Point ringcurrentFrame = new Point(0, 0);
Point ringsheetSize = new Point(6, 8);
Vector2 ringpos1 = Vector2.Zero;
const float ringspeed = 5;
Texture2D skulltexture; //骷髅头动画相关变量
Point skullframeSize = new Point(75, 75);
Point skullcurrentFrame = new Point(0, 0);
Point skullsheetSize = new Point(6, 8);
MouseState prevmousestate;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: 在此处添加初始化逻辑
base.Initialize();
}
protected override void LoadContent()
{
// 创建新的 SpriteBatch,可将其用于绘制纹理。
spriteBatch = new SpriteBatch(GraphicsDevice);
ringtexture = Content.Load<Texture2D>("Images//threerings"); //加载两幅位图
skulltexture = Content.Load<Texture2D>("Images//skullball");
// TODO: 在此处使用 this.Content 加载游戏内容
}
protected override void UnloadContent()
{
// TODO: 在此处取消加载任何非 ContentManager 内容
}
protected override void Update(GameTime gameTime)
{
// 允许游戏退出
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
++ringcurrentFrame.X; //循环三环精灵位图
if (ringcurrentFrame.X >= ringsheetSize.X)
{
ringcurrentFrame.X = 0;
++ringcurrentFrame.Y;
if (ringcurrentFrame.Y >= ringsheetSize.Y)
ringcurrentFrame.Y = 0;
}
++skullcurrentFrame.X; //循环骷髅精灵位图
if (skullcurrentFrame.X >= skullsheetSize.X)
{
skullcurrentFrame.X = 0;
++skullcurrentFrame.Y;
if (skullcurrentFrame.Y >= skullsheetSize.Y)
skullcurrentFrame.Y = 0;
}
// TODO: 在此处添加更新逻辑
&nbs
补充:软件开发 , C# ,