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; } }
/* * * Pile with tag = 90 dealt pile displayed * Pile with tag = 80 are Ace piles * Pile with tag = 70 face down cards to deal * Pile with tags 1 - 7 are play stacks * */ private void CheckCollisionResults(Entity entity) { CollisionResult cr; if (!SceneColliderDatabase.CollidedWithBox(entity, out cr)) { return; } //----------------------------------------- // we have clicked on a box collider //----------------------------------------- entity.Get <MouseComponent>().CurrentEntityChosen = cr.CompEntity; Dragging = false; switch (cr.CompEntity.Tag) { case 80: MyScene.AcePileCard2Drag(cr.CompEntity); Dragging = true; break; case 70: MyScene.DealtCard2Drag(cr.CompEntity); Dragging = true; break; case 90: MyScene.DealCard2Disp(cr.CompEntity); //from face down deal to face up break; case int n when(n >= 1 && n <= 7): Entity cardEntity = MyScene.FindCardInPlayPile(cr.CompEntity, Global.GetMousePosition()); if (cardEntity == null) { return; } // // We have card, drag it + all others under it // Dragging = true; MyScene.TakeCards2Drag(cardEntity); break; } }
/* * All active scenes use the Cross Hair cursor */ public void Execute() { var ActiveScene = (Scene)Global.CurrentScene; var entities = Context <Default> .AllOf <CrossHairComponent>().GetEntities(); foreach (var e in entities) { e.Get <Transform>().Position = Global.GetMousePosition(); if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { CollisionResult cr; if (SceneColliderDatabase.CollidedWithBox(e, out cr)) { e.Get <CrossHairComponent>().CurrentEntityChosen = cr.CompEntity; cr.CompEntity.Add <EntityCapturedComponent>(); } } } }
public void Execute() { var tmpScene = (Scene)Global.CurrentScene; if (tmpScene.GetType().Name != "CardScene") { return; } MyScene = (CardScene)tmpScene; var entities = Context <Default> .AllOf <MouseComponent>().GetEntities(); foreach (var mouseEntity in entities) { mouseEntity.Get <Transform>().Position = Global.GetMousePosition(); clickTimer += Global.DeltaTime * 1000; //if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) //{ // if (clickTimer < timerDelay) // { // CheckCollisionResults(mouseEntity); // clickTimer = 0; // } //} if (Raylib.IsMouseButtonReleased(MouseButton.MOUSE_LEFT_BUTTON)) { if (clickTimer < timerDelay) { clickTimer = 0; //double click detected } clickTimer = 0; if (Dragging) { Dragging = false; CollisionResult cr; if (!SceneColliderDatabase.CollidedWithBox(mouseEntity, out cr)) { return; } Entity collidedEntity = cr.CompEntity; // // Dealt Card is released but was not put on a stack // if (collidedEntity.Tag == 80) { // // Ace pile drop // MyScene.DropCardFromDrag2AceStack(collidedEntity); return; //ace pile stack } if ((collidedEntity.Tag >= 1) && (collidedEntity.Tag <= 7)) { // // Play pile drop // MyScene.DropCardFromDrag2PlayStack(collidedEntity); return; } // // mouse released but not on Ace or Play area, return card to its place // MyScene.ReturnCardFromDrag2Stack(); return; //drap disp stack (release of mouse outside of play area) } } if (Raylib.IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { // // if game over, don't allow movement // if (Global.StateOfGame == GameState.Over) { return; } CheckCollisionResults(mouseEntity); } } }