Застрял в 3D-моноигре с программой C# LOGIC ERRORC#

Место общения программистов C#
Ответить
Anonymous
 Застрял в 3D-моноигре с программой C# LOGIC ERROR

Сообщение Anonymous »

Я уже давно застрял в этой проблеме, это просто использование GameTime вместо целого числа милисов или что?? это единственное, о чем я могу думать, но пока не могу это изменить. Если проблема в чем-то другом, дайте мне знать. спасибо.

Код: Выделить всё

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;

namespace CoffinRaiders
{
internal class GraphicsNow: IGraphicsDeviceService
{

public GraphicsDevice GraphicsDevice { get; private set; }

// Not used:
public event EventHandler DeviceCreated;
public event EventHandler DeviceDisposing;
public event EventHandler DeviceReset;
public event EventHandler DeviceResetting;

public GraphicsNow(GraphicsDevice graphics)
{
this.GraphicsDevice = graphics;
}
}
public class Window : GameWindow
{
public int width;
public int height;
String title;
public override bool AllowUserResizing { get; set; }

public override Rectangle ClientBounds { get;}

public override Point Position { get; set; }

public override DisplayOrientation CurrentOrientation{ get;}

public override IntPtr Handle { get; }

public override string ScreenDeviceName{ get;}

public Window(int width, int height)
{//bool allowUserResizing, Rectangle clientBounds, Point position, DisplayOrientation orientation, IntPtr handle, string screenDeviceName
/*
AllowUserResizing.set(allowUserResizing);
bounds = clientBounds;
currentOrientation = orientation;
Position = position;
deviceName = screenDeviceName;
handle1 = handle;
*/
// this.SetSupportedOrientations(currentOrientation);
this.width = width;
this.height = height;

title = ("CoffinRaiders");

}
public override void BeginScreenDeviceChange(bool willBeFullScreen)
{
throw new NotImplementedException();
}

public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
{
throw new NotImplementedException();
}

protected override void SetSupportedOrientations(DisplayOrientation orientations)
{
throw new NotImplementedException();
}

protected override void SetTitle(string title)
{
this.title = title;
}
}
public class Game1 : Game, IDisposable
{
Texture2D player;
float playerSpeed;
Vector3 playerPosition;
private Window window;
private bool running;

private GameTime time;

private TimeSpan totalTime;
private TimeSpan timeSince;

private GraphicsDeviceManager graphics;

//private SpriteBatch spriteBatch;

private Vector3 cameraTarget;
private Vector3 cameraPosition;

private BasicEffect basicEffect;

private Matrix world;
private Matrix view;
private Matrix projection;

private VertexPositionColor[] triangleVerts;
VertexBuffer vertexBuffer;
public Game1()
{
}
protected override void Initialize()
{
// TODO: Add your initialization logic here

GraphicsDeviceManager graphics = new GraphicsDeviceManager(this);
window = new Window(1920, 1080);
// this.window.AllowUserResizing.set(true);

GraphicsNow graphics1 = new GraphicsNow(graphics.GraphicsDevice);
graphics.PreferredBackBufferWidth = graphics.GraphicsDevice.DisplayMode.Width;
graphics.PreferredBackBufferHeight = graphics.GraphicsDevice.DisplayMode.Height;
graphics.IsFullScreen = true;
graphics.ApplyChanges();

playerPosition = new Vector3(graphics.PreferredBackBufferWidth / 2,
graphics.PreferredBackBufferHeight / 2, 0);
playerSpeed = 100f;

window.Title = "Coffin Raiders";

Content.RootDirectory = "Content";

IsMouseVisible = true;

cameraPosition = new Vector3(window.width / 2, window.height / 2, 0.0f);
cameraTarget = new Vector3(0.0f, 500.0f, 0.0f);  // Look back at the origin

float fovAngle = MathHelper.ToRadians(45);  // convert 45 degrees to radians

float near = 1.0f; // the near clipping plane distance
float far = 1000f; // the far clipping plane distance
//10, 0 , 10 before
world = Matrix.CreateWorld(cameraTarget, Vector3.Forward, Vector3.Up);
view = Matrix.CreateLookAt(cameraPosition, cameraTarget, Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(fovAngle, GraphicsDevice.DisplayMode.AspectRatio, near, far);

IsFixedTimeStep = true;

basicEffect = new BasicEffect(GraphicsDevice);
basicEffect.Alpha = 1.0f;
basicEffect.VertexColorEnabled = true;
basicEffect.LightingEnabled = false;

vertexBuffer = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 3, BufferUsage.WriteOnly);
vertexBuffer.SetData(triangleVerts);
time = new GameTime();

//LoadContent();
//running = true;
while (running)
{
time = new GameTime(totalTime, timeSince);
Update(time);
Draw(time);

MaxElapsedTime = totalTime - timeSince;
Console.WriteLine("Elapsed Time {0}", MaxElapsedTime.TotalMilliseconds);
//  base.Initialize();
}

}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
{
running = false;
Exit();
}

// TODO: Add your update logic here
var kstate = Keyboard.GetState();

if (kstate.IsKeyDown(Keys.Up) || kstate.IsKeyDown(Keys.W))
{
playerPosition.Y -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}

if (kstate.IsKeyDown(Keys.Down) || kstate.IsKeyDown(Keys.S))
{
playerPosition.Y += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}

if (kstate.IsKeyDown(Keys.Left) || kstate.IsKeyDown(Keys.A))
{
playerPosition.X -= playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}

if (kstate.IsKeyDown(Keys.Right) || kstate.IsKeyDown(Keys.D))
{
playerPosition.X += playerSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
}
base.Draw(gameTime);
}
protected override void LoadContent()
{
player = Content.Load("player");
Model modelShip = Content.Load("Ship");

// TODO: use this.Content to load your game content here
}

protected override void Draw(GameTime gameTime)
{
String x = "ship";
Model model = Content.Load(x);  ;

graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.SetVertexBuffer(vertexBuffer);

RasterizerState rasterizerState = new RasterizerState();
rasterizerState.CullMode = CullMode.None;
GraphicsDevice.RasterizerState = rasterizerState;

foreach(ModelMesh mesh in model.Meshes)
{
foreach(BasicEffect effect in mesh.Effects)
{

effect.Projection = projection;
effect.View = view;
effect.World = world;

mesh.Draw();

}
}

base.Draw(gameTime);
}
/*
private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
{
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = world;
effect.View = view;
effect.Projection = projection;

mesh.Draw();
}
}
}*/
}
/*
*
*  using var game = new CoffinRaiders.Game1();
*  game.Run();
*
*
*
*/
class Program
{
static void Main(string[] args)
{
// Window window = new Window(true, new Rectangle(0, 0, 1920, 1080), new Point(0, 0), DisplayOrientation.Default, new IntPtr(0), "ASUS");
Game1 game = new Game1();

//game.Initialize();

}
}
}

Я пытался изменить ряд вещей, но безрезультатно... мне не удалось отобразить экран. А также я не уверен, когда вызываются функции обновления и инициализации... они автоматически вызываются программой??? или мне нужно указать. Серьезно, я нигде не могу найти никакой информации об этом.

Подробнее здесь: https://stackoverflow.com/questions/786 ... ogic-error
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»