/*********************************************************************/ /* Class Methods */ /*********************************************************************/ /// <summary> /// Inverts Pacman's current state. /// </summary> public void switchState() { if (state == PacmanState.Open) state = PacmanState.Closed; else state = PacmanState.Open; }
public void Update(float time, Grid grid) { if (oldPacmanState != pacmanState) { currentFrame = 0; totalTime = 0; } oldPacmanState = pacmanState; totalTime += time; if (pacmanState == PacmanState.Alive) { float oldiPos = iSpritePos; float oldjPos = jSpritePos; Move(ToMove, grid); if (totalTime > 0.04f) { totalTime = 0; if (oldiPos != iSpritePos || oldjPos != jSpritePos) { currentFrame += frameTick; } else { currentFrame = 0; } if (currentFrame > 2 || currentFrame < 0) { currentFrame = 1; frameTick = -frameTick; } } } else if (pacmanState == PacmanState.Dieing) { if (totalTime > 0.1f) { totalTime = 0; currentFrame++; if (currentFrame > 11) { currentFrame--; pacmanState = PacmanState.Dead; } } } else { } }
/*********************************************************************/ /* Class Methods */ /*********************************************************************/ /// <summary> /// Inverts Pacman's current state. /// </summary> public void switchState() { if (state == PacmanState.Open) { state = PacmanState.Closed; } else { state = PacmanState.Open; } }
public Pacman(int jPos = 23, int iPos = 13) { direction = Direction.Up; totalTime = 0; _jPos = jPos; _iPos = iPos; toMoveDirection = Direction.Left; iSpritePos = _iPos; jSpritePos = _jPos; currentFrame = 0; SetUpSprites(); pacmanState = PacmanState.Alive; oldPacmanState = pacmanState; }
protected override void setAnimationState() { if (gameManager.pacmanData.alive) { if (lastState == PacmanState.Die) { anim.SetInteger("AnimState", 5); lastState = PacmanState.Idle; } else { PacmanWalker pacman = walker as PacmanWalker; if (pacman.grounded()) { if (pacman.justLanded()) { anim.SetInteger("AnimState", 4); lastState = PacmanState.Idle; } else if (pacman.moving()) { anim.SetInteger("AnimState", 1); lastState = PacmanState.Run; } else { anim.SetInteger("AnimState", 0); lastState = PacmanState.Idle; } } else { if (pacman.jumpingUp()) { anim.SetInteger("AnimState", 2); lastState = PacmanState.JumpUp; } else if (pacman.jumpingDown()) { anim.SetInteger("AnimState", 3); lastState = PacmanState.JumpDown; } } } } else { if (lastState == PacmanState.Idle) { anim.SetInteger("AnimState", 8); } else if (lastState == PacmanState.JumpUp) { anim.SetInteger("AnimState", 6); } else if (lastState == PacmanState.JumpDown) { anim.SetInteger("AnimState", 7); } else if (lastState == PacmanState.Run) { anim.SetInteger("AnimState", 9); } lastState = PacmanState.Die; GameObject.FindGameObjectWithTag("Pacman").GetComponent <PacmanSounds>().pacmanDeath(); } }
public virtual void Update(GameTime gameTime, KeyboardState keyboardState, MouseState mouseState, GameState gameState, MouseState old_mouseState, KeyboardState old_keyboardState, string map, ref int score,int level) { // deroulement de jeu quand normal if (pacman_state == PacmanState.game) { if (nb_boulette == 0 || keyboardState.IsKeyDown(Keys.W)) { pacman_state = PacmanState.finish; score_transfere = life * 200; } if (pacman.IsAlive(fantome1, ref score) || pacman.IsAlive(fantome2, ref score) || pacman.IsAlive(fantome3, ref score) || pacman.IsAlive(fantome4, ref score)) pacman_state = PacmanState.death; pacman.Update(gameTime, keyboardState, ref tab_boulette, ref score, ref nb_boulette); fantome1.Update(ref tab_boulette, map,level); fantome2.Update(ref tab_boulette, map,level); fantome3.Update(ref tab_boulette, map,level); fantome4.Update(ref tab_boulette, map,level); if (keyboardState.IsKeyUp(Keys.Space) && old_keyboardState.IsKeyDown(Keys.Space)) { pacman_state = PacmanState.pause; } } else if (pacman_state == PacmanState.death) { life = life - 1; if (life == 0) pacman_state = PacmanState.over; else { pacman_state = PacmanState.inter; fantome1.Initialize(map,1,level); fantome2.Initialize(map,2,level); fantome3.Initialize(map,3,level); fantome4.Initialize(map,1,level); pacman.Initialize(map); } } else if (pacman_state == PacmanState.inter) { // initialisation vecteurs pour sprite inter vie niveau.. position_inter_vie = new Vector2(500 - inter_vie.Width / 2, 350 - inter_vie.Height / 2); position_rejouer = new Vector2(500 - rejouer.Width / 2, 350 - rejouer.Height / 2 + 50); if (mouseState.X < (position_rejouer.X + rejouer.Width) && mouseState.X > (position_rejouer.X - rejouer.Width) && mouseState.Y < (position_rejouer.Y + rejouer.Height) && mouseState.Y > (position_rejouer.Y - rejouer.Height) && mouseState.LeftButton != ButtonState.Pressed && old_mouseState.LeftButton == ButtonState.Pressed) pacman_state = PacmanState.game; } else if (pacman_state == PacmanState.over) { // initialisation vecteurs pour sprite inter vie niveau.. position_inter_vie = new Vector2(500 - inter_vie.Width / 2, 350 - inter_vie.Height / 2); position_rejouer = new Vector2(500 - rejouer.Width / 2, 350 - rejouer.Height / 2 +50); if (mouseState.X < (position_rejouer.X + rejouer.Width) && mouseState.X > (position_rejouer.X - rejouer.Width) && mouseState.Y < (position_rejouer.Y + rejouer.Height) && mouseState.Y > (position_rejouer.Y - rejouer.Height) && mouseState.LeftButton != ButtonState.Pressed && old_mouseState.LeftButton == ButtonState.Pressed) check_retour_menu = true; } else if (pacman_state == PacmanState.finish) { // initialisation vecteurs pour sprite inter vie niveau.. position_inter_vie = new Vector2(500 - inter_vie.Width / 2, 350 - inter_vie.Height / 2); position_rejouer = new Vector2(500 - rejouer.Width / 2, 350 - rejouer.Height / 2 + 50); if (score_transfere != 0) { score++; score_transfere--; score++; score_transfere--; } if (mouseState.X < (position_rejouer.X + rejouer.Width) && mouseState.X > (position_rejouer.X - rejouer.Width) && mouseState.Y < (position_rejouer.Y + rejouer.Height) && mouseState.Y > (position_rejouer.Y - rejouer.Height) && mouseState.LeftButton != ButtonState.Pressed && old_mouseState.LeftButton == ButtonState.Pressed) check_level_next = true; } else if (pacman_state == PacmanState.pause) { if (keyboardState.IsKeyUp(Keys.Space) && old_keyboardState.IsKeyDown(Keys.Space)) { pacman_state = PacmanState.game; } } }
public virtual void Initialize( string maptxt, string map, int level) { // initialisation vie + score life = 3; // initialisation de pacman pacman.Initialize(map); // etat du jeu de base pacman_state = PacmanState.game; // lecture du fichier .txt pour boulette tab_string = System.IO.File.ReadAllText("../../../"+maptxt); // initialisation boulette tab.InitializeMaps(tab_string, ref tab_boulette); nb_boulette = tab.nb_boul; // initialisation fantomes fantome1.Initialize(map,1,level); fantome2.Initialize(map,2,level); fantome3.Initialize(map,3,level); fantome4.Initialize(map,1,level); // initialisation du booleen qui sert à verifier qu'apres mort total on clique ou non sur menu check_retour_menu = false; // initialisation du booleen qui sert à verifier si passage au level 2 après win check_level_next = false; }
public Pacman() { this._state = PacmanState.Spawning; }
public void Caught() { pacmanState = PacmanState.Dieing; }
// Update is called once per frame void Update() { CharacterController contr = pacMan.GetComponent <CharacterController>(); if (superPelletCounter == 4) { superpowered = true; } switch (pacstate) { case PacmanState.Running: speed = (15.0f + ((float)pelletCount / 100)); rolltimer = 1.0f; chargeTimer = 1.0f; if (contr.isGrounded) { direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction *= speed; if (Input.GetButtonDown("Jump")) { direction.y = jumpSpeed; flightTimer = 1.8f; floatTimer.value = 1.8f; anim.SetBool("JumpB", true); anim.SetFloat("JSpeed", 1); } else { anim.SetBool("JumpB", false); } if (Input.GetButtonDown("Fire2")) { crouch(); } else { anim.SetBool("CrouchButton", false); } } else { direction = new Vector3(Input.GetAxis("Horizontal"), direction.y, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction.x *= speed; direction.z *= speed; } if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { anim.SetFloat("Speed", 1); } else { anim.SetFloat("Speed", 0); } if (direction.y == 0) { anim.SetFloat("JSpeed", 0); } if (Input.GetButton("Fire1")) { if (flightTimer > 0) { fly(); floatTimer.value -= Time.deltaTime; } } else if (Input.GetButton("Submit")) { if (chompTimer > 0) { chompState = Chomp.chomp; anim.SetBool("OnPellet", true); chompTimer -= Time.deltaTime; } else { chompState = Chomp.notChomp; anim.SetBool("OnPellet", false); } } if (chompState == Chomp.notChomp) { chompTimer = 0.5f; } direction.y -= gravity * Time.deltaTime; contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; break; case PacmanState.Ducking: direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction *= speed; direction *= 0.3f; if (Input.GetButtonDown("Fire3")) { pacstate = PacmanState.ChargeUp; } if (Input.GetButtonUp("Fire2") || !contr.isGrounded) { pacstate = PacmanState.Running; } if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { anim.SetFloat("Speed", 1); } else { anim.SetFloat("Speed", 0); } direction.y -= gravity * Time.deltaTime; contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; break; case PacmanState.Damaged: break; case PacmanState.Rolling: direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); direction = transform.TransformDirection(direction); direction *= speed; direction *= 5; anim.SetBool("DashButton", true); if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { anim.SetFloat("Speed", 1); } else { anim.SetFloat("Speed", 0); } direction.y -= gravity * Time.deltaTime; contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; rolltimer -= Time.deltaTime; chargeAndDashSlider.value -= Time.deltaTime; if (rolltimer <= 0) { pacstate = PacmanState.Running; anim.SetBool("DashButton", false); } break; case PacmanState.ChargeUp: if (Input.GetButtonUp("Fire3")) { pacstate = PacmanState.Ducking; break; } chargeTimer -= Time.deltaTime; chargeAndDashSlider.value = 1 - Time.deltaTime; if (chargeTimer <= 0) { pacstate = PacmanState.Rolling; } contr.Move(direction * Time.deltaTime); newRotation = pacMan.transform.eulerAngles; newRotation.y = camera.transform.eulerAngles.y; // lookdirection.eulerAngles = new Vector3(pacMan.transform.rotation.x, camera.transform.rotation.y, pacMan.transform.rotation.z); pacMan.transform.eulerAngles = newRotation; break; case PacmanState.Dead: break; } }
public void crouch() { pacstate = PacmanState.Ducking; anim.SetBool("CrouchButton", true); }