//Ground Collision* Code public void EndGroundJump(Ground ground) { for (int i = 0; i < 4; i++) { //Checks if she's on a ground tile if (bottomHitBox.Intersects(Ground.hitboxList[i]) == true) { onGroundPlatform = true; //Checks if she's in Jump State if (currentGlitchState == GlitchState.Jump) { hasJumped = false; //Checks whether to put her facing right or left when the collision happens and sets her state if (currentKeyState == keyboardState.Right) { currentGlitchState = GlitchState.IdleRight; } else if (currentKeyState == keyboardState.Left) { currentGlitchState = GlitchState.IdleLeft; } } } } }
//Enemy Collision* Code public bool GlitchGetsHurt(Enemy enemy) { if (hitbox.Intersects(enemy.Hitbox) == true) { if (currentKeyState == keyboardState.Right) { position.X -= 75; } else { position.X += 75; } if (Lives < 3 && Lives > 0) { currentGlitchState = GlitchState.Hurt; Lives--; } else if (Lives == 0) { Game1.currentGameState = GameState.GameOver; } return(true); } else { return(false); } }
//Vertical Collision* Code public void EndVertMoveJump(Vertical_Platform platform) { if (platform.Active == true) { //Checks if Glitch is touching a platform if (bottomHitBox.Intersects(platform.HitBox) == true) { currentPlatform = platform; onVertPlatform = true; //Checks if she's in Jump State if (currentGlitchState == GlitchState.Jump) { hasJumped = false; //Checks whether to put her facing right or left when the collision happens if (currentKeyState == keyboardState.Right) { currentGlitchState = GlitchState.IdleRight; } else if (currentKeyState == keyboardState.Left) { currentGlitchState = GlitchState.IdleLeft; } } } } }
//Falling Reset Code public void Fall() { if (hitbox.Intersects(fallBound) == true) { if (Lives == 0) { Game1.currentGameState = GameState.GameOver; } else { lives -= 1; position.X = 0; position.Y = 200; currentGlitchState = GlitchState.IdleRight; hasJumped = false; onVertPlatform = false; onHorzPlatform = false; onGroundPlatform = true; onTile1 = false; onTile2 = false; onTile3 = false; onTile4 = false; currentPlatform = null; currentKeyState = keyboardState.Right; velocity.X = 0f; velocity.Y = 0f; } } }
public void UpdatePlayerGlitch(bool grounded) { if (playerGlitchState == GlitchState.glitching) { glitchIcon.SetActive(false); glitchCol.SetActive(true); playerGlitchState = GlitchState.glitching; rb.constraints = RigidbodyConstraints2D.FreezeAll; if (grounded) { glitchTimer += Time.deltaTime; if (glitchTimer > 0.15f) { ResetGlitch(grounded); } } if (InputDev.RightBumper.WasPressed) { SetGlitchState(); } } else if (playerGlitchState == GlitchState.canGlitch) { rb.constraints = RigidbodyConstraints2D.None; rb.constraints = RigidbodyConstraints2D.FreezeRotation; glitchIcon.SetActive(true); glitchCol.SetActive(false); if (InputDev.RightBumper.WasPressed) { if (currentGlitches <= maxGlitches) { playerGlitchState = GlitchState.glitching; if (!grounded) { currentGlitches++; } } else if (grounded) { playerGlitchState = GlitchState.glitching; } else { playerGlitchState = GlitchState.cantGlitch; } } } else { glitchCol.SetActive(false); //ResetGlitch(grounded); rb.constraints = RigidbodyConstraints2D.None; rb.constraints = RigidbodyConstraints2D.FreezeRotation; if (currentGlitches < maxGlitches) { playerGlitchState = GlitchState.canGlitch; } } }
public void die() { animator.SetBool("Dying", true); state = GlitchState.dying; animationStart = Time.time; GetComponent <Image>().raycastTarget = false; document.PlaySFX(GlitchSFX.death); }
private void ResetGlitch(bool grounded) { if (grounded) { glitchTimer = 0; playerGlitchState = GlitchState.canGlitch; } rb.constraints = RigidbodyConstraints2D.None; rb.constraints = RigidbodyConstraints2D.FreezeRotation; }
public void Attack() { currentGlitchState = GlitchState.Attack; for (int i = 0; i < Game1.enemyList.Count; i++) { if (swordHitBox.Intersects(Game1.enemyList[i].Hitbox)) { Game1.enemyList[i].Hurt(this); } } }
public void SetGlitchState() { if (currentGlitches <= maxGlitches) { playerGlitchState = GlitchState.canGlitch; } else { playerGlitchState = GlitchState.cantGlitch; } }
//Constructor public Glitch() { //Setting Previous GlitchState previousGlitchState = currentGlitchState; previousKeyboardState = currentKeyState; currentGlitchState = GlitchState.IdleRight; currentKeyState = keyboardState.Right; //Setting Start* Position this.position = new Rectangle(0, 200, 580, 760); //Setting Hitbox hitbox = new Rectangle(position.X, position.Y, 125, 400); bottomHitBox = new Rectangle(position.X, position.Y, 125, 10); swordHitBox = new Rectangle(position.X, position.Y + 20, 760, 580); //Setting Life Count lives = 2; //Setting Platform Boolean onHorzPlatform = false; onVertPlatform = false; onGroundPlatform = true; onTile1 = false; onTile2 = false; onTile3 = false; onTile4 = false; //Setting fallBound fallBound = new Rectangle(-1000000, 2000, 2000000, 10); //Jump hasJumped = false; //Initialize ground TEST* ground = new Ground(); //Animation Initializers frameSize.X = 1000; frameSize.Y = 1000; currentFrame.X = 0; currentFrame.Y = 0; numFrames = 1; frameRate = 200; flip = SpriteEffects.None; //Animation Initializers swordFrameSize.X = 744; swordFrameSize.Y = 866; swordNumFrames = 5; }
public void hit() { HP--; if (HP <= 0) { die(); document.ReportKill(); } else { animator.SetBool("Hit", true); animator.SetFloat("Health", (float)HP / MaxHP); document.PlaySFX(GlitchSFX.hit); state = GlitchState.hit; animationStart = Time.time; } }
//Reset* Method public void Reset() { lives = 2; position.X = 0; position.Y = 200; currentGlitchState = GlitchState.IdleRight; hasJumped = false; onVertPlatform = false; onHorzPlatform = false; onTile1 = false; onTile2 = false; onTile3 = false; onTile4 = false; currentPlatform = null; currentKeyState = keyboardState.Right; velocity.X = 0f; velocity.Y = 0f; }
private void DropLetter(int index) { destination = document.spaces[index].monitorLocation; if ((location - destination).magnitude < movementSpeed) { location = destination; GetComponent <RectTransform>().localPosition = location; } else { location += (document.spaces[index].monitorLocation - destination).normalized * movementSpeed; GetComponent <RectTransform>().localPosition = location; } animationStart = Time.time; spaceToReplace = index; animator.SetBool("Letter", true); state = GlitchState.action; document.PlaySFX(GlitchSFX.letter); }
// Update is called once per frame void Update() { if (state == GlitchState.dying) { if (Time.time >= animationStart + 0.5f) { DestroyImmediate(this.gameObject); } return; } if (state == GlitchState.action) { if (type == GlitchType.mom) { if (Time.time >= animationStart + .6f && momSpawned == false) { momSpawned = true; GameObject newGlitch; Vector3 spawnLocation = location; spawnLocation.y += 25f; Transform monitorTransform = GameObject.Find("Monitor").transform; document.PlaySFX(GlitchSFX.birth); switch (Random.Range(0, 4)) { case 0: spawnLocation.y -= 75f; newGlitch = Instantiate((GameObject)Resources.Load("Prefabs/Looper", typeof(GameObject)), monitorTransform); newGlitch.GetComponent <Glitch>().Initiate(GlitchType.looper, spawnLocation, movementSpeed, document); break; case 1: newGlitch = Instantiate((GameObject)Resources.Load("Prefabs/Dasher", typeof(GameObject)), monitorTransform); newGlitch.GetComponent <Glitch>().Initiate(GlitchType.dasher, spawnLocation, movementSpeed, document); break; case 3: newGlitch = Instantiate((GameObject)Resources.Load("Prefabs/Eratic", typeof(GameObject)), monitorTransform); newGlitch.GetComponent <Glitch>().Initiate(GlitchType.eratic, spawnLocation, movementSpeed, document); break; default: newGlitch = Instantiate((GameObject)Resources.Load("Prefabs/Scanner", typeof(GameObject)), monitorTransform); newGlitch.GetComponent <Glitch>().Initiate(GlitchType.scanner, spawnLocation, movementSpeed, document); break; } } else if (Time.time >= animationStart + 1f) { state = GlitchState.moving; animationStart = Time.time; animator.SetBool("Birthing", false); } } else { if ((location - destination).magnitude < movementSpeed) { location = destination; GetComponent <RectTransform>().localPosition = location; document.spaces[spaceToReplace] = document.FillSpace(document.spaces[spaceToReplace]); } else { location += (destination - location).normalized * movementSpeed; GetComponent <RectTransform>().localPosition = location; } if (Time.time >= animationStart + 1f) { animator.SetBool("Letter", false); state = GlitchState.moving; if (type == GlitchType.dasher || type == GlitchType.eratic) { newDestination(); } } } return; } if (state == GlitchState.moving) { if (type == GlitchType.dasher) //check for dasher reaching its destination { if (document.spaces[dasherTargetIndex].currentChar == ' ') { if ((destination - location).magnitude <= movementSpeed) { DropLetter(dasherTargetIndex); return; } } else { newDestination(); } } else if (type == GlitchType.scanner) { for (int x = 0; x < document.spaces.Count; x++) { if (document.spaces[x].location.y == scannerCurrentRow && document.spaces[x].currentChar == ' ' && (location - document.spaces[x].monitorLocation).magnitude < 25) { DropLetter(x); return; } } } else if (type == GlitchType.mom) { if (Time.time >= animationStart + 5f) { state = GlitchState.action; animationStart = Time.time; animator.SetBool("Birthing", true); momSpawned = false; } } else { for (int x = 0; x < document.spaces.Count; x++) { if (document.spaces[x].currentChar == ' ' && (location - document.spaces[x].monitorLocation).magnitude < 25) { DropLetter(x); return; } } } if (type == GlitchType.looper) { if ((destination - looperCenter).magnitude <= movementSpeed / 2f) { looperCenter = destination; if (clockwise) { looperRotation += looperRotationalSpeed; } else { looperRotation -= looperRotationalSpeed; } location = new Vector3(looperCenter.x + Mathf.Sin(looperRotation) * 100, looperCenter.y + Mathf.Cos(looperRotation)); GetComponent <RectTransform>().localPosition = location; newDestination(); } else { looperCenter += (destination - looperCenter).normalized * movementSpeed / 2f; if (clockwise) { looperRotation += looperRotationalSpeed; } else { looperRotation -= looperRotationalSpeed; } location = new Vector3(looperCenter.x + Mathf.Sin(looperRotation) * 100, looperCenter.y + Mathf.Cos(looperRotation) * 100); GetComponent <RectTransform>().localPosition = location; } } else { if ((destination - location).magnitude <= movementSpeed) { location = destination; GetComponent <RectTransform>().localPosition = location; newDestination(); } else { location += (destination - location).normalized * movementSpeed; GetComponent <RectTransform>().localPosition = location; } } } if (state == GlitchState.hit) { if (Time.time > animationStart + .5f) { animator.SetBool("Hit", false); state = GlitchState.moving; animationStart = Time.time; } } }
//Update* public void Switch(GameTime gameTime) { //Dynamically sets hitbox hitbox.X = position.X; hitbox.Y = position.Y; swordHitBox.X = position.X; swordHitBox.Y = position.Y + 20;//change* bottomHitBox.X = position.X; //Fix this method, for some reason it crashes visual studio Loop(); //change* //Animation Logic timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; if (timeSinceLastFrame > frameRate) // time for a new frame { if (currentGlitchState == GlitchState.Attack) { timeSinceLastFrame = 0; frame++; if (frame >= swordNumFrames) { frame = 0; } if (frame == 5) { if (currentKeyState == keyboardState.Right) { currentGlitchState = GlitchState.IdleRight; } else { currentGlitchState = GlitchState.IdleLeft; } } } else { timeSinceLastFrame = 0; frame++; //Resets Animation Loop if (frame >= numFrames) { frame = 0; } } // set the upper left corner of new frame currentFrame.X = frameSize.X * frame; } if (currentGlitchState == GlitchState.IdleLeft || currentGlitchState == GlitchState.MoveLeft) { bottomHitBox.X = position.X; //change* } bottomHitBox.Y = position.Y + 345; //Animation Logic timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; if (timeSinceLastFrame > frameRate) // time for a new frame { timeSinceLastFrame = 0; frame++; //Resets Animation Loop if (frame >= numFrames) { frame = 0; } // set the upper left corner of new frame currentFrame.X = frameSize.X * frame; } //Gamestate Switch logic switch (currentGlitchState) { case GlitchState.MoveRight: hitbox.X = position.X; hitbox.Y = position.Y; Move(); //Attack(); break; case GlitchState.MoveLeft: hitbox.X = position.X; hitbox.Y = position.Y; Move(); //Attack(); break; case GlitchState.Jump: if (currentKeyState == keyboardState.Left) { hitbox.X = position.X; } Jump(); Move(); Fall(); break; case GlitchState.IdleRight: hitbox.X = position.X; hitbox.Y = position.Y; Move(); //Attack(); break; case GlitchState.IdleLeft: hitbox.X = position.X; hitbox.Y = position.Y; Move(); //Attack(); break; case GlitchState.Hurt: Move(); break; case GlitchState.Attack: //Attack(); Move(); break; case GlitchState.Dead: //Run dead animation and change state to GameOver Game1.currentGameState = GameState.GameOver; break; } }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); state = GlitchState.moving; }
//Move* public void Move() { previousKeyState = key; key = Keyboard.GetState(); if (key.IsKeyDown(Keys.Z) && previousKeyState.IsKeyUp(Keys.Z)) { Attack(); } //Moving Right* if (key.IsKeyDown(Keys.Right) == true) { //Changes the KeyState to Right currentKeyState = keyboardState.Right; //Makes sure that glitch isn't in Jump before switching the state so that she doesn't stop midair if (currentGlitchState != GlitchState.Jump) { currentGlitchState = GlitchState.MoveRight; position.X += 7; } else { //Makes sure Glitch flips visually in air if (previousGlitchState == GlitchState.MoveRight) { flip = SpriteEffects.FlipHorizontally; } position.X += 7; } Console.WriteLine(position.X); } //Moving Left* else if (key.IsKeyDown(Keys.Left) == true) { //Changes the KeyState to Right currentKeyState = keyboardState.Left; //Makes sure that glitch isn't in Jump before switching the state so that she doesn't stop midair if (currentGlitchState != GlitchState.Jump) { currentGlitchState = GlitchState.MoveLeft; position.X -= 7; } else { //Makes sure Glitch flips visually in air if (previousGlitchState == GlitchState.MoveRight) { flip = SpriteEffects.None; } position.X -= 7; } if (position.X < -280) //prevents glitch from going back too far and stops her at x = -280 { position.X = -280; } } if (previousKeyState.IsKeyUp(Keys.Left) == true && key.IsKeyDown(Keys.Left) == true) { if (currentGlitchState != GlitchState.Jump) { currentGlitchState = GlitchState.IdleLeft; } } else if (previousKeyState.IsKeyUp(Keys.Right) == true && key.IsKeyDown(Keys.Right) == true) { if (currentGlitchState != GlitchState.Jump) { currentGlitchState = GlitchState.IdleRight; } } //Makes Glitch Jump if (previousKeyState.IsKeyUp(Keys.Up) == true && key.IsKeyDown(Keys.Up) == true) { currentGlitchState = GlitchState.Jump; } //Makes her move with platform //Ground* if (onGroundPlatform == true && currentPlatform == null) { //checks to see if she's on any ground tile (1-4) if (bottomHitBox.Intersects(Ground.hitboxList[0]) == false && bottomHitBox.Intersects(Ground.hitboxList[1]) == false && bottomHitBox.Intersects(Ground.hitboxList[2]) == false && bottomHitBox.Intersects(Ground.hitboxList[3]) == false) { onGroundPlatform = false; //Makes sure that she falls hasJumped = true; currentGlitchState = GlitchState.Jump; } } //Horizontal if (onHorzPlatform == true && currentPlatform != null) { if (bottomHitBox.Intersects(currentPlatform.HitBox) == false) { onHorzPlatform = false; currentPlatform = null; hasJumped = true; currentGlitchState = GlitchState.Jump; } else { if (Horizontal_Platform.pubActive == false) { onHorzPlatform = false; currentPlatform = null; hasJumped = true; currentGlitchState = GlitchState.Jump; } } if (Horizontal_Platform.direction == true) { position.X += 5; } else { position.X -= 5; } } //Vertical if (onVertPlatform == true && currentPlatform != null) { if (bottomHitBox.Intersects(currentPlatform.HitBox) == false) { onVertPlatform = false; currentPlatform = null; hasJumped = true; currentGlitchState = GlitchState.Jump; } else { if (Vertical_Platform.pubActive == false) { onVertPlatform = false; currentPlatform = null; hasJumped = true; currentGlitchState = GlitchState.Jump; } } //Decides which position to move glitch in. if (Vertical_Platform.direction == true) { position.Y -= 5; } else { position.Y += 5; } } }
//Monogame Methods public void Initialize() { canBeHit = true; currentGlitchState = GlitchState.IdleRight; }