ครึ่งแรกค่ะ
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;
Texture2D ball;
Texture2D ball2;
Texture2D ball3;
Texture2D background;
SpriteFont font1;
Vector2 ballpos;
Vector2 ballspeed;
int currentcolor;
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
//3บรรทัดล่างนี้ ปรับขนาดจอให้เป็น 640x480
// graphics.PreferredBackBufferWidth = 640;
// graphics.PreferredBackBufferHeight = 480;
// graphics.ApplyChanges();
ballpos.X = 20;
ballpos.Y = 10;
ballspeed.X = 10;
ballspeed.Y = 10;
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
ball = Content.Load<Texture2D>("ball-red");
ball2 = Content.Load<Texture2D>("ball-blue");
ball3 = Content.Load<Texture2D>("ball-green");
currentcolor = 1;
background = Content.Load<Texture2D>("background1");
font1 = Content.Load<SpriteFont>("freesiaupc");
}
/// <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">Provides 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
if ((ballpos.X < 0) || (ballpos.X > Window.ClientBounds.Width - 64))
{
ballspeed.X *= -1;
currentcolor++;
}
if ((ballpos.Y < 0) || (ballpos.Y > Window.ClientBounds.Height - 64))
{
ballspeed.Y *= -1;
currentcolor++;
}
if (currentcolor > 3) currentcolor = 1;
ballpos.X += ballspeed.X;
ballpos.Y += ballspeed.Y;
base.Update(gameTime);
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
spriteBatch.Begin();
http://spriteBatch.Draw(background, Vector2.Zero, Color.White);
//บรรทัดล่างนี้สร้างbackground ให้ติดขอบจอ
spriteBatch.Draw(background, new Rectangle(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height), Color.White);
http://spriteBatch.Draw(ball, Vector2.Zero, Color.White);
if (currentcolor == 1) spriteBatch.Draw(ball, ballpos, Color.White);
if (currentcolor == 2) spriteBatch.Draw(ball2, ballpos, Color.White);
if (currentcolor == 3) spriteBatch.Draw(ball3, ballpos, Color.White);
spriteBatch.DrawString(font1, @"Goldenpig มาแล้วนะเด็กน้อย", new Vector2(10, 10), Color.YellowGreen);
spriteBatch.End();
base.Draw(gameTime);
}
}
}
Mon May 10, 2010 2:45 am by titr
» แนวคิดแบบหมวก 6 ใบ -- มาวิเคราะห์กันๆ
Fri Dec 11, 2009 12:28 am by Admin
» หาแนวร่วม ทำซัพนรก Anime จ้า *-*
Fri Oct 09, 2009 1:46 pm by สก๊อยผ่า
» ขอเรียกร้องสิทธิให้แก่ช่วงๆ กับหลินฮุ่ย!!!
Fri Oct 09, 2009 1:44 pm by สก๊อยผ่า
» มีอะไรมาให้เล่นอีกแล้ว(เกมสร้างสถานะการณ์)
Thu Sep 03, 2009 12:14 pm by Parakan
» อยากถามวิธีใช้ถุงพลาสติก
Sun Aug 09, 2009 2:34 am by Admin
» Xnac€hecklist-ใครทำชีทหายมาอ่านได้ที่นี่
Sat Aug 08, 2009 9:08 pm by Admin
» อยากไปเที่ยวทะเลอีกอ่ะ
Fri Jul 31, 2009 1:47 pm by Admin
» มีรูปให้ดู
Thu Jul 30, 2009 7:39 pm by SoHandsome