public override bool Update(GameContext context) { // Do our fade effect if needed. if (this.m_ChangingLevel || this.m_FadingIn) { // Check to see what stage of fading we're at. if (this.m_FadingIn && this.m_FadeLevel < 1f) this.m_FadeLevel += 0.05f; else if (!this.m_FadingIn && this.m_FadeLevel > 0f) { this.m_FadeLevel -= 0.05f; return false; } else if (this.m_FadingIn && this.m_FadeLevel >= 1f) { this.LoadLevelImmediate(this.m_LevelChangeTarget); this.m_FadingIn = false; } else if (!this.m_FadingIn && this.m_FadeLevel <= 0f) { this.m_ChangingLevel = false; return false; } } // Get the base class to also update. return true; }
public override void DrawBelow(GameContext context) { // Clear the screen. if ((this.Player as Entities.Player).Health <= 0) context.Graphics.GraphicsDevice.Clear(Color.Black); else { this.BackgroundColor = new Color( (float)( ((1) * 0.05) + ((1) * 0.15) * (this.Heartbeats.Current / 2 + 0.5) ), 0, 0 ); context.Graphics.GraphicsDevice.Clear(this.BackgroundColor); } // Create stars. foreach (var e in this.Entities) if (e is RedMeansGo.Entities.WhiteBloodCell || e is RedMeansGo.Entities.RedBloodCell) { double heartbeat = this.Heartbeats.Current; var s = (int)((heartbeat + 1) / 2 + 1); if (e is RedMeansGo.Entities.WhiteBloodCell) s += 5; context.SpriteBatch.Draw( context.Textures[e is RedMeansGo.Entities.WhiteBloodCell ? "enemy.bigbullet" : "star"], new Rectangle((int)e.X, (int)e.Y, s, s), null, e.Color, (float)e.Rotation, e.Origin, SpriteEffects.None, 1f); } }
protected virtual void DrawTilesAbove(GameContext context) { // Render tiles above. int c = 0; for (int z = Math.Max(context.World.RenderDepthValue - context.World.RenderDepthUpRange, 0); z < context.World.RenderDepthValue; z++) { for (int x = Math.Min(Math.Max(0, context.Camera.X / Tileset.TILESET_CELL_WIDTH), Tileset.TILESET_WIDTH); x <= Math.Min((context.Camera.X + context.Camera.Width) / Tileset.TILESET_CELL_WIDTH, Tileset.TILESET_WIDTH); x += 1) { for (int y = Math.Min(Math.Max(0, context.Camera.Y / Tileset.TILESET_CELL_HEIGHT), Tileset.TILESET_HEIGHT); y <= Math.Min((context.Camera.Y + context.Camera.Height) / Tileset.TILESET_CELL_HEIGHT, Tileset.TILESET_HEIGHT); y += 1) { Tile t = context.World.Tileset[x, y, z]; if (t == null) continue; if (t.Image == null) continue; float f = ((context.World.RenderDepthUpRange - c) / (float)context.World.RenderDepthUpRange); context.SpriteBatch.Draw( context.Textures[t.Image], new Rectangle(x * Tileset.TILESET_CELL_WIDTH, y * Tileset.TILESET_CELL_HEIGHT, t.Width, t.Height), null, new Color(1f, 1f, 1f, f * 0.4f).ToPremultiplied() ); } } c++; } }
public override void DrawAbove(GameContext context) { // Fade the screen. if (!context.Textures.Keys.Contains("black")) throw new ProtogameException("You must load a texture with the name 'black' in order for FadingWorld to fade to black. Check to make sure you are doing this in the LoadContent of your game."); context.SpriteBatch.Draw(context.Textures["black"], new Rectangle(0, 0, Tileset.TILESET_PIXEL_WIDTH, Tileset.TILESET_PIXEL_HEIGHT), new Color(1.0f, 1.0f, 1.0f, this.Fade)); }
public override void DrawAbove(GameContext context) { XnaGraphics xna = new XnaGraphics(context); //this.m_FieldOfViewRenderer.Render(context, xna); //int i = 0; //foreach (IPositionable p in this.m_Uniques) // xna.DrawStringLeft(8, 8 + (i++) * 16, p.ToString()); xna.DrawStringLeft(8, 8, "FPS: " + context.FPS, "Arial"); }
public void Draw(GameContext context) { // Clear the screen. context.SpriteBatch.Begin(); // Draw world below. context.World.DrawBelow(context); // Render all of the tiles. /*for (int z = 0; z < Tileset.TILESET_DEPTH; z += 1) { for (int x = context.Graphics.GraphicsDevice.Viewport.X / Tileset.TILESET_CELL_WIDTH; x < Math.Min(context.Graphics.GraphicsDevice.Viewport.X + context.Graphics.GraphicsDevice.Viewport.Width / Tileset.TILESET_CELL_WIDTH, Tileset.TILESET_WIDTH); x += 1) { for (int y = context.Graphics.GraphicsDevice.Viewport.Y / Tileset.TILESET_CELL_HEIGHT; y < Math.Min(context.Graphics.GraphicsDevice.Viewport.Y + context.Graphics.GraphicsDevice.Viewport.Height / Tileset.TILESET_CELL_HEIGHT, Tileset.TILESET_HEIGHT); y += 1) { Tile t = context.World.Tileset[x, y, z]; if (t == null) continue; if (t.Image == null) continue; context.SpriteBatch.Draw( context.Textures[t.Image], new Rectangle((int)t.X, (int)t.Y, t.Width, t.Height), (t.TX != -1 && t.TY != -1) ? new Rectangle?(new Rectangle(t.TX * t.Width, t.TY * t.Height, t.Width, t.Height)) : null, Color.White ); } } }*/ // Render all of the actors. foreach (IEntity a in context.World.Entities) if ((a is ParticleEntity) && (a as ParticleEntity).Definition.RenderMode == ParticleMode.Background) this.HandleRenderOfEntity(context, a); foreach (IEntity a in context.World.Entities) if (a.Image != null && !(a is ParticleEntity) && (!(a is IDynamicRenderingEntity) || (a as IDynamicRenderingEntity).ShouldRender(context.World))) this.HandleRenderOfEntity(context, a); foreach (IEntity a in context.World.Entities) if ((a is ParticleEntity) && (a as ParticleEntity).Definition.RenderMode == ParticleMode.Foreground) this.HandleRenderOfEntity(context, a); XnaGraphics gr = new XnaGraphics(context); foreach (IEntity a in context.World.Entities) if (!(a is IDynamicRenderingEntity) || (a as IDynamicRenderingEntity).ShouldRender(context.World)) a.Draw(context.World, gr); // Draw world above. context.World.DrawAbove(context); // Finish rendering. context.SpriteBatch.End(); }
public override bool Update(GameContext context) { if (this.m_TargetWorld != null) { (this.Game as RuntimeGame).SwitchWorld(this.m_TargetWorld); return false; } return true; }
protected void DrawDebugPathFindingGrid(GameContext context, XnaGraphics graphics) { for (int x = 0; x < this.m_PathFindingGrid.GetLength(0); x++) for (int y = 0; y < this.m_PathFindingGrid.GetLength(1); y++) if (this.m_PathFindingGrid[x, y] == (byte)PathFinderHelper.BLOCKED_TILE) graphics.DrawRectangle(new Rectangle(x * 16, y * 16, 16, 16), new Color(255, 0, 0, 128)); else if (this.m_PathFindingGrid[x, y] == (byte)PathFinderHelper.EMPTY_TILE) graphics.DrawRectangle(new Rectangle(x * 16, y * 16, 16, 16), new Color(0, 255, 0, 128)); else graphics.DrawRectangle(new Rectangle(x * 16, y * 16, 16, 16), new Color(0, 0, 255, 128)); }
public void Update(GameContext context) { bool handle = context.World.Update(context); if (!handle) return; // Update all of the actors. foreach (IEntity a in context.World.Entities.ToArray()) a.Update(context.World); // Update tick. context.World.Tick += 1; }
public override void DrawAbove(GameContext context) { XnaGraphics xna = new XnaGraphics(context); xna.DrawStringCentered(context.Camera.Width / 2, 50, "τυχαία", "TitleFont"); xna.DrawStringCentered(context.Camera.Width / 2, 200, "(tychaía)", "SubtitleFont"); MouseState state = Mouse.GetState(); foreach (Button b in this.m_Buttons) b.Process(xna, state); xna.DrawStringCentered(context.Camera.Width / 2, 750, "Using static seed: " + m_StaticSeed.ToString(), "Arial"); }
public void Focus(GameContext context, int x, int y) { this.m_CenterX = (context.Camera.Width / Tileset.TILESET_CELL_WIDTH) / 2; this.m_CenterY = (context.Camera.Height / Tileset.TILESET_CELL_HEIGHT) / 2; this.m_TargetX = x * Tileset.TILESET_CELL_WIDTH - (context.Camera.Width / 2);// (2 )); this.m_TargetY = y * Tileset.TILESET_CELL_HEIGHT - (context.Camera.Height / 2);// (2 )); context.Camera.X = this.m_TargetX % 16; context.Camera.Y = this.m_TargetY % 16; (this.Tileset as ChunkTileset).RefreshChunkReference( this.m_TargetX, this.m_TargetY); }
public void Draw(RTSWorld world, GameContext context, XnaGraphics graphics) { this.Update(world, context); graphics.DrawStringLeft(0, 0, world.ActiveLevel.GetType().Name); graphics.DrawStringLeft(0, 32, this.m_Tick.ToString()); if (this.m_LastMousePoint.HasValue && this.m_CurrentMousePoint.HasValue) graphics.DrawRectangle(this.m_LastMousePoint.Value, this.m_CurrentMousePoint.Value, Color.LimeGreen); foreach (Unit u in this.Selected) { Rectangle bb = new Rectangle((int)u.X, (int)u.Y - 1, u.Width + 1, u.Height + 1); if (u.Team != null) graphics.DrawRectangle(bb, u.Team.Color); else graphics.DrawRectangle(bb, Color.LimeGreen); } // Draw chat. int a = 16; for (int i = this.m_ChatMessages.Count - 1; i >= Math.Max(this.m_ChatMessages.Count - 11, 0); i--) { if (i < this.m_ChatMessages.Count) graphics.DrawStringLeft(0, context.Graphics.GraphicsDevice.Viewport.Height - a, this.m_ChatMessages[i]); a += 16; } // Draw graph. if (this.m_GraphFrames.Count > 1) { for (int i = 1; i < this.m_GraphFrames.Count; i++) graphics.DrawLine(i - 1, (float)this.m_GraphFrames[i - 1], i, (float)this.m_GraphFrames[i], 1, Color.Lime); } // Add frame information. if (this.m_GraphFrames.Count > 200) this.m_GraphFrames.RemoveAt(0); this.m_GraphFrames.Add(context.GameTime.ElapsedGameTime.TotalMilliseconds); this.m_Tick++; }
public void Draw(GameContext context) { // Clear the screen. context.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, context.Camera.GetTransformationMatrix()); // Draw world below. context.World.DrawBelow(context); // Render tiles below. if (context.World.Tileset != null) this.DrawTilesBelow(context); // Render all of the actors. foreach (IEntity a in context.World.Entities) if ((a is ParticleEntity) && (a as ParticleEntity).Definition.RenderMode == ParticleMode.Background) this.HandleRenderOfEntity(context, a); foreach (IEntity a in context.World.Entities) if (a.Image != null && !(a is ParticleEntity) && (!(a is IDynamicRenderingEntity) || (a as IDynamicRenderingEntity).ShouldRender(context.World))) this.HandleRenderOfEntity(context, a); foreach (IEntity a in context.World.Entities) if ((a is ParticleEntity) && (a as ParticleEntity).Definition.RenderMode == ParticleMode.Foreground) this.HandleRenderOfEntity(context, a); XnaGraphics gr = new XnaGraphics(context); foreach (IEntity a in context.World.Entities) if (!(a is IDynamicRenderingEntity) || (a as IDynamicRenderingEntity).ShouldRender(context.World)) a.Draw(context.World, gr); // Render tiles above. if (context.World.Tileset != null) this.DrawTilesAbove(context); // Draw world above. context.World.DrawAbove(context); // Finish rendering. context.SpriteBatch.End(); }
public void Render(GameContext context, XnaGraphics xna) { Point center = this.m_FieldOfView.World.GetCenter(); for (int x = 0; x < this.m_FieldOfView.BroadphaseGrid.GetLength(0); x++) for (int y = 0; y < this.m_FieldOfView.BroadphaseGrid.GetLength(1); y++) { if (!this.m_FieldOfView.BroadphaseGrid[x, y]) xna.FillRectangle(new Rectangle(x * Seperation, y * Seperation, Seperation, Seperation), new Color(0f, 0f, 0f, 0.4f).ToPremultiplied()); if (x == center.X && y == center.Y) xna.FillRectangle(new Rectangle(x * Seperation, y * Seperation, Seperation, Seperation), new Color(1f, 0f, 0f, 1).ToPremultiplied()); //xna.DrawStringLeft(x * Seperation, y * Seperation, this.m_FieldOfView.m_BroadphaseHeightGrid[x, y].ToString()); int deg = (int)MathHelper.ToDegrees(this.m_FieldOfView.m_BroadphaseAngleGrid[x, y]); xna.DrawStringLeft(x * Seperation, y * Seperation, deg.ToString(), "SmallArial"); /*if (deg < -100) xna.DrawStringLeft(x * Seperation, y * Seperation, Math.Abs(deg + 100).ToString()); else if (deg < 0) xna.DrawStringLeft(x * Seperation, y * Seperation, Math.Abs(deg).ToString()); else if (deg < 100) xna.DrawStringLeft(x * Seperation, y * Seperation, (deg).ToString()); else if (deg < 200) xna.DrawStringLeft(x * Seperation, y * Seperation, (deg - 100).ToString());*/ } }
/// <summary> /// Performs any custom drawing events for this world, after everything else has been drawn. /// </summary> /// <param name="context">The game context.</param> public abstract void DrawAbove(GameContext context);
/// <summary> /// Performs any custom drawing events for this world, prior to everything else being drawn. /// </summary> /// <param name="context">The game context.</param> public abstract void DrawBelow(GameContext context);
private void Update(RTSWorld world, GameContext context) { MouseState mouse = Mouse.GetState(); // Left mouse action. if (mouse.LeftButton == ButtonState.Pressed) { if (!this.m_LastMousePoint.HasValue) this.m_LastMousePoint = new Vector2(mouse.X, mouse.Y); else { this.m_CurrentMousePoint = new Vector2(mouse.X, mouse.Y); // Determine selected objects. Rectangle coverage = new Rectangle( (int)this.m_LastMousePoint.Value.X, (int)this.m_LastMousePoint.Value.Y, (int)this.m_CurrentMousePoint.Value.X - (int)this.m_LastMousePoint.Value.X, (int)this.m_CurrentMousePoint.Value.Y - (int)this.m_LastMousePoint.Value.Y ).Normalize(); this.Selected.Clear(); foreach (IMultiLevelEntity e in world.ActiveLevel.Entities) if (e is Unit) { Unit u = e as Unit; Rectangle bb = new Rectangle((int)u.X, (int)u.Y, u.Width, u.Height); if (coverage.Intersects(bb)) this.Selected.Add(u); } } } else { if (this.m_LastMousePoint != null && this.m_CurrentMousePoint != null) { if (this.m_LastMousePoint.Value == this.m_CurrentMousePoint.Value) { // Left mouse action. foreach (Unit u in this.Selected) { if (u.LocallyOwned) u.LeftAction(world); } } } this.m_LastMousePoint = null; this.m_CurrentMousePoint = null; } // Right mouse action. if (mouse.RightButton == ButtonState.Pressed) { this.m_JustRightClicked = true; } else if (mouse.RightButton == ButtonState.Released && this.m_JustRightClicked) { this.Log("right action triggered on " + this.Selected.Count + " selected units."); foreach (Unit u in this.Selected) { if (u.LocallyOwned) u.RightAction(world); } this.m_JustRightClicked = false; } }
/// <summary> /// Updates the game world each tick. Returns whether processing should continue in this tick or /// whether entity processing should be skipped. /// </summary> /// <param name="context">The current context of the game.</param> /// <returns>Whether processing should continue in this tick.</returns> public abstract bool Update(GameContext context);
private void HandleRenderOfEntity(GameContext context, IEntity a) { this.DrawSpriteAt(context, (float)a.X, (float)a.Y, a.Width, a.Height, a.Image, a.Color, a.ImageFlipX); // Check to see if this entity is residing on an edge of the screen. /*if (a.X >= Tileset.TILESET_PIXEL_WIDTH) a.X -= Tileset.TILESET_PIXEL_WIDTH; if (a.X < 0) a.X += Tileset.TILESET_PIXEL_WIDTH; if (a.X > Tileset.TILESET_PIXEL_WIDTH - a.Width) { // Draw a mirror image on the left side of the screen. this.DrawSpriteAt(context, (float)a.X - Tileset.TILESET_PIXEL_WIDTH, (float)a.Y, a.Width, a.Height, a.Image, a.Color, a.ImageFlipX); }*/ }
public abstract void Update(GameContext context);
protected virtual void DrawTilesBelow(GameContext context) { // Render tiles. int c = 0; for (int z = Math.Max((byte)0, context.World.RenderDepthValue); z < Math.Min(context.World.RenderDepthValue + context.World.RenderDepthDownRange, 63); z++) { for (int x = Math.Min(Math.Max(0, context.Camera.X / Tileset.TILESET_CELL_WIDTH), Tileset.TILESET_WIDTH); x <= Math.Min((context.Camera.X + context.Camera.Width) / Tileset.TILESET_CELL_WIDTH, Tileset.TILESET_WIDTH); x += 1) { for (int y = Math.Min(Math.Max(0, context.Camera.Y / Tileset.TILESET_CELL_HEIGHT), Tileset.TILESET_HEIGHT); y <= Math.Min((context.Camera.Y + context.Camera.Height) / Tileset.TILESET_CELL_HEIGHT, Tileset.TILESET_HEIGHT); y += 1) { Tile p = context.World.Tileset[x, y, z - 1]; if (z != context.World.RenderDepthValue && p != null && !(p is TransparentTile)) continue; Tile t = context.World.Tileset[x, y, z]; if (t == null) continue; if (t.Image == null) continue; float f = ((context.World.RenderDepthDownRange - c) / (float)context.World.RenderDepthDownRange); context.SpriteBatch.Draw( context.Textures[t.Image], new Rectangle(x * Tileset.TILESET_CELL_WIDTH, y * Tileset.TILESET_CELL_HEIGHT, t.Width, t.Height), null, new Color(1f, 1f, 1f, f).ToPremultiplied() ); } } c++; } }
public override void DrawBelow(GameContext context) { context.Graphics.GraphicsDevice.Clear(Color.Black); }
public override void DrawBelow(GameContext context) { // Are we waiting for players? #if MULTIPLAYER if (this.m_GlobalSession.Waiting || (this.m_GlobalSession.LoadingInitialData && !LocalNode.Singleton.IsServer)) #else if (this.m_GlobalSession.Waiting) #endif return; // Handle game normally. if (this.m_ActiveLevel != null) this.m_ActiveLevel.DrawBelow(context); else { context.Graphics.GraphicsDevice.Clear(Color.Black); new XnaGraphics(context).DrawStringCentered(context.Graphics.GraphicsDevice.Viewport.Width / 2, 128, "No active level."); } }
public override bool Update(GameContext context) { KeyboardState keystate = Keyboard.GetState(); // Are we waiting for players? if (this.m_NeedsToInitialize) { this.HandleTeamAllocations(); this.HandleUnitAllocations(); this.HandleUnitNeutrals(); this.m_NeedsToInitialize = false; return false; } else if (this.m_GlobalSession.Waiting) { // Check for ready toggle. if (keystate.IsKeyDown(Keys.Enter)) this.m_DidJustPressEnter = true; else if (keystate.IsKeyUp(Keys.Enter) && this.m_DidJustPressEnter) { this.m_LocalPlayer.MarkReady(!this.m_LocalPlayer.Ready); this.m_DidJustPressEnter = false; } // Update global state if permitted. this.m_GlobalSession.Update(context.GameTime); return false; } #if MULTIPLAYER else if (this.m_GlobalSession.LoadingInitialData && !LocalNode.Singleton.IsServer) { // Can't do anything here. return false; } #endif // Handle game normally. if (this.m_ActiveLevel != null) this.m_ActiveLevel.Update(context); if (keystate.IsKeyDown(Keys.Q)) this.m_ActiveLevel = this.m_Levels[0]; if (keystate.IsKeyDown(Keys.W)) this.m_ActiveLevel = this.m_Levels[1]; if (keystate.IsKeyDown(Keys.E)) this.m_ActiveLevel = this.m_Levels[2]; if (keystate.IsKeyDown(Keys.R)) this.m_ActiveLevel = this.m_Levels[3]; if (keystate.IsKeyDown(Keys.T)) this.m_ActiveLevel = this.m_Levels[4]; if (keystate.IsKeyDown(Keys.Q) || keystate.IsKeyDown(Keys.W) || keystate.IsKeyDown(Keys.E) || keystate.IsKeyDown(Keys.R) || keystate.IsKeyDown(Keys.T)) { // reset selection. this.m_UiManager.Selected.Clear(); } // The server is now ready, tell all clients to start loading. #if MULTIPLAYER if (this.m_GlobalSession.LoadingInitialData && LocalNode.Singleton.IsServer) #else if (this.m_GlobalSession.LoadingInitialData) #endif { if (!this.m_ServerHasRunOneTick) this.m_ServerHasRunOneTick = true; else this.m_GlobalSession.ServerReady(); } return true; }
public override void DrawAbove(GameContext context) { // Are we waiting for players? #if MULTIPLAYER if (this.m_GlobalSession.Waiting || (this.m_GlobalSession.LoadingInitialData && !LocalNode.Singleton.IsServer)) #else if (this.m_GlobalSession.Waiting) #endif { XnaGraphics graphics = new XnaGraphics(context); graphics.FillRectangle(new Rectangle(0, 0, context.Graphics.GraphicsDevice.Viewport.Width, context.Graphics.GraphicsDevice.Viewport.Height), Color.Black); int dialogX = context.Graphics.GraphicsDevice.Viewport.X + context.Graphics.GraphicsDevice.Viewport.Width / 2 - 300; int dialogY = context.Graphics.GraphicsDevice.Viewport.Y + context.Graphics.GraphicsDevice.Viewport.Height / 2 - 200; graphics.FillRectangle(new Rectangle(dialogX, dialogY, 600, 400), Color.DarkSlateGray); graphics.DrawStringCentered(dialogX + 300, dialogY + 8, this.m_GlobalSession.LobbyMessage, "BigArial"); graphics.DrawStringCentered(dialogX + 300, dialogY + 32, "Press enter to toggle ready status."); int a = 0; for (int i = 0; i < this.m_GlobalSession.Players.Count; i++) { Player p = this.m_GlobalSession.Players[i]; if (p.Ready) graphics.DrawStringLeft(dialogX + 8, dialogY + 48 + a * 16, "Player " + a + " (" + p.PlayerID + ") ready."); else graphics.DrawStringLeft(dialogX + 8, dialogY + 48 + a * 16, "Player " + a + " (" + p.PlayerID + ") not ready."); a++; } return; } // Handle game normally. if (this.m_ActiveLevel != null) this.m_ActiveLevel.DrawAbove(context); this.m_UiManager.Draw(this, context, new XnaGraphics(context)); }
public XnaGraphics(GameContext context) { this.m_Context = context; this.m_Pixel = new Texture2D(context.Graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); this.m_Pixel.SetData(new[] { Color.White }); }
public override bool Update(GameContext context) { MouseState mouse = Mouse.GetState(); // Go back to title screen if needed. if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { (this.Game as RuntimeGame).SwitchWorld(new TitleWorld()); return false; } // Player should fall (TODO: Move this into a gravity handler for chunk entities). int tz = this.SurfacePointOnTerrain(this.m_Player.WorldX, this.m_Player.WorldY); if (this.m_Player.WorldZ < tz && tz != -1) this.m_Player.WorldZ = tz; // Update player and refocus screen. KeyboardState state = Keyboard.GetState(); if (state.IsKeyDown(Keys.Up) && this.EntityCanMoveIntoPosition(this.m_Player, this.m_Player.WorldX, this.m_Player.WorldY - 1)) this.m_Player.Y -= 16; else if (state.IsKeyDown(Keys.Down) && this.EntityCanMoveIntoPosition(this.m_Player, this.m_Player.WorldX, this.m_Player.WorldY + 1)) this.m_Player.Y += 16; else if (state.IsKeyDown(Keys.Left) && this.EntityCanMoveIntoPosition(this.m_Player, this.m_Player.WorldX - 1, this.m_Player.WorldY)) this.m_Player.X -= 16; else if (state.IsKeyDown(Keys.Right) && this.EntityCanMoveIntoPosition(this.m_Player, this.m_Player.WorldX + 1, this.m_Player.WorldY)) this.m_Player.X += 16; this.Focus(context, this.m_Player.WorldX, this.m_Player.WorldY); context.Window.Title = "At " + ((int)Math.Floor(this.m_TargetX / (double)16)) + ", " + ((int)Math.Floor(this.m_TargetY / (double)16) + " depth " + this.RenderDepthValue); // Recalculate field of view. //this.m_FieldOfView.Recalculate(); // Check to see if we should regenerate. KeyboardState keystate = Keyboard.GetState(); if (keystate.IsKeyDown(Keys.R)) { if (!this.m_Regenerated) { Log.WriteLine("Starting generation..."); this.m_DynamicLoader.Regenerate(this.Tileset, 0, 0); this.m_Regenerated = true; Log.WriteLine("Generation complete."); } } else if (keystate.IsKeyUp(Keys.R)) this.m_Regenerated = false; /* if (keystate.IsKeyDown(Keys.Add)) this.RenderDepthValue += 1; else if (keystate.IsKeyDown(Keys.Subtract)) this.RenderDepthValue -= 1; if (this.RenderDepthValue == 255) this.RenderDepthValue = 63; if (this.RenderDepthValue > 63) this.RenderDepthValue = 0;*/ this.RenderDepthValue = (byte)(this.m_Player.WorldZ); this.RenderDepthUpRange = 8; this.RenderDepthDownRange = 8; return true; // update entities }
public override void DrawBelow(GameContext context) { }
private void DrawSpriteAt(GameContext context, float x, float y, int width, int height, string image, Color color, bool flipX) { if (flipX) context.SpriteBatch.Draw( context.Textures[image], new Rectangle((int)x, (int)y, width, height), null, color.ToPremultiplied(), 0, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0 ); else context.SpriteBatch.Draw( context.Textures[image], new Rectangle((int)x, (int)y, width, height), color.ToPremultiplied() ); }
public override bool Update(GameContext context) { this.Game.FixResolution(); bool handle = base.Update(context); if (!handle) return false; // Draw some stars if we feel like it. for (var i = 0; i < m_Random.NextDouble() * 150; i++) this.Entities.Add(new RedMeansGo.Entities.RedBloodCell { X = (float)m_Random.NextDouble() * Tileset.TILESET_PIXEL_WIDTH, Y = this.Player.Y - RedMeansGoGame.GAME_WIDTH, Speed = 3 * (float)m_Random.NextDouble() + 1 } ); if ((this.Player as Entities.Player).Health > 0) { for (var i = 0; i < m_Random.NextDouble() * 150; i++) if (m_Random.NextDouble() < 0.05) this.Entities.Add(new RedMeansGo.Entities.WhiteBloodCell { X = (float)m_Random.NextDouble() * Tileset.TILESET_PIXEL_WIDTH, Y = this.Player.Y - RedMeansGoGame.GAME_WIDTH, Speed = 3 * (float)m_Random.NextDouble() + 1 } ); } // Cast first. RedMeansGo.Entities.Player player = this.Player as RedMeansGo.Entities.Player; m_BackgroundAudio.Tempo = (float)((1 - player.Health) + 1); // Move viewport to player. context.Graphics.GraphicsDevice.Viewport = new Viewport((int)(-player.X + RedMeansGoGame.GAME_WIDTH / 2f), (int)(-player.Y + RedMeansGoGame.GAME_HEIGHT / 1.2f), Tileset.TILESET_PIXEL_WIDTH, Tileset.TILESET_PIXEL_HEIGHT); // Handle if player exists. if (player != null) { /*var state = Mouse.GetState(); player.X = state.X; player.Y = state.Y;*/ if (Keyboard.GetState().IsKeyDown(Keys.Left)) player.MoveLeft(this); if (Keyboard.GetState().IsKeyDown(Keys.Up)) player.MoveUp(this); if (Keyboard.GetState().IsKeyDown(Keys.Right)) player.MoveRight(this); if (Keyboard.GetState().IsKeyDown(Keys.Down)) player.MoveDown(this); if (Keyboard.GetState().IsKeyUp(Keys.Left) && Keyboard.GetState().IsKeyUp(Keys.Up) && Keyboard.GetState().IsKeyUp(Keys.Right) && Keyboard.GetState().IsKeyUp(Keys.Down)) player.MoveEnd(); if (Keyboard.GetState().IsKeyDown(Keys.A) && player.Health > 0) player.Health -= 0.001; if (Keyboard.GetState().IsKeyDown(Keys.Z)) { player.ShootSomeMotherFudgingBullets(context.World); } if (Keyboard.GetState().IsKeyDown(Keys.R)) { this.Restart(); } } // Update enumerator. if ((this.Player as Entities.Player).Health > 0) this.Heartbeats.MoveNext(); else { this.Heartbeats = Heartbeat.HeartbeatEnumerator.YieldStopped(this).GetEnumerator(); m_BackgroundAudio.Stop(); } // Continue entity updates. return true; }