public override void Draw(RoomGraphics g) { DepthLayer depthLayer = Graphics.CurrentDepthLayer; // Draw tools under. foreach (UnitTool tool in tools) { if (!tool.DrawAboveUnit) { Vector2F drawPosition = position - new Vector2F(0, zPosition) + Graphics.DrawOffset + tool.DrawOffset; g.DrawAnimationPlayer(tool.AnimationPlayer, tool.ImageVariantID, drawPosition, depthLayer, position); } } // Draw entity. base.Draw(g); // Draw tools over. foreach (UnitTool tool in tools) { if (tool.DrawAboveUnit) { Vector2F drawPosition = position - new Vector2F(0, zPosition) + Graphics.DrawOffset + tool.DrawOffset; g.DrawAnimationPlayer(tool.AnimationPlayer, tool.ImageVariantID, drawPosition, depthLayer, position); } } }
// Create an effect that plays an animation and then dissapears public Effect(Animation animation, DepthLayer depthLayer, bool updateOnRoomPaused = false) : this() { destroyTimer = -1; destroyOnAnimationComplete = true; Graphics.PlayAnimation(animation); Graphics.DepthLayer = depthLayer; this.UpdateOnRoomPaused = updateOnRoomPaused; }
public DrawablePart(string path, Vector2 frameSize, DepthLayer depthlayer) { this.path = path; this.frameSize = frameSize; color = Color.White; defaultColor = color; alpha = 1f; sourceRectangle = new Rectangle(0, 0, (int)frameSize.X, (int)frameSize.Y); scale = Vector2.One; depthLayer = depthlayer; rotation = 0; }
public void Draw(RoomGraphics g) { if (!isVisible) { return; } // Determine the depth layer based on the tile grid layer. if (tile.Layer == 0) { depthLayer = DepthLayer.TileLayer1; } else if (tile.Layer == 1) { depthLayer = DepthLayer.TileLayer2; } else if (tile.Layer == 2) { depthLayer = DepthLayer.TileLayer3; } // Determine draw position. Vector2F drawPosition = (useAbsoluteDrawPosition ? absoluteDrawPosition : tile.Position); drawPosition += (raisedDrawOffset + drawOffset); // Draw the tile's as-object sprite. if (tile.IsMoving && !tile.SpriteAsObject.IsNull) { g.DrawSpriteAnimation(tile.SpriteAsObject, imageVariant, tile.RoomControl.GameControl.RoomTicks, drawPosition, depthLayer, tile.Position); } // Draw the animation player. else { float playbackTime; if (syncPlaybackWithRoomTicks) { playbackTime = tile.RoomControl.GameControl.RoomTicks; } else { playbackTime = animationPlayer.PlaybackTime; } g.DrawAnimationPlayer(animationPlayer, imageVariant, playbackTime, drawPosition, depthLayer, tile.Position); } }
//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public TileGraphicsComponent(Tile tile) { this.tile = tile; this.animationPlayer = new AnimationPlayer(); this.isVisible = true; this.depthLayer = DepthLayer.TileLayer1; this.imageVariant = 0; this.raisedDrawOffset = Point2I.Zero; this.drawOffset = Point2I.Zero; this.syncPlaybackWithRoomTicks = true; this.isAnimatedWhenPaused = false; this.absoluteDrawPosition = Vector2F.Zero; this.useAbsoluteDrawPosition = false; }
// Draw the entity's graphics on the given depth layer. public void Draw(RoomGraphics g, DepthLayer layer) { if (!isVisible) { return; } // Draw the shadow. if (isShadowVisible && entity.ZPosition >= 1 && entity.GameControl.RoomTicks % 2 == 0 && !entity.RoomControl.IsSideScrolling) { g.DrawSprite(GameData.SPR_SHADOW, Entity.Position + shadowDrawOffset, DepthLayer.Shadows); } if (isFlickering && !flickerIsVisible) { return; } // Change the variant if hurting. int newImageVariant = imageVariant; if (isHurting && entity.GameControl.RoomTicks % 8 >= 4) { newImageVariant = GameData.VARIANT_HURT; } // Draw the sprite/animation. Vector2F drawPosition = Entity.Position - new Vector2F(0, Entity.ZPosition); g.DrawAnimationPlayer(animationPlayer, newImageVariant, drawPosition + drawOffset, layer, entity.Position); // Draw the ripples effect. if (isRipplesEffectVisible && entity.Physics.IsEnabled && entity.Physics.IsInPuddle) { g.DrawAnimation(GameData.ANIM_EFFECT_RIPPLES, entity.GameControl.RoomTicks, entity.Position + ripplesDrawOffset, layer, entity.Position); } // Draw the grass effect. if (isGrassEffectVisible && entity.Physics.IsEnabled && entity.Physics.IsInGrass) { g.DrawAnimation(GameData.ANIM_EFFECT_GRASS, grassAnimationTicks, entity.Position + grassDrawOffset, layer, entity.Position); } }
// Sort a depth layer. Sprites with smaller y coordinates // will be drawn before ones with larger y coordinates. public void SortDepthLayer(DepthLayer layer) { // Check if the layer is empty. int layerIndex = (int)layer; if (layerHeads[layerIndex] == null) { return; } // Create a list of the drawing instructions. List <DrawingInstruction> instructions = new List <DrawingInstruction>(layerCounts[layerIndex]); DrawingInstruction instruction = layerHeads[layerIndex]; while (instruction != null) { instructions.Add(instruction); instruction = instruction.next; } // Sort the list by depth origin Y. instructions.Sort(delegate(DrawingInstruction a, DrawingInstruction b) { if (Math.Round(a.depthOrigin.Y) < Math.Round(b.depthOrigin.Y)) { return(-1); } return(1); }); // Update the drawing instruction linked list. layerHeads[layerIndex] = instructions[0]; layerTails[layerIndex] = instructions[instructions.Count - 1]; for (int i = 0; i < instructions.Count; i++) { if (i + 1 < instructions.Count) { instructions[i].next = instructions[i + 1]; } else { instructions[i].next = null; } } }
/// <summary> /// Draws a specific depth layer immediately. /// </summary> /// <param name="layer"></param> private void DrawDepthLayer(DepthLayer layer) { foreach (Texture texture in new List <Texture>(Textures.Values)) { if (!layer.BlockEntriesByTexture.ContainsKey(texture)) { continue; } List <BlockEntity> entities = layer.BlockEntriesByTexture[texture]; GraphicsManager.SetTexture(texture); foreach (BlockEntity entity in entities) { DrawBlockEntity(entity); } } }
//----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- public GraphicsComponent(Entity entity) { this.entity = entity; this.animationPlayer = new AnimationPlayer(); this.depthLayer = DepthLayer.None; this.depthLayerInAir = DepthLayer.None; this.isVisible = true; this.isShadowVisible = true; this.grassDrawOffset = Point2I.Zero; this.ripplesDrawOffset = Point2I.Zero; this.shadowDrawOffset = Point2I.Zero; this.isGrassEffectVisible = true; this.isRipplesEffectVisible = true; this.grassAnimationTicks = 0; this.drawOffset = Point2I.Zero; this.isFlickering = false; this.flickerAlternateDelay = 2; this.flickerTimer = 0; this.flickerIsVisible = true; this.imageVariant = GameData.VARIANT_NONE; this.isAnimatedWhenPaused = false; this.isHurting = false; }
// Draw a sprite. public void DrawSprite(Sprite sprite, int imageVariant, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { // There's a bias of 0.001f to account for rounding inconsistancies with the value 0.5f. position.X = GMath.Round(position.X + 0.001f); position.Y = GMath.Round(position.Y + 0.001f); DrawingInstruction instruction = new DrawingInstruction( sprite, imageVariant, position, depthOrigin); // Add the instruction to the end of the linked list for its layer. int layerIndex = (int)depth; if (layerHeads[layerIndex] == null) { layerHeads[layerIndex] = instruction; layerTails[layerIndex] = instruction; } else { layerTails[layerIndex].next = instruction; layerTails[layerIndex] = instruction; } layerCounts[layerIndex]++; }
public EffectFallingObject(DepthLayer depthLayer) : base(GameData.ANIM_EFFECT_FALLING_OBJECT) { Graphics.DepthLayer = depthLayer; }
//----------------------------------------------------------------------------- // Entity Drawing Functions (with variants, no depth origin) //----------------------------------------------------------------------------- // Draw an animation player. public void DrawAnimationPlayer(AnimationPlayer animationPlayer, int imageVariant, Vector2F position, DepthLayer depth) { DrawAnimationPlayer(animationPlayer, imageVariant, position, depth, Vector2F.Zero); }
// Draw an animation at the given playback time. public void DrawAnimation(Animation animation, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { if (animation.LoopMode == LoopMode.Repeat) { if (animation.Duration == 0) time = 0; else time %= animation.Duration; } for (int i = 0; i < animation.Frames.Count; ++i) { AnimationFrame frame = animation.Frames[i]; if (time < frame.StartTime) return; if (time < frame.StartTime + frame.Duration || (time >= animation.Duration && frame.StartTime + frame.Duration == animation.Duration)) { DrawSprite(frame.Sprite, imageVariant, position, depth, depthOrigin); } } }
// Draw an animation at the given playback time. public void DrawAnimation(Animation animation, int imageVariant, float time, Vector2F position, DepthLayer depth) { DrawAnimation(animation, imageVariant, time, position, depth, Vector2F.Zero); }
// Draw an sprite or animation at the given playback time. public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { if (spriteAnimation.IsAnimation) DrawAnimation(spriteAnimation.Animation, imageVariant, time, position, depth, depthOrigin); else DrawSprite(spriteAnimation.Sprite, imageVariant, position, depth, depthOrigin); }
// Draw an sprite or animation at the given playback time. public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, int imageVariant, float time, Vector2F position, DepthLayer depth) { DrawSpriteAnimation(spriteAnimation, imageVariant, time, position, depth, Vector2F.Zero); }
// Draw an animation at the given playback time. public void DrawAnimation(Animation animation, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { DrawAnimation(animation, 0, time, position, depth, depthOrigin); }
//----------------------------------------------------------------------------- // Entity Drawing Functions (no variants, with depth origin) //----------------------------------------------------------------------------- // Draw an animation player. public void DrawAnimationPlayer(AnimationPlayer animationPlayer, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { DrawAnimationPlayer(animationPlayer, 0, position, depth, depthOrigin); }
// Draw an animation at the given playback time. public void DrawAnimation(Animation animation, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { if (animation.LoopMode == LoopMode.Repeat) { if (animation.Duration == 0) { time = 0; } else { time %= animation.Duration; } } for (int i = 0; i < animation.Frames.Count; ++i) { AnimationFrame frame = animation.Frames[i]; if (time < frame.StartTime) { return; } if (time < frame.StartTime + frame.Duration || (time >= animation.Duration && frame.StartTime + frame.Duration == animation.Duration)) { DrawSprite(frame.Sprite, imageVariant, position, depth, depthOrigin); } } }
// Draw an sprite or animation at the given playback time. public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { if (spriteAnimation.IsAnimation) { DrawAnimation(spriteAnimation.Animation, imageVariant, time, position, depth, depthOrigin); } else { DrawSprite(spriteAnimation.Sprite, imageVariant, position, depth, depthOrigin); } }
// Draw an animation player at the given time. public void DrawAnimationPlayer(AnimationPlayer animationPlayer, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { if (animationPlayer.Sprite != null) { DrawSprite(animationPlayer.Sprite, imageVariant, position, depth, depthOrigin); } else if (animationPlayer.SubStrip != null) { DrawAnimation(animationPlayer.SubStrip, imageVariant, time, position, depth, depthOrigin); } }
//----------------------------------------------------------------------------- // Entity Drawing Functions (with variants, with depth origin) //----------------------------------------------------------------------------- // Draw an animation player. public void DrawAnimationPlayer(AnimationPlayer animationPlayer, int imageVariant, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { DrawAnimationPlayer(animationPlayer, imageVariant, animationPlayer.PlaybackTime, position, depth, depthOrigin); }
// Draw a sprite. public void DrawSprite(Sprite sprite, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { DrawSprite(sprite, 0, position, depth, depthOrigin); }
// Draw an animation player at the given playback time. public void DrawAnimationPlayer(AnimationPlayer animationPlayer, float time, Vector2F position, DepthLayer depth) { DrawAnimationPlayer(animationPlayer, 0, time, position, depth, Vector2F.Zero); }
// Draw the entity's graphics on the given depth layer. public void Draw(RoomGraphics g, DepthLayer layer) { if (!isVisible) return; // Draw the shadow. if (isShadowVisible && entity.ZPosition >= 1 && entity.GameControl.RoomTicks % 2 == 0 && !entity.RoomControl.IsSideScrolling) { g.DrawSprite(GameData.SPR_SHADOW, Entity.Position + shadowDrawOffset, DepthLayer.Shadows); } if (isFlickering && !flickerIsVisible) return; // Change the variant if hurting. int newImageVariant = imageVariant; if (isHurting && entity.GameControl.RoomTicks % 8 >= 4) newImageVariant = GameData.VARIANT_HURT; // Draw the sprite/animation. Vector2F drawPosition = Entity.Position - new Vector2F(0, Entity.ZPosition); g.DrawAnimationPlayer(animationPlayer, newImageVariant, drawPosition + drawOffset, layer, entity.Position); // Draw the ripples effect. if (isRipplesEffectVisible && entity.Physics.IsEnabled && entity.Physics.IsInPuddle) { g.DrawAnimation(GameData.ANIM_EFFECT_RIPPLES, entity.GameControl.RoomTicks, entity.Position + ripplesDrawOffset, layer, entity.Position); } // Draw the grass effect. if (isGrassEffectVisible && entity.Physics.IsEnabled &&entity.Physics.IsInGrass) { g.DrawAnimation(GameData.ANIM_EFFECT_GRASS, grassAnimationTicks, entity.Position + grassDrawOffset, layer, entity.Position); } }
// Draw a sprite. public void DrawSprite(Sprite sprite, int imageVariant, Vector2F position, DepthLayer depth) { DrawSprite(sprite, imageVariant, position, depth, Vector2F.Zero); }
// Draw a sprite. public void DrawSprite(Sprite sprite, int imageVariant, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { // There's a bias of 0.001f to account for rounding inconsistancies with the value 0.5f. position.X = GMath.Round(position.X + 0.001f); position.Y = GMath.Round(position.Y + 0.001f); DrawingInstruction instruction = new DrawingInstruction( sprite, imageVariant, position, depthOrigin); // Add the instruction to the end of the linked list for its layer. int layerIndex = (int) depth; if (layerHeads[layerIndex] == null) { layerHeads[layerIndex] = instruction; layerTails[layerIndex] = instruction; } else { layerTails[layerIndex].next = instruction; layerTails[layerIndex] = instruction; } layerCounts[layerIndex]++; }
// Draw an sprite or animation at the given playback time. public void DrawSpriteAnimation(SpriteAnimation spriteAnimation, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { DrawSpriteAnimation(spriteAnimation, 0, time, position, depth, depthOrigin); }
// Sort a depth layer. Sprites with smaller y coordinates // will be drawn before ones with larger y coordinates. public void SortDepthLayer(DepthLayer layer) { // Check if the layer is empty. int layerIndex = (int) layer; if (layerHeads[layerIndex] == null) return; // Create a list of the drawing instructions. List<DrawingInstruction> instructions = new List<DrawingInstruction>(layerCounts[layerIndex]); DrawingInstruction instruction = layerHeads[layerIndex]; while (instruction != null) { instructions.Add(instruction); instruction = instruction.next; } // Sort the list by depth origin Y. instructions.Sort(delegate(DrawingInstruction a, DrawingInstruction b) { if (Math.Round(a.depthOrigin.Y) < Math.Round(b.depthOrigin.Y)) return -1; return 1; }); // Update the drawing instruction linked list. layerHeads[layerIndex] = instructions[0]; layerTails[layerIndex] = instructions[instructions.Count - 1]; for (int i = 0; i < instructions.Count; i++) { if (i + 1 < instructions.Count) instructions[i].next = instructions[i + 1]; else instructions[i].next = null; } }
// Draw an animation player at the given time. public void DrawAnimationPlayer(AnimationPlayer animationPlayer, int imageVariant, float time, Vector2F position, DepthLayer depth, Vector2F depthOrigin) { if (animationPlayer.Sprite != null) DrawSprite(animationPlayer.Sprite, imageVariant, position, depth, depthOrigin); else if (animationPlayer.SubStrip != null) DrawAnimation(animationPlayer.SubStrip, imageVariant, time, position, depth, depthOrigin); }
// Draw a sprite. public void DrawSprite(Sprite sprite, Vector2F position, DepthLayer depth) { DrawSprite(sprite, 0, position, depth, Vector2F.Zero); }
public void Draw(RoomGraphics g) { if (!isVisible) return; // Determine the depth layer based on the tile grid layer. if (tile.Layer == 0) depthLayer = DepthLayer.TileLayer1; else if (tile.Layer == 1) depthLayer = DepthLayer.TileLayer2; else if (tile.Layer == 2) depthLayer = DepthLayer.TileLayer3; // Determine draw position. Vector2F drawPosition = (useAbsoluteDrawPosition ? absoluteDrawPosition : tile.Position); drawPosition += (raisedDrawOffset + drawOffset); // Draw the tile's as-object sprite. if (tile.IsMoving && !tile.SpriteAsObject.IsNull) { g.DrawSpriteAnimation(tile.SpriteAsObject, imageVariant, tile.RoomControl.GameControl.RoomTicks, drawPosition, depthLayer, tile.Position); } // Draw the animation player. else { float playbackTime; if (syncPlaybackWithRoomTicks) playbackTime = tile.RoomControl.GameControl.RoomTicks; else playbackTime = animationPlayer.PlaybackTime; g.DrawAnimationPlayer(animationPlayer, imageVariant, playbackTime, drawPosition, depthLayer, tile.Position); } }