internal void InitializeBeforeRun() { try { using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize)) { // Make sure that the device is already created graphicsDeviceManager.CreateDevice(); // Gets the graphics device service graphicsDeviceService = Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; if (graphicsDeviceService == null) { throw new InvalidOperationException("No GraphicsDeviceService found"); } // Checks the graphics device if (graphicsDeviceService.GraphicsDevice == null) { throw new InvalidOperationException("No GraphicsDevice found"); } // Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc BeginDraw(); // Initialize this instance and all game systems Initialize(); LoadContentInternal(); IsRunning = true; BeginRun(); timer.Reset(); updateTime.Reset(totalUpdateTime); // Run the first time an update updateTimer.Reset(); using (Profiler.Begin(GameProfilingKeys.GameUpdate)) { Update(updateTime); } updateTimer.Tick(); singleFrameUpdateTime += updateTimer.ElapsedTime; // Reset PlayTime playTimer.Reset(); // Unbind Graphics Context without presenting EndDraw(false); } } catch (Exception ex) { Log.Error("Unexpected exception", ex); throw; } }
public override void Update() { base.Update(); if (IsActive() && !hit) { base.Update(); if (!Main.instance.gameOver) { if (type == UFOType.Large) { if (largeUFOSoundInstance.PlayState != PlayState.Playing) { largeUFOSoundInstance.Play(); } } else { if (smallUFOSoundInstance.PlayState != PlayState.Playing) { smallUFOSoundInstance.Play(); } } } CheckForCollusion(); if (position.X > edge.X || position.X < -edge.X) { Disable(); } CheckForEdge(); vectorTimer.Tick(); fireTimer.Tick(); if (vectorTimer.TotalTime.Seconds > vectorAmount) { vectorTimer.Reset(); ChangeVector(); } if (fireTimer.TotalTime.Seconds > fireAmount) { fireTimer.Reset(); Fire(); } } }
public DrawingSurfaceSIS(IRenderer renderer1, IRenderer renderer2) { gameTime = new GameTime(); totalGameTime = new TimeSpan(); timer = new TimerTick(); IsFixedTimeStep = true; maximumElapsedTime = TimeSpan.FromMilliseconds(500.0); TargetElapsedTime = TimeSpan.FromTicks(10000000 / 60); // target elapsed time is by default 60Hz lastUpdateCount = new int[4]; nextLastUpdateCountIndex = 0; // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 ) // Example for a moving average of 4: // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates) var maxLastCount = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length); updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length; timer.Reset(); gameTime.Update(totalGameTime, TimeSpan.Zero, false); //gameTime.FrameCount = 0; Init(renderer1, renderer2); }
public void ResetTimer() { spawnTimer.Reset(); float adj = Main.instance.Wave * 0.1f; spawnAdj = Main.instance.RandomMinMax(-adj, adj * 0.5f); }
private void InitializeBeforeRun() { try { using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize)) { // Initialize this instance and all game systems before trying to create the device. Initialize(); _gameEngine.LoadContent(); IsRunning = true; BeginRun(); _autoTickTimer.Reset(); _updateTime.Reset(_updateTime.Total); // Run the first time an update using (Profiler.Begin(GameProfilingKeys.GameUpdate)) { _gameEngine.InitialUpdate(); } } } catch (Exception ex) { _logger.Error("Unexpected exception.", ex); throw; } }
internal void InitializeBeforeRun() { // Make sure that the device is already created deviceManager.CreateDevice(); // Gets the graphics device service deviceService = Services.GetService(typeof(IDirectXDeviceService)) as IDirectXDeviceService; if (deviceService == null) { throw new InvalidOperationException("No deviceService found"); } // Checks the graphics device if (deviceService.DirectXDevice == null) { throw new InvalidOperationException("No device found"); } // Initialize this instance and all game systems Initialize(); IsRunning = true; //BeginRun(); timer.Reset(); appTime.Update(totalTime, TimeSpan.Zero, false); appTime.FrameCount = 0; // Run an update for the first time updateCallback.Update(appTime); isFirstUpdateDone = true; }
private void InitializeBeforeRun() { if (graphicsDeviceManager == null) { graphicsDeviceManager = new GraphicsDeviceManager(this); } // Make sure that the device is already created graphicsDeviceManager.CreateDevice(); // Checks the graphics device if (graphicsDeviceManager.GraphicsDevice == null) { throw new InvalidOperationException("No GraphicsDevice found"); } // Initialize this instance and all game systems //LoadContent is called in base.Initialize Initialize(); IsRunning = true; BeginRun(); timer.Reset(); gameTime.Update(totalGameTime, TimeSpan.Zero, false); gameTime.FrameCount = 0; // Run the first time an update Update(gameTime); isFirstUpdateDone = true; }
public void Spawn(Vector3 position, float timer, float speed) { m_Position = position; m_Timer.Reset(); m_TimerAmount = timer; m_DotMesh.Enabled = true; SetVelocity(speed); UpdatePR(); }
public void Spawn(Vector3 position, Vector3 velocity, float timer) { m_Position = position; m_Velocity = velocity; m_Timer.Reset(); m_TimerAmount = timer; m_ShotMesh.Enabled = true; UpdatePR(); }
internal void InitializeBeforeRun() { try { using (var profile = Profiler.Begin(GameProfilingKeys.GameInitialize)) { // Initialize this instance and all game systems before trying to create the device. Initialize(); // Make sure that the device is already created graphicsDeviceManager.CreateDevice(); // Gets the graphics device service graphicsDeviceService = Services.GetService <IGraphicsDeviceService>(); if (graphicsDeviceService == null) { throw new InvalidOperationException("No GraphicsDeviceService found"); } // Checks the graphics device if (graphicsDeviceService.GraphicsDevice == null) { throw new InvalidOperationException("No GraphicsDevice found"); } // Setup the graphics device if it was not already setup. SetupGraphicsDeviceEvents(); // Bind Graphics Context enabling initialize to use GL API eg. SetData to texture ...etc BeginDraw(); LoadContentInternal(); IsRunning = true; BeginRun(); autoTickTimer.Reset(); UpdateTime.Reset(UpdateTime.Total); // Run the first time an update using (Profiler.Begin(GameProfilingKeys.GameUpdate)) { Update(UpdateTime); } // Unbind Graphics Context without presenting EndDraw(false); } } catch (Exception ex) { Log.Error("Unexpected exception", ex); throw; } }
public void Spawn(Vector3 position) { this.position = position; lifeTimer.Reset(); lineMesh.Enabled = true; rotation = Main.instance.RandomRadian(); rotationVelocity = Main.instance.RandomMinMax(-1.5f, 1.5f); timerAmount = Main.instance.RandomMinMax(0.5f, 6.75f); SetVelocity(Main.instance.RandomMinMax(1.5f, 3.5f)); UpdatePR(); }
public void Spawn(Vector3 position, float rotation, float timer, float speed, float rotationSpeed) { m_Position = position; m_Rotation = rotation; m_RotationVelocity = rotationSpeed; m_Timer.Reset(); m_TimerAmount = timer; m_LineMesh.Enabled = true; SetVelocity(speed); UpdatePR(); }
public void Spawn(Vector3 position) { base.position = position; float timer = Main.instance.RandomMinMax(0.1f, 1.25f); float speed = Main.instance.RandomMinMax(0.001f, 0.125f); aliveTimer.Reset(); timerAmount = timer; dotMesh.Enabled = true; velocity = SetVelocity(speed); UpdatePR(); }
//public DrawingSurfaceSIS(IRenderer renderer, DeviceManager deviceManager) public DrawingSurfaceSIS(Action <GameTime> updateRendererAction, Action <TargetBase> renderRendererAction, Action <DeviceManager> initializeRendererAction, Action <Windows.UI.Xaml.UIElement, Windows.UI.Xaml.UIElement> initializeUIRendererAction, Action <string> loadAssetUriRendererAction, Action unloadRendererAction, DeviceManager deviceManager) { _deviceManager = deviceManager; _updateRendererAction = updateRendererAction; _renderRendererAction = renderRendererAction; _initializeRendererAction = initializeRendererAction; _initializeUIRendererAction = initializeUIRendererAction; _loadAssetUriRendererAction = loadAssetUriRendererAction; _unloadRendererAction = unloadRendererAction; gameTime = new GameTime(); totalGameTime = new TimeSpan(); timer = new TimerTick(); IsFixedTimeStep = true; maximumElapsedTime = TimeSpan.FromMilliseconds(500.0); TargetElapsedTime = TimeSpan.FromTicks(10000000 / 60); // target elapsed time is by default 60Hz lastUpdateCount = new int[4]; nextLastUpdateCountIndex = 0; // Calculate the updateCountAverageSlowLimit (assuming moving average is >=3 ) // Example for a moving average of 4: // updateCountAverageSlowLimit = (2 * 2 + (4 - 2)) / 4 = 1.5f const int BadUpdateCountTime = 2; // number of bad frame (a bad frame is a frame that has at least 2 updates) var maxLastCount = 2 * Math.Min(BadUpdateCountTime, lastUpdateCount.Length); updateCountAverageSlowLimit = (float)(maxLastCount + (lastUpdateCount.Length - maxLastCount)) / lastUpdateCount.Length; timer.Reset(); //gameTime.Update(totalGameTime, TimeSpan.Zero, false); //gameTime.FrameCount = 0; //this.FrameCountPerRender = 1; //by default every frame results in a dxsurface render this.InitializeComponent(); //_effectRenderer = renderer; _hasEffectRenderer = true; }
internal void InitializeBeforeRun() { try { // Initialize this instance and all game systems before trying to create the device. Initialize(); IsRunning = true; IsActive = true; autoTickTimer.Reset(); UpdateTime.Reset(UpdateTime.Total); // Run the first time an update Update(UpdateTime); } catch (Exception ex) { Log.Error("Unexpected exception", ex); throw; } }
void Thrust() { if (Input.IsKeyDown(Keys.Up)) { m_ThurstSoundInstance.Play(); float max = 50; float thrustAmount = 0.4f; float testX; float testY; if (m_Velocity.Y < 0) { testY = -m_Velocity.Y; } else { testY = m_Velocity.Y; } if (m_Velocity.X < 0) { testX = -m_Velocity.X; } else { testX = m_Velocity.X; } if (testX + testY < max) { m_Acceleration = new Vector3((float)Math.Cos(m_Rotation) * thrustAmount, (float)Math.Sin(m_Rotation) * thrustAmount, 0); if (m_FlameTimer.TotalTime.Milliseconds > 18) { m_FlameTimer.Reset(); if (m_FlameMesh.Enabled) { m_FlameMesh.Enabled = false; } else { m_FlameMesh.Enabled = true; } } } else { m_Acceleration.X = -m_Velocity.X * 0.001f; m_Acceleration.Y = -m_Velocity.Y * 0.001f; } } else { m_FlameMesh.Enabled = false; m_Acceleration = Vector3.Zero; if (m_Velocity.X > 0 || m_Velocity.X < 0) { m_Acceleration.X = -m_Velocity.X * 0.001f; } if (m_Velocity.Y > 0 || m_Velocity.Y < 0) { m_Acceleration.Y = -m_Velocity.Y * 0.001f; } } }
public override void Update() { m_NumberOfRocksLastFrame = m_NumberOfRocksThisFrame; int rockCount = 0; int smrockCount = 0; int mdrockCount = 0; int lgrockCount = 0; bool playerClear = true; foreach (Rock rock in m_LargeRocks) { if (rock.m_Hit) { rock.Destroy(); SpawnMedRocks(rock.m_Position); } if (rock.Active()) { rockCount++; lgrockCount++; } } foreach (Rock rock in m_MedRocks) { if (rock.m_Hit) { rock.Destroy(); SpawnSmallRocks(rock.m_Position); } if (rock.Active()) { rockCount++; mdrockCount++; } } foreach (Rock rock in m_SmallRocks) { if (rock.m_Hit) { rock.Destroy(); } if (rock.Active()) { rockCount++; smrockCount++; } } m_NumberOfRocksThisFrame = rockCount; if (m_NumberOfRocksLastFrame != m_NumberOfRocksThisFrame) //If([size]rockCount < 4) {pitch = 1.2f + (0.05f × ( 4 - mdrockCount))} { float pitch = 1; if (lgrockCount == 0) { if (mdrockCount > 3) { pitch = 1.2f; } else if (mdrockCount == 3) { pitch = 1.25f; } else if (mdrockCount == 2) { pitch = 1.3f; } else if (mdrockCount == 1) { pitch = 1.35f; } if (mdrockCount == 0) { if (smrockCount > 3) { pitch = 1.4f; } else if (smrockCount == 3) { pitch = 1.45f; } else if (smrockCount == 2) { pitch = 1.5f; } else if (smrockCount == 1) { pitch = 1.55f; } } } else if (lgrockCount > 3) { pitch = 1; } else if (lgrockCount == 3) { pitch = 1.05f; } else if (lgrockCount == 2) { pitch = 1.1f; } else if (lgrockCount == 1) { pitch = 1.15f; } m_Background.Pitch = pitch; } if (rockCount == 0) { m_LargeRockCount += 2; SpawnLargeRocks(m_LargeRockCount); } if (m_UFOTimer.TotalTime.TotalSeconds > m_UFOTimerSet && !m_UFO.Active()) { m_UFOTimerSet = (float)m_Random.NextDouble() * m_UFOTimerAmount + ((m_UFOTimerAmount - m_Wave) * 0.5f); m_UFOTimer.Reset(); m_UFO.Spawn(m_UFOCount, m_Wave); m_UFOCount++; } if (m_UFO.m_Done || m_UFO.m_Hit) { m_UFOTimer.Reset(); m_UFO.Destroy(); } if (m_Player.m_Hit) { foreach (Rock rock in m_LargeRocks) { if (rock.Active()) { if (m_Player.m_Hit) { if (!rock.CheckPlayerCLear()) { playerClear = false; break; } } } } foreach (Rock rock in m_MedRocks) { if (rock.Active()) { if (m_Player.m_Hit) { if (!playerClear) { break; } if (!rock.CheckPlayerCLear()) { playerClear = false; break; } } } } foreach (Rock rock in m_SmallRocks) { if (rock.Active()) { if (m_Player.m_Hit) { if (!playerClear) { break; } if (!rock.CheckPlayerCLear()) { playerClear = false; break; } } } } if (playerClear) { m_Player.m_Spawn = true; } if (m_UFO.Active()) { if (!m_UFO.CheckPlayerClear()) { m_Player.m_Spawn = false; } } if (m_UFO.m_Shot.Active()) { if (!m_UFO.m_Shot.CheckPlayerClear()) { m_Player.m_Spawn = false; } } } m_UFOTimer.Tick(); if (m_Player.m_GameOver) { if (!m_Player.m_NewHighScore) { if (Input.IsKeyPressed(Keys.N) || Input.IsKeyPressed(Keys.S) || Input.IsKeyPressed(Keys.Return)) { NewGame(); } } if (!m_UFO.m_GameOver) { m_Background.Stop(); foreach (Rock rock in m_LargeRocks) { rock.m_GameOver = true; } foreach (Rock rock in m_MedRocks) { rock.m_GameOver = true; } foreach (Rock rock in m_SmallRocks) { rock.m_GameOver = true; } m_UFO.m_GameOver = true; } } else { m_UFO.m_GameOver = false; if (m_Player.m_Pause) { if (Input.IsKeyPressed(Keys.P)) { m_Background.Play(); foreach (Rock rock in m_LargeRocks) { rock.Pause(false); } foreach (Rock rock in m_MedRocks) { rock.Pause(false); } foreach (Rock rock in m_SmallRocks) { rock.Pause(false); } m_UFO.Pause(false); m_Player.Pause(false); foreach (Shot shot in m_Player.m_Shots) { shot.Pause(false); } } } else { m_Background.Play(); if (Input.IsKeyPressed(Keys.P)) { m_Background.Stop(); foreach (Rock rock in m_LargeRocks) { rock.Pause(true); } foreach (Rock rock in m_MedRocks) { rock.Pause(true); } foreach (Rock rock in m_SmallRocks) { rock.Pause(true); } m_UFO.Pause(true); m_Player.Pause(true); foreach (Shot shot in m_Player.m_Shots) { shot.Pause(true); } } } } }
public override void Update() { if (!m_Pause) { if (m_Hit = CheckCollisions()) { Explode(); } if (Active() && !m_Hit && !b_Done) { base.Update(); if (!m_GameOver) { if (m_Large) { m_LargeUFOSoundInstance.Play(); } else { m_SmallUFOSoundInstance.Play(); } } if (m_Position.X > m_Edge.X || m_Position.X < -m_Edge.X) { b_Done = true; } else { CheckForEdge(); } if (m_ShotTimer.TotalTime.Seconds > m_ShotTimerAmount) { m_FireSoundInstance.Stop(); if (!m_GameOver) { m_FireSoundInstance.Play(); } m_ShotTimer.Reset(); float speed = 30; float rad = 0; if (m_Large) { rad = RandomRadian(); } else { rad = (float)Math.Atan2(m_Player.m_Position.Y - m_Position.Y, m_Player.m_Position.X - m_Position.X); rad += (float)m_Random.NextDouble() * 0.1f - 0.1f; } Vector3 dir = new Vector3((float)Math.Cos(rad) * speed, (float)Math.Sin(rad) * speed, 0); Vector3 offset = new Vector3((float)Math.Cos(rad) * m_Radius, (float)Math.Sin(rad) * m_Radius, 0); m_Shot.Spawn(m_Position + offset, dir + m_Velocity * 0.25f, 1.05f); } if (m_VectorTimer.TotalTime.Seconds > m_VectorTimerAmount) { m_VectorTimer.Reset(); float vChange = (float)m_Random.NextDouble() * 10; if (vChange < 5) { if ((int)m_Velocity.Y == 0 && vChange < 2.5) { m_Velocity.Y = m_Speed; } else if ((int)m_Velocity.Y == 0) { m_Velocity.Y = -m_Speed; } else { m_Velocity.Y = 0; } } } m_ShotTimer.Tick(); m_VectorTimer.Tick(); } } }