Exemplo n.º 1
0
    public static Rectangle RandomShrinkClone(this Rectangle r, int rx, int ry, int rxm, int rym)
    {
        var newr = r.Clone();

        newr.Width    -= Randy.NextInt(rxm * 2);
        newr.Height   -= Randy.NextInt(rym * 2);
        newr.Location += new Point(Randy.NextInt(rx), Randy.NextInt(ry));
        return(Rectangle.Intersect(newr, r));
    }
Exemplo n.º 2
0
 public void SpawnEnemy()
 {
     interval_ += lastDT;
     if (interval_ > 3)
     {
         interval_ = 0;
         Vector2 position = new Vector2(Randy.Range(20, 40), Randy.Range(6, 20));
         CreateWorldSprite(position, Atlas.enemyA);
     }
 }
Exemplo n.º 3
0
 public override void Initialize()
 {
     base.Initialize();
     AddEntity(new TiledMap("testnr1"));
     if (IsHost)
     {
         Randy = new Randy(false);
         Doug  = new Doug(true);
         AddEntity(Doug);
         AddEntity(Randy);
     }
     if (!IsHost)
     {
         Randy = new Randy(true);
         Doug  = new Doug(false);
         AddEntity(Randy);
         AddEntity(Doug);
     }
 }
Exemplo n.º 4
0
    public void DrawDebug()
    {
        foreach (KeyValuePair <Point, List <T> > chunk in chunks_)
        {
            var pos  = chunk.Key;
            var comp = chunk.Value;

            //draw region square
            var regionRect = new Rectangle(pos.X * CHUNK_SIZE, pos.Y * CHUNK_SIZE, CHUNK_SIZE, CHUNK_SIZE);
            Dbg.AddDebugRect(regionRect, debugColor, Randy.NextFloat(0.25f));

            Dbg.AddDebugText(comp.Count.ToString(), regionRect.Location.ToVector2(), debugColor);

            for (var index = 0; index < comp.Count; index++)
            {
                T component = comp[index];
                //DebugHelper.AddDebugText(index.ToString(), component.entity.Position, debugColor);
            }
        }
    }
Exemplo n.º 5
0
    public override void Update()
    {
        float movement    = Keys.W.IsDown() ? SPEED : Keys.S.IsDown() ? -SPEED : 0;
        float dbgmovement = Keys.D.IsDown() ? SPEED : Keys.A.IsDown() ? -SPEED : 0;
        float multiplier  = Keys.LeftShift.IsDown() ? 2 : 0.5f;

        entity.Position += new Vector2(dbgmovement * Core.lastDT * multiplier, movement * multiplier * Core.lastDT);

        entity.Rotation += Keys.Q.IsDown() ? 0.03f : Keys.E.IsDown() ? -0.03f : 0; //TODO this is dbg

        if (Input.LMB.IsDown())
        {
            entity.GetComponent <SoundPlayer>()?.Play(); //you'll want to cache this

            for (int i = 0; i < 32; i++)
            {
                var bullet = new Entity(entity.Position + Randy.UnitCircle(), Core.mainCam.WorldMousePosition - (entity.Position + Randy.UnitCircle()));
                new QuadComponent(bullet, new QuadData(Atlas.small_projectile)); //add quad to render bullet
                new Projectile(bullet, 60);                                      // add projectile script to bullet
            }
        }
        Dbg.AddDebugLine(entity.Position, Core.mainCam.WorldMousePosition, Color.Green);
    }
Exemplo n.º 6
0
    protected override void Initialize()
    {
        Atlas.RegisterPipelineAssets();

        ExplosionSound = Sound.Cache.explosion;

        //create our player
        Entity player = new Entity(new Vector2(8, 15));

//        new Quad(player, new QuadData(Atlas.player));
        new Sprite(player, new SpriteData(Vector2.One * 8, Color.White, Atlas.player.GetSprite().UvToPixels()));
        new PlayerScript(player);
        new LightOccluder(player, LightOccluder.OccluderShape.Horizontal, 2f);
        new SoundPlayer(player, Sound.laser); //jesus christ :(

        //we add a light for the player ship
        Texture2D lightTexture = Content.Load <Texture2D>(Other.light);
        Entity    headlight    = new Entity(player.Position + Vector2.UnitX, Vector2.UnitX); //pointing right (unitx)

        new LightProjector(headlight, 20, -15, lightTexture, Color.White);

        //we parent the light to the player entity
        new EntityContainer(player).AddChild(headlight);


        //create some rotating lights
        clearColor      = Color.DarkGray;
        lightsBlendMode = BlendState.Additive;
        LightProjector.Systems.Default.BlendState = BlendState.Additive;
        LightOccluder.Systems.Default.shadowBias  = 0;
        for (int i = 1; i < 4; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                var light = new Entity(new Vector2(i * 9, j * 23));
                new LightProjector(light, 20, -15, lightTexture, Randy.NextSaturatedColor());
                new Rotate(light, Randy.Range(-3f, 3f));
            }
        }

        //subscribe event
        OnBeforePhysicsUpdate += SpawnEnemy;

        //audio
        MediaPlayer.Play(Music.Cache.bgm);
        MediaPlayer.Volume = 0.4f;


        //list all sprites in some UI
        UI.Layout spritesLo = UI.RootRect.AddChild(new UI.Layout(0, 0, 40, 40));
        spritesLo.AddLayoutter(new UI.Layout.ExpandToParentSize(UI.Layout.Mode.Horizontal));
        spritesLo.AddLayoutter(new UI.Layout.AlignRelativeToParent(1, 1));
        spritesLo.AddLayoutter(new UI.Layout.LayoutChildren(UI.Layout.Mode.Horizontal));

        foreach (var sprite in Sheet.Sprites)
        {
            spritesLo.AddChild(new SpriteUIRect(0, 0, 56, 32, sprite.Key));
        }

        //some help UI
        UI.RootRect.AddChild(new UI.TextRect(0, 0, 200, 10,
                                             "Controls: W,A,LMB. Drag and drop sprites from bottom onto scene, press 1 to save scene, 2 to load"
                                             ));

        //subscribe event, dropping sprites onto scene creates entities with the sprite
        UI.RootRect.OnDrop += WorldDropFromUI;


        //saving and loading scene
        OnBeforeLogicUpdate += () =>
        {
            if (Keys.D1.WasPressed())
            {
                Entity.SaveAll("savedata");
            }
            else if (Keys.D2.WasPressed())
            {
                Entity.DestroyAll();
                Entity.LoadAll("savedata");
            }
        };
    }