public override void Update(double dt) { UpdateLoop.Update(dt); if (KeyboardInputService.IsDown("Quit")) { Game.Exit(); } }
public override void Update(double dt) { Entities.Update(dt); UpdateLoop.Update(dt); if (KeyboardInputService.IsDown("Quit") || Entities.List <Ball>().Count == 0) { Game.Exit(); } }
public override void Update(double dt) { Entities.Update(dt); UpdateLoop.Update(dt); if (KeyboardInputService.IsDown("Quit")) { Game.Exit(); } DrawableScore.Text = $"Score: {Game.Score}"; }
public override void Initialize() { Random = new Random(); KeyboardInputService.SetKeyAlias("Quit", SDL.SDL_Keycode.SDLK_ESCAPE); KeyboardInputService.SetKeyAlias("Left", SDL.SDL_Keycode.SDLK_LEFT); KeyboardInputService.SetKeyAlias("Right", SDL.SDL_Keycode.SDLK_RIGHT); Scenes = CreateSceneHandler(); Scenes.Window = WindowService.CreateWindow("Brakeout", new Vec2(100, 100), ScreenSize); Scenes.Canvas = WindowService.CreateCanvas(Scenes.Window); Scenes.ContentLoader = WindowService.CreateContentLoader(Scenes.Canvas); Scenes.SetScene <GameScene>(); }
public override void Update(double dt) { if (KeyboardInputService.IsDown("Left") && Entity.Position.X > 0) { Entity.Position = Entity.Position.TransformX(-EntityData.Speed * dt); } else if (KeyboardInputService.IsDown("Right") && Entity.Position.X + Entity.Size.X < Scene.Window.Size.X) { Entity.Position = Entity.Position.TransformX(EntityData.Speed * dt); } if (KeyboardInputService.IsDown("Up") && Entity.Position.Y > 0) { Entity.Position = Entity.Position.TransformY(-EntityData.Speed * dt); } else if (KeyboardInputService.IsDown("Down") && Entity.Position.Y + Entity.Size.Y < Scene.Window.Size.Y) { Entity.Position = Entity.Position.TransformY(EntityData.Speed * dt); } if (Entity.Position.X < 0) { Entity.Position = Entity.Position.SetX(0); } if (Entity.Position.X > Scene.Window.Size.X - Entity.Size.X) { Entity.Position = Entity.Position.SetX(Scene.Window.Size.X - Entity.Size.X); } if (Entity.Position.Y < 0) { Entity.Position = Entity.Position.SetY(0); } if (Entity.Position.Y > Scene.Window.Size.Y - Entity.Size.Y) { Entity.Position = Entity.Position.SetY(Scene.Window.Size.Y - Entity.Size.Y); } ShootTimer += dt; if (KeyboardInputService.IsDown("Shoot")) { if (ShootTimer >= ShootTime) { ShootTimer = 0; Entity.Shoot(); } } }
public override void Update(double dt) { ShootTimer += dt; if (KeyboardInputService.IsDown("Shoot")) { if (ShootTimer >= ShootTime) { ShootTimer = 0; Scene.Entities.Create <Bullet>(new Vec2(Entity.Position.X + Entity.Size.X / 2 - 2, Entity.Position.Y)).EntityData.Speed += EntityData.Speed; } } PowerUpTimer += dt; if (PowerUpTimer >= PowerUpTime) { Entity.Logics.Destroy <PlayerPowerUpLogic>(); } }
public override void Initialize() { Logger.Log("Starting up the Game!"); Random = new Random(); KeyboardInputService.SetKeyAlias("Quit", SDL.SDL_Keycode.SDLK_ESCAPE); KeyboardInputService.SetKeyAlias("Left", SDL.SDL_Keycode.SDLK_LEFT); KeyboardInputService.SetKeyAlias("Right", SDL.SDL_Keycode.SDLK_RIGHT); KeyboardInputService.SetKeyAlias("Up", SDL.SDL_Keycode.SDLK_UP); KeyboardInputService.SetKeyAlias("Down", SDL.SDL_Keycode.SDLK_DOWN); KeyboardInputService.SetKeyAlias("Shoot", SDL.SDL_Keycode.SDLK_z); Scenes = CreateSceneHandler(); Scenes.Window = WindowService.CreateWindow("Space Invader", new Vec2(100, 100), ScreenSize); Scenes.Canvas = WindowService.CreateCanvas(Scenes.Window); Scenes.ContentLoader = WindowService.CreateContentLoader(Scenes.Canvas); Scenes.SetScene <SpaceScene>(); }
public void Update(double dt) { if (KeyboardInputService.IsDown("Left") && Position.X > 0) { Position = Position.TransformX(-Speed * dt); } else if (KeyboardInputService.IsDown("Right") && Position.X + Size.X < Scene.Window.Size.X) { Position = Position.TransformX(Speed * dt); } if (Position.X < 0) { Position = Position.SetX(0); } if (Position.X > Scene.Window.Size.X - Size.X) { Position = Position.SetX(Scene.Window.Size.X - Size.X); } foreach (var ball in Scene.Entities.List <Ball>()) { var r1x = Position.X; var r1y = Position.Y; var r1w = Size.X; var r1h = Size.Y; var r2x = ball.Position.X; var r2y = ball.Position.Y; var r2w = ball.Size.X; var r2h = ball.Size.Y; if (r1x + r1w >= r2x && r1x <= r2x + r2w && r1y + r1h >= r2y && r1y <= r2y + r2h) { var p = ((ball.Position.X + ball.Size.X / 2) - (Position.X + Size.X / 2)) / Size.X; if (p >= -0.15 && p <= 0.15) { ball.Direction = new Vec2(0, -1); } else { ball.Direction = new Vec2(ball.Direction.X + p, -ball.Direction.Y); } ball.Direction.Normalize(); ball.Position = ball.Position.SetY(Position.Y - ball.Size.Y - 1); } } foreach (var entity in Scene.Entities.ListAll()) { if (!(entity is Powerup)) { continue; } var powerup = entity as Powerup; var r1x = Position.X; var r1y = Position.Y; var r1w = Size.X; var r1h = Size.Y; var r2x = powerup.Position.X; var r2y = powerup.Position.Y; var r2w = powerup.Size.X; var r2h = powerup.Size.Y; if (r1x + r1w >= r2x && r1x <= r2x + r2w && r1y + r1h >= r2y && r1y <= r2y + r2h) { powerup.Pickup(); powerup.Remove(); } } }
public KeyboardGameplayInputManager(ref ActionMap actions) : base(ref actions) { InputService = new KeyboardInputService(); }