/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (Main game = new Main()) { game.Run(); } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { foreach (Vector4 particle in particles) { spriteBatch.Draw(dirt, new Vector2(particle.X, particle.Y), null, Color.SaddleBrown, 0f, Vector2.Zero, (float) (2.0f + random.NextDouble()), SpriteEffects.None, 0f); } if (countdown == 4) { spriteBatch.DrawString(game.font, "SHAKE", new Vector2(480, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } else if (countdown > 0) { spriteBatch.DrawString(game.font, "" + countdown, new Vector2(630, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } if (shakeCounter >= 3 && shakeCounter <= 11) spriteBatch.DrawString(game.font, "Almost there..", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); switch (heartState) { case 0: spriteBatch.Draw(heartTexture0, heartPosition, Color.White); break; case 1: spriteBatch.Draw(heartTexture1, heartPosition, Color.White); break; case 2: spriteBatch.Draw(heartTexture2, heartPosition, Color.White); spriteBatch.DrawString(game.font, "GOOD!", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); break; } }
public static void GotoRandomMinigame(Main game) { GameState nextGame = game.currentState; switch (new Random().Next(0, 5)) { case 0: nextGame = new MiniGame1State(); break; case 1: nextGame = new MiniGame2State(); break; case 2: nextGame = new MiniGame3State(); break; case 3: nextGame = new MiniGame4State(); break; case 4: nextGame = new MiniGame5State(); break; default: break; } if (nextGame == game.currentState) { GotoRandomMinigame(game); } else { game.currentState = nextGame; } }
void GameState.Update(Main game, GameTime gameTime) { if (game.keyboard.IsKeyDown(Keys.Space)) { game.currentState = new MenuState(); } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { if (operationSuccessful) { spriteBatch.DrawString(game.font, "GOOD!", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); quitTimer--; if (quitTimer == 0) { Util.gamesWon++; if (Util.gamesWon < Util.GAMES_TO_WIN) { Util.GotoRandomMinigame(game); } else { game.currentState = new CutsceneState(); } } } else { spriteBatch.Draw(patientTexture, patientPosition, Color.White); spriteBatch.Draw(heartTexture, heartPosition, Color.White); } if (countdown == 4) { spriteBatch.DrawString(game.font, "INSERT", new Vector2(480, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } else if (countdown > 0) { spriteBatch.DrawString(game.font, "" + countdown, new Vector2(630, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { spriteBatch.Draw(currentHeartTexture, heartPosition, Color.White); if (!hittingHeart) spriteBatch.Draw(waterTexture, waterPosition, new Rectangle(currentFrame/4 * 45, 100, waterTexture.Width / 2, waterTexture.Height-100), Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); else spriteBatch.Draw(waterTexture, waterPosition, new Rectangle(currentFrame / 4 * 45, 200, waterTexture.Width / 2, waterTexture.Height - 200), Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); spriteBatch.Draw(tapTexture, tapPosition, null, Color.White, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); if (countdown == 4) { spriteBatch.DrawString(game.font, "WASH", new Vector2(480, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } else if (countdown > 0) { spriteBatch.DrawString(game.font, "" + countdown, new Vector2(630, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { spriteBatch.DrawString(game.font, "Mini Game 3 State", new Vector2(10, 10), Color.White); if (countdown == 4) { spriteBatch.DrawString(game.font, "AVOID", new Vector2(480, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } else if (countdown > 0) { spriteBatch.DrawString(game.font, "" + countdown, new Vector2(630, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } if (attackedByBugs) { spriteBatch.DrawString(game.font, "FAIL!", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } else if (timer >= TIMER) { spriteBatch.DrawString(game.font, "GOOD!", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); stopUpdate = true; quitTimer--; if (quitTimer == 0) { Util.gamesWon++; if (Util.gamesWon < Util.GAMES_TO_WIN) { Util.GotoRandomMinigame(game); } else { game.currentState = new CutsceneState(); } } } else { foreach (Vector2 bug in bugPositions) { spriteBatch.Draw(bugTexture, bug, Color.White); } spriteBatch.Draw(heartTexture, heartPosition, Color.White); } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { spriteBatch.Draw(heartTexture, heartPosition, Color.White); spriteBatch.Draw(syringeTexture, syringePosition, Color.White); if (countdown > 3) { spriteBatch.DrawString(game.font, "STAB", new Vector2(480, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } else if (countdown > 0) { spriteBatch.DrawString(game.font, "" + countdown, new Vector2(630, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); } if (stab_countdown > 0 && stab_countdown < 4) spriteBatch.DrawString(game.font, ""+stab_countdown, new Vector2(630, 100), Color.Red, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); if (hit) spriteBatch.DrawString(game.font, "GOOD!", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); if (miss) spriteBatch.DrawString(game.font, "FAIL!", new Vector2(450, 100), Color.White, 0f, Vector2.Zero, 5f, SpriteEffects.None, 0f); }
void GameState.Update(Main game, GameTime gameTime) { if (game.keyboard.IsKeyDown(Keys.Escape)) { game.currentState = new MenuState(); } if (countdown != 0) { frameCounter--; if (frameCounter == 0) { countdown--; frameCounter = 40; } } else { if (heartState != 2) { // Update heart position according to mouse position currentMouseState = Mouse.GetState(); float posDiff = currentMouseState.X - heartPosition.X; heartPosition.X += posDiff * 0.1f; if (heartPosition.X < 0) heartPosition.X = 0; if (heartPosition.X > 1280 - heartTexture0.Width) heartPosition.X = 1280 - heartTexture0.Width; posDiff = currentMouseState.Y - heartPosition.Y; heartPosition.Y += posDiff * 0.1f; if (heartPosition.Y < 0) heartPosition.Y = 0; if (heartPosition.Y > 720 - heartTexture0.Height) heartPosition.Y = 720 - heartTexture0.Height; // Check if mouse is moved with a certain velocity if ((currentMouseState.X - oldMouseState.X) > CHANGE_X_PER_FRAME) { shakeCounter--; } if ((currentMouseState.X - oldMouseState.X) > 0) { int counter = random.Next(0, 1 * SHAKE_COUNTER); for (int i = 0; i < counter; i++) { //float angle = (float)(random.NextDouble() * Math.PI * 0.8 + Math.PI * 1.5); float angle = (float)(random.NextDouble() * MathHelper.TwoPi); particles.Add(new Vector4(heartPosition.X + random.Next(-30, 30) + heartTexture0.Width / 2, heartPosition.Y + heartTexture0.Height / 2, (float)Math.Cos(angle), (float)Math.Sin(angle))); } } // if mouse has been moved with specified velocity, remove dirt (change texture) if (shakeCounter == SHAKE_COUNTER / 2) { heartState = 1; } else if (shakeCounter == 0) { heartState = 2; } oldMouseState = currentMouseState; } else { quitTimer--; } if (quitTimer == 0) { Util.gamesWon++; if (Util.gamesWon < Util.GAMES_TO_WIN) { Util.GotoRandomMinigame(game); } else { game.currentState = new CutsceneState(); } } } for (int i = 0; i < particles.Count; i++) { Vector4 particle = particles[i]; particle.Z += 0.1f; particle.X += particle.W; particle.Y += particle.Z; particles[i] = particle; } }
void GameState.Update(Main game, GameTime gameTime) { if (!stopUpdate) { if (game.keyboard.IsKeyDown(Keys.Escape)) { game.currentState = new MenuState(); } if (countdown != 0) { frameCounter--; if (frameCounter == 0) { countdown--; frameCounter = 40; } } else { timer += (float)gameTime.ElapsedGameTime.TotalSeconds; // Update heart position according to mouse position MouseState currentMouseState = new MouseState(); currentMouseState = Mouse.GetState(); float posDiff = currentMouseState.X - heartPosition.X; heartPosition.X += posDiff * 0.1f; if (heartPosition.X < 0) heartPosition.X = 0; if (heartPosition.X > 1280 - heartTexture.Width) heartPosition.X = 1280 - heartTexture.Width; posDiff = currentMouseState.Y - heartPosition.Y; heartPosition.Y += posDiff * 0.1f; if (heartPosition.Y < 0) heartPosition.Y = 0; if (heartPosition.Y > 720 - heartTexture.Height) heartPosition.Y = 720 - heartTexture.Height; // bug moving randomly towards heart for (int i = 0; i < bugPositions.Count; i++) { Vector2 bug = new Vector2(bugPositions[i].X, bugPositions[i].Y); Vector2 bugTarget = new Vector2(bugTargetPositions[i].X, bugTargetPositions[i].Y); Random random = new Random(); if (bug.X < (bugTargetPositions[i].X + BUG_SPEED) && bug.X > (bugTargetPositions[i].X - BUG_SPEED)) bugTarget.X = random.Next(-bugTexture.Width, (1280 - bugTexture.Width)); if (bug.Y < (bugTargetPositions[i].Y + BUG_SPEED) && bug.Y > (bugTargetPositions[i].Y - BUG_SPEED)) bugTarget.Y = random.Next(-bugTexture.Height, (720 - bugTexture.Height)); if (bug.X < bugTargetPositions[i].X) bug.X += BUG_SPEED; if (bug.X > bugTargetPositions[i].X) bug.X -= BUG_SPEED; if (bug.Y < bugTargetPositions[i].Y) bug.Y += BUG_SPEED; if (bug.Y > bugTargetPositions[i].Y) bug.Y -= BUG_SPEED; bugPositions[i] = bug; bugTargetPositions[i] = bugTarget; } // check if heart touches any bug foreach (Vector2 bug in bugPositions) { float x = heartPosition.X + 70; float y = heartPosition.Y + 120; if (x < (bug.X + 30) && x > (bug.X - 30) && y < (bug.Y + 50) && y > (bug.Y - 50)) attackedByBugs = true; } } } }
void GameState.Update(Main game, GameTime gameTime) { if (countdown != 0) { frameCountdown--; if (frameCountdown == 0) { frameCountdown = 40; countdown--; } } else { // Update heart position according to mouse position currentMouseState = Mouse.GetState(); float posDiff = currentMouseState.X - heartPosition.X; heartPosition.X += posDiff * 0.1f; if (heartPosition.X < 0) heartPosition.X = 0; if (heartPosition.X > 1280 - heartTexture.Width) heartPosition.X = 1280 - heartTexture.Width; posDiff = currentMouseState.Y - heartPosition.Y; heartPosition.Y += posDiff * 0.1f; if (heartPosition.Y < 0) heartPosition.Y = 0; if (heartPosition.Y > 720 - heartTexture.Height) heartPosition.Y = 720 - heartTexture.Height; // Randomize movement of patient Random random = new Random(); if (patientPosition.X < (patientTargetPosition.X + PATIENT_SPEED) && patientPosition.X > (patientTargetPosition.X - PATIENT_SPEED)) patientTargetPosition.X = random.Next(-290, 1000); if (patientPosition.Y < (patientTargetPosition.Y + PATIENT_SPEED) && patientPosition.Y > (patientTargetPosition.Y - PATIENT_SPEED)) patientTargetPosition.Y = random.Next(-400, 250); if (patientPosition.X < patientTargetPosition.X) patientPosition.X += PATIENT_SPEED; if (patientPosition.X > patientTargetPosition.X) patientPosition.X -= PATIENT_SPEED; if (patientPosition.Y < patientTargetPosition.Y) patientPosition.Y += PATIENT_SPEED; if (patientPosition.Y > patientTargetPosition.Y) patientPosition.Y -= PATIENT_SPEED; // check if heart is clicked around patient woundPosition.X = patientPosition.X + 300; woundPosition.Y = patientPosition.Y + 320; if (previousMouseState.LeftButton == ButtonState.Released && Mouse.GetState().LeftButton == ButtonState.Pressed) { if ((Math.Abs(woundPosition.X - heartPosition.X) < POSITION_MATCH_ERROR) && (Math.Abs(woundPosition.Y - heartPosition.Y) < POSITION_MATCH_ERROR)) operationSuccessful = true; } previousMouseState = Mouse.GetState(); } }
void GameState.Update(Main game, GameTime gameTime) { if (!failure) { if (backgrounds.Count <= 3) { PlaySound(voiceSuccess, 1.0f, true); Util.GotoRandomMinigame(game); } currentSprite = runAnimTexture; playerPosition.Y = GROUND_HEIGHT; screenAdjustment = RUN_SPEED - ((CENTER - playerPosition.X) * SPEED_INFLUENCE); if (knockbackTimer < 0) { HandleMovement(game.keyboard); HandleSlide(game.keyboard); HandlePunch(game.keyboard, game.prevKeyboard); HandleJump(game.keyboard, game.prevKeyboard); HandleObstacles(); if (knockbackTimer <= KNOCKBACK_BUFFER || knockbackTimer == KNOCKBACK_DURATION) { MoveScreen(screenAdjustment); PlaySound(voiceRandom, VOICE_RANDOM_CHANCE, false); } else { currentSprite = hitTexture; knockbackTimer--; if (knockbackTimer == KNOCKBACK_BUFFER + 1) PlaySound(voiceRecover, VOICE_RECOVER_CHANCE, true); } } else { currentSprite = hitTexture; knockbackTimer--; MoveScreen(-KNOCKBACK_DISTANCE / KNOCKBACK_DURATION); } heart.Update(gameTime); if (heart.heartMeter == 0) failure = true; if (heart.beat) { Vector2[] tempArray = new Vector2[blipPositions.Length+1]; for (int j = 0; j < blipPositions.Length; j++) { tempArray[j] = blipPositions[j]; } tempArray[tempArray.Length - 1] = new Vector2(-monitorBlipTexture.Width, 14); blipPositions = (Vector2[])tempArray.Clone(); } } else { currentSprite = hitTexture; if (quitTimer == QUIT_DURATION) PlaySound(voiceFailure, VOICE_FAILURE_CHANCE, true); quitTimer--; if (quitTimer == 0) { Main.SubmitResult("Defeat", 0); game.currentState = new MenuState(); } } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { float scale = 1000 / Main.SCREEN_WIDTH; spriteBatch.Draw(background, new Rectangle(0, 0, (int)Main.SCREEN_WIDTH, (int)(Main.SCREEN_HEIGHT * scale)), Color.White); }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { float scale = 1000 / Main.SCREEN_WIDTH; spriteBatch.Draw(background, new Rectangle(0, 50, (int)Main.SCREEN_WIDTH, (int)(Main.SCREEN_HEIGHT * scale)), Color.White); // Draw title with white outline spriteBatch.DrawString(game.headerFont, TITLE_TEXT, POSITION_TITLE + new Vector2(-2, -2), Color.White, 0, ORIGIN, 1, SpriteEffects.None, 1f); spriteBatch.DrawString(game.headerFont, TITLE_TEXT, POSITION_TITLE + new Vector2(-2, +2), Color.White, 0, ORIGIN, 1, SpriteEffects.None, 1f); spriteBatch.DrawString(game.headerFont, TITLE_TEXT, POSITION_TITLE + new Vector2(+2, +2), Color.White, 0, ORIGIN, 1, SpriteEffects.None, 1f); spriteBatch.DrawString(game.headerFont, TITLE_TEXT, POSITION_TITLE + new Vector2(+2, -2), Color.White, 0, ORIGIN, 1, SpriteEffects.None, 1f); spriteBatch.DrawString(game.headerFont, TITLE_TEXT, POSITION_TITLE, Color.Black); // Vector2 offset = game.font.MeasureString(PROMPT_TEXT); spriteBatch.DrawString(game.font, PROMPT_TEXT, new Vector2(505, 680), Color.Black); foreach (Button button in buttons) { Color color = selectedButton == button.index ? Color.Red : Color.White; spriteBatch.Draw(game.placeholderTexture, new Rectangle(button.x, button.y, 20, 20), color); spriteBatch.DrawString(game.font, button.text, new Vector2(button.x + 25, button.y), color); } }
void GameState.Update(Main game, GameTime gameTime) { if (Util.IsAnyKeyPressed(game.keyboard, game.prevKeyboard, cancelKeys)) { game.Exit(); } if (Util.IsAnyKeyDown(game.keyboard, acceptKeys)) { //buttons[selectedButton].action.BeginInvoke(game, null, null); game.currentState = new PlatformingState(); } /* if (Util.IsAnyKeyPressed(game.keyboard, game.prevKeyboard, downKeys)) { selectedButton++; if (selectedButton >= totalButtons) selectedButton = 0; } if (Util.IsAnyKeyPressed(game.keyboard, game.prevKeyboard, upKeys)) { selectedButton--; if (selectedButton < 0) selectedButton = totalButtons-1; } * */ }
void GameState.Update(Main game, GameTime gameTime) { if (countdown != 0) { frameCountdown--; if (frameCountdown == 0) { frameCountdown = 40; countdown--; } } else { float posDiff = Mouse.GetState().X - heartPosition.X; heartPosition.X += posDiff * 0.1f; if (heartPosition.X < 0) heartPosition.X = 0; if (heartPosition.X > 1280 - heartTexture.Width) heartPosition.X = 1280 - heartTexture.Width; if (Math.Abs(tapPosition.X - tapGoal) >= 10) { if (tapPosition.X < tapGoal) tapPosition.X += 10; else if (tapPosition.X > tapGoal) tapPosition.X -= 10; waterPosition = new Vector2(tapPosition.X - 23, tapPosition.Y + 200); } else { Random random = new Random(); tapGoal = random.Next(50, 1000); } hittingHeart = false; if (heartPosition.X < waterPosition.X + waterTexture.Width / 4 && heartPosition.X > waterPosition.X + waterTexture.Width / 4 - heartTexture.Width) { dirt--; hittingHeart = true; } currentHeartTexture = heartDirty2Texture; if (dirt <= 75) currentHeartTexture = heartDirty1Texture; if (dirt <= 0) { currentHeartTexture = heartTexture; quitTimer--; } if (quitTimer == 0) { Util.gamesWon++; if (Util.gamesWon < Util.GAMES_TO_WIN) { Util.GotoRandomMinigame(game); } else { game.currentState = new CutsceneState(); } } } currentFrame++; if (currentFrame > 7) currentFrame = 0; }
void GameState.Update(Main game, GameTime gameTime) { if (countdown <= 1) { if (!hit) { float posDiff = Mouse.GetState().X - heartPosition.X; heartPosition.X += posDiff * 0.1f; if (heartPosition.X < 0) heartPosition.X = 0; if (heartPosition.X > 1280 - heartTexture.Width) heartPosition.X = 1280 - heartTexture.Width; } if (stab_countdown != 0) { frameCountdown--; if (frameCountdown == 0) { frameCountdown = 40; stab_countdown--; countdown--; Random random = new Random(); if (stab_countdown != 0) syringeGoal = random.Next(0, 1280 - syringeTexture.Width); } syringePosition.X += (syringeGoal - syringePosition.X) * 0.1f; } else if (!hit) { syringePosition.Y += 20; } if (hit || miss) { quitTimer--; } if (quitTimer == 0) { if (hit) { Util.gamesWon++; if (Util.gamesWon < Util.GAMES_TO_WIN) { Util.GotoRandomMinigame(game); } else { game.currentState = new CutsceneState(); } } else { Util.GotoRandomMinigame(game); } } syringeRect = new Rectangle((int)syringePosition.X + 28, (int)syringePosition.Y + 227, 2, 56); heartRect = new Rectangle((int)heartPosition.X, (int)heartPosition.Y + 100, (int)heartTexture.Width, (int)heartTexture.Height - 100); if (syringeRect.Intersects(heartRect)) { hit = true; } if (syringePosition.Y == 720) { miss = true; } } else { frameCountdown--; if (frameCountdown == 0) { frameCountdown = 40; countdown--; } } }
void GameState.Draw(Main game, SpriteBatch spriteBatch) { int i = 0; foreach (Texture2D background in backgrounds) { spriteBatch.Draw(background, new Vector2(backgroundPosition.X + (Util.scale(backgroundWidth) * i), backgroundPosition.Y), null, Color.White, 0f, Vector2.Zero, Util.SCALE, SpriteEffects.None, 0f); i++; } spriteBatch.Draw(currentObstacle.sprite, currentObstacle.position, null, Color.White, 0f, Vector2.Zero, Util.SCALE, SpriteEffects.None, 0f); if (currentSprite != runAnimTexture && currentSprite != jumpAnimTexture) spriteBatch.Draw(currentSprite, playerPosition, null, Color.White, 0f, Vector2.Zero, Util.SCALE, SpriteEffects.None, 0f); else { Rectangle rect = new Rectangle(0, 0, 0, 0); if (currentSprite == runAnimTexture) rect = animBoxes[currentFrame/3]; if (currentSprite == jumpAnimTexture) rect = animBoxes[(int)(currentFrame/(JUMP_DURATION/8))]; spriteBatch.Draw(currentSprite, playerPosition, rect, Color.White, 0f, Vector2.Zero, Util.SCALE, SpriteEffects.None, 0f); currentFrame++; if (currentSprite == runAnimTexture) if (currentFrame == 8*3) currentFrame = 0; if (currentSprite == jumpAnimTexture) if (currentFrame == 6*(JUMP_DURATION/8)) currentFrame = 0; } Color uiColor; uiColor = Color.White; if (heart.heartMeter < 35) uiColor = Color.Yellow; if (heart.heartMeter < 20) uiColor = Color.Orange; if (heart.heartMeter < 10) uiColor = Color.Red; spriteBatch.Draw(uibg, Vector2.Zero, uiColor); Console.WriteLine(blipPositions.Length); for (int j = 0; j < blipPositions.Length; j++) { spriteBatch.Draw(monitorBlipTexture, blipPositions[j], uiColor); blipPositions[j].X += 10; } spriteBatch.Draw(uibgo, Vector2.Zero, uiColor); if (heart.justPressed) { spriteBatch.DrawString(game.font, heart.performance.ToString(), new Vector2(10, 150), uiColor, 0f, Vector2.Zero, 2f, SpriteEffects.None, 0f); } heart.Draw(spriteBatch, 1080, 0); }