public void LockToSprite(AnimatedSprite sprite) { Position.X = sprite.Position.X + sprite.Width / 2 - (TileEngine.ViewportWidth / 2); Position.Y = sprite.Position.Y + sprite.Height / 2 - (TileEngine.ViewportHeight / 2); }
protected override void Load() { SpriteFont font = Engine.Content.Load<SpriteFont>("Content/Georgia"); Explosion = new AnimatedSprite(0, 0, 0,"Content/explosions",-4,0,64, 64, 16); Explosion.NextSheetLine(0); this.AddComponent(Explosion); // Used for getting keyevents /* KeyboardInput kInput = new KeyboardInput(); kInput.Name = "keyboard"; this.AddComponent(kInput);*/ Sprite sprite = new Sprite(300, 300, 0, "Content/puppy"); sprite.Name = "puppy"; this.AddComponent(sprite); sprite.SourceRectangle = new Rectangle(0, 0, 160, 150); sprite.Scale = 2f; Sprite sprite2 = new Sprite(200, 300, 0, "Content/puppy"); sprite2.Name = "puppy2"; this.AddComponent(sprite2); sprite2.SourceRectangle = new Rectangle(50, 40, 160, 150); sprite2.Scale = 2f; Sprite sprite3 = new Sprite(200, 1000, 0, "Content/puppy"); sprite3.Name = "puppy3"; this.AddComponent(sprite3); sprite3.SourceRectangle = new Rectangle(0, 0, 160, 150); sprite3.Scale = 2f; }
public bool CheckUnWalkableTile(AnimatedSprite sprite, Vector2 motion) { Vector2 nextLocation = sprite.Position + motion; Rectangle nextRectangle = new Rectangle( (int)nextLocation.X, (int)nextLocation.Y, sprite.Width, sprite.Height); if (motion.Y < 0 && motion.X < 0) { return Session.CurrentMap.CheckUpAndLeft(nextRectangle); } else if (motion.Y < 0 && motion.X == 0) { return Session.CurrentMap.CheckUp(nextRectangle); } else if (motion.Y < 0 && motion.X > 0) { return Session.CurrentMap.CheckUpAndRight(nextRectangle); } else if (motion.Y == 0 && motion.X < 0) { return Session.CurrentMap.CheckLeft(nextRectangle); } else if (motion.Y == 0 && motion.X > 0) { return Session.CurrentMap.CheckRight(nextRectangle); } else if (motion.Y > 0 && motion.X < 0) { return Session.CurrentMap.CheckDownAndLeft(nextRectangle); } else if (motion.Y > 0 && motion.X == 0) { return Session.CurrentMap.CheckDown(nextRectangle); } return Session.CurrentMap.CheckDownAndRight(nextRectangle); }
protected override void Load() { // TODO: Test worked, no just put it to use content pipeline // Load each tile used in map and ask for a TileList TileLoader loader = new TileLoader("Content/XMLmap/testi.xml", Engine.Content); TileList list = loader.GetTileList(); // Load all the layers from file and ask for a maplayer list LayerLoader layerLoader = new LayerLoader("Content/XMLmap/layertesti.xml", list); List<MapLayer> layers = layerLoader.GetLayerList(); tileEngine = new TileEngine(32, 32, Engine.GameRef); // Make map with all those layers Session.CurrentMap = new TileMap(layers); // Add components and controls etc animations = new Dictionary<AnimationKey, Animation>(); ; Texture2D playerTexture = Engine.Content.Load<Texture2D>("content/Sprites/malefighter"); Animation animation = new Animation(3, 28, 28, 0, 0); animations.Add(AnimationKey.Down, animation); animation = new Animation(3, 28, 28, 0, 28); animations.Add(AnimationKey.Left, animation); animation = new Animation(3, 28, 28, 0, 56); animations.Add(AnimationKey.Right, animation); animation = new Animation(3, 28, 28, 0, 84); animations.Add(AnimationKey.Up, animation); playerSprite = new AnimatedSprite(playerTexture, animations); playerSprite.IsAnimating = true; AddComponent(playerSprite); SpriteFont spriteFont = Engine.Content.Load<SpriteFont>("Content/Fonts/Georgia"); Label text = new Label(spriteFont, Engine.SpriteBatch); text.Text = "HakaGame 1.0"; text.Size = spriteFont.MeasureString(text.Text); text.Position = new Vector2(100, 100); Controls.Add(text); base.Load(); }