/// <summary> /// Uppdates the position of the Change direction Cubes if they have been taken /// or if their timer has run out /// </summary> /// <param name="gameTime"></param> public void update(GameTime gameTime) { width = Game.Instance.GraphicsDevice.Viewport.Width; height = Game.Instance.GraphicsDevice.Viewport.Height; if (entities.Count > 0) { foreach (var item in entities) { ChangeCubeComponent change = ComponentManager.Instance.GetEntityComponent <ChangeCubeComponent>(item); change.time += (float)gameTime.ElapsedGameTime.TotalSeconds; if (change.isTaken || change.time > 5) { AnimationComponent ani = ComponentManager.Instance.GetEntityComponent <AnimationComponent>(item); ani.currentFrame = 0; PositionComponent pos = ComponentManager.Instance.GetEntityComponent <PositionComponent>(item); pos.position.X = rand.Next(0, width); pos.position.Y = rand.Next(0, height); change.isTaken = false; change.time = 0; } } } }
/// <summary> /// handles player versus changeDirectionCube collision /// </summary> /// <param name="Player"> Id of the player entity </param> /// <param name="Cube"> Id of the Cube entity </param> private void PlayerVsCubeColl(int Player, int Cube) { PlayerComponent plaCom = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(Player); ChangeCubeComponent change = ComponentManager.Instance.GetEntityComponent <ChangeCubeComponent>(Cube); if (!plaCom.isFalling && change.time > 0.5F) { ComponentManager.Instance.AddComponentToEntity(Player, new SoundEffectComponent("signhit")); DirectionComponent dir = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(Player); changeDir(dir); change.isTaken = true; } }
public int CreateChangeCube(Vector2 position, string texture, int width, int height) { int id = ComponentManager.Instance.CreateID(); ChangeCubeComponent cdc = new ChangeCubeComponent(); PositionComponent pos = new PositionComponent(position); CollisionComponent col = new CollisionComponent(false); CollisionRectangleComponent colRec = new CollisionRectangleComponent(new Rectangle((int)position.X, (int)position.Y, width, height)); DrawableComponent draw = new DrawableComponent(Game.Instance.GetContent <Texture2D>(texture), SpriteEffects.None); AnimationComponent ani = new AnimationComponent(50, 50, draw.texture.Width, draw.texture.Height, 0.08f); ani.oneTime = true; ComponentManager.Instance.AddComponentToEntity(id, cdc); ComponentManager.Instance.AddComponentToEntity(id, pos); ComponentManager.Instance.AddComponentToEntity(id, col); ComponentManager.Instance.AddComponentToEntity(id, colRec); ComponentManager.Instance.AddComponentToEntity(id, draw); ComponentManager.Instance.AddComponentToEntity(id, ani); return(id); }