|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 04/12/2009 at 02:38PM PDT, ID: 24316113 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: |
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;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
namespace WindowsGame1
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
//Global Variable Declarations
Texture2D backgroundTexture;
Texture2D sprite;
Texture2D sprite1;
Point frameCounter = new Point(0,0);
Point frameCounter1 = new Point(0, 0);
Vector2 position = Vector2.Zero;
Vector2 speed = Vector2.Zero;
SpriteEffects se =SpriteEffects.FlipHorizontally;
double frameDelay = 0.1;
double frameDelay1 = 0.5;
Level level; //xml level code that will be serialized into this object
SpriteFont spriteFont;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
XmlSerializer s = new XmlSerializer(typeof(Level));
TextReader r = new StreamReader("Content/Level.xml");
level = (Level)s.Deserialize(r);
r.Close();
foreach (Level.character c in level.allCharacters)
{
c.sprite = Content.Load<Texture2D>(c.textureAsset);
c.bound = new BoundingSphere(new Vector3(c.position , 0), 50);
}
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
spriteFont = Content.Load<SpriteFont>("Arial");
backgroundTexture = Content.Load<Texture2D>("Background");
sprite = Content.Load<Texture2D>("Boy");
sprite1 = Content.Load<Texture2D>("Tree");
//================= Help me here ============================
//
//create new sprite here called Fence or wall
//png file will be added into the content called Fence.png
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime)
{
KeyboardState kb = new KeyboardState();
kb = Keyboard.GetState();
speed = Vector2.Zero;
bool moving = false;
if (kb.IsKeyDown(Keys.Right))
{
speed.X = 2;
moving = true;
se = SpriteEffects.FlipHorizontally;
frameCounter.Y = 0;
}
if (kb.IsKeyDown(Keys.Up))
{
speed.Y = -2;
moving = true;
frameCounter.Y = sprite.Height * 2 / 3;
}
if (kb.IsKeyDown(Keys.Left))
{
speed.X = -2;
moving = true;
se = SpriteEffects.None;
frameCounter.Y = 0;
}
if (kb.IsKeyDown(Keys.Down))
{
speed.Y = 2;
moving = true;
frameCounter.Y = sprite.Height / 3;
}
position += speed;
if (moving)
{
frameDelay -= gameTime.ElapsedGameTime.TotalSeconds;
if (frameDelay < 0)
{
frameDelay = 0.1;
frameCounter.X += sprite.Width / 8;
if (frameCounter.X >= sprite.Width) frameCounter.X = 0;
}
}
frameDelay1 -= gameTime.ElapsedGameTime.TotalSeconds;
if (frameDelay1 < 0)
{
frameDelay1 = 0.5;
frameCounter1.X += sprite1.Width / 5;
if (frameCounter1.X >= sprite1.Width) frameCounter1.X = 0;
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Green);
spriteBatch.Begin();
//Draw Background (Background with trees, rock, garden etc...)
spriteBatch.Draw(backgroundTexture, new Rectangle(0,0,Window.ClientBounds.Width, Window.ClientBounds.Height), null, Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
//Draw Sprite1 (Tree)
spriteBatch.Draw(sprite1, new Vector2(300, 500), new Rectangle(frameCounter1.X, frameCounter1.Y, sprite1.Width / 6, sprite1.Height), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 0);
//Draw Sprite (Boy character)
spriteBatch.Draw(sprite, position, new Rectangle(frameCounter.X, frameCounter.Y, sprite.Width/8, sprite.Height/3), Color.White,0,Vector2.Zero,1,se,0);
//================= Help me here ============================
//
//Draw new sprite (Fence)
//The boy cannot past through the fence
//create a bounding sphere at the players current position
BoundingSphere playerSphere = new BoundingSphere(new Vector3(position,0),1);
//In this loop we draw each Male/Female character...
foreach (Level.character c in level.allCharacters)
{
spriteBatch.Draw(c.sprite, c.position, new Rectangle(0, 0, c.sprite.Height, c.sprite.Height), Color.White, 0, Vector2.Zero,c.scale, SpriteEffects.None, 0);
if (c.bound.Intersects(playerSphere))
{
spriteBatch.DrawString(spriteFont, c.greeting, (c.position + new Vector2(10, -10)), Color.White);
}
}
spriteBatch.End();
base.Draw(gameTime);
}
}
}
|
Advertisement