public override void update(MouseInfo mouse, KeyInfo keys, float deltaTime) { base.update(mouse, keys, deltaTime); centerMouseOff = mouse.pos - (new Vector2(1920, 1080) / 2); }
public void input(MouseInfo mouse, KeyInfo keys, float deltaTime) { if (keys.pressed(Keys.D1)) { editLayer = 0; } if (keys.pressed(Keys.D2)) { editLayer = 1; } if (keys.pressed(Keys.D3)) { editLayer = 2; } Point mousePoint = pointAt(mouse.pos); if (mouse.leftPressed) { if (keys.down(Keys.LeftShift)) { wiring = true; } else { selecting = true; } clickStart = mousePoint; } clickEnd = mousePoint; if (mouse.leftUnpressed) { if (selecting) { rects.Add(genRect()); } if (wiring) { connections.Add(genWire()); } selecting = false; wiring = false; } if (mouse.rightPressed) { Point pointClick = mousePoint; for (int i = rects.Count - 1; i >= 0; i--) { if (rects[i].layer == editLayer && rects[i].rect.Contains(pointClick)) { rects.RemoveAt(i); } } } for (int i = connections.Count - 1; i >= 0; i--) { WireConnection wire = connections[i]; bool hasFrom = false, hasTo = false; foreach (var rect in rects) { Rectangle bounds = rect.rect; if (bounds.Contains(wire.from)) { hasFrom = true; } if (bounds.Contains(wire.to)) { hasTo = true; } } if (!hasFrom || !hasTo) { connections.RemoveAt(i); } } }
protected override void Update(GameTime gameTime) { base.Update(gameTime); float deltaTime = delta(gameTime); fpsCounter.update(deltaTime); if ((int)gameTime.TotalGameTime.TotalSeconds > secondsPassed) { secondsPassed = (int)gameTime.TotalGameTime.TotalSeconds; Window.Title = "FPS: " + (int)fpsCounter.AverageFramesPerSecond; } KeyboardState keyState = Keyboard.GetState(); MouseState mouseState = Mouse.GetState(); KeyInfo keys = new KeyInfo(keyState, lastKeyState); MouseInfo mouse = new MouseInfo(mouseState, lastMouseState); lastKeyState = keyState; lastMouseState = mouseState; if (keys.down(Keys.Escape)) { exitGame(); } if (uiScreen != null) { uiScreen.update(mouse, keys, deltaTime); return; } if (keys.pressed(Keys.L)) { startEditMode(); } if (keys.pressed(Keys.S) && keys.down(Keys.LeftControl)) { wiringEditor?.saveWiring(levelName); } if (keys.pressed(Keys.T)) { wiringEditor?.applyWiring(); } if (keys.pressed(Keys.G)) { player.godMode = !player.godMode; } if (keys.pressed(Keys.R)) { restartRun(); } // debug change level if (keys.pressed(Keys.Left)) { lastLevel(); } if (keys.pressed(Keys.Right)) { nextLevel(); } // UI for (int i = uiTransitions.Count - 1; i >= 0; i--) { UITransition transition = uiTransitions[i]; if (transition.deleteFlag) { uiTransitions.RemoveAt(i); continue; } transition.update(deltaTime); } foreach (var element in uiElements) { element.update(mouse, keys, deltaTime); } if (keys.pressed(Keys.P)) { if (!paused) { paused = true; pauseTimer = 0; uiElements = pauseUI; UI.transitionAll(uiElements, element => new SlideIn(element) { endTime = pauseTransitionTime }); } else { unPauseClicked(); } } if (paused && endingPause && uiTransitions.Count == 0) { paused = false; endingPause = false; uiElements = gameUI; } if (paused) { if (endingPause) { pauseTimer -= deltaTime; } else { pauseTimer += deltaTime; } } pauseTimer = Math.Min(pauseTimer, pauseTransitionTime); // Must Be Un-paused to Run Following Code ======= if (paused) { return; } if (!player.dead) { attemptTime += deltaTime; } adjustMusicFade(); if (mouse.leftPressed && keys.down(Keys.LeftShift)) { player.pos = camera.toWorld(mouse.pos, player.zPos); } player.input(keys, deltaTime); if (editMode) { wiringEditor?.input(mouse, keys, deltaTime); } updateEntities(deltaTime); updateParticles(deltaTime); map.update(deltaTime); camera.pos = player.pos - Vector2.UnitY * 5; // screen shake if (screenShakeTime > 0) { screenShakeTime -= deltaTime; camera.pos += Util.polar(screenShakeIntensity * screenShakeTime / screenShakeStart, Util.randomAngle()); } Vector2 diff = camera.screenCenter / (camera.scale * camera.farMult(-2)); float clampCameraBottom = ChunkMap.mapHeight() - 1 - diff.Y; float clampCameraTop = 1 + diff.Y; camera.pos.Y = Math.Clamp(camera.pos.Y, clampCameraTop, clampCameraBottom); for (int i = 0; i < entities.Length; i++) { entities[i] = new List <Entity>(); } foreach (var entity in updatedEntities) { sortIntoEntities(entity); } }
public void input(KeyInfo keys, float deltaTime) { //control scheme if (dead) { return; } int inputX = 0; if (keys.down(Keys.A)) { inputX--; } if (keys.down(Keys.D)) { inputX++; } if (keys.pressed(Keys.W) || keys.pressed(Keys.Up)) { startSwitchTo(zPos - 1); } if (keys.pressed(Keys.S) || keys.pressed(Keys.Down)) { startSwitchTo(zPos + 1); } float accelSpeed = (inputX == 0 && grounded) ? 5 : 2.5F; vel.X += ((inputX * speed) - vel.X) * deltaTime * accelSpeed; if (!godMode) { jumpTime -= deltaTime; if (grounded && vel.Y >= 0 && keys.down(Keys.Space) && jumpTime < jumpTimeStart - 0.1F) { jump(jumpHeight); } if (!grounded && keys.down(Keys.Space) && jumpTime > 0) { float fade = jumpTime / jumpTimeStart; vel.Y -= 50F * deltaTime * fade * gravityDir; } } else { int inputY = 0; if (keys.down(Keys.Space)) { inputY--; } if (keys.down(Keys.LeftShift)) { inputY++; } vel.Y += ((inputY * speed) - vel.Y) * deltaTime * accelSpeed; } }