论坛风格切换
  • 1078阅读
  • 11回复

WindowsGame1 [复制链接]

上一主题 下一主题
离线galekkomari
 
发帖
40
重量
2000
香味
212
好感度
200
200
只看楼主 倒序阅读 使用道具 0F 发表于: 2010-09-14
game1.cs


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;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

List<Ball> balls = new List<Ball>();
Texture2D ballTexture;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

Ball.SetBounds(800, 600);
for (int i = 0; i < 3; i++)
{
balls.Add(Ball.CreateBall());
}

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
ballTexture = Content.Load<Texture2D>("Sprites\\yellowBall");
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">rovides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

// TODO: Add your update logic here

foreach (Ball ball in balls)
ball.Update();

base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">rovides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

spriteBatch.Begin();
foreach (Ball b in balls)
spriteBatch.Draw(ballTexture, new Vector2(b.XPosition, b.YPosition),
Color.White);
spriteBatch.End();

base.Draw(gameTime);
}
}
}


Ball.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsGame1
{
class Ball
{
public float XVelocity { get; private set; }
public float YVelocity { get; private set; }
public float XPosition { get; private set; }
public float YPosition { get; private set; }

private static int Width;
private static int Height;

static Random rand = new Random();

private Ball(float xvel, float yvel, float xpos, float ypos)
{
XVelocity = xvel;
YVelocity = yvel;
XPosition = xpos;
YPosition = ypos;
}

public static void SetBounds(int w, int h)
{
Width = w;
Height = h;
}

public static Ball CreateBall()
{

return new Ball(

(float)(20*rand.NextDouble()),
(float)(20*rand.NextDouble()),
Width/2,
Height/2
);
}

public void Update()
{
XPosition += XVelocity;
YPosition += YVelocity;

if (XPosition < 0 || XPosition > Width)
{
XVelocity *= -1;
}

if (YPosition < 0 || YPosition > Height)
{
YVelocity *= -1;
}
}
}
}
1条评分
ヘイズ  +1 N大姐早..? 2010-09-14
离线galekkomari
发帖
40
重量
2000
香味
212
好感度
200
200
只看该作者 1F 发表于: 2010-09-14
Code
附件: WindowsGame1.zip (60 K) 下载次数:7
离线夏影
发帖
1945
重量
2065
香味
4608
好感度
200
195
只看该作者 2F 发表于: 2010-09-14
VS2010打开不能……
离线Exocet
发帖
1912
重量
2085
香味
1388
好感度
200
200
只看该作者 3F 发表于: 2010-09-14
強大的語法啊(汗
魚雷充填……完成!
目標鎖定……完成!
深海作戰艦-飛魚,魚雷發射!
离线galekkomari
发帖
40
重量
2000
香味
212
好感度
200
200
只看该作者 4F 发表于: 2010-09-14
VS2010打开不能……
夏影 发表于 2010年9月14日 07:10



平台是VS2008 + XNA Studio,没有后者的话肯定是打开不能的
离线galekkomari
发帖
40
重量
2000
香味
212
好感度
200
200
只看该作者 5F 发表于: 2010-09-21
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;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WindowsGame1
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

List<Ball> balls = new List<Ball>();
Texture2D ballTexture;

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

Ball.SetBounds(800, 600);
for (int i = 0; i < 3; i++)
{
balls.Add(Ball.CreateBall());
}

base.Initialize();
}

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);

// TODO: use this.Content to load your game content here
ballTexture = Content.Load<Texture2D>("Sprites\\yellowBall");
}

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">rovides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
KeyboardState keys = Keyboard.GetState();
KeyboardState oldKeystate = new KeyboardState();

if (keys.IsKeyDown(Keys.Escape))
this.Exit();

if (oldKeystate.IsKeyUp(Keys.Enter) && keys.IsKeyDown(Keys.Enter))
balls.Add(Ball.CreateBall());

oldKeystate = keys;

// TODO: Add your update logic here

foreach (Ball ball in balls)
ball.Update();

base.Update(gameTime);
}

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">rovides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

spriteBatch.Begin();
foreach (Ball b in balls)
spriteBatch.Draw(ballTexture, new Vector2(b.XPosition, b.YPosition),
Color.White);
spriteBatch.End();

base.Draw(gameTime);
}
}
}
附件: WindowsGame1.zip (62 K) 下载次数:2
离线小演
发帖
3533
重量
2202
香味
6944
好感度
200
200
只看该作者 6F 发表于: 2010-09-21
半個都沒有的飄過......
离线傻俊〞
发帖
4169
重量
2003
香味
4624
好感度
200
200
只看该作者 7F 发表于: 2010-09-21
小...小演懂啊....
摸摸牡丹,抱抱土豆,再蹭蹭小貓……最後請膜拜團子~...
离线galekkomari
发帖
40
重量
2000
香味
212
好感度
200
200
只看该作者 8F 发表于: 2010-09-28

SpriteSheetAnimator

-<<C# Properties>>
Position: Vector2

-<<C# Properties>> CurrentFrame: int

-spriteSheet: Texture2D

-DISTANCE: int =5

-rectangles : List <Rectangle>

+SpriteSheetAnimator (sheet : Texture2D , position : Vector2, rectangles)



......etc
附件: WindowsGame2.rar (190 K) 下载次数:1
20-10-07-97-13-D8-61-1D-C0-EF-07-2F-82-05-04-F6
离线fhja
发帖
1830
重量
2120
香味
2506
好感度
200
200
只看该作者 9F 发表于: 2010-09-28
不打算安装了…
离线mKoori
发帖
509
重量
2012
香味
62
好感度
200
200
只看该作者 10F 发表于: 2010-09-28
有XNA就代表着你的VS不是Express=_=....N妈妈乃个米人=3=

Storage部分完成
离线galekkomari
发帖
40
重量
2000
香味
212
好感度
200
200
只看该作者 11F 发表于: 2010-09-28
晒一下工作环境


以下是例题。
附件: progs.zip (637 K) 下载次数:0
20-10-07-97-13-D8-61-1D-C0-EF-07-2F-82-05-04-F6
快速回复
限100 字节
克里喵子:注意回帖时随时存档,随时使用草稿功能才是上策!
 
上一个 下一个