Засоби технології Microsoft XNA як основа розробки тривимірних ігрових додатків

Сучасні API для програмування тривимірної графіки, математичні основи. Віртуальна камера, конвеєр візуалізації. Вершинні та піксельні шейдери. Розробка та реалізація ігрового додатку. Система постобробки зображення. Реалізація механіки ігрового процесу.

Рубрика Программирование, компьютеры и кибернетика
Вид дипломная работа
Язык украинский
Дата добавления 27.06.2013
Размер файла 4,7 M

Отправить свою хорошую работу в базу знаний просто. Используйте форму, расположенную ниже

Студенты, аспиранты, молодые ученые, использующие базу знаний в своей учебе и работе, будут вам очень благодарны.

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-3000, 800, 300), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-450, 800, 930), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-800, -900, -200), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(4000, 2000, 0), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(5000, 900, -3000), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(1000, 800, 1000), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-500, 800, -1000), 2.1f, 0.003f, 0, 0));

Fon_Sphere_Array.Add(new World_Sphere("Normal", Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-450, -800, -930), 2.1f, 0.003f, 0, 0));

foreach (World_Sphere bm in Fon_Sphere_Array)

{

bm.Lighting = false;

}

world_sphere.Lighting = false;

}

public void LevelLoad()

{

((Main)Game).camera.Restart();

((Main)Game).camera.cameraDirection = new Vector3(-1, 0, 0);

((Main)Game).camera.Initialize();

player_sphere = new Player_Sphere("Player1", "Normal", 25, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(0, 0, 0), 0.1f, 0.000f, 0, 0);

Enemys_Array.Clear();

Enemys_Array.Add(new Enemy_Sphere("E1", "Normal", 80, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(0, 140, 10), 0.4f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E2", "Normal", 60, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(150, 10, 30), 0.3f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E3", "Normal", 40, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(110, 110, 30), 0.2f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E4", "Normal", 40, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(40, 0, -90), 0.2f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E5", "Normal", 20, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(0, 0, -150), 0.1f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E5", "Normal", 30, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-120, 0, -150), 0.15f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E5", "Normal", 50, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(-150, 90, -80), 0.25f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E5", "Normal", 20, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(10, -90, -60), 0.1f, 0.003f, 0, 0));

Enemys_Array.Add(new Enemy_Sphere("E5", "Normal", 70, 100, Game.Content.Load<Model>(@"Models\MSphere"), new Vector3(90, -120, 60), 0.35f, 0.003f, 0, 0));

((Main)Game).isLoad = true;

}

public override void Update(GameTime gameTime)

{

// TODO: Add your update code here

base.Update(gameTime);

}

}

}

Вихідний код модуля ModelManager.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 DPSF.ParticleSystems;

namespace _3D

{

public class ModelManager : DrawableGameComponent

{

List<Space_Object> models = new List<Space_Object>();

List<Space_Object> Menu_models = new List<Space_Object>();

List<Space_Object> Test_Scene_models = new List<Space_Object>();

public List<Enemy_Sphere> Enemys_Array = new List<Enemy_Sphere>();

public List<World_Sphere> Fon_Sphere_Array = new List<World_Sphere>();

PlayerParticle playerParticle;

CloudsParticle cloudsParticle;

public List<ExplosionParticle> Explosions = new List<ExplosionParticle>();

SpriteBatch spriteBatch;

PostProcessor postprocessor;

//===========================

RenderCapture renderCapture;

RenderCapture glowCapture;

RenderCapture glowCaptureFin;

GaussianBlur blur;

//===========================

public SkyBox sb;

//============================

Texture2D Fon;

Texture2D WinFon;

Texture2D LossFon;

int PlayerTextureIndex = 1;

double seconds=0;

public ModelManager(Game game)

: base(game)

{

}

public override void Initialize()

{

sb = new SkyBox(Game, "cubemap",@"Models\textures\cubemapx5x",600f,600f,600f);

Game.Components.Add(sb);

sb.Visible = false;

base.Initialize();

models = ((Main)Game).loader.models;

Menu_models = ((Main)Game).loader.Menu_models;

Test_Scene_models = ((Main)Game).loader.Test_Scene_models;

Enemys_Array = ((Main)Game).loader.Enemys_Array;

Fon_Sphere_Array = ((Main)Game).loader.Fon_Sphere_Array;

}

protected override void LoadContent()

{

playerParticle = new PlayerParticle(Game);

cloudsParticle = new CloudsParticle(Game);

playerParticle.AutoInitialize(this.GraphicsDevice, Game.Content, null);

cloudsParticle.AutoInitialize(this.GraphicsDevice, Game.Content, null);

Fon = Game.Content.Load<Texture2D>(@"Sprites\Menu_Fon");

WinFon = Game.Content.Load<Texture2D>(@"Sprites\Win");

LossFon = Game.Content.Load<Texture2D>(@"Sprites\Loss");

spriteBatch = new SpriteBatch(GraphicsDevice);

renderCapture = new RenderCapture(GraphicsDevice);

glowCapture = new RenderCapture(GraphicsDevice);

glowCaptureFin = new RenderCapture(GraphicsDevice);

postprocessor = new PostProcessor(Game.Content.Load<Effect>

(@"Shaders\Glow_effect"), GraphicsDevice);

blur = new GaussianBlur(GraphicsDevice, Game.Content, 4);

}

protected override void UnloadContent()

{

playerParticle.Destroy();

cloudsParticle.Destroy();

}

public override void Update(GameTime gameTime)

{

if (((Main)Game).GameState == "Menu")

{

cloudsParticle.SetWorldViewProjectionMatrices(Matrix.Identity, ((Main)Game).camera.view, ((Main)Game).camera.projection);

cloudsParticle.SetCameraPosition(((Main)Game).camera.cameraPosition);

cloudsParticle.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

}

if (((Main)Game).GameState == "Game")

{

seconds += gameTime.ElapsedGameTime.TotalMilliseconds;

if (seconds > 80.0)

{

seconds -= 80.0;

PlayerTextureIndex++;

if (PlayerTextureIndex > 44)

PlayerTextureIndex = 0;

}

playerParticle.Emitter.PositionData.Position = ((Main)Game).loader.player_sphere.world.Translation;

playerParticle.SetWorldViewProjectionMatrices(Matrix.Identity, ((Main)Game).camera.view, ((Main)Game).camera.projection);

playerParticle.SetCameraPosition(((Main)Game).camera.cameraPosition); playerParticle.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

((Main)Game).modelManager.playerParticle.InitialProperties.PositionMin = new Vector3(((Main)Game).loader.player_sphere.Size * 50f,

((Main)Game).loader.player_sphere.Size * 50f, ((Main)Game).loader.player_sphere.Size * 50f);

((Main)Game).modelManager.playerParticle.InitialProperties.PositionMax = new Vector3(((Main)Game).loader.player_sphere.Size * -50f,

((Main)Game).loader.player_sphere.Size * -50f, ((Main)Game).loader.player_sphere.Size * -50f); ((Main)Game).modelManager.playerParticle.InitialProperties.VelocityMin = new Vector3(((Main)Game).loader.player_sphere.Size * 50f,

((Main)Game).loader.player_sphere.Size * 50f, ((Main)Game).loader.player_sphere.Size * 50f);

((Main)Game).modelManager.playerParticle.InitialProperties.VelocityMax = new Vector3(((Main)Game).loader.player_sphere.Size * -50f,

((Main)Game).loader.player_sphere.Size * -50f, ((Main)Game).loader.player_sphere.Size * -50f);

cloudsParticle.SetWorldViewProjectionMatrices(Matrix.Identity, ((Main)Game).camera.view, ((Main)Game).camera.projection);

cloudsParticle.SetCameraPosition(((Main)Game).camera.cameraPosition); cloudsParticle.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

foreach (ExplosionParticle explosionParticle in Explosions)

{explosionParticle.SetWorldViewProjectionMatrices(Matrix.Identity, ((Main)Game).camera.view, ((Main)Game).camera.projection);

explosionParticle.SetCameraPosition(((Main)Game).camera.cameraPosition); explosionParticle.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

}

}

base.Update(gameTime);

}

public override void Draw(GameTime gameTime)

{

// космос

if (((Main)Game).GameState == "Space")

{

renderCapture.Begin();

GraphicsDevice.Clear(Color.Black);

sb.Draw(gameTime);

foreach (Space_Object bm in models)

{

if (bm.Name == "Sun_SP")

bm.Lighting = false;

bm.Draw(((Main)Game).camera);

}

base.Draw(gameTime);

renderCapture.End();

glowCapture.Begin();

GraphicsDevice.Clear(Color.Black);

sb.Draw(gameTime);

foreach (Space_Object bm in models)

{

if (bm.Name == "Sun_SP")

bm.Lighting = false;

bm.Draw(((Main)Game).camera);

}

base.Draw(gameTime);

glowCapture.End();

glowCaptureFin.Begin();

postprocessor.Input = glowCapture.GetTexture();

postprocessor.Draw();

glowCaptureFin.End();

blur.Input = glowCaptureFin.GetTexture();

blur.ResultCapture = glowCaptureFin;

blur.Draw();

GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);

spriteBatch.Draw(renderCapture.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.Draw(glowCaptureFin.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

}

//меню

if (((Main)Game).GameState == "Menu")

{

renderCapture.Begin();

GraphicsDevice.Clear(Color.Black);

// отрисовка фона

spriteBatch.Begin();

spriteBatch.Draw(Fon,new Rectangle(0,0,GraphicsDevice.Viewport.Width,GraphicsDevice.Viewport.Height), Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };

foreach (Space_Object bm in Menu_models)

{

bm.Draw(((Main)Game).camera);

}

cloudsParticle.Draw();

base.Draw(gameTime);

GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.CullClockwiseFace };

renderCapture.End();

glowCapture.Begin();

GraphicsDevice.Clear(Color.Black);

// отрисовка фона

spriteBatch.Begin();

spriteBatch.Draw(Fon, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };

foreach (Space_Object bm in Menu_models)

{

bm.Draw(((Main)Game).camera);

}

cloudsParticle.Draw();

base.Draw(gameTime);

GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.CullClockwiseFace };

glowCapture.End();

glowCaptureFin.Begin();

postprocessor.Input = glowCapture.GetTexture();

postprocessor.Draw();

glowCaptureFin.End();

blur.Input = glowCaptureFin.GetTexture();

blur.ResultCapture = glowCaptureFin;

blur.Draw();

GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);

spriteBatch.Draw(renderCapture.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.Draw(glowCaptureFin.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

}

// заставка

if (((Main)Game).GameState == "ScreenWin")

{

spriteBatch.Begin();

spriteBatch.Draw(WinFon, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };

}

if (((Main)Game).GameState == "ScreenLoss")

{

spriteBatch.Begin();

spriteBatch.Draw(LossFon, new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };

}

//====================================================

// Тестовая сцена

if (((Main)Game).GameState == "Test")

{

renderCapture.Begin();

GraphicsDevice.Clear(Color.Black);

sb.Draw(gameTime);

foreach (Space_Object bm in Test_Scene_models)

{

bm.Lighting = false;

bm.Draw(((Main)Game).camera);

}

base.Draw(gameTime);

renderCapture.End();

glowCapture.Begin();

GraphicsDevice.Clear(Color.Black);

sb.Draw(gameTime);

foreach (Space_Object bm in Test_Scene_models)

{

bm.Lighting = false;

bm.Draw(((Main)Game).camera);

}

base.Draw(gameTime);

glowCapture.End();

glowCaptureFin.Begin();

postprocessor.Input = glowCapture.GetTexture();

postprocessor.Draw();

glowCaptureFin.End();

blur.Input = glowCaptureFin.GetTexture();

blur.ResultCapture = glowCaptureFin;

blur.Draw();

GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);

spriteBatch.Draw(renderCapture.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.Draw(glowCaptureFin.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

}

//====================================================

// игра

if (((Main)Game).GameState == "Game")

{

renderCapture.Begin();

GraphicsDevice.Clear(Color.Black);

GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };

((Main)Game).loader.world_sphere.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\world_sphere"), ((Main)Game).loader.TextureEffect);

int tex = 1;

foreach (World_Sphere bm in Fon_Sphere_Array)

{ tex++;

if((tex%2)==0)

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\world_sphere"), ((Main)Game).loader.TextureEffect);

else

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\world_sphere2"), ((Main)Game).loader.TextureEffect);

}

base.Draw(gameTime);

GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None };

((Main)Game).loader.player_sphere.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()),

((Main)Game).loader.TextureEffect);

foreach (Enemy_Sphere bm in Enemys_Array)

{

if( bm.Health>=60)

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffectGreen);

else

if(( bm.Health<60)&&(bm.Health>=30))

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffectOrange);

else

if (bm.Health<30)

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffectRed);}

base.Draw(gameTime);

cloudsParticle.Draw();

playerParticle.Draw();

foreach (ExplosionParticle explosionParticle in Explosions)

{

explosionParticle.Draw();

}

base.Draw(gameTime);

renderCapture.End();

glowCapture.Begin();

GraphicsDevice.Clear(Color.Black);

GraphicsDevice.RasterizerState = new RasterizerState() { FillMode = FillMode.WireFrame, CullMode = CullMode.None };

((Main)Game).loader.world_sphere.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\world_sphere"), ((Main)Game).loader.TextureEffect);

tex = 1;

foreach (World_Sphere bm in Fon_Sphere_Array)

{

tex++;

if ((tex % 2) == 0)

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\world_sphere"), ((Main)Game).loader.TextureEffect);

else

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\world_sphere2"), ((Main)Game).loader.TextureEffect);

}

base.Draw(gameTime);

GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.None };

foreach (Enemy_Sphere bm in Enemys_Array)

{

if (bm.Health >= 60)

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffectGreen);

else

if ((bm.Health < 60) && (bm.Health >= 30))

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffectOrange);

else

if (bm.Health < 30)

bm.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffectRed);

}

((Main)Game).loader.player_sphere.Draw(((Main)Game).camera, Game.Content.Load<Texture2D>(@"Textures\PlayerTextures\Water" + PlayerTextureIndex.ToString()), ((Main)Game).loader.TextureEffect);

cloudsParticle.Draw();

playerParticle.Draw();

foreach (ExplosionParticle explosionParticle in Explosions)

{

explosionParticle.Draw();

}

base.Draw(gameTime);

glowCapture.End();

GraphicsDevice.RasterizerState = new RasterizerState() { CullMode = CullMode.CullClockwiseFace };

glowCaptureFin.Begin();

postprocessor.Input = glowCapture.GetTexture();

postprocessor.Draw();

glowCaptureFin.End();

blur.Input = glowCaptureFin.GetTexture();

blur.ResultCapture = glowCaptureFin;

blur.Draw();

GraphicsDevice.Clear(Color.Black);

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive);

spriteBatch.Draw(renderCapture.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.Draw(glowCaptureFin.GetTexture(), Vector2.Zero, Color.White);

spriteBatch.End();

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

GraphicsDevice.BlendState = BlendState.Opaque;

}

}

}

}

Вихідний код модуля Key_Handler.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;

namespace _3D

{

public class Key__Handler : Microsoft.Xna.Framework.GameComponent

{ // переменные для обработки нажатия клавишь клавиатуры

KeyboardState keys;

KeyboardState Oldkeys;

public Key__Handler(Game game)

: base(game)

{

}

public override void Initialize()

{

base.Initialize();

}

public override void Update(GameTime gameTime)

{

keys = Keyboard.GetState();

if (((Main)Game).GameState == "Space")

{

if ((keys.IsKeyDown(Keys.Escape)) && (Oldkeys.IsKeyUp(Keys.Escape)))

{

((Main)Game).GameState = "Test";

((Main)Game).camera.Restart();

}

// условие на включение, выключение каркаса

if ((keys.IsKeyDown(Keys.K)) && (((Main)Game).karkas == false) && (Oldkeys.IsKeyUp(Keys.K)))

{

((Main)Game).karkas = true;

}

else

if ((keys.IsKeyDown(Keys.K)) && (((Main)Game).karkas == true) && (Oldkeys.IsKeyUp(Keys.K)))

{

((Main)Game).karkas = false;

}

if ((keys.IsKeyDown(Keys.PageUp)) && (((Main)Game).CameraSpeed <= 15) && (Oldkeys.IsKeyUp(Keys.PageUp)))

{

((Main)Game).CameraSpeed++;

((Main)Game).camera.speed = ((Main)Game).CameraSpeed;

}

if ((keys.IsKeyDown(Keys.PageDown)) && (((Main)Game).CameraSpeed >= 1) && (Oldkeys.IsKeyUp(Keys.PageDown)))

{

((Main)Game).CameraSpeed--;

((Main)Game).camera.speed = ((Main)Game).CameraSpeed;

}

if ((keys.IsKeyDown(Keys.OemPlus)) && (((Main)Game).SpaceSpeed <= 9) && (Oldkeys.IsKeyUp(Keys.OemPlus)))

{

((Main)Game).SpaceSpeed++;

}

if ((keys.IsKeyDown(Keys.OemMinus)) && (((Main)Game).SpaceSpeed >= 1) && (Oldkeys.IsKeyUp(Keys.OemMinus)))

{

((Main)Game).SpaceSpeed--;

}

Oldkeys = keys;

}

if (((Main)Game).GameState == "Test")

{

if ((keys.IsKeyDown(Keys.Escape)) && (Oldkeys.IsKeyUp(Keys.Escape)))

{

((Main)Game).GameState = "Menu";

((Main)Game).SpaceSpeed = 3;

((Main)Game).camera.Restart();

((Main)Game).ui.Enabled = false;

((Main)Game).ui.Visible = false;

((Main)Game).menu.Enabled = true;

((Main)Game).menu.Visible = true;

((Main)Game).menu.MenuMusik(true);

((Main)Game).IsMouseVisible = true;

}

keys = Keyboard.GetState();

if ((keys.IsKeyDown(Keys.K)) && (((Main)Game).karkas == false) && (Oldkeys.IsKeyUp(Keys.K)))

{

((Main)Game).karkas = true;

}

else

if ((keys.IsKeyDown(Keys.K)) && (((Main)Game).karkas == true) && (Oldkeys.IsKeyUp(Keys.K)))

{

((Main)Game).karkas = false;

}

//скорость камеры

if ((keys.IsKeyDown(Keys.PageUp)) && (((Main)Game).CameraSpeed <= 15) && (Oldkeys.IsKeyUp(Keys.PageUp)))

{

((Main)Game).CameraSpeed++;

((Main)Game).camera.speed = ((Main)Game).CameraSpeed;

}

if ((keys.IsKeyDown(Keys.PageDown)) && (((Main)Game).CameraSpeed >= 1) && (Oldkeys.IsKeyUp(Keys.PageDown)))

{

((Main)Game).CameraSpeed--;

((Main)Game).camera.speed = ((Main)Game).CameraSpeed;}

if ((keys.IsKeyDown(Keys.OemPlus)) && (((Main)Game).SpaceSpeed <= 9) && (Oldkeys.IsKeyUp(Keys.OemPlus)))

{

((Main)Game).SpaceSpeed++;

}

if ((keys.IsKeyDown(Keys.OemMinus)) && (((Main)Game).SpaceSpeed >= 1) && (Oldkeys.IsKeyUp(Keys.OemMinus)))

{

((Main)Game).SpaceSpeed--;

}

Oldkeys = keys;

}

if (((Main)Game).GameState == "Game")

{

if ((keys.IsKeyDown(Keys.Escape)) && (Oldkeys.IsKeyUp(Keys.Escape)))

{

((Main)Game).GameState = "Menu";

((Main)Game).SpaceSpeed = 1;

((Main)Game).camera.Restart();

((Main)Game).camera.cameraDirection = new Vector3(0, 0, 1);

// ((Main)Game).camera.cameraPosition = new Vector3(0, 0, 0);

((Main)Game).ui.Enabled = false;

((Main)Game).ui.Visible = false;

((Main)Game).menu.Enabled = true;

((Main)Game).menu.Visible = true;

((Main)Game).menu.MenuMusik(true);

((Main)Game).IsMouseVisible = true;

}

keys = Keyboard.GetState();

if ((keys.IsKeyDown(Keys.K)) && (((Main)Game).karkas == false) && (Oldkeys.IsKeyUp(Keys.K)))

{

((Main)Game).karkas = true;

}

else

if ((keys.IsKeyDown(Keys.K)) && (((Main)Game).karkas == true) && (Oldkeys.IsKeyUp(Keys.K)))

{

((Main)Game).karkas = false;

}

if ((keys.IsKeyDown(Keys.PageUp)) && (((Main)Game).CameraSpeed <= 15) && (Oldkeys.IsKeyUp(Keys.PageUp)))

{

((Main)Game).CameraSpeed++;

((Main)Game).camera.speed = ((Main)Game).CameraSpeed;

}

if ((keys.IsKeyDown(Keys.PageDown)) && (((Main)Game).CameraSpeed >= 1) && (Oldkeys.IsKeyUp(Keys.PageDown)))

{

((Main)Game).CameraSpeed--;

((Main)Game).camera.speed = ((Main)Game).CameraSpeed;

}

if ((keys.IsKeyDown(Keys.OemPlus)) && (((Main)Game).SpaceSpeed <= 9) && (Oldkeys.IsKeyUp(Keys.OemPlus)))

{

((Main)Game).SpaceSpeed++;

}

if ((keys.IsKeyDown(Keys.OemMinus)) && (((Main)Game).SpaceSpeed >= 1) && (Oldkeys.IsKeyUp(Keys.OemMinus)))

{

((Main)Game).SpaceSpeed--;

}

Oldkeys = keys;

}

if (((Main)Game).GameState == "Menu")

{

if ((keys.IsKeyDown(Keys.Escape)) && (Oldkeys.IsKeyUp(Keys.Escape)))

{

if (((Main)Game).isLoad == true)

{

((Main)Game).GameState = "Game";

// запуск компонентов

((Main)Game).modelManager.Enabled = true;

((Main)Game).modelManager.Visible = true;

((Main)Game).camera.Enabled = true;

((Main)Game).camera.Restart();

((Main)Game).camera.cameraDirection = new Vector3(-1, 0, 0);

((Main)Game).camera.Initialize();

((Main)Game).ui.Enabled = true;

((Main)Game).ui.Visible = true;

// настройка курсора

((Main)Game).IsMouseVisible = false;

((Main)Game).sightPos = new Vector2(((Main)Game).Window.ClientBounds.Width / 2,

((Main)Game).Window.ClientBounds.Height / 2);

((Main)Game).menu.MenuMusik(false);

((Main)Game).menu.Enabled = false;

((Main)Game).menu.Visible = false;

}

}

Oldkeys = keys;

}

base.Update(gameTime);

}

}

}

Вихідний код модуля LogicGameObjects.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 DPSF.ParticleSystems;

namespace _3D

{

public class LogicGameObjects : Microsoft.Xna.Framework.GameComponent

{

// данные

//================================

double seconds = 0;

// методы

//================================

public LogicGameObjects(Game game)

: base(game)

{}

public override void Initialize()

{

base.Initialize();

}

void ClearExplosions(GameTime gameTime)

{

seconds += gameTime.ElapsedGameTime.TotalSeconds;

if (seconds > 2.0)

{

if (((Main)Game).modelManager.Explosions.Count > 0)

{

foreach (ExplosionParticle explosionParticle in ((Main)Game).modelManager.Explosions)

{

explosionParticle.InitialProperties.PositionMin = Vector3.Zero;

explosionParticle.InitialProperties.PositionMax = Vector3.Zero;

explosionParticle.InitialProperties.VelocityMin = Vector3.Zero;

explosionParticle.InitialProperties.VelocityMax = Vector3.Zero;

}

}

}

if (seconds > 4.0)

{

seconds -= 4.0;

if (((Main)Game).modelManager.Explosions.Count > 0)

{

foreach (ExplosionParticle explosionParticle in ((Main)Game).modelManager.Explosions)

{

explosionParticle.Destroy();

}

((Main)Game).modelManager.Explosions.Clear();

}

}

}

public Ray GetPickRay()

{

MouseState mouseState = Mouse.GetState();

int mouseX = mouseState.X+10;

int mouseY = mouseState.Y+10;

Vector3 nearsource = new Vector3((float)mouseX, (float)mouseY, 0.0f);

Vector3 farsource = new Vector3((float)mouseX, (float)mouseY, 1.0f);

Vector3 nearPoint = ((Main)Game).graphics.GraphicsDevice.Viewport.Unproject(nearsource, ((Main)Game).camera.projection, ((Main)Game).camera.view, Matrix.Identity);

Vector3 farPoint = ((Main)Game).graphics.GraphicsDevice.Viewport.Unproject(farsource, ((Main)Game).camera.projection, ((Main)Game).camera.view, Matrix.Identity);

Vector3 direction = farPoint - nearPoint;

direction.Normalize();

Ray pickRay = new Ray(nearPoint, direction);

return pickRay;

}

// метод для проверки столкновения двух сфер

bool Model_Collide(Model M1, Model M2, float Size1, float Size2, Matrix World1, Matrix World2)

{

BoundingSphere boundingSphere1;

BoundingSphere boundingSphere2;

boundingSphere1 = M1.Meshes[0].BoundingSphere.Transform(World1);

boundingSphere1.Radius = boundingSphere1.Radius * Size1;

boundingSphere2 = M2.Meshes[0].BoundingSphere.Transform(World2);

boundingSphere2.Radius = boundingSphere2.Radius * Size2;

if (boundingSphere1.Intersects(boundingSphere2))

{

return true;

}

else

return false;

}

// метод для проверки столкновения с мировой сферой

bool World_Sphere_Collide(Model World_Sphere,Model Object_Sphere, float World_Size, float Object_Size, Matrix World, Matrix Object)

{

BoundingSphere boundingSphere_World;

BoundingSphere boundingSphere_Object;

boundingSphere_World = World_Sphere.Meshes[0].BoundingSphere.Transform(World);

boundingSphere_World.Radius = boundingSphere_World.Radius * World_Size;

boundingSphere_Object = Object_Sphere.Meshes[0].BoundingSphere.Transform(Object);

boundingSphere_Object.Radius = boundingSphere_Object.Radius * Object_Size;

if(Vector3.Distance( boundingSphere_World.Center,boundingSphere_Object.Center ) > boundingSphere_World.Radius - boundingSphere_Object.Radius)

{

return true;

}

return false; }

public override void Update(GameTime gameTime)

{

// космос

if (((Main)Game).GameState == "Space")

{

for (int i = 0; i < ((Main)Game).loader.models.Count; ++i)

{

((Main)Game).loader.models[i].Speed = (((Main)Game).SpaceSpeed);

((Main)Game).loader.models[i].Update(((Main)Game).loader.models[((Main)Game).loader.models[i].Index_Object].world);

}

}

// Меню

if (((Main)Game).GameState == "Menu")

{

for (int i = 0; i < ((Main)Game).loader.Menu_models.Count; ++i)

{

((Main)Game).loader.Menu_models[i].Speed = (((Main)Game).SpaceSpeed); ((Main)Game).loader.Menu_models[i].Update(((Main)Game).loader.Menu_models[((Main)Game).loader.Menu_models[i].Index_Object].world);

}

}

// Тестовая сцена

if (((Main)Game).GameState == "Test")

{

MouseState mouseState = Mouse.GetState();

for (int i = 0; i < ((Main)Game).loader.Test_Scene_models.Count; ++i)

{

((Main)Game).loader.Test_Scene_models[i].Speed = (((Main)Game).SpaceSpeed); ((Main)Game).loader.Test_Scene_models[i].Update(((Main)Game).loader.Test_Scene_models[((Main)Game).loader.Test_Scene_models[i].Index_Object].world);

if(((Main)Game).loader.Test_Scene_models[i].CheckRayIntersection(GetPickRay()) == true)

{

if (mouseState.LeftButton == ButtonState.Pressed)

{

((Main)Game).GameState = "Space";

((Main)Game).loader.models.Clear(); ((Main)Game).loader.models.Add(newSpace_Object(((Main)Game).loader.Test_Scene_models[i].Name + "_SP",

((Main)Game).loader.Test_Scene_models[i].model, new Vector3(0, 0, 200), 1.0f, 0.003f, 0f, 0.0f, 0, 0, 0, 0));

if (i == 3)

((Main)Game).loader.models.Add(new Space_Object("Moon",

Game.Content.Load<Model>(@"Models\Moon"), new Vector3(600, -50, 200), 0.2f, 0f, 0f, 0f, 0, 0.004f, 0.0006f, 0.0f));

((Main)Game).camera.Restart();

}

}

}

}

// игра

if (((Main)Game).GameState == "Game")

{

ClearExplosions(gameTime);

MouseState mouseState = Mouse.GetState();

((Main)Game).loader.player_sphere.Speed_Rotation = (((Main)Game).SpaceSpeed);

if (((Main)Game).loader.player_sphere.Step == false)

{

((Main)Game).loader.player_sphere.Update();

}

((Main)Game).loader.player_sphere.Step = false;

foreach (World_Sphere bm in ((Main)Game).modelManager.Fon_Sphere_Array)

{

bm.Speed_Rotation = (((Main)Game).SpaceSpeed);

bm.Update();

}

foreach (Enemy_Sphere bm in ((Main)Game).modelManager.Enemys_Array)

{

bm.Speed_Rotation = (((Main)Game).SpaceSpeed);

if(bm.Step==false)

{bm.Update();}

bm.Step = false;

}

if (mouseState.LeftButton == ButtonState.Pressed)

{

if(((Main)Game).loader.player_sphere.CheckRayIntersection(GetPickRay()) == true)

{

if (((Main)Game).Power < 100)

{((Main)Game).Power++; }

}

}

if (mouseState.LeftButton == ButtonState.Released)

{

if(((Main)Game).Power != 0)

{if (((Main)Game).loader.player_sphere.CheckRayIntersection(GetPickRay()) == true)

{

((Main)Game).loader.player_sphere.Power = ((Main)Game).Power;

((Main)Game).loader.player_sphere.Mov_Direction = GetPickRay().Direction;

if(((Main)Game).Power>=60) ((Main)Game).loader.player_sphere.Health=(int)((((Main)Game).loader.player_sphere.Health) - (((Main)Game).loader.player_sphere.Health / 100f) * 5f);

else if (((Main)Game).Power >= 30)

((Main)Game).loader.player_sphere.Health = (int)((((Main)Game).loader.player_sphere.Health) - (((Main)Game).loader.player_sphere.Health / 100f) * 3f);

else if (((Main)Game).Power <30)

((Main)Game).loader.player_sphere.Health = (int)((((Main)Game).loader.player_sphere.Health) - (((Main)Game).loader.player_sphere.Health / 100f) * 2f);

}

((Main)Game).Power = 0;

}

}

//проверка на Столкновение мировой сферы с игроком

if (World_Sphere_Collide(((Main)Game).loader.world_sphere.model, ((Main)Game).loader.player_sphere.model,

((Main)Game).loader.world_sphere.Size, ((Main)Game).loader.player_sphere.Size,

((Main)Game).loader.world_sphere.world, ((Main)Game).loader.player_sphere.world) == true)

{

Vector3 NewDirection;

float mvX=((Main)Game).loader.player_sphere.Mov_Direction.X;

float mvY=((Main)Game).loader.player_sphere.Mov_Direction.Y;

float mvZ=((Main)Game).loader.player_sphere.Mov_Direction.Z;

NewDirection.X = mvX;

NewDirection.Y = mvY;

NewDirection.Z = mvZ;

Vector3 Start;

Vector3 PosColl;

Start.X = 0;

Start.Y = 0;

Start.Z = 0;

PosColl.X = ((Main)Game).loader.player_sphere.world.Translation.X;

PosColl.Y = ((Main)Game).loader.player_sphere.world.Translation.Y;

PosColl.Z = ((Main)Game).loader.player_sphere.world.Translation.Z;

Vector3 Normal = PosColl - Start;

Normal.Normalize();

NewDirection = 2 * Vector3.Dot(-(((Main)Game).loader.player_sphere.Mov_Direction), Normal) * Normal + ((Main)Game).loader.player_sphere.Mov_Direction;

((Main)Game).loader.player_sphere.Mov_Direction = NewDirection;

((Main)Game).loader.player_sphere.Prev();

((Main)Game).loader.player_sphere.Update();

((Main)Game).loader.player_sphere.Step = true;

}

//проверка на Столкновение мировой сферы с вражескими сферами

foreach (Enemy_Sphere bm in ((Main)Game).modelManager.Enemys_Array)

{

if (World_Sphere_Collide(((Main)Game).loader.world_sphere.model, bm.model,

((Main)Game).loader.world_sphere.Size, bm.Size,

((Main)Game).loader.world_sphere.world, bm.world) == true)

{

Vector3 NewDirection;

float mvX = bm.Mov_Direction.X;

float mvY = bm.Mov_Direction.Y;

float mvZ = bm.Mov_Direction.Z;

NewDirection.X = mvX;

NewDirection.Y = mvY;

NewDirection.Z = mvZ;

Vector3 Start;

Vector3 PosColl;

Start.X = 0;

Start.Y = 0;

Start.Z = 0;

PosColl.X = bm.world.Translation.X;

PosColl.Y = bm.world.Translation.Y;

PosColl.Z = bm.world.Translation.Z;

Vector3 Normal = PosColl - Start;

Normal.Normalize();

NewDirection = 2 * Vector3.Dot(-(bm.Mov_Direction), Normal) * Normal + bm.Mov_Direction;

bm.Mov_Direction = NewDirection;

bm.Prev();

bm.Update();

bm.Step = true;

}

}

// Cтолкновения игрока с другими сферами

foreach (Enemy_Sphere bm in ((Main)Game).modelManager.Enemys_Array)

{

if (Model_Collide(((Main)Game).loader.player_sphere.model, bm.model, ((Main)Game).loader.player_sphere.Size,

bm.Size, ((Main)Game).loader.player_sphere.world, bm.world) == true)

{

// Игровая логика

if (bm.Power > ((Main)Game).loader.player_sphere.Power)

{

if (bm.Power >= 60)

((Main)Game).loader.player_sphere.Health = (int)(((Main)Game).loader.player_sphere.Health - bm.Health / 3f);

if ((bm.Power >= 30) && (bm.Power < 60))

((Main)Game).loader.player_sphere.Health = (int)(((Main)Game).loader.player_sphere.Health - bm.Health / 6f);

if (bm.Power < 30)

((Main)Game).loader.player_sphere.Health (int)(((Main)Game).loader.player_sphere.Health - bm.Health / 9f);

bm.Health = (int)(bm.Health - ((Main)Game).loader.player_sphere.Health / 9f); }

else

{

if (((Main)Game).loader.player_sphere.Power >= 60)

bm.Health = bm.Health - (int)(((Main)Game).loader.player_sphere.Health / 3f);

if ((((Main)Game).loader.player_sphere.Power >= 30) && (((Main)Game).loader.player_sphere.Power < 60))

bm.Health = bm.Health - (int)(((Main)Game).loader.player_sphere.Health / 6f);

if (((Main)Game).loader.player_sphere.Power < 30)

bm.Health = bm.Health - (int)(((Main)Game).loader.player_sphere.Health / 9f);

((Main)Game).loader.player_sphere.Health = (int)(((Main)Game).loader.player_sphere.Health - bm.Health / 9f)}

if (bm.Health <= 0)

{

seconds = 0;

((Main)Game).modelManager.Explosions.Add(new ExplosionParticle(Game)); ((Main)Game).modelManager.Explosions.Last().AutoInitialize(((Main)Game).modelManager.GraphicsDevice, Game.Content, null); ((Main)Game).modelManager.Explosions.Last().Emitter.PositionData.Position = bm.world.Translation; ((Main)Game).modelManager.Explosions.Last().InitialProperties.PositionMin = new Vector3(bm.Size * 50, bm.Size * 50, bm.Size * 50); ((Main)Game).modelManager.Explosions.Last().InitialProperties.PositionMax = new Vector3(bm.Size * -50, bm.Size * -50, bm.Size * -50); ((Main)Game).modelManager.Explosions.Last().InitialProperties.VelocityMin = new Vector3(bm.Size * 500, bm.Size * 500, bm.Size * 500); ((Main)Game).modelManager.Explosions.Last().InitialProperties.VelocityMax = new Vector3(bm.Size * -500, bm.Size * -500, bm.Size * -500);

}

// логика столкновения

if (((Main)Game).loader.player_sphere.Power >= bm.Power)

{

((Main)Game).loader.player_sphere.Prev();}

else

bm.Prev();

Vector3 pb1, pb2, U1x, U1y, U2x, U2y, V1x,V1y, V2x, V2y;

float a, b;

pb1.X = ((Main)Game).loader.player_sphere.world.Translation.X;

pb1.Y = ((Main)Game).loader.player_sphere.world.Translation.Y;

pb1.Z = ((Main)Game).loader.player_sphere.world.Translation.Z;

pb2.X = bm.world.Translation.X;

pb2.Y = bm.world.Translation.Y;

pb2.Z = bm.world.Translation.Z;

Vector3 xaxis;

xaxis = Vector3.Normalize(pb2 - pb1);

a=Vector3.Dot(xaxis,(((Main)Game).loader.player_sphere.Mov_Direction*(((Main)Game). loader.player_sphere.Power/5)));

U1x = xaxis*a;

a = Vector3.Dot(xaxis, (((Main)Game).loader.player_sphere.Mov_Direction * (((Main)Game).loader.player_sphere.Power / 5)));

U1y = (((Main)Game).loader.player_sphere.Mov_Direction * (((Main)Game).loader.player_sphere.Power / 5)) - U1x;

xaxis = Vector3.Normalize(pb1 - pb2);

b = Vector3.Dot(xaxis, (bm.Mov_Direction * (bm.Power / 5)));

U2x = xaxis * b;

U2y = (bm.Mov_Direction * (bm.Power / 5)) - U2x;

V1x = (U1x + U2x - (U1x - U2x)) * 0.5f;

V2x = (U1x + U2x - (U2x - U1x)) * 0.5f;

V1y = U1y;

V2y = U2y;

((Main)Game).loader.player_sphere.Mov_Direction = Vector3.Normalize(V1x + V1y);

bm.Mov_Direction = Vector3.Normalize(V2x + V2y);

//==========================

Vector3 SF1 = V1x + V1y;

Vector3 SF2 = V2x + V2y; if((Math.Abs(SF1.X)>=Math.Abs(SF1.Y))&&(Math.Abs(SF1.X)>=Math.Abs(SF1.Z)))

{

((Main)Game).loader.player_sphere.Power = Math.Abs(SF1.X) * 5;}

if ((Math.Abs(SF1.Y) >= Math.Abs(SF1.X)) && (Math.Abs(SF1.Y) >= Math.Abs(SF1.Z)))

{

((Main)Game).loader.player_sphere.Power = Math.Abs(SF1.Y)*5;

}

if ((Math.Abs(SF1.Z) >= Math.Abs(SF1.X)) && (Math.Abs(SF1.Z) >= Math.Abs(SF1.Y)))

{

((Main)Game).loader.player_sphere.Power = Math.Abs(SF1.Z)*5;

}

if ((Math.Abs(SF2.X) >= SF2.Y) && (Math.Abs(SF2.X) >= Math.Abs(SF2.Z)))

{

bm.Power = Math.Abs(SF2.X)*5;

}

if ((Math.Abs(SF2.Y) >= Math.Abs(SF2.X)) && (Math.Abs(SF2.Y) >= Math.Abs(SF2.Z)))

{

bm.Power = Math.Abs(SF2.Y)*5;

}

if ((Math.Abs(SF2.Z) >= Math.Abs(SF2.X)) && (Math.Abs(SF2.Z) >= Math.Abs(SF2.Y)))

{

bm.Power = Math.Abs(SF2.Z)*5;

}

//=======================================

if (bm.Power < 10)

{ bm.Power = 10;}

if (((Main)Game).loader.player_sphere.Power < 10)

{ ((Main)Game).loader.player_sphere.Power = 10; }

}

}

foreach (Enemy_Sphere bm1 in ((Main)Game).modelManager.Enemys_Array)

{

foreach (Enemy_Sphere bm2 in ((Main)Game).modelManager.Enemys_Array)

{

if (bm1 != bm2)

{

if (Model_Collide(bm1.model, bm2.model, bm1.Size,

bm2.Size, bm1.world, bm2.world) == true)

{

// игровая логика

if (bm1.Power > bm2.Power)

{if (bm1.Power >= 60)

bm2.Health = (int)(bm2.Health - bm1.Health / 3f);

if ((bm1.Power >= 30) && (bm1.Power < 60))

bm2.Health = (int)(bm2.Health - bm1.Health / 6f);

if (bm1.Power < 30)

bm2.Health = (int)(bm2.Health - bm1.Health / 9f);

bm1.Health = (int)(bm1.Health - bm2.Health / 9f);

}

else

{

if (bm2.Power >= 60)

bm1.Health = (int)(bm1.Health - bm2.Health / 3f);

if ((bm2.Power >= 30) && (bm2.Power < 60))

bm1.Health = (int)(bm1.Health - bm2.Health / 6f);

if (bm2.Power < 30)

bm1.Health =(int)(bm1.Health - bm2.Health / 9f);

bm2.Health = (int)(bm2.Health - bm1.Health / 9f);}

if (bm1.Health <= 0)

{

seconds = 0;

((Main)Game).modelManager.Explosions.Add(new ExplosionParticle(Game)); ((Main)Game).modelManager.Explosions.Last().AutoInitialize(((Main)Game).modelManager.GraphicsDevice, Game.Content, null); ((Main)Game).modelManager.Explosions.Last().Emitter.PositionData.Position = bm1.world.Translation;

((Main)Game).modelManager.Explosions.Last().InitialProperties.PositionMin = new Vector3(bm1.Size * 50, bm1.Size * 50, bm1.Size * 50); ((Main)Game).modelManager.Explosions.Last().InitialProperties.PositionMax = new Vector3(bm1.Size * -50, bm1.Size * -50, bm1.Size * -50); ((Main)Game).modelManager.Explosions.Last().InitialProperties.VelocityMin = new Vector3(bm1.Size * 500, bm1.Size * 500, bm1.Size * 500); ((Main)Game).modelManager.Explosions.Last().InitialProperties.VelocityMax = new Vector3(bm1.Size * -500, bm1.Size * -500, bm1.Size * -500);}

if (bm2.Health <= 0)

{

seconds = 0;

((Main)Game).modelManager.Explosions.Add(new ExplosionParticle(Game));

((Main)Game).modelManager.Explosions.Last().AutoInitialize(((Main)Game).modelManager.GraphicsDevice, Game.Content, null); ((Main)Game).modelManager.Explosions.Last().Emitter.PositionData.Position = bm2.world.Translation; ((Main)Game).modelManager.Explosions.Last().InitialProperties.PositionMin = new Vector3(bm2.Size * 50, bm2.Size * 50, bm2.Size * 50); ((Main)Game).modelManager.Explosions.Last().InitialProperties.PositionMax = new Vector3(bm2.Size * -50, bm2.Size * -50, bm2.Size * -50); ((Main)Game).modelManager.Explosions.Last().InitialProperties.VelocityMin = new Vector3(bm2.Size * 500, bm2.Size * 500, bm2.Size * 500); ((Main)Game).modelManager.Explosions.Last().InitialProperties.VelocityMax = new Vector3(bm2.Size * -500, bm2.Size * -500, bm2.Size * -500);}

// логика столкновения

if (bm1.Power >= bm2.Power)

{

bm1.Prev();

}

else

{

bm2.Prev();

}

Vector3 pb1, pb2, U1x, U1y, U2x, U2y, V1x, V1y, V2x, V2y;

float a, b;

pb1.X = bm1.world.Translation.X;

pb1.Y = bm1.world.Translation.Y;

pb1.Z = bm1.world.Translation.Z;

pb2.X = bm2.world.Translation.X;

pb2.Y = bm2.world.Translation.Y;

pb2.Z = bm2.world.Translation.Z;

Vector3 xaxis;

xaxis = Vector3.Normalize(pb2 - pb1);

a = Vector3.Dot(xaxis, (bm1.Mov_Direction * (bm1.Power / 5)));

U1x = xaxis * a;

a = Vector3.Dot(xaxis, (bm1.Mov_Direction * (bm1.Power / 5)));

U1y = (bm1.Mov_Direction * bm1.Power / 5) - U1x;

xaxis = Vector3.Normalize(pb1 - pb2);

b = Vector3.Dot(xaxis, (bm2.Mov_Direction * (bm2.Power / 5)));

U2x = xaxis * b;

U2y = (bm2.Mov_Direction * (bm2.Power / 5)) - U2x;

V1x = (U1x + U2x - (U1x - U2x)) * 0.5f;

V2x = (U1x + U2x - (U2x - U1x)) * 0.5f;

V1y = U1y;

V2y = U2y;

bm1.Mov_Direction = Vector3.Normalize(V1x + V1y);

bm2.Mov_Direction = Vector3.Normalize(V2x + V2y);

Vector3 SF1 = V1x + V1y;

Vector3 SF2 = V2x + V2y;

if ((Math.Abs(SF1.X) >= Math.Abs(SF1.Y)) && (Math.Abs(SF1.X) >= Math.Abs(SF1.Z)))

{

bm1.Power = Math.Abs(SF1.X) * 5;

}

if ((Math.Abs(SF1.Y) >= Math.Abs(SF1.X)) && (Math.Abs(SF1.Y) >= Math.Abs(SF1.Z)))

{

bm1.Power = Math.Abs(SF1.Y) * 5;

}

if ((Math.Abs(SF1.Z) >= Math.Abs(SF1.X)) && (Math.Abs(SF1.Z) >= Math.Abs(SF1.Y)))

{

bm1.Power = Math.Abs(SF1.Z) * 5;

}

if ((Math.Abs(SF2.X) >= SF2.Y) && (Math.Abs(SF2.X) >= Math.Abs(SF2.Z)))

{

bm2.Power = Math.Abs(SF2.X) * 5;

}

if ((Math.Abs(SF2.Y) >= Math.Abs(SF2.X)) && (Math.Abs(SF2.Y) >= Math.Abs(SF2.Z)))

{

bm2.Power = Math.Abs(SF2.Y) * 5;

}

if ((Math.Abs(SF2.Z) >= Math.Abs(SF2.X)) && (Math.Abs(SF2.Z) >= Math.Abs(SF2.Y)))

{bm2.Power = Math.Abs(SF2.Z) * 5;}

if (bm1.Power < 10)

{

bm1.Power = 10;

}

if (bm2.Power < 10)

{

bm2.Power = 10;

}

}

}

}

}

((Main)Game).loader.world_sphere.Speed_Rotation = (((Main)Game).SpaceSpeed);

((Main)Game).loader.world_sphere.Update();

// логика уничтожения

for(int i=0; i<((Main)Game).modelManager.Enemys_Array.Count;i++)

{

if (((Main)Game).modelManager.Enemys_Array[i].Health <= 0)

{ ((Main)Game).loader.player_sphere.Health = ((Main)Game).loader.player_sphere.Health + ((Main)Game).modelManager.Enemys_Array[i].StartHealth/2; ((Main)Game).modelManager.Enemys_Array.Remove(((Main)Game).modelManager.Enemys_Array[i]);

}

}

if ((((Main)Game).modelManager.Enemys_Array.Count <= 0)&&(((Main)Game).loader.player_sphere.Health>0))

{

((Main)Game).GameState = "ScreenWin";

}

if (((Main)Game).loader.player_sphere.Health <= 0)

{

((Main)Game).GameState = "ScreenLoss";

}

}

// заставка

if ((((Main)Game).GameState == "ScreenWin")||(((Main)Game).GameState == "ScreenLoss"))

{

seconds += gameTime.ElapsedGameTime.TotalSeconds;

if (seconds > 5.0)

{

((Main)Game).isLoad = false;

((Main)Game).GameState = "Menu";

((Main)Game).SpaceSpeed = 1;

((Main)Game).camera.Restart();

((Main)Game).camera.cameraDirection = new Vector3(0, 0, 1);

// ((Main)Game).camera.cameraPosition = new Vector3(0, 0, 0);

((Main)Game).ui.Enabled = false;

((Main)Game).ui.Visible = false;

((Main)Game).menu.Enabled = true;

((Main)Game).menu.Visible = true;

((Main)Game).menu.MenuMusik(true);

((Main)Game).IsMouseVisible = true;

seconds = 0;

}

}

base.Update(gameTime);

}

}

}

Вихідний код модуля UI.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;

namespace _3D

{

public class UI : DrawableGameComponent

{

SpriteBatch spriteBatch;

Texture2D sight;

Texture2D PowerBar;

Texture2D HealthBar;

Texture2D PowerTex;

// информация

SpriteFont Font;

SpriteFont Font2;

string OutStringX;

string OutStringY;

string OutStringZ;

string OutStringCamSpeed;

string OutStringSpaceSpeed;

string OutStringPower;

Vector2 sightPos;

Rectangle PowerRectangle;

Rectangle HealthRectangle;

public UI(Game game)

: base(game)

{ }

public override void Initialize()

{

sightPos = new Vector2(Game.Window.ClientBounds.Width / 2,

Game.Window.ClientBounds.Height / 2);

OutStringX = "X";

OutStringY = "Y";

OutStringZ = "Z";

OutStringCamSpeed = "Швидкість ";

OutStringSpaceSpeed = "Час обертання х5";

OutStringPower = "Потужність 0";

PowerRectangle = new Rectangle(0, Game.Window.ClientBounds.Height - 51, 0, 50);

HealthRectangle = new Rectangle(Game.Window.ClientBounds.Width - 390, Game.Window.ClientBounds.Height - 51, 130, 50);

base.Initialize();

}

protected override void LoadContent()

{

spriteBatch = new SpriteBatch(GraphicsDevice);

PowerTex = Game.Content.Load<Texture2D>(@"Sprites\PowerTex");

PowerBar = Game.Content.Load<Texture2D>(@"Sprites\Bar2");

HealthBar = Game.Content.Load<Texture2D>(@"Sprites\Bar1");

sight = Game.Content.Load<Texture2D>(@"Sprites\sight");

Font = Game.Content.Load<SpriteFont>(@"Fonts\Times New Roman");

Font2 = Game.Content.Load<SpriteFont>(@"Fonts\Times New Roman2");

}

public override void Update(GameTime gameTime)

{

OutStringX = "X " + ((Main)Game).camera.cameraPosition.X.ToString();

OutStringY = "Y " + ((Main)Game).camera.cameraPosition.Y.ToString();

OutStringZ = "Z " + ((Main)Game).camera.cameraPosition.Z.ToString();

OutStringCamSpeed = "Швидкість " + ((Main)Game).camera.speed.ToString();

OutStringSpaceSpeed = "Час обертання х" + ((Main)Game).SpaceSpeed.ToString();

OutStringPower = "Потужність " + ((Main)Game).Power.ToString();

if (((Main)Game).GameState == "Game")

{PowerRectangle.Width = ((Main)Game).Power*4;}

if (((Main)Game).GameState == "Game")

{HealthRectangle.Width = ((Main)Game).loader.player_sphere.Health*4;}

base.Update(gameTime);

}

public override void Draw(GameTime gameTime)

{

// интерфейс

if (((Main)Game).GameState == "Game")

{

// информация

spriteBatch.Begin(SpriteSortMode.FrontToBack, BlendState.AlphaBlend);

spriteBatch.Draw(sight, sightPos, null, Color.White, 0, Vector2.Zero, 0.5f,

SpriteEffects.None, 0);

spriteBatch.DrawString(Font2, "Камера", new Vector2(10, 10), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.DrawString(Font, OutStringX, new Vector2(10, 30), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.DrawString(Font, OutStringY, new Vector2(10, 50), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.DrawString(Font, OutStringZ, new Vector2(10, 70), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.DrawString(Font2, OutStringCamSpeed, new Vector2(10, 90), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.DrawString(Font2, OutStringSpaceSpeed, new Vector2(10, 110), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.DrawString(Font2, OutStringPower, new Vector2(10, 130), Color.Red,

0, Vector2.Zero, 1.0f, SpriteEffects.None, 0.5f);

spriteBatch.Draw(PowerTex, PowerRectangle, Color.White);

spriteBatch.Draw(PowerTex, HealthRectangle, Color.Red);

spriteBatch.Draw(HealthBar, new Vector2(Game.Window.ClientBounds.Width - 420, Game.Window.ClientBounds.Height - 45), null, Color.White, 0, Vector2.Zero, 1.0f,

SpriteEffects.None, 0);

spriteBatch.Draw(HealthBar, new Vector2(Game.Window.ClientBounds.Width - 420, Game.Window.ClientBounds.Height - 45), null, Color.White, 0, Vector2.Zero, 1.0f,

SpriteEffects.None, 0);

spriteBatch.Draw(PowerBar, new Vector2(-30f, Game.Window.ClientBounds.Height - 45), null, Color.White, 0, Vector2.Zero, 1.0f,

SpriteEffects.None, 0);

spriteBatch.End();

}

// обнуление настроек для вывода 3D

GraphicsDevice.BlendState = BlendState.Opaque;

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

base.Draw(gameTime);

}

}

}

Вихідний код модуля MainMenu.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;

namespace _3D

{

public class MainMenu : DrawableGameComponent

{

SpriteBatch spriteBatch;

// Текстуры

Texture2D Start_Active_Tex;

Texture2D Start_Passive_Tex;

Texture2D Exit_Active_Tex;

Texture2D Exit_Passive_Tex;

Texture2D Options_Active_Tex;

Texture2D Options_Passive_Tex;

Texture2D Test_Active_Tex;

Texture2D Test_Passive_Tex;

Texture2D Panel_Active_Tex;

Texture2D Panel_Passive_Tex;

// размер окна

Rectangle WindowRect;

// кнопки

Button ButtonStart;

Button ButtonExit;

Button ButtonOptions;

Button ButtonTest;

Button ButtonPanel;

// музика

Song Menu_Song;

public MainMenu(Game game)

: base(game)

{ }

public override void Initialize()

{

base.Initialize();

MenuMusik(true);

WindowRect.X = 0;

WindowRect.Y = 0;

WindowRect.Width = 1280;

WindowRect.Height = 1024;

ButtonPanel = new Button(new Vector2(((Main)Game).Window.ClientBounds.Width / 2 - 150, ((Main)Game).Window.ClientBounds.Height / 2-150),

300, 300, Panel_Active_Tex, Panel_Passive_Tex, spriteBatch);

ButtonStart = new Button(new Vector2(((Main)Game).Window.ClientBounds.Width / 2 - 150, ((Main)Game).Window.ClientBounds.Height / 2-200),

300, 60, Start_Active_Tex, Start_Passive_Tex, spriteBatch);

ButtonExit = new Button(new Vector2(((Main)Game).Window.ClientBounds.Width / 2 - 150, ((Main)Game).Window.ClientBounds.Height / 2 + 130),

300, 60, Exit_Active_Tex, Exit_Passive_Tex, spriteBatch);

ButtonOptions = new Button(new Vector2(((Main)Game).Window.ClientBounds.Width / 2 - 340, ((Main)Game).Window.ClientBounds.Height / 2 - 30),

300, 60, Options_Active_Tex, Options_Passive_Tex, spriteBatch);

ButtonTest = new Button(new Vector2(((Main)Game).Window.ClientBounds.Width / 2 + 40, ((Main)Game).Window.ClientBounds.Height / 2 - 30),

300, 60, Test_Active_Tex, Test_Passive_Tex, spriteBatch);}

protected override void LoadContent()

{

spriteBatch = new SpriteBatch(GraphicsDevice);

Start_Active_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_A_S_2");

Start_Passive_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_P_S_2");

Exit_Active_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_A_V_2");

Exit_Passive_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_P_V_2");

Options_Active_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_A_O_2");

Options_Passive_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_P_O_2");

Test_Active_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_A_T_2");

Test_Passive_Tex = Game.Content.Load<Texture2D>(@"Sprites\Button_P_T_2");


Подобные документы

  • Розробка програмного додатку - гри "Jump way", яка поєднала в собі сучасні методи побудови 2D ігор. Обґрунтування вибору мови програмування. Проектування UML-діаграм класів. Користувацький інтерфейс. Програмна реалізація гри. Інструкція користувача.

    курсовая работа [1,2 M], добавлен 09.01.2017

  • Концепції об'єктно-орієнтованого програмування. Методи створення класів. Доступ до методів базового класу. Структура даних, функції. Розробка додатку на основі діалогових вікон, програми меню. Засоби розробки програмного забезпечення мовами Java та С++.

    курсовая работа [502,5 K], добавлен 01.04.2016

  • Поняття та сфери використання тривимірної графіки. Описання та характеристика можливостей бібліотеки OpenGL. Загальний опис інтерфейсу мови програмування Borland C++, лістинг програми, що демонструє її можливості. Розрахунок витрат на виконання проекту.

    дипломная работа [1,6 M], добавлен 24.06.2015

  • Особливості Unity у створенні віртуального робочого середовища. Моделювання у віртуальному середовищі навчальних проектів у вигляді лабораторних робіт з фізики, які спрямовані на покращення і спрощення навчального та практичного процесу навчання.

    курсовая работа [74,0 K], добавлен 30.08.2014

  • Загальні відомості по графічним графікам та функціям. Аналіз функцій графічної підсистеми, яка входить до складу системи MATLAB та підтримує як засоби візуалізації двовимірної і тривимірної графіки на екран терміналу, так і засоби презентаційної графіки.

    реферат [255,2 K], добавлен 30.04.2013

  • Практична реалізація гри в "хрестики-нулики" в середовищі програмування Turbo C++ версії 3.0. Моделювання ігрового поля квадратною матрицею третього порядку. Процедури програми гри. Створення програми Tic_Tac, що дозволяє людині грати у гру з комп’ютером.

    курсовая работа [145,8 K], добавлен 23.04.2010

  • Розробка ігрового додатку за технологією IDE Visual Studio та WPF. Опис вхідної та вихідної інформації. Назва та призначення модулів програми. Основні поля класу, необхідні для ігрової логіки. Блок-схема алгоритму гри. Інструкція з експлуатації системи.

    курсовая работа [1,3 M], добавлен 02.06.2015

  • Дослідження інструментальних засобів для створення систем спільного навчання. Створення Windows-додатків на основі Visual C#. Функціональні можливості та програмна реалізація системи інтерактивної взаємодії. Програмна реалізація модулю прийому зображення.

    дипломная работа [4,5 M], добавлен 22.10.2012

  • Історія виникнення та сфери використання тримірної графіки. Дослідження процесу візуалізації тримірного зображення. Створення програмного забезпечення, здатного перетворювати стандартні графічні зображення до графічних зображень внутрішніх форматів Мауа.

    дипломная работа [3,6 M], добавлен 23.09.2013

  • Принципи організації баз даних (БД) при проектуванні клієнт-серверних додатків. Інструментальні засоби створення системи. Різновиди архітектур БД. Функції та програмна реалізація. Економічне обґрунтування доцільності розробки програмного продукту.

    дипломная работа [2,1 M], добавлен 22.10.2012

Работы в архивах красиво оформлены согласно требованиям ВУЗов и содержат рисунки, диаграммы, формулы и т.д.
PPT, PPTX и PDF-файлы представлены только в архивах.
Рекомендуем скачать работу.