示例#1
0
        private void OnCameraShake(params object[] args)
        {
            float str = args.Length > 0 ? (float)args[0] : 10.0f;
            float dur = args.Length > 1 ? (float)args[1] : 1.0f;

            // Get a random number [-1..1]
            float randX = ((float)FP.Rand(200) - 100.0f) / 100.0f;
            float randY = ((float)FP.Rand(200) - 100.0f) / 100.0f;

            // Scale it by the strength
            offsetX = str * (randX);
            offsetY = str * (randY);

            if (prevShaker != null)
            {
                prevShaker.Cancel();
            }

            var shaker = new MultiVarTween(OnShakeDone, Tween.ONESHOT);

            Parent.AddTween(shaker);
            shaker.Tween(this, new { offsetX = 0.0f, offsetY = 0.0f }, dur, Ease.ElasticOut);
            shaker.Start();

            prevShaker = shaker;
        }
示例#2
0
        public void onDamage(int amount, float force, Vector2f direction)
        {
            if (isHurt)
            {
                return;
            }

            isHurt = true;

            health -= amount;
            if (health <= 0)
            {
                onDeath();
                return;
            }

            //make the animation make sense and good
            physics.velocity.X += force * direction.X;
            physics.velocity.Y += force * direction.Y;

            if (FP.Rand(2) == 1)
            {
                bodySprites.Play("Stagger1");
            }
            else
            {
                bodySprites.Play("Stagger2");
            }
            faceSprites.Play("None");
        }
示例#3
0
文件: NoHat.cs 项目: Tankooni/terunks
        public override string attackEnd()
        {
            int i = timeCharged >= 3? 3 : 1;

            while (i-- > 0)
            {
                float x = parent.World.MouseX - parent.X;
                float y = parent.Y - parent.World.MouseY;
                //add some variance
                x *= .8f + FP.Rand(4000) / 10000f;
                y *= .8f + FP.Rand(4000) / 10000f;

                //normalize them
                float mag = (float)Math.Sqrt(x * x + y * y);
                x *= bubblespeed / mag;
                y *= bubblespeed / mag;

                var bubble = new Bubble(x, y);
                bubble.X = parent.X - 20;
                bubble.Y = parent.Y - 80;
                parent.World.Add(bubble);
            }

            return("Idle");
        }
示例#4
0
 public override void Added()
 {
     base.Added();
     World.Add(new Part(this, 1, 0, 0));
     Type       = "EmptyShip";
     ShipCenter = Image.CreateRect(64, 64, FP.Color(0xffffff));
     ShipCenter.CenterOO();
     X = FP.Rand(SpaceWorld.WorldLength);
     Y = FP.Rand(SpaceWorld.WorldHeight);
 }
示例#5
0
        public TileMap()
        {
            var startIndex = Tuple.Create <int, int>(FP.Rand(MapWidth), FP.Rand(MapHeight));
            var endIndex   = Tuple.Create <int, int>(FP.Rand(MapWidth), FP.Rand(MapHeight));

            while (startIndex.Item1 == endIndex.Item1 && startIndex.Item1 == endIndex.Item2)
            {
                endIndex = Tuple.Create <int, int>(FP.Rand(MapWidth), FP.Rand(MapHeight));
            }
            for (int y = 0; y < MapHeight; y++)
            {
                int    rowOffset = (y % 2 == 1) ? OddRowXOffset : 0;
                MapRow row       = new MapRow();
                for (int x = 0; x < MapWidth; x++)
                {
                    TileType tileType;
                    if (x == startIndex.Item1 && y == startIndex.Item2)
                    {
                        tileType = TileType.Start;
                    }
                    else if (x == endIndex.Item1 && y == endIndex.Item2)
                    {
                        tileType = TileType.End;
                    }
                    else
                    {
                        tileType = FP.Choose.EnumWeighted <TileType>(0, 0, 0, 1, .65f, 0);
                    }
                    MapCell mc = new MapCell(tileType, TileSize, Tuple.Create <int, int>(x, y))
                    {
                        X = x * TileStepX + rowOffset,
                        Y = y * TileStepY
                    };
                    mc.SetPathNode(new PathNode(mc, null, mc.X, mc.Y));
                    this.AddComponent <Image>(mc);
                    row.Columns.Add(mc);
                }
                Rows.Add(row);
            }

            //CoroutineHost coHost1 = AddComponent<CoroutineHost>(new CoroutineHost());
            //coHost1.Start(RunBuildNodeConnections());

            foreach (MapRow mr in Rows)
            {
                foreach (MapCell mc in mr.Columns)
                {
                    PathNode.ConnectedNodes[mc.MyNode] = SelectTilesAroundTile(mc.Index.Item1, mc.Index.Item2);
                }
            }

            CoroutineHost coHost2 = AddComponent <CoroutineHost>(new CoroutineHost());

            coHost2.Start(RunBuildPath(startIndex, endIndex));
        }
示例#6
0
        public TileMap()
        {
            var startIndex = Tuple.Create <int, int>(FP.Rand(MapWidth), FP.Rand(MapHeight));
            var endIndex   = Tuple.Create <int, int>(FP.Rand(MapWidth), FP.Rand(MapHeight));

            while (startIndex.Item1 == endIndex.Item1 && startIndex.Item1 == endIndex.Item2)
            {
                endIndex = Tuple.Create <int, int>(FP.Rand(MapWidth), FP.Rand(MapHeight));
            }
            for (int y = 0; y < MapHeight; y++)
            {
                MapRow row = new MapRow();
                for (int x = 0; x < MapWidth; x++)
                {
                    TileType tileType;
                    if (x == startIndex.Item1 && y == startIndex.Item2)
                    {
                        tileType = TileType.Start;
                    }
                    else if (x == endIndex.Item1 && y == endIndex.Item2)
                    {
                        tileType = TileType.End;
                    }
                    else
                    {
                        tileType = FP.Choose.EnumWeighted <TileType>(0, 0, 0, 1, .65);
                    }
                    MapCell mc = new MapCell(tileType, TileSize, Tuple.Create <int, int>(x, y))
                    {
                        X = x * TileSize,
                        Y = y * TileSize
                    };
                    mc.SetPathNode(new PathNode(mc, null, x, y));
                    this.AddComponent <Image>(mc);
                    row.Columns.Add(mc);
                }
                Rows.Add(row);
            }

            foreach (MapRow mr in Rows)
            {
                foreach (MapCell mc in mr.Columns)
                {
                    PathNode.ConnectedNodes[mc.MyNode] = SelectTilesAroundTile(mc.Index.Item1, mc.Index.Item2);
                }
            }

            CoroutineHost coHost = AddComponent <CoroutineHost>(new CoroutineHost());

            coHost.Start(Things(startIndex, endIndex));
        }
示例#7
0
 public override void Update()
 {
     base.Update();
     if (created == 2)
     {
         for (int i = 0; i < shipParts.Count; i++)
         {
             if (shipParts[i] as EmptyPart != null)
             {
                 World.Add(new Part(this, (int)(FP.Rand(2) + 1), shipParts[i].curCol, shipParts[i].curRow));
             }
         }
         created = 3;
     }
     else if (created < 2)
     {
         created++;
     }
     //X += Velocity.X;
     //Y += Velocity.Y;
     //FP.Log(X, Y);
 }
示例#8
0
        public override void Update()
        {
            base.Update();

            if (FP.Rand(100) < 5)
            {
                arms.Play("Attack");

                float vx = p.X + 32 - X;
                float vy = Y + 32 - p.Y + 50;

                vx *= .8f + FP.Rand(4000) / 10000f;
                vy *= .8f + FP.Rand(4000) / 10000f;

                float mag = (float)Math.Sqrt(vx * vx + vy * vy);
                vx *= fireballSpeed / mag;
                vy *= fireballSpeed / mag;

                Fireball fireball = new Fireball(vx, vy);
                fireball.X = X + 32;                //hand
                fireball.Y = Y + 32;
                World.Add(fireball);
            }
        }
示例#9
0
 /// <summary>
 /// Assigns the Spritemap to a random frame.
 /// </summary>
 public void RandFrame()
 {
     _frame = (int)FP.Rand((uint)FrameCount);
 }
示例#10
0
        public override void Update()
        {
            base.Update();

            if (health <= 0)
            {
                if (myShip != null)
                {
                    if (myShip as Ship == null)
                    {
                        List <PartBase> temp = myShip.shipParts;
                        World.Remove(myShip);
                        for (int i = 0; i < temp.Count; i++)
                        {
                            if (temp[i].MyType != 0)
                            {
                                Part replacementPart = new Part(temp[i].MyType);
                                replacementPart.X = temp[i].X;
                                replacementPart.Y = temp[i].Y;
                                World.Add(replacementPart);
                            }

                            World.Remove(temp[i]);
                        }
                        World.Remove(myShip);
                    }
                    else
                    {
                        World.Add(new EmptyPart(myShip, curCol, curRow, curCol, curRow));
                        World.Remove(this);
                        if (myShip.shipParts.Count <= 0)
                        {
                            var Title = new Text("Game Over! Press R to Restart The Game.", 100, FP.HalfHeight - 200, 0, 0);
                            Title.Size = 100;
                            AddGraphic(Title);
                        }
                    }
                }
                else
                {
                    World.Remove(this);
                }
            }

            if (Attached)
            {
                SetHitboxTo(aPart);
                aPart.CenterOO();
                CenterOrigin();

                FP.AnchorTo(ref X, ref Y, myShip.X, myShip.Y, Distance, Distance);
                FP.RotateAround(ref X, ref Y, myShip.X, myShip.Y, myShip.ShipCenter.Angle + angle, false);

                aPart.Angle = myShip.ShipCenter.Angle;

                if (PartNum == 3)
                {
                    //FP.Log(FP.Angle(X, Y, World.MouseX, World.MouseY));

                    if (myShip.ShipCenter.Angle + 2 > 360)
                    {
                        myShip.ShipCenter.Angle = (myShip.ShipCenter.Angle + 2) - 360;
                    }
                    if (myShip.ShipCenter.Angle - 2 <= 0)
                    {
                        myShip.ShipCenter.Angle = (myShip.ShipCenter.Angle - 2) + 360;
                    }


                    if ((myShip.ShipCenter.Angle + 45 > FP.Angle(X, Y, World.MouseX, World.MouseY)) && (myShip.ShipCenter.Angle - 45 < FP.Angle(X, Y, World.MouseX, World.MouseY)))
                    {
                        aPart.Angle = FP.Angle(X, Y, World.MouseX, World.MouseY);
                        if (Mouse.IsButtonPressed(Mouse.Button.Right))
                        {
                            TurretSfx.Volume = FP.Random * 20 + 20;
                            TurretSfx.Pitch  = FP.Random * .3f + .2f;
                            TurretSfx.Play();

                            World.Add(new Bullet(X, Y, new Vector2f((float)Math.Cos(aPart.Angle * FP.RAD) * 5, (float)Math.Sin(aPart.Angle * FP.RAD) * 5), myShip));
                        }
                        else
                        {
                            //TurretSfx.Pitch = .01f; //+ 0.5f;
                        }
                    }
                    else
                    {
                        //TurretSfx.Pitch = .01f; //+ 0.5f;
                        aPart.Angle = myShip.ShipCenter.Angle;
                    }
                }
                else
                {
                    aPart.Angle = myShip.ShipCenter.Angle + rotationOffSet;
                }
            }
            else
            {
                SetHitboxTo(aPart);
                aPart.CenterOO();
                CenterOrigin();
                EmptyPart temp = World.CollideRect("EmptyPart", X, Y, Width, Height) as EmptyPart;
                if (temp != null)
                {
                    float t   = (float)Math.Atan2(temp.curRow - temp.parentRow, temp.curCol - temp.parentCol);
                    Part  add = new Part(temp.myShip, MyType, temp.curCol, temp.curRow);
                    add.rotationOffSet = (t * FP.DEG) - 90;
                    add.rotationOffSet = (float)Math.Round(add.rotationOffSet);
                    if (add.rotationOffSet < 0.0002 && add.rotationOffSet > -0.0002)
                    {
                        add.rotationOffSet = 0;
                    }
                    World.Add(add);
                    World.Remove(temp);
                    World.Remove(this);
                }

                if (Input.Pressed(Mouse.Button.Left))
                {
                    if (World.CollidePoint("Part", World.MouseX, World.MouseY) == this)
                    {
                        Dragging = true;
                    }
                }
                else if (Input.Released(Mouse.Button.Left))
                {
                    Dragging = false;
                }

                if (Dragging)
                {
                    X      = World.MouseX;
                    Y      = World.MouseY;
                    Flying = false;
                }
                if (Flying)
                {
                    X += FP.Rand(2);
                    Y += FP.Rand(2);
                }
            }
            //aPart.Color = FP.Color(0x000000);
            aPart.Color = new SFML.Graphics.Color((byte)(byte)(FP.Clamp <int>((int)((health / totalHealth) * 255), 0, 255)), (byte)(byte)(FP.Clamp <int>((int)((health / totalHealth) * 255), 0, 255)), (byte)(byte)(FP.Clamp <int>((int)((health / totalHealth) * 255), 0, 255)));
        }
示例#11
0
 public EmptyShip()
 {
     shipParts = new List <PartBase>();
     Velocity  = new Vector2f(FP.Rand(2), FP.Rand(2));
     created   = 0;
 }