public void Execute() { var MyScene = (Scene)Global.CurrentScene; if (MyScene.GetType().Name != "PlayScene") { return; } // new API for getting group with all matched entities from context var entities = Context <Default> .AllOf <FireComponent>().GetEntities(); foreach (var e in entities) { if (!e.Get <Transform>().Enabled) { continue; } FireComponent tc = e.Get <FireComponent>(); Transform tr = e.Get <Transform>(); Vector2 pos = e.Modify <Transform>().Position; // new API for trigger Monitor/ReactiveSystem pos.Y += Raylib.GetFrameTime() * tc.Speed; CollisionResult cr; //BoxCollider bx = e.Get<SpriteAnimation>().BoxCollider; // // e is entity moving // cr.CompEntity.tag is entity we colided with // if (SceneColliderDatabase.CollidedWithBox(e, out cr)) { if (cr.CompEntity.Tag == 1000) //if cursor then do nothing { e.Get <Transform>().Position = pos; e.Get <Transform>().Enabled = true; return; } //Global.AddEntityToDestroy(e); // cr.CompEntity is the entity we cloided with // e.Get <Transform>().Enabled = false; //else this code is executed Global.DestroyGameEntity(e); //ActiveScene.ChangeSprite(cr.CompEntity); return; } // // if we leave the world, then destroy the entity // if ((pos.X >= Global.WorldWidth || pos.X <= 0) || (pos.Y >= Global.WorldHeight || pos.Y <= 0)) { e.Get <Transform>().Enabled = false; //else this code is executed every frame Global.DestroyGameEntity(e); return; } //e.Get<Transform>().Position = pos; } }
public void Execute() { // // Make sure you are in the correct scene! // var MyScene = (Scene)Global.CurrentScene; if (MyScene.GetType().Name != "PlayScene") { return; } var ActiveScene = (PlayScene)Global.CurrentScene; // new API for getting group with all matched entities from context var entities = Context <Default> .AllOf <TurretComponent>().GetEntities(); foreach (var entity in entities) { Transform tr = entity.Get <Transform>(); //if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) //{ // tr.LookAt(Raylib.GetMousePosition()); //} float rot = Global.LookAt(Raylib.GetMousePosition(), entity.Get <Transform>().Position); entity.Get <Transform>().Rotation = rot; //entity.Modify<Transform>().LookAt(Global.GetMousePosition()) ; // // shot fired // if (Raylib.IsKeyPressed(KeyboardKey.KEY_SPACE)) { var tComp = entity.Get <TurretComponent>(); ActiveScene.FireMissile(Raylib.GetMousePosition(), entity.Get <Transform>().Position, tr.Rotation); //ActiveScene.FireMissile(Raylib.GetMousePosition(), // tComp.BulletPlaceHolder.Get<Transform>().Position, // tr.Rotation); } } }
public void Execute() { var MyScene = (Scene)Global.CurrentScene; if (MyScene.GetType().Name != "PlayScene") { return; } // new API for getting group with all matched entities from context var entities = Context <Default> .AllOf <TankComponent>().GetEntities(); foreach (var e in entities) { TankComponent tc = e.Get <TankComponent>(); InputController inpCnt = e.Get <InputController>(); // // We move tank if it was clicked on // Transform tr = e.Get <Transform>(); Vector2 pos = e.Get <Transform>().Position; // // Input controller gives us direction to go // if (inpCnt.Direction != Vector2.Zero) { if (e.Get <Transform>().Rotation != 0) { inpCnt.Direction = (inpCnt.Direction * e.Get <Transform>().Rotation); } pos += inpCnt.Direction * Raylib.GetFrameTime() * tc.Speed; } //// //// Move the tank using keyboard //// //if (Raylib.IsKeyDown(KeyboardKey.KEY_RIGHT)) //{ // pos.X += Raylib.GetFrameTime() * tc.Speed; // //ActiveScene.Camera.offset.X -= Raylib.GetFrameTime() * tc.Speed; //} //if (Raylib.IsKeyDown(KeyboardKey.KEY_LEFT)) //{ // pos.X -= Raylib.GetFrameTime() * tc.Speed; // //ActiveScene.Camera.offset.X += Raylib.GetFrameTime() * tc.Speed; //} //if (Raylib.IsKeyDown(KeyboardKey.KEY_UP)) //{ // pos.Y -= Raylib.GetFrameTime() * tc.Speed; // //ActiveScene.Camera.offset.Y += Raylib.GetFrameTime() * tc.Speed; //} //if (Raylib.IsKeyDown(KeyboardKey.KEY_DOWN)) //{ // pos.Y += Raylib.GetFrameTime() * tc.Speed; // //ActiveScene.Camera.offset.Y -= Raylib.GetFrameTime() * tc.Speed; //} if (Raylib.IsKeyDown(KeyboardKey.KEY_Q)) { e.Get <Transform>().Rotation -= .05f; } if (Raylib.IsKeyDown(KeyboardKey.KEY_E)) { e.Get <Transform>().Rotation += .05f; } // // Test to make sure we don't leave the world // if (Global.EntityOutOfBound(pos)) { pos = e.Get <Transform>().Position; } else { e.Get <Transform>().Position = pos; } } }