コード例 #1
0
ファイル: Autonomous.cs プロジェクト: Zeldorks/Zeldorks
 private static void ChangeVelocity(
     Comps.Velocity velocity,
     Orientation.Cardinal direction,
     float moveSpeed,
     Comps.Orientations.Cardinal orientation
     )
 {
     velocity.data    = direction.GetPhysicalVector2() * moveSpeed;
     orientation.data = direction;
     velocity.decay   = 1;
 }
コード例 #2
0
ファイル: Autonomous.cs プロジェクト: Zeldorks/Zeldorks
        public static void Run(Registry registry)
        {
            HashSet <Entity> entities = registry.GetEntities(
                typeof(Comps.Velocity),
                typeof(Comps.Orientations.Cardinal),
                typeof(Comps.Autonomous)
                );

            Tick   tick   = Global.tick;
            Random random = Global.random;

            foreach (Entity entity in entities)
            {
                Comps.Autonomous autonomous = registry
                                              .GetComponentUnsafe <Comps.Autonomous>(entity);

                Comps.Velocity velocity = registry
                                          .GetComponentUnsafe <Comps.Velocity>(entity);

                Comps.Orientations.Cardinal orientation = registry
                                                          .GetComponentUnsafe <Comps.Orientations.Cardinal>(entity);

                float moveSpeed    = autonomous.moveSpeed;
                float changePeriod = 60 * autonomous.changePeriod;

                if (tick % changePeriod == 0)
                {
                    if (autonomous.attackChance > random.NextDouble())
                    {
                        var p = Factories.Projectile.Create(autonomous.attackType, entity, registry);

                        if (autonomous.spreadShots)
                        {
                            CreateSpreadshots(entity, autonomous, p, registry);
                        }

                        if (autonomous.stopWhileAttacking)
                        {
                            velocity.data = PhysicalVector2.Zero;
                            continue;
                        }
                    }
                }

                switch (autonomous.kind)
                {
                case Comps.Autonomous.Kind.Basic:
                    if (tick % changePeriod == 0)
                    {
                        int r = random.Next(4);
                        ChangeVelocity(velocity, GetCardinal(r), moveSpeed, orientation);
                    }
                    break;

                case Comps.Autonomous.Kind.Charging:
                    if (tick % (2 * changePeriod) == 0)
                    {
                        int r = 1 + 2 * random.Next(2);
                        moveSpeed *= 1.5f;
                        ChangeVelocity(velocity, GetCardinal(r), moveSpeed, orientation);
                    }
                    else if (tick % changePeriod == 0)
                    {
                        int r = 2 * random.Next(2);
                        moveSpeed *= 0.5f;
                        ChangeVelocity(velocity, GetCardinal(r), moveSpeed);
                    }
                    break;

                case Comps.Autonomous.Kind.Flying:
                    moveSpeed *= (float)(1 + Math.Sin((tick / (changePeriod * 5)) * 2 * Math.PI));
                    if (tick % changePeriod == 0)
                    {
                        int r = random.Next(4);
                        ChangeVelocity(velocity, GetCardinal(r), moveSpeed, orientation);
                    }
                    else
                    {
                        ChangeVelocity(velocity, orientation.data, moveSpeed);
                    }
                    break;

                case Comps.Autonomous.Kind.Shuffling:
                    if (tick % changePeriod == 0)
                    {
                        if (velocity.data.Length() == 0)
                        {
                            ChangeVelocity(velocity, orientation.data, moveSpeed);
                        }
                        else
                        {
                            velocity.data *= -1;
                        }
                    }
                    break;

                default:
                    break;
                }
            }
        }
コード例 #3
0
ファイル: Characters.cs プロジェクト: Zeldorks/Zeldorks
        private static CompsExt.Visibles.Sprite CreateVisibleComp(
            Comps.Character characterComp,
            Comps.Orientations.Cardinal orientationComp,
            ContentManager contentManager
            )
        {
            switch (characterComp.kind)
            {
            case Comps.Character.Kind.Link:
                switch (orientationComp.data)
                {
                case Physical.Orientation.Cardinal.Up:
                    if (characterComp.attacking)
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(16 * 1, 16 * 3, 16, 16 * 2),
                            destRectangle = new Drawing.Rectangle(16 * 4, 16 * 8),
                            destOffset = new DrawingVector(0, 16)         // TODO: Why does this value work?
                        });
                    }
                    else
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(32, 32, 16, 16),
                            destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                        });
                    }

                case Physical.Orientation.Cardinal.Left:
                    if (characterComp.attacking)
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(16 * 2, 16, 16 * 2, 16),
                            destRectangle = new Drawing.Rectangle(16 * 8, 16 * 4),
                            destOffset = new DrawingVector(16, 0)         // TODO: Why does this value work?
                        });
                    }
                    else
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(8 * 16, 16, 16, 16),
                            destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                        });
                    }

                case Physical.Orientation.Cardinal.Down:
                    if (characterComp.attacking)
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(16 * 7, 16 * 2, 16, 16 * 2),
                            destRectangle = new Drawing.Rectangle(16 * 4, 16 * 8),
                            destOffset = new DrawingVector(0, -16)         // TODO: Why does this value work?
                        });
                    }
                    else
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(0, 32, 16, 16),
                            destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                        });
                    }

                case Physical.Orientation.Cardinal.Right:
                    if (characterComp.attacking)
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(16 * 4, 0, 16 * 2, 16),
                            destRectangle = new Drawing.Rectangle(16 * 8, 16 * 4),
                            destOffset = new DrawingVector(-16, 0)         // TODO: Why does this value work?
                        });
                    }
                    else
                    {
                        return(new CompsExt.Visibles.Sprite {
                            texture = contentManager.Load <Texture2D>("Sprites/Link"),
                            texturePosRectangle = new DrawingPosRectangle(8 * 16, 0, 16, 16),
                            destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                        });
                    }

                default:
                    throw new ArgumentException(
                              "Invalid orientation direction"
                              );
                }

            case Comps.Character.Kind.Aquamentus:
                switch (orientationComp.data)
                {
                case Physical.Orientation.Cardinal.Left:
                    return(new CompsExt.Visibles.Sprite {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(0, 0, 32, 32),
                        destRectangle = new Drawing.Rectangle(32 * 4, 32 * 4)
                    });

                case Physical.Orientation.Cardinal.Right:
                    return(new CompsExt.Visibles.Sprite {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(0, 32, 32, 32),
                        destRectangle = new Drawing.Rectangle(32 * 4, 32 * 4)
                    });

                default:
                    throw new ArgumentException(
                              "Invalid orientation direction"
                              );
                }

            case Comps.Character.Kind.Zol:
                return(new CompsExt.Visibles.Sprite {
                    texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                    texturePosRectangle = new DrawingPosRectangle(96, 32, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Character.Kind.Goriya:
                switch (orientationComp.data)
                {
                case Physical.Orientation.Cardinal.Up:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(32, 64, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Left:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(96, 64, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Down:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(0, 64, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Right:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(64, 64, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                default:
                    throw new ArgumentException(
                              "Invalid orientation direction"
                              );
                }

            case Comps.Character.Kind.Dodongos:
                switch (orientationComp.data)
                {
                case Physical.Orientation.Cardinal.Up:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(64, 96, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Left:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(64, 80, 32, 16),
                        destRectangle = new Drawing.Rectangle(32 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Down:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(128, 80, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Right:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(0, 80, 32, 16),
                        destRectangle = new Drawing.Rectangle(32 * 4, 16 * 4)
                    });

                default:
                    throw new ArgumentException(
                              "Invalid orientation direction"
                              );
                }

            case Comps.Character.Kind.Stalfos:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                    texturePosRectangle = new DrawingPosRectangle(128, 64, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Character.Kind.Rope:
                switch (orientationComp.data)
                {
                case Physical.Orientation.Cardinal.Right:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(0, 112, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Left:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                        texturePosRectangle = new DrawingPosRectangle(32, 112, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                default:
                    throw new ArgumentException(
                              "Invalid orientation direction"
                              );
                }

            case Comps.Character.Kind.Keese:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                    texturePosRectangle = new DrawingPosRectangle(128, 96, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Character.Kind.Wallmaster:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                    texturePosRectangle = new DrawingPosRectangle(64, 112, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            default:
                throw new ArgumentException("Invalid character kind");
            }
        }
コード例 #4
0
        private static CompsExt.Visibles.Sprite CreateVisibleComp(
            Comps.Projectile projectileComp,
            Comps.Orientations.Cardinal orientationComp,
            ContentManager contentManager
            )
        {
            switch (projectileComp.kind)
            {
            case Comps.Projectile.Kind.Arrow:
                switch (orientationComp.data)
                {
                case Physical.Orientation.Cardinal.Up:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Items"),
                        texturePosRectangle = new DrawingPosRectangle(16, 32, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                    });

                case Physical.Orientation.Cardinal.Down:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Items"),
                        texturePosRectangle = new DrawingPosRectangle(16, 32, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4),
                        effects = SpriteEffects.FlipVertically
                    });

                case Physical.Orientation.Cardinal.Right:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Items"),
                        texturePosRectangle = new DrawingPosRectangle(16, 32, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4),
                        rotation = (float)Math.PI / 2,
                        destOffset = new DrawingVector(-16 * 4, 0)
                    });

                case Physical.Orientation.Cardinal.Left:
                    return(new CompsExt.Visibles.Sprite
                    {
                        texture = contentManager.Load <Texture2D>("Sprites/Items"),
                        texturePosRectangle = new DrawingPosRectangle(16, 32, 16, 16),
                        destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4),
                        rotation = (float)Math.PI / 2,
                        destOffset = new DrawingVector(-16 * 4, 0),
                        effects = SpriteEffects.FlipVertically
                    });

                default:
                    throw new ArgumentException("Invalid orientation direction");
                }

            case Comps.Projectile.Kind.Bomb:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(130, 18, 14, 14),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.Boomerang:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(36, 19, 11, 11),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.RedKey:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(28, 0, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.BlueKey:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(28, 0, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.GreenKey:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(28, 0, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.PurpleKey:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(28, 0, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.YellowKey:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Items"),
                    texturePosRectangle = new DrawingPosRectangle(28, 0, 16, 16),
                    destRectangle = new Drawing.Rectangle(16 * 4, 16 * 4)
                });

            case Comps.Projectile.Kind.Fireball:
                return(new CompsExt.Visibles.Sprite
                {
                    texture = contentManager.Load <Texture2D>("Sprites/Enemies"),
                    texturePosRectangle = new DrawingPosRectangle(100, 51, 10, 10),
                    destRectangle = new Drawing.Rectangle(10 * 4, 10 * 4)
                });

            default:
                throw new NotImplementedException("TODO");
            }
        }