Beispiel #1
0
        public TransformTest()
        {
            Transform transform = GetComponent <Transform>();

            transform.Translate(new Vector2(50, 0));
            transform.Rotate(45);

            BasicSprite s = ItemSpriteFactory.Instance.CreateBlueArrow();

            AddComponent(new Sprite(s));

            TransformDebugger t = new TransformDebugger();

            AddComponent(t);

            // Add test child entity
            // Position purely arbitrary and just for testing
            Item child = new Item(EnemySpriteFactory.Instance.CreateBlueKeese(), new Vector2(200, 200));

            GetComponent <Transform>().AddChild(child);

            Transform childTransform = child.GetComponent <Transform>();

            childTransform.position = new Vector2(100, 10);
        }
Beispiel #2
0
        // This class is kind of weird
        // First of all, all elements are drawn to external texture, why?
        // To ensure that the HUD is
        // a) drawn all at once
        // b) drawn over everything else (we will draw the HUD last in the draw order of the main draw function)
        // and c) not a part of collision detection
        // This also allows us to define custom behavior for drawing whatever sprites are added to
        // the HUD's list of sprites to draw. And adjust the color of the entire HUD itself.
        public HUD(Game game, GraphicsDevice d) : base(new RenderTarget2D(d,
                                                                          d.PresentationParameters.BackBufferWidth,
                                                                          d.PresentationParameters.BackBufferHeight,
                                                                          false,
                                                                          d.PresentationParameters.BackBufferFormat,
                                                                          DepthFormat.Depth24), false)
        {
            BasicSprite hud_key_frame = new BasicSprite(game, "hud_key_frame", false);

            hud_key_frame.spriteSize = new Point(60, 60);
            hud_key_frame.spritePos  = new Vector2(740, 0);

            BasicSprite hud_health_frame = new BasicSprite(game, "health_bar_frame", false);

            hud_health_frame.spriteSize = new Point(200, 30);
            hud_health_frame.spritePos  = new Vector2(1, 0);

            BasicSprite hud_health_color = new BasicSprite(game, "health_bar_color", false);

            hud_health_color.spriteSize = new Point(202, 32);
            hud_health_color.spritePos  = new Vector2(0, 0);

            hud_key_frame.addTo(hudSprites);
            hud_health_color.addTo(hudSprites);
            hud_health_frame.addTo(hudSprites);

            gd = d;
        }
Beispiel #3
0
        // This class is kind of weird
        // First of all, all elements are drawn to external texture, why?
        // To ensure that the HUD is
        // a) drawn all at once
        // b) drawn over everything else (we will draw the HUD last in the draw order of the main draw function)
        // and c) not a part of collision detection
        // This also allows us to define custom behavior for drawing whatever sprites are added to
        // the HUD's list of sprites to draw. And adjust the color of the entire HUD itself.
        public HUD(Game game, GraphicsDevice d)
            : base(new RenderTarget2D(d,
                d.PresentationParameters.BackBufferWidth,
                d.PresentationParameters.BackBufferHeight,
                false,
                d.PresentationParameters.BackBufferFormat,
                DepthFormat.Depth24), false)
        {
            BasicSprite hud_key_frame = new BasicSprite(game, "hud_key_frame", false);
            hud_key_frame.spriteSize = new Point(60, 60);
            hud_key_frame.spritePos = new Vector2(740, 0);

            BasicSprite hud_health_frame = new BasicSprite(game, "health_bar_frame", false);
            hud_health_frame.spriteSize = new Point(200, 30);
            hud_health_frame.spritePos = new Vector2(1, 0);

            BasicSprite hud_health_color = new BasicSprite(game, "health_bar_color", false);
            hud_health_color.spriteSize = new Point(202, 32);
            hud_health_color.spritePos = new Vector2(0, 0);

            hud_key_frame.addTo(hudSprites);
            hud_health_color.addTo(hudSprites);
            hud_health_frame.addTo(hudSprites);

            gd = d;
        }
        public Aquamentus(Vector2 pos)
        {
            GetComponent <Transform>().position = pos;
            Constants.SetLayerDepth(this, Constants.LayerDepth.Enemy);

            BasicSprite spriteImage = BossSpriteFactory.Instance.CreateAquamentus();
            Sprite      sprite      = new Sprite(spriteImage);

            AddComponent(sprite);
            sprite.SetAnimate(true);

            BehaviorScript attack = new AquamentusAttack();

            AddComponent(attack);

            BehaviorScript movement = new AquamentusMovement();

            AddComponent(movement);

            Collider coll = new Collider();

            AddComponent(coll);
            // ToDo: what is Aquamentus' damage?
            coll.response = new EnemyCollisionResponse(this, Constants.STALFO_CONTACT_DAMAGE);

            BehaviorScript health = new AquamentusHealthManagement(Constants.AQUAMENTUS_HEALTH);

            AddComponent(health);
        }
Beispiel #5
0
 //doors that will open when the player has acquired the key
 public Door(Game game, string orientation)
     : base(game, "closed_door_" + orientation + "_metal", true)
 {
     openSprite = new BasicSprite(game, "open_door_" + orientation + "_metal", false);
     doorLight = new LightEffect(game, "Lights\\open_door_" + orientation + "_light", Color.White);
     doorLight.hidden = true;
 }
Beispiel #6
0
        public Stalfo(Vector2 pos)
        {
            GetComponent <Transform>().position = pos;

            BasicSprite spriteImage = EnemySpriteFactory.Instance.CreateStalfo();
            Sprite      sprite      = new Sprite(spriteImage);

            AddComponent(sprite);
            sprite.SetAnimate(false);

            BehaviorScript state = new StalfoStatePattern(this);

            AddComponent(state);

            BehaviorScript movement = new StalfoMovement();

            AddComponent(movement);

            var coll = new Collider();

            coll.response = new EnemyCollisionResponse(this, Constants.STALFO_CONTACT_DAMAGE);
            AddComponent(coll);
            Constants.SetLayerDepth(this, Constants.LayerDepth.Enemy);

            BehaviorScript health = new StalfoHealthManagement(Constants.STALFO_HEALTH);

            AddComponent(health);
        }
Beispiel #7
0
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Rectangle bounds)
        {
            float scale = 32 * Zoom;
            int   minX  = Math.Max((int)(Camera.X / 32 - 1), 0);
            int   minY  = Math.Max((int)(Camera.Y / 32 - 1), 0);
            int   maxX  = Math.Min((int)((Camera.X / 32 + bounds.Width / scale) + 2), Map.SizeX);
            int   maxY  = Math.Min((int)((Camera.Y / 32 + bounds.Height / scale) + 2), Map.SizeY);

            spriteBatch.Begin(SpriteSortMode.FrontToBack);
            for (int x = minX; x < maxX; x++)
            {
                for (int y = minY; y < maxY; y++)
                {
                    Tile tile = Map.Tiles[x, y];
                    spriteBatch.Draw(tile.Sprite.Texture, (tile.ScreenPosition - Camera) * Zoom, tile.Sprite.Source,
                                     Color.White, 0f, Vector2.Zero, Zoom, SpriteEffects.None, tile.DrawDepth);
                }
            }
            foreach (Creature creature in Map.Creatures)
            {
                BasicSprite sprite = Mods.Textures["Human"];
                spriteBatch.Draw(sprite.Texture, (creature.ScreenPosition - Camera) * Zoom, sprite.Source,
                                 Color.White, 0f, Vector2.Zero, Zoom, SpriteEffects.None, 1.0f);
            }
            spriteBatch.End();
        }
Beispiel #8
0
        private void LoadBiomes()
        {
            XmlDocument xml = new XmlDocument();

            xml.Load("Content/XML/Biomes.xml");
            foreach (XmlNode node in xml.SelectNodes("Biomes/Biome"))
            {
                string uid  = node.Attributes.GetNamedItem("UID").Value;
                string file = node.Attributes.GetNamedItem("File").Value;
                string name = node.Attributes.GetNamedItem("Name").Value;
                try
                {
                    using (Texture2D texture = TextureUtility.LoadTexture(GraphicsDevice, "Content/Graphics/Biomes/" + file))
                    {
                        Texture2D[,] variants = TextureUtility.Split(GraphicsDevice, texture, 64, 64);
                        BasicSprite[] sprites = new BasicSprite[variants.Length];
                        int           i = 0, maxY = variants.GetLength(1), maxX = variants.GetLength(0);
                        for (int y = 0; y < maxY; y++)
                        {
                            for (int x = 0; x < maxX; x++)
                            {
                                sprites[i] = Textures.Copy(variants[x, y]);
                                i++;
                            }
                        }
                        Biome biome = new Biome(uid, name, sprites);
                        Data.Biomes.Add(uid, biome);
                    }
                }
                catch
                {
                }
            }
            Textures.ApplyChanges();
        }
        public GoriyaBehavior(string color)
        {
            // Initial State
            state                = State.MOVING;
            direction            = Constants.Direction.RIGHT;
            framesSinceTurn      = 0;
            framesSinceThrow     = 0;
            framesBeforeLastFlip = 0;

            framesUntilThrow = Constants.GetRandomIntMinMax(50, 90);

            // sprites
            if (color.Equals("red"))
            {
                GoriyaLeft        = EnemySpriteFactory.Instance.CreateRedGoriyaLeft();
                GoriyaRight       = EnemySpriteFactory.Instance.CreateRedGoriyaRight();
                GoriyaUp          = EnemySpriteFactory.Instance.CreateRedGoriyaUp();
                GoriyaUpFlipped   = EnemySpriteFactory.Instance.CreateRedGoriyaUpFlipped();
                GoriyaDown        = EnemySpriteFactory.Instance.CreateRedGoriyaDown();
                GoriyaDownFlipped = EnemySpriteFactory.Instance.CreateRedGoriyaDownFlipped();
            }
            else
            {
                GoriyaLeft        = EnemySpriteFactory.Instance.CreateBlueGoriyaLeft();
                GoriyaRight       = EnemySpriteFactory.Instance.CreateBlueGoriyaRight();
                GoriyaUp          = EnemySpriteFactory.Instance.CreateBlueGoriyaUp();
                GoriyaUpFlipped   = EnemySpriteFactory.Instance.CreateBlueGoriyaUpFlipped();
                GoriyaDown        = EnemySpriteFactory.Instance.CreateBlueGoriyaDown();
                GoriyaDownFlipped = EnemySpriteFactory.Instance.CreateBlueGoriyaDownFlipped();
            }
        }
Beispiel #10
0
 public Tile(GameMap map, ushort x, ushort y, Terrain terrain, Random random)
     : base(map, x, y)
 {
     Terrain   = terrain;
     Sprite    = terrain.SpriteGroup.GetVariant(random);
     DrawDepth = (float)random.NextDouble();
 }
 public static Vector2 collisionDirection(BasicSprite s1, BasicSprite s2)
 {
     if (willCollide(s1, s2))
         return (s2.velocity - s1.velocity).getDirection();
     else
         return Vector2.Zero;
 }
Beispiel #12
0
 public UIWindowDynamicSprite(int edgeMargin,
                              BasicSprite topLeft, BasicSprite top, BasicSprite topRight,
                              BasicSprite middleLeft, BasicSprite fill, BasicSprite middleRight,
                              BasicSprite bottomLeft, BasicSprite bottom, BasicSprite bottomRight
                              ) : base(topLeft, top, topRight, middleLeft, fill, middleRight, bottomLeft, bottom, bottomRight)
 {
     EdgeMargin = edgeMargin;
 }
 public static Vector2 collisionDirection(BasicSprite s1, BasicSprite s2, GameTime time)
 {
     //returns the direction of how one collision box is colliding with another (i.e. The Gentleman hits the ground going straight down and the game recognizes that)
     if (willCollide(s1, s2, time))
         return (s2.velocity - s1.velocity).getDirection();
     else
         return Vector2.Zero;
 }
        // See comment in CreditScreen class
        public InstructionScreen(Game game)
        {
            instruct = new BasicSprite(game, "Interface\\Instructions", false);
            instruct.spritePos = new Vector2(0, 100);

            returnButton = new BasicSprite(game, "Interface\\return", false);
            returnButton.spritePos = new Vector2(690, 20);
        }
Beispiel #15
0
        public CreditScreen(Game game)
        {
            credits = new BasicSprite(game, "Interface\\creditsPage", false);
            credits.spritePos = new Vector2(10, 100);

            returnButton = new BasicSprite(game, "Interface\\return", false);
            returnButton.spritePos = new Vector2(690, 20);
        }
Beispiel #16
0
        public WinScreen(Game game)
        {
            winText = new BasicSprite(game, "Interface\\WinText", false);
            winText.spritePos = new Vector2(300, 100);
            returnToStart = new BasicSprite(game, "Interface\\returnStart", false);
            returnToStart.spritePos = new Vector2(250, 240);

            exit = new BasicSprite(game, "Interface\\exit", false);
            exit.spritePos = new Vector2(300, 280);
        }
        public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
        {
            base.onCollide(collided, data, time);

            // only if on top
            if (data.Height >= 1.0f)
            {
                collided.updatePositionFromVelocity(Velocity.FromCoordinates(0.0f, collided.velocity.getY() + velocity.getY()));
            }
        }
Beispiel #18
0
        public NPC(BasicSprite givenSprite, Vector2 pos)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = pos;
            Constants.SetLayerDepth(this, Constants.LayerDepth.Enemy);

            Sprite sprite = new Sprite(givenSprite);

            AddComponent(sprite);
        }
 public static Vector2 collisionDirection(BasicSprite s1, BasicSprite s2)
 {
     if (willCollide(s1, s2))
     {
         return((s2.velocity - s1.velocity).getDirection());
     }
     else
     {
         return(Vector2.Zero);
     }
 }
Beispiel #20
0
        public AboutScreen(Game game)
        {
            about = new BasicSprite(game, "Interface\\aboutPage", false);
            about.spritePos = new Vector2(0, 100);

            returnButton = new BasicSprite(game, "Interface\\return", false);
            returnButton.spritePos = new Vector2(690, 20);

            about.addTo(aboutSprites);
            returnButton.addTo(aboutSprites);
        }
Beispiel #21
0
        } = 1;                              // mostly for rupees
        public Item(BasicSprite sprite, Vector2 position)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = position;

            Constants.SetLayerDepth(this, Constants.LayerDepth.Item);

            Sprite spriteComponent = new Sprite(sprite);

            AddComponent(spriteComponent);
        }
Beispiel #22
0
 public UIDynamicSprite(Texture2D texture, int gridSize)
 {
     TopLeft     = new BasicSprite(texture, new Rectangle(0 * gridSize, 0 * gridSize, gridSize, gridSize));
     Top         = new BasicSprite(texture, new Rectangle(1 * gridSize, 0 * gridSize, gridSize, gridSize));
     TopRight    = new BasicSprite(texture, new Rectangle(2 * gridSize, 0 * gridSize, gridSize, gridSize));
     MiddleLeft  = new BasicSprite(texture, new Rectangle(0 * gridSize, 1 * gridSize, gridSize, gridSize));
     Fill        = new BasicSprite(texture, new Rectangle(1 * gridSize, 1 * gridSize, gridSize, gridSize));
     MiddleRight = new BasicSprite(texture, new Rectangle(2 * gridSize, 1 * gridSize, gridSize, gridSize));
     BottomLeft  = new BasicSprite(texture, new Rectangle(0 * gridSize, 2 * gridSize, gridSize, gridSize));
     Bottom      = new BasicSprite(texture, new Rectangle(1 * gridSize, 2 * gridSize, gridSize, gridSize));
     BottomRight = new BasicSprite(texture, new Rectangle(2 * gridSize, 2 * gridSize, gridSize, gridSize));
 }
 public static void update(BasicSprite character, SpriteContainer staticSprites, GameTime time)
 {
     for (int i = staticSprites.Count - 1; i >= 0; i--)
     {
         if (willCollide(character, staticSprites[i], time))
         {
             character.velocity = collisionWithSlip(character, staticSprites[i], time);
             character.onCollide(staticSprites[i], data, time);
             staticSprites[i].onCollide(character, data, time);
         }
     }
     character.updatePosition();
 }
Beispiel #24
0
        public HUDItem(BasicSprite sprite, Vector2 position, float scalar = 1.0f, bool visible = true)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = position;

            Constants.SetLayerDepth(this, Constants.LayerDepth.Debug);

            Sprite spriteComponent = new Sprite(sprite);

            spriteComponent.SetVisible(visible);
            spriteComponent.sprite.scalar *= scalar;
            AddComponent(spriteComponent);
        }
Beispiel #25
0
        public Link(Vector2 pos)
        {
            // ToDo: move to an appropriate place in this constructor
            AddComponent(new LinkLevelBehavior());

            this.name = "Link";

            // don't do any logic here, just add Components that do the logic
            Transform transform = GetComponent <Transform>();

            transform.position = pos;

            BasicSprite imageSprite = LinkSpriteFactory.Instance.CreateLinkWalkingUp();
            Sprite      sprite      = new Sprite(imageSprite);

            sprite.SetAnimate(false);
            AddComponent(sprite);


            var wideLink = new WideLink();

            transform.AddChild(wideLink);
            var sword = new Sword();

            transform.AddChild(sword);
            BehaviorScript script = new LinkBehavior(sword, wideLink);

            AddComponent(script);

            BehaviorScript inventory = new LinkInventory();

            AddComponent(inventory);

            BehaviorScript healthManagement = new LinkHealthManagement();

            AddComponent(healthManagement);

            Collider coll = new Collider(new RectangleF(6, 38, 30, 24));

            AddComponent(coll);
            coll.response = new LinkCollisionResponse(this);

            Constants.SetLayerDepth(this, Constants.LayerDepth.Player);

            BehaviorScript xp = new LinkXPManager();

            AddComponent(xp);

            //transform.AddChild(new TransformTest());
        }
Beispiel #26
0
 public override void onCollide(BasicSprite collided)
 {
     base.onCollide(collided);
     // The Gentleman picked up the key
     if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
     {
         container.Remove(this);
         hud.addKey(this);
         onHUD = true;
         double angle = Math.Atan2(5 - spritePos.Y, 745 - spritePos.X) * 180.0 / Math.PI;
         velocity = Velocity.FromDirection((float)angle, 10.0f);
         timer.Start();
     }
 }
Beispiel #27
0
 public override void onCollide(BasicSprite collided)
 {
     base.onCollide(collided);
     // The Gentleman picked up the key
     if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
     {
         container.Remove(this);
         hud.addKey(this);
         onHUD = true;
         double angle = Math.Atan2(5 - spritePos.Y, 745 - spritePos.X) * 180.0 / Math.PI;
         velocity = Velocity.FromDirection((float)angle, 10.0f);
         timer.Start();
     }
 }
Beispiel #28
0
 public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
 {
     base.onCollide(collided, data, time);
     // The Gentleman picked up the key
     if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
     {
         container.Remove(this);
         hud.addKey(this);
         onHUD = true;
         double angle = Math.Atan2(10 - spritePos.Y, game.GraphicsDevice.Viewport.Width - 52 - spritePos.X) * 180.0 / Math.PI;
         velocity = Velocity.FromDirection((float)angle, 10.0f);
         timer.Start();
     }
 }
Beispiel #29
0
 public void Initialize(XmlElement node, ModManager manager)
 {
     foreach (XmlElement variantNode in node.SelectNodes("Variants/Variant"))
     {
         BasicSprite texture   = manager.Textures[variantNode.GetAttribute("Texture")];
         int         x         = texture.X + int.Parse(variantNode.GetAttribute("X"), CultureInfo.InvariantCulture);
         int         y         = texture.Y + int.Parse(variantNode.GetAttribute("Y"), CultureInfo.InvariantCulture);
         int         w         = int.Parse(variantNode.GetAttribute("Width"), CultureInfo.InvariantCulture);
         int         h         = int.Parse(variantNode.GetAttribute("Height"), CultureInfo.InvariantCulture);
         Rectangle   rectangle = new Rectangle(x, y, w, h);
         BasicSprite variant   = new BasicSprite(texture.Texture, rectangle);
         Variants.Add(variant);
     }
 }
Beispiel #30
0
        public HUD()
        {
            _BottomBar = new BasicSprite(0, Game.CANVAS_HEIGHT - 64, Game.CANVAS_WIDTH, 64);

            // temp y coord for _BottomBar
            var ry = _BottomBar.GetBounds().Y;

            _InvButton = new Button(4, ry + 4, 96, 56, "Inventory", delegate() { Game.P.GetInventory().ToggleOpen(); });
            _InvButton.SetFont(new Font("ariel", 8));
            _InvButton.SetColor(Brushes.White);
            _InvButton.SetFontColor(Brushes.Black);
            _InvButton.SetFocusedColor(Brushes.LightGray);
            _Buttons.Add(_InvButton);
        }
Beispiel #31
0
        // See comment in CreditScreen class
        public PauseScreen(Game game)
        {
            logo = new BasicSprite(game, "Interface\\logo", false);
            logo.spritePos = new Vector2(300, 20);

            resume = new BasicSprite(game, "Interface\\resume", false);
            resume.spritePos = new Vector2(300, 240);

            help = new BasicSprite(game, "Interface\\InstructionsButton", false);
            help.spritePos = new Vector2(300, 290);

            exit = new BasicSprite(game, "Interface\\exit", false);
            exit.spritePos = new Vector2(300, 340);
        }
Beispiel #32
0
        public Block(BasicSprite sprite, Vector2 position)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = position;
            Constants.SetLayerDepth(this, Constants.LayerDepth.Block);

            Sprite s = new Sprite(sprite);

            AddComponent(s);

            var coll = new Collider();

            AddComponent(coll);
            coll.response = new BaseCollisionResponse(this);
        }
Beispiel #33
0
        // Commit from separate branch; Will probably need to work in:  public Item(BasicSprite sprite)
        public MovingItem(bool moving, bool disappearing, int framesToDraw, Constants.Direction directionThrown)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = new Vector2(250, 200);

            BasicSprite a      = ItemSpriteFactory.Instance.CreateBomb();
            Sprite      sprite = new Sprite(a);

            AddComponent(sprite);

            // Controls the item sprite actually moving across the screen. This isn't input-based movement.
            ItemMovement movement = new ItemMovement(moving, disappearing, framesToDraw, directionThrown);

            AddComponent(movement);
        }
Beispiel #34
0
        public ManualDrawing(Color color, Rectangle rect)
        {
            Transform transform = GetComponent <Transform>();

            Constants.SetLayerDepth(this, Constants.LayerDepth.Text);
            Texture2D texture = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1);

            texture.SetData(new[] { color });
            List <Rectangle> frames = new List <Rectangle>()
            {
                rect
            };
            BasicSprite basicSprite = new BasicSprite(texture, frames);
            Sprite      sprite      = new Sprite(basicSprite);
        }
Beispiel #35
0
        public Rope(Vector2 pos)
        {
            GetComponent <Transform>().position = pos;

            BasicSprite spriteImage = EnemySpriteFactory.Instance.CreateRopeLeft();
            Sprite      sprite      = new Sprite(spriteImage);

            AddComponent(sprite);
            sprite.SetAnimate(true);

            //var coll = new Collider();
            //coll.response = new EnemyCollisionResponse(this, Constants.ROPE_CONTACT_DAMAGE);
            //AddComponent(coll);
            //Constants.SetLayerDepth(this, Constants.LAYER_DEPTH_ENEMY);
        }
Beispiel #36
0
        public Poof(Vector2 pos, Entity entity)
        {
            GetComponent <Transform>().position = pos;
            Constants.SetLayerDepth(this, Constants.LayerDepth.Enemy);

            BasicSprite spriteImage = LinkItemSpriteFactory.Instance.CreateExplosion();
            Sprite      sprite      = new Sprite(spriteImage);

            AddComponent(sprite);
            sprite.SetAnimate(true);

            BehaviorScript behavior = new PoofBehavior(entity);

            AddComponent(behavior);
        }
        public BombExplosion(BasicSprite sprite, Vector2 position) : base(sprite, position)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = position;

            Constants.SetLayerDepth(this, Constants.LayerDepth.Enemy);

            BehaviorScript behavior = new BombExplosionBehaviorScript();

            AddComponent(behavior);

            Collider coll = new Collider();

            coll.response = new BombCollisionResponse(this);
            this.AddComponent(coll);
        }
Beispiel #38
0
 public UIDynamicSprite(
     BasicSprite topLeft, BasicSprite top, BasicSprite topRight,
     BasicSprite middleLeft, BasicSprite fill, BasicSprite middleRight,
     BasicSprite bottomLeft, BasicSprite bottom, BasicSprite bottomRight
     )
 {
     TopLeft     = topLeft;
     Top         = top;
     TopRight    = topRight;
     MiddleLeft  = middleLeft;
     Fill        = fill;
     MiddleRight = middleRight;
     BottomLeft  = bottomLeft;
     Bottom      = bottom;
     BottomRight = bottomRight;
 }
Beispiel #39
0
        public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
        {
            base.onCollide(collided, data, time);
            // The Gentleman pushs into a box
            if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
            {
                if (data.Width <=0)
                {
                    this.velocity = Velocity.FromDirection(0.0f, 0.5f);
                }else if (data.Width>=0)
                {
                    this.velocity = Velocity.FromDirection(0.0f, 0.5f);
                }

             }
        }
Beispiel #40
0
        public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
        {
            base.onCollide(collided, data, time);
            if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
            {
                ((TheGentleman)collided).health -= damage;
            }

            if (collided.collidable)
            {
                if (data.Width <= 0)
                {
                    this.velocity = Velocity.FromDirection(0.0f, 0.0f);
                }
            }
        }
Beispiel #41
0
        public override void Initialize(XmlElement node, GameDataManager manager)
        {
            BasicSprite sprite  = manager.Textures[node.GetAttribute("Texture")];
            Texture2D   texture = sprite.Texture;

            string[] offset  = node.GetAttribute("Offset").Split(',');
            int      offsetX = int.Parse(offset[0]);
            int      offsetY = int.Parse(offset[1]);

            string[]  size   = node.GetAttribute("Size").Split(',');
            int       sizeX  = int.Parse(size[0]);
            int       sizeY  = int.Parse(size[1]);
            Rectangle source = new Rectangle(offsetX, offsetY, sizeX, sizeY);

            source.Offset(sprite.Source.Location);
            Base = new BasicSprite(texture, source);
        }
        public static Velocity collisionWithSlip(BasicSprite s1, BasicSprite s2)
        {
            if (willCollide(s1, s2))
            {
                s1.onCollide(s2);
                s2.onCollide(s1);
                if (s1.collidable && s2.collidable)
                {
                    float     vf1, vf2;
                    Velocity  v1        = Velocity.FromCoordinates(s1.velocity.getDirection().X, 0.0f);
                    Velocity  v2        = Velocity.FromCoordinates(s2.velocity.getDirection().X, 0.0f);
                    Rectangle collision = Rectangle.Intersect(new Rectangle(s1.getUpdatePositionFromVelocity(v1).ToPoint(), s1.spriteSize), new Rectangle(s2.getUpdatePositionFromVelocity(v2).ToPoint(), s2.spriteSize));
                    if (collision != Rectangle.Empty)
                    {
                        vf1 = (int)v1.getDirection().X + (Math.Sign(v1.getDirection().X) * -collision.Width);
                    }
                    else
                    {
                        vf1 = v1.getDirection().X;
                    }

                    v1        = Velocity.FromCoordinates(0.0f, s1.velocity.getDirection().Y);
                    v2        = Velocity.FromCoordinates(0.0f, s2.velocity.getDirection().Y);
                    collision = Rectangle.Intersect(new Rectangle(s1.getUpdatePositionFromVelocity(v1).ToPoint(), s1.spriteSize), new Rectangle(s2.getUpdatePositionFromVelocity(v2).ToPoint(), s2.spriteSize));
                    if (collision != Rectangle.Empty)
                    {
                        vf2 = (int)v1.getDirection().Y + (Math.Sign(v1.getDirection().Y) * -collision.Height);
                    }
                    else
                    {
                        vf2 = v1.getDirection().Y;
                    }

                    return(Velocity.FromCoordinates(vf1, vf2));
                }
                else
                {
                    return(s1.velocity);
                }
            }
            else
            {
                return(s1.velocity);
            }
        }
Beispiel #43
0
        public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
        {
            base.onCollide(collided, data, time);
            //Seeing if security hit the Gentleman
            if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
            {
                //call method to handle damage and effects
            }
            //Checking to see if security hit a object
            if (collided.collidable)
            {
                if (data.Width <= 0)
                {
                    this.velocity = Velocity.FromDirection(0.0f, 0.0f);
                }

            }
        }
        public InvisibleBlock(BasicSprite sprite, Vector2 position) : base(sprite, position)
        {
            // don't do any logic here, just add Components that do the logic
            GetComponent <Transform>().position = position;
            Constants.SetLayerDepth(this, Constants.LayerDepth.Block);

            Sprite s = new Sprite(sprite);

            AddComponent(s);

            var coll = new Collider();
            var rect = GetRectColliders();

            rect.Y             += Constants.INVIS_BLOCK_OFFSET / 4;
            rect.Height        += Constants.INVIS_BLOCK_OFFSET;
            coll.colliderBounds = new ManualColliderBounds(coll, rect);
            AddComponent(coll);
            coll.response = new InvisibleBlockCollisionResponse(this);
        }
Beispiel #45
0
        public BladeTrap(Vector2 pos)
        {
            GetComponent <Transform>().position = pos;

            BasicSprite spriteImage = EnemySpriteFactory.Instance.CreateBladeTrap();
            Sprite      sprite      = new Sprite(spriteImage);

            AddComponent(sprite);
            sprite.SetAnimate(false);

            BehaviorScript movement = new BladeTrapMovement();

            AddComponent(movement);

            var coll = new Collider();

            coll.response = new BladeTrapCollisionResponse(this, Constants.BLADETRAP_CONTACT_DAMAGE);
            AddComponent(coll);
            Constants.SetLayerDepth(this, Constants.LayerDepth.Enemy);
        }
Beispiel #46
0
        public DeathScreen(Game game)
        {
            DeathText= new BasicSprite(game, "Interface\\DeathText", false);
            DeathText.spritePos = new Vector2(300, 100);

            ReturnToStart = new BasicSprite(game, "Interface\\returnStart", false);
            ReturnToStart.spritePos = new Vector2(250, 240);

            restartCP = new BasicSprite(game, "Interface\\returnCheck", false);
            restartCP.spritePos = new Vector2(250, 290);

            restartL = new BasicSprite(game, "Interface\\restartLevel", false);
            restartL.spritePos = new Vector2(250, 340);

            chooseL = new BasicSprite(game, "Interface\\chooseLevel", false);
            chooseL.spritePos = new Vector2(250, 390);

            exit = new BasicSprite(game, "Interface\\exit", false);
            exit.spritePos = new Vector2(300, 440);
        }
        public static Velocity collisionWithSlip(BasicSprite s1, BasicSprite s2, GameTime time)
        {
            if (s1.collidable && s2.collidable)
            {
                double vfx, vfy;
                Velocity v1 = Velocity.FromCoordinates(s1.velocity.getX(), 0.0f);
                Velocity v2 = Velocity.FromCoordinates(s2.velocity.getX(), 0.0f);
                Rectangle collision = Rectangle.Intersect(new Rectangle(s1.getUpdatePositionFromVelocity(v1).ToPoint(), s1.spriteSize), new Rectangle(s2.getUpdatePositionFromVelocity(v2).ToPoint(), s2.spriteSize));
                if (collision != Rectangle.Empty)
                    vfx =  v1.getX() - collision.Width * Math.Sign(v1.getX());
                else
                    vfx = v1.getX();

                if (Math.Abs(vfx) < 1.0f)
                    vfx = 0.0f;

                data.X = collision.X;
                data.Width = (Math.Sign(v1.getX())) * collision.Width;

                v1 = Velocity.FromCoordinates((float)vfx, s1.velocity.getY());
                v2 = Velocity.FromCoordinates((float)vfx, s2.velocity.getY());

                collision = Rectangle.Intersect(new Rectangle(s1.getUpdatePositionFromVelocity(v1).ToPoint(), s1.spriteSize), new Rectangle(s2.getUpdatePositionFromVelocity(v2).ToPoint(), s2.spriteSize));
                if (collision != Rectangle.Empty)
                    vfy = v1.getY() - (collision.Height * Math.Sign(v1.getY()));
                else
                    vfy = v1.getY();

                if (Math.Abs(vfy) < 1.0f) // stupid floats
                    vfy = 0.0f;

                data.Y = collision.Y;
                data.Height = Math.Sign(v1.getY()) * collision.Height;

                return Velocity.FromCoordinates((float)vfx, (float)vfy);
            }
            else
            {
                return s1.velocity;
            }
        }
Beispiel #48
0
        public Wall(BasicSprite sprite, Vector2 position) : base(sprite, position)
        {
            name = "wall";
            // add colliders to each wall to keep characters inside the room
            float thickness = Constants.WALL_THICKNESS;
            float topWallWidth = Constants.WALL_TOP_WIDTH;
            float sideWallWidth = Constants.WALL_SIDE_WIDTH;
            float thicknessTopWall = Constants.WALL_THICKNESS_TOP;

            Rectangle frame = sprite.frames[sprite.currentFrame];
            float width = frame.Width * sprite.scalar;
            float height = frame.Height * sprite.scalar;

            Collider topLeft = new Collider(new RectangleF(0, 0, topWallWidth, thicknessTopWall));
            Collider leftTop = new Collider(new RectangleF(0, 0, thickness, sideWallWidth));
            Collider topRight = new Collider(new RectangleF(width - topWallWidth, 0, topWallWidth, thicknessTopWall));
            Collider rightTop = new Collider(new RectangleF(width - thickness, 0, thickness, sideWallWidth));

            Collider bottomLeft = new Collider(new RectangleF(0, height - thickness, topWallWidth, thickness));
            Collider leftBottom = new Collider(new RectangleF(0, height - sideWallWidth, thickness, sideWallWidth));
            Collider bottomRight = new Collider(new RectangleF(width - topWallWidth, height - thickness, topWallWidth, thickness));
            Collider rightBottom = new Collider(new RectangleF(width - thickness, height - sideWallWidth, thickness, sideWallWidth));

            List<Collider> colls = new List<Collider>();
            colls.Add(topLeft);
            colls.Add(leftTop);
            colls.Add(topRight);
            colls.Add(rightTop);

            colls.Add(bottomLeft);
            colls.Add(leftBottom);
            colls.Add(bottomRight);
            colls.Add(rightBottom);

            foreach (var coll in colls)
            {
                coll.response = new WallCollisionResponse(this);
                AddComponent(coll);
            }

        }
Beispiel #49
0
        public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
        {
            base.onCollide(collided, data, time);
            //Seeing if security hit the Gentleman
            if (collided.ToString() == "KeysToInsanity.Code.TheGentleman")
            {
                TheGentleman tg = (TheGentleman)collided;
                if (!tg.invincible)
                {
                    tg.health -= damage;
                }
            }
            if (collided.collidable)
            {
                if (data.Width <= 0)
                {
                    velocity = Velocity.FromCoordinates(-velocity.getX(), 0.0f);
                }

            }
        }
Beispiel #50
0
        public StartScreen(Game game)
        {
            // load sprites
            logo = new BasicSprite(game, "Interface\\logo", false);
            logo.spritePos = new Vector2(300, 20);

            startButton = new BasicSprite(game, "Interface\\start", false);
            startButton.spritePos = new Vector2(300, 240);

            aboutButton = new BasicSprite(game, "Interface\\aboutButton", false);
            aboutButton.spritePos = new Vector2(350, 290);

            instructButton = new BasicSprite(game, "Interface\\InstructionsButton", false);
            instructButton.spritePos = new Vector2(300, 340);

            creditsButton = new BasicSprite(game, "Interface\\creditsButton", false);
            creditsButton.spritePos = new Vector2(350, 390);

            exitButton = new BasicSprite(game, "Interface\\exit", false);
            exitButton.spritePos = new Vector2(300, 440);
        }
Beispiel #51
0
        // This class is kind of weird
        // First of all, all elements are drawn to external texture, why?
        // To ensure that the HUD is
        // a) drawn all at once
        // b) drawn over everything else
        // and c) not a part of collision detection (most important reason)
        // This also allows us to define custom behavior for drawing whatever sprites are added to
        // the HUD's list of sprites to draw. And adjust the color of the entire HUD itself.
        public HUD(Game game)
            : base(new RenderTarget2D(game.GraphicsDevice,
                game.GraphicsDevice.PresentationParameters.BackBufferWidth,
                game.GraphicsDevice.PresentationParameters.BackBufferHeight), false)
        {
            spriteTex = new RenderTarget2D(game.GraphicsDevice,
                game.GraphicsDevice.PresentationParameters.BackBufferWidth,
                game.GraphicsDevice.PresentationParameters.BackBufferHeight);

            BasicSprite hud_key_frame = new BasicSprite(game, "hud_key_frame", false);
            hud_key_frame.spriteSize = new Point(60, 60);
            hud_key_frame.spritePos = new Vector2(740, 0);

            BasicSprite hud_health_frame = new BasicSprite(game, "health_bar_frame", false);
            hud_health_frame.spriteSize = new Point(200, 30);
            hud_health_frame.spritePos = new Vector2(1, 0);

            BasicSprite hud_insanity_frame = new BasicSprite(game, "insanity_bar_frame", false);
            hud_insanity_frame.spriteSize = new Point(200, 30);
            hud_insanity_frame.spritePos = new Vector2(211, 0);

            healthBar = new Bar(game, "health_bar_color");
            healthBar.spriteSize = new Point(202, 32);
            healthBar.spritePos = new Vector2(0, 0);
            healthBar.level = 100;

            insanityBar = new Bar(game, "insanity_bar_color");
            insanityBar.spriteSize = new Point(0, 32);
            insanityBar.spritePos = new Vector2(210, 0);
            insanityBar.level = 0;

            hud_key_frame.addTo(hudSprites);
            healthBar.addTo(hudSprites);
            hud_health_frame.addTo(hudSprites);
            insanityBar.addTo(hudSprites);
            hud_insanity_frame.addTo(hudSprites);

            gd = game.GraphicsDevice;
        }
        public LevelSwitcher(Game game, uint startLevel, uint totalLevels)
        {
            // load sprites
            background = new BasicSprite(game, "Interface\\LevelSwitcher", false);
            background.spritePos = new Vector2(0, 0);
            background.spriteSize = new Point(800, 850);

            layer2 = new BasicSprite(game, "Interface\\levelSwitcherLayer2", false);
            layer2.spritePos = new Vector2(0, 0);
            layer2.spriteSize = new Point(720, 131);

            levelHover = new BasicSprite(game, "Interface\\levelHover", false); // don't draw this until mouse is over a target area
            levelHover.spriteSize = new Point(720, 131);

            levelCover = new BasicSprite(game, "Interface\\levelCover", false);
            levelCover.spriteSize = new Point(150, 100);

            arrowUp = new BasicSprite(game, "arrow", false);
            arrowUp.spritePos = new Vector2(game.GraphicsDevice.Viewport.Width - 30, 0);
            arrowUp.spriteSize = new Point(30, 60);

            arrowDown = new BasicSprite(game, "arrow", false);
            arrowDown.spritePos = new Vector2(game.GraphicsDevice.Viewport.Width - 30, game.GraphicsDevice.Viewport.Height - 60);
            arrowDown.spriteSize = new Point(30, 60);

            level = startLevel;
            this.totalLevels = totalLevels;

            // calculate clickZones
            clickZones = new Rectangle[totalLevels];
            for (int i = 0; i < totalLevels; i++)
            {
                // i * (height of rectangle + space between them)
                clickZones[i] = new Rectangle(50, 126 + (i * (135 + 15)), 720, 131);
            }

            setUnlockedLevels(1);
        }
        public static Velocity collisionWithSlip(BasicSprite s1, BasicSprite s2)
        {
            if (willCollide(s1, s2))
            {
                s1.onCollide(s2);
                s2.onCollide(s1);
                if (s1.collidable && s2.collidable)
                {
                    float vf1, vf2;
                    Velocity v1 = Velocity.FromCoordinates(s1.velocity.getDirection().X, 0.0f);
                    Velocity v2 = Velocity.FromCoordinates(s2.velocity.getDirection().X, 0.0f);
                    Rectangle collision = Rectangle.Intersect(new Rectangle(s1.getUpdatePositionFromVelocity(v1).ToPoint(), s1.spriteSize), new Rectangle(s2.getUpdatePositionFromVelocity(v2).ToPoint(), s2.spriteSize));
                    if (collision != Rectangle.Empty)
                        vf1 = (int)v1.getDirection().X + (Math.Sign(v1.getDirection().X) * -collision.Width);
                    else
                        vf1 = v1.getDirection().X;

                    v1 = Velocity.FromCoordinates(0.0f, s1.velocity.getDirection().Y);
                    v2 = Velocity.FromCoordinates(0.0f, s2.velocity.getDirection().Y);
                    collision = Rectangle.Intersect(new Rectangle(s1.getUpdatePositionFromVelocity(v1).ToPoint(), s1.spriteSize), new Rectangle(s2.getUpdatePositionFromVelocity(v2).ToPoint(), s2.spriteSize));
                    if (collision != Rectangle.Empty)
                        vf2 = (int)v1.getDirection().Y + (Math.Sign(v1.getDirection().Y) * -collision.Height);
                    else
                        vf2 = v1.getDirection().Y;

                    return Velocity.FromCoordinates(vf1, vf2);
                }
                else
                {
                    return s1.velocity;
                }
            } else
            {
                return s1.velocity;
            }
        }
Beispiel #54
0
 public void addStatic(BasicSprite s)
 {
     s.addTo(statics);
     s.addTo(collidables);
 }
Beispiel #55
0
 public override void onCollide(BasicSprite s)
 {
 }
 public static bool willCollide(BasicSprite s1, BasicSprite s2)
 {
     return new Rectangle(s1.getUpdatePosition().ToPoint(), s1.spriteSize).Intersects(new Rectangle(s2.getUpdatePosition().ToPoint(), s2.spriteSize));
 }
        public override void onCollide(BasicSprite collided, Rectangle data, GameTime time)
        {
            base.onCollide(collided, data, time);

            collided.updatePositionFromVelocity(velocity);
        }
Beispiel #58
0
 public override void onCollide(BasicSprite s, Rectangle data, GameTime time)
 {
     base.onCollide(s, data, time);
 }
Beispiel #59
0
 public void addFadeInObject(BasicSprite s)
 {
     s.addTo(fadeIns);
 }
Beispiel #60
0
 public BasicInput(Game game, BasicSprite sprite)
 {
     this.game = game;
     this.sprite = sprite;
 }