public override void Update(RenderContext renderContext) { //Handle pressing of the button. if (IsPressed && doorsToggled == false) { animmodel.PlayAnimation("Press", false, 0f); soundEffects.PlaySound("Button"); doorsToggled = true; foreach (SwitchableObject door in LinkedDoors) { door.Toggle(renderContext); } } else if (!IsPressed && doorsToggled == true) { animmodel.PlayAnimation("Pop", false, 0f); soundEffects.PlaySound("Button"); doorsToggled = false; foreach (SwitchableObject door in LinkedDoors) { door.Toggle(renderContext); } } IsPressed = false; //button resets to up unless current pressed animmodel.Update(renderContext); base.Update(renderContext); }
/// <summary> /// Move the box in the current moveDir. /// </summary> /// <param name="renderContext"></param> /// <param name="moveDir"></param> /// <param name="movementAmount"></param> public void Move(RenderContext renderContext, GameConstants.DIRECTION moveDir, float movementAmount) { facingDirection = moveDir; //Rotate(0f, -90f, 0f); //No need to rotate moving platform to set its direction Vector3 newPosition; Vector3 PositionChange; //Get position change depending on direction if(moveDir == LEFT) PositionChange = new Vector3(-movementAmount, 0, 0); else if (moveDir == RIGHT) PositionChange = new Vector3(movementAmount, 0, 0); else if (moveDir == UP) PositionChange = new Vector3(0, movementAmount, 0); else// if (moveDir == DOWN) PositionChange = new Vector3(0, -movementAmount, 0); newPosition = Position + PositionChange; currDistance += movementAmount; Translate(newPosition); //if player is on the platform, move the player just as much as the platform does if (PlayerOnPlatform) { Vector3 newPlayerPosition = renderContext.Player.Position + PositionChange; renderContext.Player.Translate(newPlayerPosition); } }
//Opens or closes the door depending on current state public override void Toggle(RenderContext renderContext) { if (isOpen) isOpen = false; else isOpen = true; }
public void CheckProjectileCollision(RenderContext renderContext, List<CellObject> returnObjs) { // if collision with player, handle /* if(this.Hitbox.Intersects(renderContext.Player.Hitbox)) { active = false; TransVelocity = Vector3.Zero; renderContext.Player.SetHealth(GameConstants.PLAYER_DAMAGE); }*/ // Quad tree collison checks - Steven foreach (CellObject worldObject in returnObjs) { if (!worldObject.IsPassable && Hitbox.Intersects(worldObject.Hitbox)) { Console.Out.WriteLine(worldObject); if (worldObject.GetType() == typeof(Character)) { active = false; renderContext.Player.TakeDamage(GameConstants.PLAYER_DAMAGE, renderContext.GameTime); TransVelocity = Vector3.Zero; } else { active = false; TransVelocity = Vector3.Zero; } } } //foreach (GameObject3D worldObject in renderContext.Level.gameObjects[typeof(Character)]) //{ // if (Hitbox.Intersects(worldObject.Hitbox) && worldObject.GetType() != typeof(LaserTurret)) // { // active = false; // TransVelocity = Vector3.Zero; // renderContext.Player.SetHealth(GameConstants.PLAYER_DAMAGE); // } //} //foreach (GameObject3D worldObject in renderContext.Level.gameObjects[typeof(BasicBlock)]) //{ // if (Hitbox.Intersects(worldObject.Hitbox) && worldObject.GetType() != typeof(LaserTurret)) // { // active = false; // TransVelocity = Vector3.Zero; // } //} //foreach (GameObject3D worldObject in renderContext.Level.gameObjects[typeof(PickableBox)]) //{ // if (Hitbox.Intersects(worldObject.Hitbox) && worldObject.GetType() != typeof(LaserTurret)) // { // active = false; // TransVelocity = Vector3.Zero; // } //} //Position += TransVelocity; }
public GameTimer(RenderContext renderContext) { elapsedTime = TimeSpan.Zero; this.renderContext = renderContext; string time = string.Format("Time: {0}", elapsedTime); //time = time.Remove(time.Length - 5); position = new Vector2(GameConstants.X_RESOLUTION - renderContext.SpriteFont.MeasureString(time).X, 50); }
public override void Draw(RenderContext renderContext) { animmodel.Draw(renderContext); //renderContext.SpriteBatch.Begin(); //renderContext.SpriteBatch.Draw(texture, enemyRangeL, Color.Black); //renderContext.SpriteBatch.Draw(texture, enemyRangeR, Color.Black); //renderContext.SpriteBatch.End(); }
public Enemy(int column, int row, RenderContext rendeerContext) : base(column, row) { texture = new Texture2D(rendeerContext.GraphicsDevice, 1, 1); texture.SetData(new Color[] { Color.Gray }); animmodel = new GameAnimatedModel("Doomba", column, row, this); animmodel.PlayAnimation("Move", true, 0f); isCollidable = false; wallsToCheck = new List<GameObject3D>(); Scale(40f, 40f, 40f); // 48,48,48 Position = new Vector3(Position.X, Position.Y - 18, Position.Z); // position.y - 18 }
int WPM = 600; //default WPM for text #endregion Fields #region Constructors public MessageEvent(int column, int row, RenderContext renderContext) : base(column, row) { base.isCollidable = true; base.IsPassable = true; this.typingState = GameConstants.TYPING_STATE.NotTyped; Scale(48f, 48f, 48f); //Position = new Vector3(Position.X, Position.Y - 2, Position.Z - 27); //not sure about this position //HitboxHeightOffset = 2; HitboxHeight = GameConstants.SINGLE_CELL_SIZE; HitboxWidth = GameConstants.SINGLE_CELL_SIZE; //Translate(new Vector3(0, 0, 0)); typedMessageLines = new List<String>(4); typedMessage = ""; }
public void CheckSonarCollision(RenderContext renderContext, List<CellObject> returnObjs) { foreach (CellObject worldObject in returnObjs) { if (!worldObject.IsPassable && Hitbox.Intersects(worldObject.Hitbox) && worldObject.GetType() != typeof(Enemy) ) { if (worldObject.GetType() == typeof(Character)) { active = false; TransVelocity = Vector3.Zero; //sourceEnemy.AttackMode(); } else { active = false; TransVelocity = Vector3.Zero; //sourceEnemy.StandDown(); } } } }
//Makes door unCollidable when open public override void Update(RenderContext renderContext) { if (isOpen) { //Animate opening door if not done yet. float nextPos = Position.Z - DOOR_SPEED; if (nextPos > DOOR_CLOSED_ZPOSITION) this.Position = new Vector3(Position.X, Position.Y, nextPos); else this.Position = new Vector3(Position.X, Position.Y, DOOR_CLOSED_ZPOSITION); isCollidable = false; }else { //Animate closing door if not done yet. float nextPos = Position.Z + DOOR_SPEED; if (nextPos < 0) this.Position = new Vector3(Position.X, Position.Y, nextPos); else this.Position = new Vector3(Position.X, Position.Y, 0); isCollidable = true; } base.Update(renderContext); }
public override void Draw(RenderContext renderContext) { Matrix[] bones = null; bones = _animationPlayer.GetSkinTransforms(); // Render the skinned mesh. foreach (ModelMesh mesh in Model.Meshes) { foreach (SkinnedEffect effect in mesh.Effects) { effect.SetBoneTransforms(bones); effect.EnableDefaultLighting(); effect.AmbientLightColor = new Vector3(.3f, .3f, .3f); effect.View = renderContext.Camera.View; effect.Projection = renderContext.Camera.Projection; effect.SpecularColor = new Vector3(1,1,1); effect.SpecularPower = 200; } mesh.Draw(); } }
public void DrawPlayerHealthV3(RenderContext _renderContext) { Rectangle healthTexturePos = new Rectangle(195, 150, 250, 30); Rectangle playerGear = new Rectangle(50, 50, 150, 150); Rectangle playerHealthGear = new Rectangle(195, 60, 100, 100); Rectangle playerHealthCountGear = new Rectangle(190, 120, 60, 60); Rectangle centerHealthGear = new Rectangle(75, 75, 100, 100); Texture2D healthTexture; if (player.GetHealth() == GameConstants.HEALTH) { healthTexture = _textures["LightGreen"]; } else if (player.GetHealth() < GameConstants.HEALTH && player.GetHealth() > 1) { healthTexture = _textures["LightYellow"]; } else { healthTexture = _textures["LightRed"]; } spriteBatch.End(); healthState.Parameters["healthState"].SetValue((float)player.GetHealth() / (float)GameConstants.HEALTH); spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, healthState); spriteBatch.Draw(healthTexture, centerHealthGear, Color.White); spriteBatch.End(); Matrix matrix = Matrix.CreateTranslation(0, -centerHealthGear.Center.Y + playerBob* 10, 0) * Matrix.CreateRotationX(playerBob) * Matrix.CreateTranslation(0, centerHealthGear.Center.Y - playerBob * 10, 0) * Matrix.CreateScale(1, 1, 0); spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, null, matrix); spriteBatch.Draw(_textures["PlayerPortrait"], new Rectangle(centerHealthGear.X, centerHealthGear.Y, centerHealthGear.Width, centerHealthGear.Height), Color.White); spriteBatch.End(); spriteBatch.Begin(); Vector2 origin = new Vector2(_textures["Gear2"].Bounds.Width / 2, _textures["Gear2"].Bounds.Height / 2); spriteBatch.Draw( _textures["Gear2"], new Vector2(playerGear.X + 75, playerGear.Y + 75), null, Color.White, rotationAngle, origin, (float)playerGear.Width / _textures["Gear2"].Width, SpriteEffects.None, 0); }
/// <summary> /// Basic placeholder UI for player health /// </summary> /// <param name="_renderContext"></param> public void DrawPlayerHealth(RenderContext _renderContext) { Rectangle healthTexturePos = new Rectangle(195, 150, 250, 30); Rectangle playerGear = new Rectangle(50, 50, 150, 150); Rectangle playerHealthGear = new Rectangle(195, 60, 100, 100); Texture2D healthTexture; string currentState; if (player.GetHealth() == GameConstants.HEALTH) { healthTexture = _textures["LaserGreen"]; currentState = ":)"; } else if (player.GetHealth() < GameConstants.HEALTH && player.GetHealth() > 1) { healthTexture = _textures["LaserOrange"]; currentState = ":|"; } else { healthTexture = _textures["LaserRed"]; currentState = ":("; } Vector2 stateTextSize = font.MeasureString(currentState); Vector2 currentStatePos = new Vector2(playerGear.Center.X, playerGear.Center.Y); string currentHealth = player.GetHealth().ToString() + "/" + GameConstants.HEALTH; Vector2 textSize = font.MeasureString(currentHealth); Vector2 currentHealthPos = new Vector2(playerHealthGear.Center.X - textSize.X / 2, playerHealthGear.Center.Y - textSize.Y / 2); Vector2 origin = new Vector2(_textures["Gear"].Bounds.Width / 2, _textures["Gear"].Bounds.Height / 2); spriteBatch.DrawString(font, currentHealth, currentHealthPos, Color.Black); spriteBatch.DrawString(font, currentState, currentStatePos, Color.Black, MathHelper.PiOver2, new Vector2(stateTextSize.X / 2, stateTextSize.Y / 2), 1f, SpriteEffects.None, 1); spriteBatch.Draw( _textures["Gear"], new Vector2(playerGear.X + 75, playerGear.Y + 75), null, Color.White, rotationAngle, origin, (float)playerGear.Width / _textures["Gear"].Width, SpriteEffects.None, 0); spriteBatch.Draw( _textures["Gear"], new Vector2(playerHealthGear.X + playerHealthGear.Width / 2, playerHealthGear.Y + playerHealthGear.Height / 2), null, Color.White, -rotationAngle, origin, (float)playerHealthGear.Width / _textures["Gear"].Width, SpriteEffects.None, 0); spriteBatch.Draw(healthTexture, healthTexturePos, Color.White); }
/// <summary> /// Used for debugging hitboxes - Steven /// Refactored by Jacob into an actual minimap /// </summary> /// <param name="_renderContext"></param> public void DrawDebugMap(RenderContext _renderContext) { if (player.MapEnabled) { //Can set size of minimap and it will scale accordingly. //It can be a fixed size (eg. 300x300, and the level objects would resize accordingly), or size dependent on level, etc. Point MinimapSize = new Point ( LevelBuilder.levelwidth*10, LevelBuilder.levelheight*10); const int TOP_RIGHT = 1, BOTTOM_RIGHT = 2, BOTTOM_LEFT = 3; //Jacob: Added a couple of customizations to the minimap. Can set it accordingly to positons of the screen. int MinimapPosition = TOP_RIGHT; //Can set position of minimap int MinimapBorder = 5; //Can also set border thickness of minimap int MinimapSideOffset = 10; Rectangle BorderBox, InnerBox; //Draw border switch (MinimapPosition) { case TOP_RIGHT: BorderBox = new Rectangle ( GameConstants.X_RESOLUTION - (MinimapSize.X + MinimapBorder) - MinimapSideOffset, MinimapSideOffset - MinimapBorder, (MinimapSize.X + MinimapBorder * 2), (MinimapSize.Y + MinimapBorder * 2) ); InnerBox = new Rectangle ( GameConstants.X_RESOLUTION - MinimapSize.X - MinimapSideOffset, MinimapSideOffset, MinimapSize.X, MinimapSize.Y ); break; case BOTTOM_RIGHT: BorderBox = new Rectangle ( GameConstants.X_RESOLUTION - (MinimapSize.X + MinimapBorder) - MinimapSideOffset, GameConstants.Y_RESOLUTION - (MinimapSize.Y + MinimapBorder) - MinimapSideOffset, (MinimapSize.X + MinimapBorder * 2), (MinimapSize.Y + MinimapBorder * 2) ); InnerBox = new Rectangle ( GameConstants.X_RESOLUTION - MinimapSize.X - MinimapSideOffset, GameConstants.Y_RESOLUTION - (MinimapSize.Y) - MinimapSideOffset, MinimapSize.X, MinimapSize.Y ); break; case BOTTOM_LEFT: BorderBox = new Rectangle ( MinimapSideOffset - MinimapBorder, GameConstants.Y_RESOLUTION - (MinimapSize.Y + MinimapBorder) - MinimapSideOffset, (MinimapSize.X + MinimapBorder * 2), (MinimapSize.Y + MinimapBorder * 2) ); InnerBox = new Rectangle ( MinimapSideOffset, GameConstants.Y_RESOLUTION - (MinimapSize.Y) - MinimapSideOffset, MinimapSize.X, MinimapSize.Y ); break; default: BorderBox = new Rectangle ( MinimapSideOffset - MinimapBorder, GameConstants.Y_RESOLUTION - (MinimapSize.Y + MinimapBorder) - MinimapSideOffset, (MinimapSize.X + MinimapBorder * 2), (MinimapSize.Y + MinimapBorder * 2) ); InnerBox = new Rectangle ( MinimapSideOffset, GameConstants.Y_RESOLUTION - (MinimapSize.Y) - MinimapSideOffset, MinimapSize.X, MinimapSize.Y ); break; } spriteBatch.Draw ( dummyTexture, BorderBox, Color.Black * 0.8f ); spriteBatch.Draw ( dummyTexture, InnerBox, Color.LightGray * 0.8f ); const int CELL = GameConstants.SINGLE_CELL_SIZE; int xLeftWall = (GameConstants.SINGLE_CELL_SIZE * LevelBuilder.startWall) - (GameConstants.X_RESOLUTION / 2); int xRightWall = (GameConstants.SINGLE_CELL_SIZE * (LevelBuilder.levelwidth - 1 + LevelBuilder.startWall)) - (GameConstants.X_RESOLUTION / 2); //x value derived from CellObject implementation, BaseCamera int yCeilingBlock = CELL * ((LevelBuilder.startFloor + 1) + LevelBuilder.levelheight - 1) - (GameConstants.Y_RESOLUTION / 2); //not int yFloor = (GameConstants.SINGLE_CELL_SIZE * (LevelBuilder.startFloor + 1)) - (GameConstants.Y_RESOLUTION / 2); //y value derived from CellObject implementation int LevelXSize = xRightWall - xLeftWall + CELL; int LevelYSize = yCeilingBlock - yFloor + CELL; foreach (CellObject obj in basicLevel.collidableObjects) { //Move minimap to the top right of the screen //convert yFloor position to the bottom of the screen, xRightWall to the right of the screen //everything a fraction of (yCeilingBlock - yFloor + 1 cell) and (xRightWall - xLeftWall + 1 cell) // so (converting level to minimap:) box X position = XRightScreen (ie. GameConstants.X_RESOLUTION) - (1 - fraction of that) * minimapSize.X // box Y position = YTopScreen + MinimapSize - (1 - fraction of that) * minimapSize.Y Rectangle box = obj.Hitbox; box.Width = (box.Width * MinimapSize.X / LevelXSize); //convert width from level to minimap size box.Height = (box.Height * MinimapSize.Y / LevelYSize); //convert height from level to minimap size int XPositionOfLevel = (box.X - xLeftWall); //position of level when normalized as a proportion of its size int YPositionOfLevel = (box.Y - (yFloor - CELL)); //returns distance of bottom (in game coords) of box from bottom of level switch (MinimapPosition) { case TOP_RIGHT: box.X = GameConstants.X_RESOLUTION - (LevelXSize - XPositionOfLevel) * MinimapSize.X / LevelXSize - MinimapSideOffset; //convert from position in level to position in minimap box.Y = MinimapSize.Y - YPositionOfLevel * MinimapSize.Y / LevelYSize - box.Height + MinimapSideOffset; break; case BOTTOM_RIGHT: box.X = GameConstants.X_RESOLUTION - (LevelXSize - XPositionOfLevel) * MinimapSize.X / LevelXSize - MinimapSideOffset; //convert from position in level to position in minimap box.Y = GameConstants.Y_RESOLUTION - YPositionOfLevel * MinimapSize.Y / LevelYSize - box.Height - MinimapSideOffset; break; case BOTTOM_LEFT: box.X = XPositionOfLevel * MinimapSize.X / LevelXSize+ MinimapSideOffset; //convert from position in level to position in minimap box.Y = GameConstants.Y_RESOLUTION - YPositionOfLevel * MinimapSize.Y / LevelYSize - box.Height - MinimapSideOffset; break; } /* box.X /= 4; box.Y /= 4; box.Width /= 4; box.Height /= 4; box.X += 400; box.Y += 300;*/ //box.Y = GameConstants.Y_RESOLUTION - box.Y; //Jacob: convert game logic coords (+ is up, 0 is floor) to screen coords (+ is down, 0 is top) if (obj.GetType() == typeof(Character)) spriteBatch.Draw(dummyTexture, box, Color.Blue * 0.8f); else if (obj.GetType() == typeof(BasicBlock)) spriteBatch.Draw(dummyTexture, box, Color.DarkSlateGray * 0.8f); else if (obj.GetType() == typeof(PickableBox)) spriteBatch.Draw(dummyTexture, box, Color.White * 0.8f); else if (obj.GetType() == typeof(Door)) spriteBatch.Draw(dummyTexture, box, Color.Black * 0.8f); else if (obj.GetType() == typeof(Button)) spriteBatch.Draw(dummyTexture, box, Color.ForestGreen * 0.8f); else if (obj.GetType() == typeof(ToggleSwitch)) spriteBatch.Draw(dummyTexture, box, Color.Green * 0.8f); else if (obj.GetType() == typeof(Enemy)) { //Enemy enemy = (Enemy)obj; //Rectangle e = enemy.enemyRangeL; //e.Width = (e.Width * MinimapSize.X / LevelXSize); //convert width from level to minimap size //e.Height = (e.Height * MinimapSize.Y / LevelYSize); //convert height from level to minimap size //XPositionOfLevel = (e.X - xLeftWall); //position of level when normalized as a proportion of its size //YPositionOfLevel = (e.Y - (yFloor - CELL)); //returns distance of bottom (in game coords) of box from bottom of level //e.X = GameConstants.X_RESOLUTION - (LevelXSize - XPositionOfLevel) * MinimapSize.X / LevelXSize - MinimapSideOffset; //convert from position in level to position in minimap //e.Y = MinimapSize.Y - YPositionOfLevel * MinimapSize.Y / LevelYSize - e.Height + MinimapSideOffset; spriteBatch.Draw(dummyTexture, box, Color.Red * 0.8f); //spriteBatch.Draw(dummyTexture, e, Color.Yellow * 0.8f); } else if (obj.GetType() == typeof(LaserTurret)) spriteBatch.Draw(dummyTexture, box, Color.DarkRed * 0.8f); else spriteBatch.Draw(dummyTexture, box, Color.Purple * 0.8f); } } }
public override void Update(RenderContext renderContext) { CheckPlatformBoxCollision(renderContext); if (currDistance > maxDistance) { //reverse direction if exceeding distance if (movingDirection == LEFT) { movingDirection = RIGHT; } else if (movingDirection == RIGHT) { movingDirection = LEFT; } else if (movingDirection == UP) { movingDirection = DOWN; } else if (movingDirection == DOWN) { movingDirection = UP; } currDistance = 0; } Move ( renderContext, movingDirection, GameConstants.MOVEAMOUNT ); //Move box in the respective direction base.Update(renderContext); }
//Creates buffer for background public void setBackgroundBuffer(RenderContext renderContext) { for (int texturePatternIndex = 0; texturePatternIndex < Background.Length; texturePatternIndex++) { List<BackgroundBlock> patternedBlocks = Background[texturePatternIndex]; List<VertexPositionTexture> vertexList = new List<VertexPositionTexture>(); foreach (BackgroundBlock backgroundBlock in patternedBlocks) { foreach (VertexPositionTexture vertex in backgroundBlock.GetBillboardVertices()) { vertexList.Add(vertex); } } //if there are background blocks of this pattern if (vertexList.Count != 0) { backgroundBuffer[texturePatternIndex] = new VertexBuffer(renderContext.GraphicsDevice, VertexPositionTexture.VertexDeclaration, vertexList.Count, BufferUsage.WriteOnly); backgroundBuffer[texturePatternIndex].SetData<VertexPositionTexture>(vertexList.ToArray()); } } }
public override void Update(RenderContext renderContext) { List<CellObject> returnObjs = new List<CellObject>(); renderContext.Quadtree.clear(); foreach (CellObject obj in renderContext.Level.collidableObjects) { if (obj.GetType() != typeof(LaserTurret)) renderContext.Quadtree.insert(obj); } renderContext.Quadtree.retrieve(returnObjs, Hitbox); if (active) { CheckSonarCollision(renderContext, returnObjs); Position += TransVelocity * SPEED; } else { renderContext.Level.RemoveChild(this); } base.Update(renderContext); }
public override void Update(RenderContext renderContext) { base.Update(renderContext); PopulateTypeList(renderContext); }
/// <summary> /// Note: As of 11/18/15, the current version of the collision code has some bugs. It sometimes detects boxes next to it as being eg. collidable from the bottom. /// </summary> /// <param name="renderContext"></param> private void CheckPlatformBoxCollision(RenderContext renderContext) { foreach (CellObject levelObject in renderContext.Level.Children) { bool typeAllowed = levelObject.GetType () == typeof ( BasicBlock ) || levelObject.GetType () == typeof ( MovingPlatform ) || levelObject.GetType () == typeof ( Door ) || levelObject.GetType () == typeof ( Trapdoor ); //Collide only with objects under typeAllowed; other objects will not influence MovingPlatform's position if (levelObject.isCollidable && typeAllowed && Hitbox.Intersects(levelObject.Hitbox) && levelObject != this) { Rectangle intersect = Rectangle.Intersect(Hitbox, levelObject.Hitbox); // Reverse moving direction based on this method of checking collision. /**Determining what side was hit**/ float wy = (levelObject.Hitbox.Width + Hitbox.Width) * (((levelObject.Hitbox.Y + levelObject.Hitbox.Height) / 2) - (Hitbox.Y + Hitbox.Height) / 2); float hx = (Hitbox.Height + levelObject.Hitbox.Height) * (((levelObject.Hitbox.X + levelObject.Hitbox.Width) / 2) - (Hitbox.X + Hitbox.Width) / 2); // Reverse directions based on collision with another object // Given issues with quickly flipping directions due to faulty collisions, // Will have to figure a workaround. // Maybe not rely on collision to determine moving platform movement, and instead just activate\inactivate moving platforms ... if (wy > hx) { if (wy > -hx) { if (movingDirection == UP) { movingDirection = DOWN; currDistance = 0; } } else { if (movingDirection == LEFT) { movingDirection = RIGHT; currDistance = 0; } } } else //Right, down { if (wy > -hx) { if (movingDirection == RIGHT) { movingDirection = LEFT; currDistance = 0; } } else { if (movingDirection == DOWN) { Position = new Vector3 ( Position.X, levelObject.Hitbox.Y + this.Hitbox.Height, 0 ); //clip to the top of the colliding object movingDirection = UP; currDistance = 0; } } } } } }
//Draws Background seperate: was able to get huge performance increase doing this way private void drawBackground(RenderContext renderContext) { //TODO: allow multiple backgrounds //Draw background renderContext.BasicEffect.TextureEnabled = true; renderContext.BasicEffect.World = Matrix.Identity; renderContext.BasicEffect.View = renderContext.Camera.View; renderContext.BasicEffect.Projection = renderContext.Camera.Projection; //Store state so we can go back to it RasterizerState oldState = renderContext.GraphicsDevice.RasterizerState; //Matt: couldn't get it drawing without doing this...could use some help creating vertices and maybe get rid of this RasterizerState rs = new RasterizerState(); rs.CullMode = CullMode.CullClockwiseFace; rs.MultiSampleAntiAlias = false; renderContext.GraphicsDevice.RasterizerState = rs; for (int patternIndex = 0; patternIndex < backgroundBuffer.Length; patternIndex++) { //if there are no patterned blocks of this type if (backgroundBuffer[patternIndex] == null) continue; switch (patternIndex) { case 0: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_Gray"]; break; case 1: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_White"]; break; case 2: renderContext.BasicEffect.Texture = renderContext.Textures["Vent"]; break; case 3: renderContext.BasicEffect.Texture = renderContext.Textures["Pipes1"]; break; case 4: renderContext.BasicEffect.Texture = renderContext.Textures["Pipes2"]; break; case 5: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_Black"]; break; case 6: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_Gray_Stain"]; break; case 7: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_Gray_Stain2"]; break; case 8: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_Gray_Stain3"]; break; case 9: renderContext.BasicEffect.Texture = renderContext.Textures["Tile_Gray_Stain1"]; break; case 10: renderContext.BasicEffect.Texture = renderContext.Textures["Emcsquare"]; break; case 11: renderContext.BasicEffect.Texture = renderContext.Textures["Einstien"]; break; case 12: renderContext.BasicEffect.Texture = renderContext.Textures["atom1"]; break; case 13: renderContext.BasicEffect.Texture = renderContext.Textures["atom2"]; break; case 14: renderContext.BasicEffect.Texture = renderContext.Textures["chalkboard1"]; break; case 15: renderContext.BasicEffect.Texture = renderContext.Textures["chalkboard2"]; break; case 16: renderContext.BasicEffect.Texture = renderContext.Textures["chalkboard3"]; break; case 17: renderContext.BasicEffect.Texture = renderContext.Textures["chalkboard4"]; break; } if (backgroundBuffer[patternIndex] != null) { foreach (EffectPass pass in renderContext.BasicEffect.CurrentTechnique.Passes) { pass.Apply(); renderContext.GraphicsDevice.SetVertexBuffer(backgroundBuffer[patternIndex]); renderContext.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, backgroundBuffer[patternIndex].VertexCount / 3); } } } //Set back to normal renderContext.GraphicsDevice.RasterizerState = oldState; }
public override void Update(RenderContext renderContext) { /* * Matt: there is probably a more efficient way to do this, but my Matrix math is awful. */ WorldMatrix = Matrix.CreateFromQuaternion(parent.LocalRotation) * Matrix.CreateScale(parent.LocalScale) * Matrix.CreateTranslation(new Vector3(parent.Position.X, parent.Position.Y - VerticalOffset, parent.Position.Z)); _animationPlayer.Update(renderContext.GameTime.ElapsedGameTime, true, WorldMatrix); }
private void drawForeground(RenderContext renderContext) { RasterizerState oldState = renderContext.GraphicsDevice.RasterizerState; renderContext.GraphicsDevice.RasterizerState = drawState; //renderContext.GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; // Gather instance transform matrices into a single array. Array.Resize(ref instanceTransforms, foregroundBlockInstances.Count); for (int i = 0; i < foregroundBlockInstances.Count; i++) { instanceTransforms[i] = foregroundBlockInstances[i].GetWorldMatrix(); } //The actual drawing technique: if (instanceTransforms.Length == 0) return; // If we have more instances than room in our vertex buffer, grow it to the neccessary size. if ((instanceVertexBuffer == null) || (instanceTransforms.Length > instanceVertexBuffer.VertexCount)) { if (instanceVertexBuffer != null) instanceVertexBuffer.Dispose(); instanceVertexBuffer = new DynamicVertexBuffer(renderContext.GraphicsDevice, instanceVertexDeclaration, instanceTransforms.Length, BufferUsage.WriteOnly); } // Transfer the latest instance transform matrices into the instanceVertexBuffer. instanceVertexBuffer.SetData(instanceTransforms, 0, instanceTransforms.Length, SetDataOptions.Discard); foreach (ModelMesh mesh in instancedModel.Meshes) { foreach (ModelMeshPart meshPart in mesh.MeshParts) { // Tell the GPU to read from both the model vertex buffer plus our instanceVertexBuffer. renderContext.GraphicsDevice.SetVertexBuffers( new VertexBufferBinding(meshPart.VertexBuffer, meshPart.VertexOffset, 0), new VertexBufferBinding(instanceVertexBuffer, 0, 1) ); renderContext.GraphicsDevice.Indices = meshPart.IndexBuffer; // Set up the instance rendering effect. Effect effect = meshPart.Effect; effect.CurrentTechnique = effect.Techniques["HardwareInstancing"]; effect.Parameters["World"].SetValue(instancedModelBones[mesh.ParentBone.Index]); effect.Parameters["View"].SetValue(renderContext.Camera.View); effect.Parameters["Projection"].SetValue(renderContext.Camera.Projection); // Draw all the instance copies in a single call. foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); renderContext.GraphicsDevice.DrawInstancedPrimitives(PrimitiveType.TriangleList, 0, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount, instanceTransforms.Length); } } renderContext.GraphicsDevice.RasterizerState = oldState; //set back to original } }
public override void Update(RenderContext renderContext) { base.Update(renderContext); if (followTarget != null) { Position = new Vector3(Position.X, Position.Y, cameraDistance.Z); CameraFollow(followTarget); } BuildViewMatrix(); //Calculate view matrix every frame handleInput(); }
private void DrawMessage(RenderContext renderContext) { foreach(MessageEvent msg in Messages.Values) { if(msg.typingState == GameConstants.TYPING_STATE.DoneTyping || msg.typingState == GameConstants.TYPING_STATE.Typing) { msg.DisplayMessage(renderContext); } } }
/// <summary> /// Draws the visual feedback for the player when interacting with objects and carrying the box /// </summary> /// <param name="_renderContext"></param> public void DrawInteractiveUI(RenderContext _renderContext) { Character player = _renderContext.Player; // Provides a visual feedback if the user is able to pick up a box - Steven if (player.AdjacentObj != null && player.AdjacentObj.GetType() == typeof(PickableBox) && player.interactState == 0) { Vector3 screenPos = _renderContext.GraphicsDevice.Viewport.Project( player.AdjacentObj.WorldPosition, _renderContext.Camera.Projection, _renderContext.Camera.View, player.AdjacentObj.GetWorldMatrix()); int offset = 30; // Offsets the B button and arrow to the center of the box spriteBatch.Draw(_renderContext.Textures["B_Button"], new Rectangle((int)screenPos.X - offset, (int)screenPos.Y, 48, 48), Color.White); // Added a bob to the arrow spriteBatch.Draw(_renderContext.Textures["Arrow"], new Rectangle((int)screenPos.X, (int)screenPos.Y - arrowBobEffect, 48, 48), Color.LawnGreen); } // Draws a B button when near switches else if (player.InteractiveObj != null && player.InteractiveObj.GetType() == typeof(ToggleSwitch)) { Vector3 screenPos = _renderContext.GraphicsDevice.Viewport.Project( player.InteractiveObj.WorldPosition, _renderContext.Camera.Projection, _renderContext.Camera.View, player.InteractiveObj.GetWorldMatrix()); ToggleSwitch toggleSwitch = (ToggleSwitch)player.InteractiveObj; // Stops drawing if the switch uses is used up if (player.interactState == 0 && toggleSwitch.RemainingToggles != 0 || toggleSwitch.InfinitelyToggleable) spriteBatch.Draw(_renderContext.Textures["B_Button"], new Rectangle((int)screenPos.X - 24, (int)screenPos.Y - 96, 48, 48), Color.White); } // Provides visual feedback for where the box will be placed - Steven if (player.interactState != 0 && (!player.jumping || !player.falling)) { Vector3 arrowPos; if (player.GetFacingDirection == 1) // Left arrowPos = player.Position - new Vector3(24, 0, 0); else arrowPos = player.Position + new Vector3(24, 0, 0); // Using Jacob's logic for readjusting the placed box - Steven float startX = (GameConstants.SINGLE_CELL_SIZE * 1) - (GameConstants.X_RESOLUTION / 2); float startY = (GameConstants.SINGLE_CELL_SIZE * 1) - (GameConstants.Y_RESOLUTION / 2); Vector3 CELLREMAINDER = new Vector3((arrowPos.X - startX) % GameConstants.SINGLE_CELL_SIZE, (arrowPos.Y - startY) % GameConstants.SINGLE_CELL_SIZE, arrowPos.Z); //Move positions to the nearest cell if (CELLREMAINDER.X < GameConstants.SINGLE_CELL_SIZE / 2) arrowPos = new Vector3(arrowPos.X - CELLREMAINDER.X, arrowPos.Y, arrowPos.Z); else arrowPos = new Vector3(arrowPos.X - CELLREMAINDER.X + GameConstants.SINGLE_CELL_SIZE, arrowPos.Y, arrowPos.Z); // Grabs the screen position for arrow in the world - Steven Matrix arrowWorldMatrix = player.GetWorldMatrix(); arrowWorldMatrix.Translation = arrowPos; Vector3 screenPos = _renderContext.GraphicsDevice.Viewport.Project(player.WorldPosition, _renderContext.Camera.Projection, _renderContext.Camera.View, arrowWorldMatrix); // Determines what color the arrow will be, will add logic to check whether the player can place the block - Steven Color color; if (player.canPlace) color = Color.LawnGreen * 0.6f; else color = Color.Red * 0.6f; int offset = 6; // Centers the arrow indicator to the center of a cell Vector2 origin = new Vector2(_renderContext.Textures["Arrow"].Bounds.Width / 2, _renderContext.Textures["Arrow"].Bounds.Height / 2); spriteBatch.Draw(_renderContext.Textures["Arrow"], new Rectangle((int)screenPos.X - offset, (int)screenPos.Y - arrowBobEffect, GameConstants.SINGLE_CELL_SIZE, GameConstants.SINGLE_CELL_SIZE), null, color, 0f, origin, SpriteEffects.FlipVertically, 0f); } }
public override void Draw(RenderContext renderContext) { Vector3 screenPos = renderContext.GraphicsDevice.Viewport.Project(WorldPosition, renderContext.Camera.Projection, renderContext.Camera.View, WorldMatrix); Vector2 screenPos2D = new Vector2(screenPos.X, screenPos.Y); if (screenPos2D.X >= -GameConstants.SINGLE_CELL_SIZE*2 && screenPos2D.X <= renderContext.GraphicsDevice.Viewport.Width + GameConstants.SINGLE_CELL_SIZE*2 && screenPos2D.Y >= -GameConstants.SINGLE_CELL_SIZE * 2 && screenPos2D.Y <= renderContext.GraphicsDevice.Viewport.Width * 2) { foreach (ModelMesh mesh in Model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); if (Texture != null) { renderContext.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; effect.Texture = Texture; effect.TextureEnabled = true; } effect.View = renderContext.Camera.View; effect.Projection = renderContext.Camera.Projection; effect.World = WorldMatrix; } mesh.Draw(); } } }
public void DrawPlayerHealthV2(RenderContext _renderContext) { Texture2D healthTexture; if (player.GetHealth() == GameConstants.HEALTH) { healthTexture = _textures["LightGreen"]; } else if (player.GetHealth() < GameConstants.HEALTH && player.GetHealth() > 1) { healthTexture = _textures["LightYellow"]; } else { healthTexture = _textures["LightRed"]; } Vector2 origin = new Vector2(_textures["Gear2"].Bounds.Width / 2, _textures["Gear2"].Bounds.Height / 2); // The background the health gears rests on spriteBatch.Draw(_textures["GearHealthBar"], new Rectangle(playerHealthCountGear.X , playerHealthCountGear.Center.Y - 15, playerHealthCountGear.Width * GameConstants.HEALTH + 5, 30), Color.White); float empAngle = 0f; // Draw the amount of gears based on max health count for (int i = 0; i < GameConstants.HEALTH; i++) { float angle = rotationAngle; Vector2 position = new Vector2(playerHealthCountGear.X + playerHealthCountGear.Width / 2 + i * (playerHealthCountGear.Width - 3), playerHealthCountGear.Y + playerHealthCountGear.Height / 2); // Reverse the spin of every odd gears if (i % 2 == 0) angle = -(angle+2f); // Centers and resizes the health lights inside the health gears int offset = 20; if (i < player.GetHealth()) // Gears for health that has not taken damage { spriteBatch.Draw(healthTexture, new Rectangle((int)position.X - offset, (int)position.Y - offset, playerHealthCountGear.Width - offset, playerHealthCountGear.Width - offset), Color.White); spriteBatch.Draw(_textures["Gear2"], position, null, Color.White, angle, origin, (float)playerHealthCountGear.Width / _textures["Gear2"].Width, SpriteEffects.None, 0); } else if (i == player.GetHealth()) // The gear that animates from left to right when damage is taken { if (player.GetHealth() == 1) healthTexture = _textures["LightYellow"]; if (player.IsInvuln()) { spriteBatch.End(); healthState.Parameters["healthState"].SetValue(player.GetTimeScale()); spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, healthState); spriteBatch.Draw(healthTexture, new Rectangle((int)(position.X - offset + 20 * player.damageDelayTime), (int)position.Y - offset, playerHealthCountGear.Width - offset, playerHealthCountGear.Width - offset), Color.White); spriteBatch.End(); spriteBatch.Begin(); spriteBatch.Draw(_textures["Gear2"], new Vector2(position.X + 20 * player.damageDelayTime, position.Y), null, Color.White, angle, origin, (float)playerHealthCountGear.Width / _textures["Gear2"].Width, SpriteEffects.None, 0); damageTaken = true; empAngle = angle; } else { if (damageTaken) { healthGearAnglesList.Add(angle); damageTaken = false; } spriteBatch.End(); healthState.Parameters["healthState"].SetValue(0); spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, healthState); spriteBatch.Draw(healthTexture, new Rectangle((int)(position.X - offset + 20 * player.damageDelayTime), (int)position.Y - offset, playerHealthCountGear.Width - offset, playerHealthCountGear.Width - offset), Color.White); spriteBatch.End(); spriteBatch.Begin(); spriteBatch.Draw(_textures["Gear2"], new Vector2(position.X + 20, position.Y), null, Color.White, healthGearAnglesList[GameConstants.HEALTH - i - 1], origin, (float)playerHealthCountGear.Width / _textures["Gear2"].Width, SpriteEffects.None, 0); } } else // Stop rotating the gears that represent missing health { if (player.GetHealth() == 1) healthTexture = _textures["LightYellow"]; spriteBatch.End(); healthState.Parameters["healthState"].SetValue(0); spriteBatch.Begin(0, BlendState.AlphaBlend, null, null, null, healthState); spriteBatch.Draw(healthTexture, new Rectangle((int)(position.X - offset + 20), (int)position.Y - offset, playerHealthCountGear.Width - offset, playerHealthCountGear.Width - offset), Color.White); spriteBatch.End(); spriteBatch.Begin(); spriteBatch.Draw(_textures["Gear2"], new Vector2(position.X + 20, position.Y), null, Color.White, healthGearAnglesList[GameConstants.HEALTH - i - 1], origin, (float)playerHealthCountGear.Width / _textures["Gear2"].Width, SpriteEffects.None, 0); } } // Player Portrait spriteBatch.Draw(_textures["LightGreen"], centerHealthGear, new Color(0.7f, 0, 0.7f)); spriteBatch.Draw(_textures["PlayerPortrait"], centerHealthGear, Color.White); spriteBatch.Draw(_textures["Gear2"], new Vector2(playerGear.X + 75, playerGear.Y + 75), null, Color.White, rotationAngle, origin, (float)playerGear.Width / _textures["Gear2"].Width, SpriteEffects.None, 0); }
//Will need to override update to move hitbox as well. public override void Update(RenderContext renderContext) { base.Update(renderContext); }
/// <summary> /// Constructor. Initialize game data here /// </summary> public GameplayScreen(int levelNum) { this.levelNum = levelNum; // Sets level data to level and sets level par time from file. levelData = new GameData.LevelData(levelNum, TimeSpan.Zero); // transition time used for screen transitions TransitionOnTime = TimeSpan.FromSeconds(1); TransitionOffTime = TimeSpan.FromSeconds(0.5); pauseAction = new InputAction( new Buttons[] { Buttons.Start, Buttons.Back }, new Keys[] { Keys.Escape }, true); // initialize rendercontext and camera _renderContext = new RenderContext(); _camera = new BaseCamera(); _camera.Translate(new Vector3(0, 0, 10)); _renderContext.Camera = _camera; // initialize models,textures,sounds _models = new Dictionary<string, Model>(); _textures = new Dictionary<string, Texture2D>(); _sounds = new Dictionary<string, SoundEffect>(); random = new Random(); //init fps counter fpsCount = new FPSCounter(_renderContext); healthGearAnglesList = new List<float>(); messageActive = false; }
public override void Draw(RenderContext renderContext) { //Do nothing - don't call base }