private void handleDamage(DamageEvent evt) { if (entity.IsDead || entity[Key_IsInvulnerable]) { return; } int health = entity[Key_Health]; health -= evt.Damage; entity[Key_Health] = health; if (health <= 0) { int lifes = entity[Key_Lifes]; lifes -= 1; entity[Key_Lifes] = lifes; entity.State = EntityState.Dying; if (entity.Type == "player") { HudEvent hudEvent = HudEvent.UpdateLifes(lifes); eventManager.Queue(hudEvent); CreateEntityEvent createEvt = CreateEntityEvent.New("player_death"); Vector2D position = entity[SpatialBehavior.Key_Position]; position.X -= 90; position.Y -= 90; createEvt.AddAttribute(SpatialBehavior.Key_Position, position); eventManager.Queue(createEvt); entity[RenderBehavior.Key_IsRenderable] = false; } if (lifes <= 0) { Entity projectile = entity.Game.World.Entities[evt.SourceEntityID]; Entity projectileOwner = projectile[ProjectileBehavior.Key_ProjectileOwner]; int destroyedByEntityID = projectile.ID; if (projectileOwner != null) { destroyedByEntityID = projectileOwner.ID; } eventManager.Queue(DestroyEntityEvent.Destroy(entity.ID, destroyedByEntityID)); Console.WriteLine("[" + this.GetType().Name + "] Entity " + entity + " died a horrible death!"); } else { RespawnEntityEvent respawnEvent = RespawnEntityEvent.Respawn(entity.ID); eventManager.Queue(respawnEvent); Console.WriteLine("[" + this.GetType().Name + "] Entity " + entity + " lost a life. " + lifes + " lifes remaining. Respawning..."); } } }
public override void Start() { base.Start(); playerController = playerGameObject.gameObject.GetComponent <PlayerController> (); collectorAnimator = gameObject.transform.GetChild(0).gameObject.GetComponent <Animator> (); //Image Animator ScoreLabel = playerController.ScoreBoard.GetComponent <Text> (); HudEvent.ResetCollectorData(); ScoreLabel.text = HudEvent.LogData(); }
public void OnEvent(Event evt) { switch (evt.Type) { case HudEvent.UPDATE: { HudEvent hudMsg = (HudEvent)evt; if (hudMsg.Lifes != null) { this.lifesValueLabel.Text = hudMsg.Lifes.ToString(); } if (hudMsg.Score != null) { this.scoreValueLabel.Text = hudMsg.Score.ToString(); } break; } } }
void Start() { isPlayerDead = false; originalPosition = gameObject.transform.localPosition; scaleData = transform.localScale.x; controller = GetComponent <Controller2D> (); playerAnimator = playerGameObjectHolder.gameObject.GetComponent <Animator> (); kinematicEquationForPlayer(); hudEvent = EventSystem.GetComponent <HudEvent> (); PlayBackAudioSource(); if (GlobalVariables.ISMainBackAudio) { volBackImage.sprite = Vol_ON; } else { volBackImage.sprite = Vol_OFF; } }
public override void OnEvent(Event evt) { switch (evt.Type) { case AwardPointsEvent.AWARD_POINTS: { AwardPointsEvent msg = (AwardPointsEvent)evt; int points = entity[Key_PointsCollected]; points += msg.Points; entity[Key_PointsCollected] = points; HudEvent hudEvent = HudEvent.UpdateScore(points); eventManager.Queue(hudEvent); Console.WriteLine("[" + this.GetType().Name + "] " + entity + " collected " + msg.Points + " points for destroying " + msg.SourceEntityID + " (total points: " + points + " )"); break; } } }
void CalculatePlayerMovement(Vector3 mainPositon) { float directionX = Mathf.Sign(mainPositon.x); float directionY = Mathf.Sign(mainPositon.y); bool isPlayerHit = false; //FOR HORIZONTAL { float rayLength = Mathf.Abs(mainPositon.x) + skinWidth; if (Mathf.Abs(mainPositon.x) < skinWidth) { rayLength = 2 * skinWidth; } for (int i = 0; i < this.horizontalRayCount; i++) { //-------------------------------->Side A Vector2 rayOrigin = raycastOrigins.bottomLeft; rayOrigin += Vector2.up * (horizontalRaySpacing * i); RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, playerMask); Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red); if (hit) //Collision Begin A { isPlayerHit = true; } //---------------------------------->Side B rayOrigin = raycastOrigins.bottomRight; rayOrigin += Vector2.up * (horizontalRaySpacing * i); hit = Physics2D.Raycast(rayOrigin, Vector2.right * directionX, rayLength, playerMask); Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red); if (hit) //Collision Begin B { isPlayerHit = true; } } } //FOR VERTICAL { float rayLength = Mathf.Abs(mainPositon.y) + skinWidth; for (int i = 0; i < this.verticalRayCount; i++) { //------------------------------------->Side A Vector2 rayOrigin = raycastOrigins.bottomLeft; rayOrigin += Vector2.right * (verticalRaySpacing * i + mainPositon.y); RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, playerMask); Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red); if (hit) //Collision Begin A { isPlayerHit = true; } rayOrigin = raycastOrigins.topLeft; rayOrigin += Vector2.right * (verticalRaySpacing * i + mainPositon.y); hit = Physics2D.Raycast(rayOrigin, Vector2.up * directionY, rayLength, playerMask); Debug.DrawRay(rayOrigin, Vector2.up * directionY * rayLength, Color.red); if (hit) //Collision Begin B { isPlayerHit = true; } } } if (isPlayerHit) { isColliderCollide = true; collectorAnimator.SetBool("GlowCollectorAdded", true); HudEvent.IncrementCollectorData(); ScoreLabel.text = HudEvent.LogData(); } //----------------------------------> }