public static PlatformContext Load(BinaryReader reader) { var version = reader.ReadInt32(); if (version != Version) { throw new InvalidDataException("Bad version"); } var context = new PlatformContext(); context.BlockStore = BinBlockStoreSerializer.Load(reader); context.Map = BinTileMapSerializer.Load(reader); var numLights = reader.ReadInt32(); while (numLights > 0) { context.AttachLightSource(BinLightSerializer.Load(reader)); numLights--; } context.LightsEnabled = reader.ReadBoolean(); context.Time = TimeSpan.FromSeconds(reader.ReadDouble()); var numSpawns = reader.ReadInt32(); while (numSpawns > 0) { var spawn = BinSpawnSerializer.Load(reader); context.Spawn.Add(spawn); numSpawns--; } return(context); }
public void AddPrefabs(PlatformContext context) { context.BlockStore.Prefabs.Add("tree1", new VisibleObjectPrefab(context, Store.Instance.Sprites <ISpriteTemplate>("Base", "tree1"))); context.BlockStore.Prefabs.Add("tree2", new VisibleObjectPrefab(context, Store.Instance.Sprites <ISpriteTemplate>("Base", "tree2"))); context.BlockStore.Prefabs.Add("tree3", new VisibleObjectPrefab(context, Store.Instance.Sprites <ISpriteTemplate>("Base", "tree3"))); context.BlockStore.Prefabs.Add("tree4", new VisibleObjectPrefab(context, Store.Instance.Sprites <ISpriteTemplate>("Base", "tree4"))); }
public static void Save(string filename, PlatformContext context) { using (var stream = File.OpenWrite(filename)) using (var writer = new BinaryWriter(stream)) { Save(writer, context); } }
public CharacterObject(PlatformContext context) : base(context) { this.facing = Facing.Right; this.actions = Actions.None; this.currentAnimation = null; this.character = null; this.controller = null; this.OnCollide += this.Collide; }
public static void Save(BinaryWriter writer, PlatformContext context) { writer.Write((Int32)Version); BinBlockStoreSerializer.Save(writer, context.BlockStore); BinTileMapSerializer.Save(writer, context.Map); var lights = context.LightSources.ToList(); writer.Write((Int32)lights.Count); foreach (var light in lights) { BinLightSerializer.Save(writer, light); } writer.Write(context.LightsEnabled); writer.Write((Double)context.Time.TotalSeconds); writer.Write((Int32)context.Spawn.Count); foreach (var spawn in context.Spawn) { BinSpawnSerializer.Save(writer, spawn); } }
public override void Draw(Renderer renderer, GameTime gameTime) { this.frame += gameTime.GetElapsedSeconds() * this.Sprite.FPS; var intFrame = (int)Math.Floor(this.frame); if (intFrame >= this.Sprite.NumberOfFrames) { intFrame = 0; this.frame = 0; } if (this.IsVisible()) { var depth = PlatformContext.ZToDepth(this.Z); var colour = Color.White; var scale = Vector2.One; var offset = Vector2.Zero; if (this.Z < 0.5f) { var alpha = (byte)((1f - (0.5f - this.Z) * 2) * 255); colour = new Color(alpha, alpha, alpha, alpha); //scale = new Vector2(1f - (this.Z - 0.5f) * 2); //offset = new Vector2((1f - scale.X) * this.sprite.Width / 2, (1f - scale.Y) * this.sprite.Height); } this.Sprite.DrawSprite(renderer.World, intFrame, this.Position + offset, colour, 0, scale, SpriteEffects.None, depth); if (AbstractObject.DebugInfo) { renderer.World.DrawRectangle(this.bounds, Color.White); var font = Store.Instance.Fonts("Base", "debug"); var sb = this.DebugData().ToString(); var size = font.Font.MeasureString(sb); renderer.Screen.DrawString(font, sb, this.Context.WorldToScreen(this.Position) - new Vector2(0, size.Y), Color.White); //renderer.World.DrawString(Store.Instance.Fonts("Base", "debug"), $"{this.bounds}, {this.velocity}, {this.OnGround}", this.Position - new Vector2(0, 20), Color.White); } } base.Draw(renderer, gameTime); }
public VisiblePlatformObject(PlatformContext context) : base(context) { }
public PlatformObject(PlatformContext context) : base(context) { //context.AddObject(this); }
public VisibleObjectPrefab(PlatformContext context, ISpriteTemplate sprite) { this.context = context; this.sprite = sprite; }
public PlayerSpawn(PlatformContext context, Character character, Vector2 position) { this.context = context; this.character = character; this.position = position; }