/// <summary> /// Handles player versus platform collision /// </summary> /// <param name="Player"> Id of the player entity </param> /// <param name="Platform"> Id of the platform entity </param> private void PlayerVsPlatformColl(int Player, int Platform, GameTime gameTime) { PlayerComponent playComp = ComponentManager.Instance.GetEntityComponent <PlayerComponent>(Player); DirectionComponent dc = ComponentManager.Instance.GetEntityComponent <DirectionComponent>(Player); VelocityComponent pvc = ComponentManager.Instance.GetEntityComponent <VelocityComponent>(Player); PositionComponent ppc = ComponentManager.Instance.GetEntityComponent <PositionComponent>(Player); CollisionRectangleComponent pcrc = ComponentManager.Instance.GetEntityComponent <CollisionRectangleComponent>(Player); PlatformComponent pc = ComponentManager.Instance.GetEntityComponent <PlatformComponent>(Platform); HealthComponent hc = ComponentManager.Instance.GetEntityComponent <HealthComponent>(Player); if (!playComp.isFalling) { if (pcrc.CollisionRec.Intersects(pc.TopRec)) // @TODO tänk om gällande pixlePerfect, kanske { //@todo hur fan ska man ta bort n om spelarn hoppar ifrån eller blir nerputtad if (!ComponentManager.Instance.CheckIfEntityHasComponent <TTLComponent>(Player)) { TTLComponent ttl = new TTLComponent(5f); ComponentManager.Instance.AddComponentToEntity(Player, ttl); } else { TTLComponent ttl = ComponentManager.Instance.GetEntityComponent <TTLComponent>(Player); if (ttl.curTime >= ttl.maxTime) { playComp.isFalling = true; //hc.health -= 1; ComponentManager.Instance.RemoveComponentFromEntity(Player, ttl); } } changeDir(dc); if (dc.directio != Direction.Still) { dc.preDir = dc.directio; dc.directio = Direction.Still; } pvc.velocity.Y = 0; pvc.velocity.Y -= 500 * (float)gameTime.ElapsedGameTime.TotalSeconds; } else { if (dc.directio != Direction.Still) { changeDir(dc); dc.preDir = dc.directio; dc.directio = Direction.Still; } pvc.velocity.Y = 0; pvc.velocity.Y += 500 * (float)gameTime.ElapsedGameTime.TotalSeconds; playComp.isFalling = true; ComponentManager.Instance.AddComponentToEntity(Player, new SoundEffectComponent("pfhit")); //hc.health -= 1; } } }
public void update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; Dictionary <int, IComponent> dic = ComponentManager.Instance.GetAllEntitiesAndComponentsWithComponentType <TTLComponent>(); if (dic != null) { foreach (var item in dic) { TTLComponent ttl = (TTLComponent)item.Value; ttl.curTime += dt; } } }
public void draw(GameTime gameTime, SpriteBatch spriteBatch) { Dictionary <int, IComponent> dic = ComponentManager.Instance.GetAllEntitiesAndComponentsWithComponentType <TTLComponent>(); if (dic != null) { foreach (var item in dic) { TTLComponent ttl = (TTLComponent)item.Value; float timeLeft = ttl.maxTime - ttl.curTime; PositionComponent pos = ComponentManager.Instance.GetEntityComponent <PositionComponent>(item.Key); Vector2 offset = new Vector2(10, -30); Vector2 position = pos.position + offset; spriteBatch.DrawString(font, timeLeft + "", position, Color.Black); } } }