public SoundControl(Ballz game) { Game = game; loadedSounds = new Dictionary <string, SoundEffect>(); WinnerSounds.Add("Germoney", "Sounds/germoney"); WinnerSounds.Add("Murica", "Sounds/freedom_fuckyeah"); }
public void Start() { Peer.Start(); HandleNewPlayer(null, new LobbyPlayerGreeting { PlayerName = Ballz.The().Settings.PlayerName }); }
private void HandleMatchStart(GameStartInfo startInfo) { var settings = MatchSettings.Deserialize(startInfo.Settings); Ballz.The().Network.StartNetworkGame(settings, startInfo.YourPlayerId); Ballz.The().Match.IsRemoteControlled = true; }
protected override void ImplInitializeSession(Ballz game, MatchSettings settings) { var mapTexture = MapName == "Generated" ? TerrainGenerator.GenerateTerrain(width, height): game.Content.Load <Texture2D>("Worlds/" + MapName); settings.MapName = MapName; settings.MapTexture = mapTexture; }
public override void FireShot() { if (ShotsFired < MaxShots || !Game.Match.UsePlayerTurns) { ++ShotsFired; Game.Services.GetService <SoundControl>().PlaySound(SoundControl.PistolSound); var muzzle = SpriteGraphicsEffect.CreateMuzzle( Game.Match.GameTime, Ball.Position + 2f * Ball.AimDirection, Ball.AimDirection.RotationFromDirection() ); Game.Match.World.GraphicsEvents.Add(muzzle); var rayHit = Game.Match.Physics.Raycast(Ball.Position, Ball.Position + Ball.AimDirection * 1000f); if (rayHit.HasHit) { Game.Match.World.StaticGeometry.SubtractCircle(rayHit.Position.X, rayHit.Position.Y, ExplosionRadius); Ballz.The().Match.World.GraphicsEvents.Add(SpriteGraphicsEffect.CreateExplosion(Ballz.The().Match.GameTime, rayHit.Position, 0, 0.2f)); if (rayHit.Entity != null) { if (rayHit.Entity is Ball) { Ball theBall = rayHit.Entity as Ball; if (theBall.Health > 0) { theBall.ChangeHealth(-Damage); } } } } } }
public SoundControl(Ballz game) { Game = game; loadedSounds = new Dictionary<string, SoundEffect>(); WinnerSounds.Add("Germoney","Sounds/germoney"); WinnerSounds.Add("Murica", "Sounds/freedom_fuckyeah"); }
public Session(Ballz _game, World.World world, MatchSettings settings) { World = world; Terrain = World.StaticGeometry; GameSettings = settings; Physics = new Physics.PhysicsControl(_game); Physics.Enabled = false; _game.Components.Add(Physics); GameRenderer = new Renderer.GameRenderer(_game); GameRenderer.Enabled = false; GameRenderer.Visible = false; _game.Components.Add(GameRenderer); DebugRenderer = new Renderer.DebugRenderer(_game); DebugRenderer.Enabled = false; DebugRenderer.Visible = false; _game.Components.Add(DebugRenderer); SessionLogic = new Logic.GameLogic(_game, this); SessionLogic.Enabled = false; _game.Components.Add(SessionLogic); Logic = _game.Services.GetService <LogicControl>(); Logic.Message += Physics.HandleMessage; Logic.Message += GameRenderer.HandleMessage; Logic.Message += SessionLogic.HandleMessage; Logic.Message += DebugRenderer.HandleMessage; Input = _game.Services.GetService <Input.InputTranslator>(); Game = _game; }
public void Start() { BrowserThread = new Thread(() => { Browser = new WebBrowser(); Browser.Width = Ballz.The().GraphicsDevice.Viewport.Width; Browser.Height = Ballz.The().GraphicsDevice.Viewport.Height; Browser.ScrollBarsEnabled = false; //Browser.IsWebBrowserContextMenuEnabled = false; LatestBitmap = new Bitmap(Browser.Width, Browser.Height); Browser.Validated += (s, e) => { lock (this) { Browser.DrawToBitmap(LatestBitmap, new Rectangle(0, 0, Browser.Width, Browser.Height)); } }; Browser.DocumentCompleted += (s, e) => { lock (this) { Browser.DrawToBitmap(LatestBitmap, new Rectangle(0, 0, Browser.Width, Browser.Height)); } }; Browser.Navigate("file://C:/Users/Lukas/Documents/gui.html"); var context = new ApplicationContext(); Application.Run(); }); BrowserThread.SetApartmentState(ApartmentState.STA); BrowserThread.Start(); }
public void SetMainMenu(MenuPanel menu) { activeMenu.Clear(); activeMenu.Push(menu); //TODO: uncast state = GameState.MenuState; menu.OnOpen(); Ballz.The().LockMouse = false; }
// StartSession must _not_ modify GameSettings public Session StartSession(Ballz game, MatchSettings settings, bool isMultiplayer, int localPlayerId) { if (!IsInitialized) { InitializeSession(game, settings); } return(ImplStartSession(game, settings, isMultiplayer, localPlayerId)); }
private void ProcessMouseInput() { if (CurrentMouseState.LeftButton != PreviousMouseState.LeftButton) { var isPressed = CurrentMouseState.LeftButton == ButtonState.Pressed; var player = Ballz.The().Match?.PlayerByNumber(1); OnInput(InputMessage.MessageType.ControlsAction, pressed: isPressed, player: player); } }
public override void OnEntityCollision(Entity other) { if (Ballz.The().Match.IsRemoteControlled) { return; } //TODO: Player damage onAnyCollision(); }
public static Texture2D LoadTextureData(string pngdata) { var png = Convert.FromBase64String(pngdata); using (var ms = new MemoryStream(png)) { var texture = Texture2D.FromStream(Ballz.The().GraphicsDevice, ms); return(texture); } }
public PerformanceReporter(Ballz game) { StackFrame frame = new StackFrame(1); var method = frame.GetMethod(); var type = method.DeclaringType; Name = type.Name+"."+method.Name; Game=game; Sw = new Stopwatch(); Sw.Start(); }
private void HandleRemoteInput(NetConnection sender, InputMessage msg) { var player = PlayersByConnection[sender.RemoteUniqueIdentifier].MatchPlayer; msg.Player = player; if (player != null) { Ballz.The().Input.InjectInputMessage(msg, player); } }
public LogicControl(Ballz game) { Game = game; Composite menu = Game.MainMenu;// = DefaultMenu(); //push the root menuToPrepare activeMenu.Push(menu); //TODO: uncast RegisterMenuEvents(menu); state = GameState.MenuState; }
public PerformanceReporter(Ballz game) { StackFrame frame = new StackFrame(1); var method = frame.GetMethod(); var type = method.DeclaringType; Name = type.Name + "." + method.Name; Game = game; Sw = new Stopwatch(); Sw.Start(); }
protected virtual void RaiseMessageEvent(Message msg) { Message?.Invoke(this, msg); if (state == GameState.MenuState) { Ballz.The().Services.GetService <SoundControl>().StartMusic(SoundControl.MenuMusic); } else { Ballz.The().Services.GetService <SoundControl>().StopMusic(SoundControl.MenuMusic); } }
public void OpenMenu(MenuPanel newMenu) { var oldMenu = activeMenu.Peek(); oldMenu.OnClose(); newMenu.OnOpen(); activeMenu.Push(newMenu); RaiseMessageEvent(new MenuMessage(activeMenu.Peek())); state = GameState.MenuState; Ballz.The().LockMouse = false; }
public BallControl(Ballz game, Session match, Ball ball) { Game = game; Match = match; Ball = ball; KeyPressed[InputMessage.MessageType.ControlsAction] = false; KeyPressed[InputMessage.MessageType.ControlsUp] = false; KeyPressed[InputMessage.MessageType.ControlsDown] = false; KeyPressed[InputMessage.MessageType.ControlsLeft] = false; KeyPressed[InputMessage.MessageType.ControlsRight] = false; }
public Texture2D GetTerrainTypeTexture() { Update(); lock (PublicShape) { if (PublicShape.TypeTexture == null) { PublicShape.TypeTexture = new Texture2D(Ballz.The().GraphicsDevice, width, height); PublicShape.TypeTexture.SetData(PublicShape.TypeData); } } return(PublicShape.TypeTexture); }
private void OnInput(InputMessage.MessageType inputType, bool pressed = false, char key = char.MinValue, Player player = null) { var inputMessage = new InputMessage(inputType, pressed, key, player); if (Ballz.The().MessageOverlay != null) { Ballz.The().MessageOverlay.HandleInput(inputMessage); } else { Input?.Invoke(this, inputMessage); //todo: use object pooling and specify message better } }
public UserControl(Ballz game, Session match, Ball ball) : base(game, match, ball) { AvailableWeapons.Add(new Weapons.Potato(ball, game)); AvailableWeapons.Add(new Weapons.Grenade(ball, game)); AvailableWeapons.Add(new Weapons.RopeTool(ball, game)); AvailableWeapons.Add(new Weapons.Bazooka(ball, game)); AvailableWeapons.Add(new Weapons.Pistol(ball, game)); AvailableWeapons.Add(new Weapons.Waterbomb(ball, game)); AvailableWeapons.Add(new Weapons.Drill(ball, game)); Weapon = AvailableWeapons[SelectedWeaponIndex]; Ball.HoldingWeapon = AvailableWeapons[SelectedWeaponIndex].Icon; }
public UserControl(Ballz game, Session match, Ball ball): base(game, match, ball) { AvailableWeapons.Add(new Weapons.Potato(ball, game)); AvailableWeapons.Add(new Weapons.Grenade(ball, game)); AvailableWeapons.Add(new Weapons.RopeTool(ball, game)); AvailableWeapons.Add(new Weapons.Bazooka(ball, game)); AvailableWeapons.Add(new Weapons.Pistol(ball, game)); AvailableWeapons.Add(new Weapons.Waterbomb(ball, game)); AvailableWeapons.Add(new Weapons.Drill(ball, game)); Weapon = AvailableWeapons[SelectedWeaponIndex]; Ball.HoldingWeapon = AvailableWeapons[SelectedWeaponIndex].Icon; }
private void SendWorldState() { var entities = Ballz.The().Match.World.Entities; foreach (var e in entities) { Broadcast(e); } var sessionState = Ballz.The().Match.GetState(); Broadcast(sessionState); }
public void Update(GameTime time) { NetIncomingMessage im; while ((im = Peer.ReadMessage()) != null) { // handle incoming message switch (im.MessageType) { case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: Console.WriteLine($"NetMessage {im.MessageType}: {im.ReadString()}"); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)im.ReadByte(); if (status == NetConnectionStatus.Connected) { IsConnected = true; Sync.AddConnection(im.SenderConnection); Connected?.Invoke(this, null); SendToServer(new LobbyPlayerGreeting { PlayerName = Ballz.The().Settings.PlayerName }); // TODO: Use actual player name } else { IsConnected = false; } if (status == NetConnectionStatus.Disconnected) { Disconnected?.Invoke(this, null); } break; case NetIncomingMessageType.Data: Sync.ReadMessage(im); break; default: Console.WriteLine($"Unhandled message type: {im.MessageType} {im.LengthBytes} bytes"); break; } Peer.Recycle(im); } }
public void LoadSettings() { var GameSettings = Ballz.The().Settings; EnableFullscreen.Checked = GameSettings.Fullscreen; PlayerName.Value = GameSettings.PlayerName ?? ""; if (Ballz.The().GetResolutions().Contains(Ballz.The().Settings.ScreenResolution)) { Resolution.SelectedIndex = Ballz.The().GetResolutions().IndexOf(Ballz.The().Settings.ScreenResolution); } MasterVolume.Value = GameSettings.MasterVolume; MusicVolume.Value = GameSettings.MusicVolume; }
public void StartNetworkGame(MatchSettings gameSettings, int localPlayerId) { if (Role == NetworkRole.Server) { server.StartNetworkGame(gameSettings); } else if (Role == NetworkRole.Client) { gameSettings.GameMode.InitializeSession(Ballz.The(), gameSettings); Ballz.The().Logic.StartGame(gameSettings, true, localPlayerId); } GameState = NetworkGameState.InGame; }
public BallControl(Ballz game, Session match, Ball ball) { Game = game; Match = match; Ball = ball; Weapon = new Weapons.RopeTool(ball, game); KeyPressed[InputMessage.MessageType.ControlsAction] = false; KeyPressed[InputMessage.MessageType.ControlsUp] = false; KeyPressed[InputMessage.MessageType.ControlsDown] = false; KeyPressed[InputMessage.MessageType.ControlsLeft] = false; KeyPressed[InputMessage.MessageType.ControlsRight] = false; }
public virtual void FireProjectile() { if (Ballz.The().Match.IsRemoteControlled) { return; } Game.Services.GetService <SoundControl>().PlaySound(SoundControl.BazookaSound); Shot newShot = CreateShot(); ProjectileInAir = newShot; Game.Match.World.AddEntity(newShot); Ball.PhysicsBody.ApplyForce(-10000 * Ball.ShootCharge * newShot.Recoil * Ball.AimDirection); }
public OptionsMenu() : base("Options") { Skin = PanelSkin.Default; PlayerName.PlaceholderText = "Enter your Name"; Resolution = new DropDown(new Vector2(0, 280)); var resolutions = Ballz.The().GetResolutions(); foreach (var resolution in resolutions) { Resolution.AddItem($"{resolution.Width}x{resolution.Height}"); } LoadSettings(); AddItem(new Label("Player Name:")); AddItem(PlayerName); AddItem(EnableFullscreen); AddItem(new Label("Screen Resolution:")); AddItem(Resolution); AddItem(new Label("Sound Volume:")); AddItem(MasterVolume); AddItem(new Label("Music Volume:")); AddItem(MusicVolume); var backButton = new MenuButton( "Back", size: new Vector2(0.5f, -1.0f), skin: ButtonSkin.Alternative, anchor: Anchor.BottomLeft, click: () => Ballz.The().Logic.MenuGoBack() ); AddItem(backButton); var saveButton = new MenuButton( "OK", size: new Vector2(0.5f, -1.0f), skin: ButtonSkin.Alternative, anchor: Anchor.BottomRight, click: SaveSettings ); AddItem(saveButton); }
public InputTranslator(Ballz game) : base(game) { Mode = InputMode.PROCESSED; PreviousKeyboardState = Keyboard.GetState(); CurrentKeyboardState = PreviousKeyboardState; previousGamePadState = new GamePadState[4]; gamePadPlayerIndex = new PlayerIndex[4]; gamePadPlayerIndex[0] = PlayerIndex.One; gamePadPlayerIndex[1] = PlayerIndex.Two; gamePadPlayerIndex[2] = PlayerIndex.Three; gamePadPlayerIndex[3] = PlayerIndex.Four; //previousGamePadState = GamePad.GetState( }
public InputTranslator(Ballz game) : base(game) { Mode = InputMode.PROCESSED; previousState = Keyboard.GetState(); currentState = previousState; previousGamePadState = new GamePadState[4]; gamePadPlayerIndex = new PlayerIndex[4]; gamePadPlayerIndex[0] = PlayerIndex.One; gamePadPlayerIndex[1] = PlayerIndex.Two; gamePadPlayerIndex[2] = PlayerIndex.Three; gamePadPlayerIndex[3] = PlayerIndex.Four; //previousGamePadState = GamePad.GetState( }
public LogicControl(Ballz game) { Game = game; state = GameState.Unknown; ButtonRepeat = new Timer(62.5); ButtonRepeat.AutoReset = true; repeatHandler = (s,e)=>{}; ButtonRepeat.Elapsed += repeatHandler; ButtonDelay = new Timer(1000); ButtonDelay.AutoReset = false; ButtonDelay.Elapsed += (s, e) => { ButtonRepeat.Stop(); ButtonRepeat.Start(); }; }
public LogicControl(Ballz game) { Game = game; state = GameState.Unknown; ButtonRepeat = new Timer(62.5); ButtonRepeat.AutoReset = true; repeatHandler = (s, e) => {}; ButtonRepeat.Elapsed += repeatHandler; ButtonDelay = new Timer(1000); ButtonDelay.AutoReset = false; ButtonDelay.Elapsed += (s, e) => { ButtonRepeat.Stop(); ButtonRepeat.Start(); }; }
public override void OnTerrainCollision(Terrain terrain, Vector2 position) { if (Ballz.The().Match.IsRemoteControlled) { return; } float impact = 0.04f * Velocity.Length() * BulletHoleRadius; if (impact > 0.2) { // Destroy terrain and die terrain.SubtractCircle(position.X, position.Y, impact); } onAnyCollision(); }
public void Explode() { if (ExplosionRadius <= 0.0f) { return; } Ballz.The().Match.World.StaticGeometry.SubtractCircle(Position.X, Position.Y, ExplosionRadius); Ballz.The().Match.World.GraphicsEvents.Add(new CameraShakeEffect { Intensity = 2f, Duration = 0.2f, Start = Ballz.The().Match.GameTime }); Ballz.The().Match.World.GraphicsEvents.Add(SpriteGraphicsEffect.CreateExplosion(Ballz.The().Match.GameTime, Position, 0)); // TODO: damage to all players within explosion radius foreach (var p in Ballz.The().Match.Players) { foreach (var b in p.OwnedBalls) { if (Vector2.Distance(b.Position, this.Position) < ExplosionRadius) { if (!Ballz.The().Settings.FriendlyFire&& b.Player.TeamName == Team) { break; } b.ChangeHealth(-this.HealthDecreaseFromExplosionImpact * Vector2.Distance(b.Position, this.Position) / ExplosionRadius); b.PhysicsBody.ApplyLinearImpulse(HealthDecreaseFromExplosionImpact * Vector2.Distance(b.Position, this.Position) / ExplosionRadius * Vector2.Normalize(b.Position - this.Position) ); } } } if (ShotType == ShotType_T.Generating) { Ballz.The().Match.World.Water.AddParticles(this.Position, 20); } // Remove projectile Dispose(); }
public ChargedProjectileWeapon(Ball ball, Ballz game) : base(ball, game) { }
public PhysicsControl(Ballz game) : base(game) { Game = game; }
public MenuRenderer(Ballz game, Item defaultMenu = null) : base(game) { Menu = defaultMenu; }
public SoundControl(Ballz game) { Game = game; loadedSounds = new Dictionary<string, SoundEffect>(); }
public BaseRenderer(Ballz game) : base(game) { Game = game; }
public GameLogic(Ballz game, Session session) : base(game) { Game = game; Session = session; }
public DebugRenderer(Ballz _game) : base(_game) { Game = _game; }
public GameLogic(Ballz game) : base(game) { Game = game; }
public Potato(Ball ball, Ballz game) : base(ball, game) { }
public WeaponControl(Ball ball, Ballz game) { Ball = ball; Game = game; }
public WaterRenderer(Ballz game) { Game = game; }
protected override Session ImplStartSession(Ballz game, GameSettings settings, bool remoteControlled, int localPlayerId) { var session = new Session(game, new World(new Terrain(settings.MapTexture)), settings) { UsePlayerTurns = this.UsePlayerTurns, Terrain = new Terrain(settings.MapTexture) }; FindSpawnPoints(settings.MapTexture, session.Terrain.Scale); var spawnPoints = SelectSpawnpoints(settings.Teams.Select(t=>t.NumberOfBallz).Sum()); // Create players and Ballz var currBallCreating = 0; foreach (var team in settings.Teams) { var player = new Player { Id = team.Id, Name = team.Name, TeamName = team.Country, IsLocal = !remoteControlled || localPlayerId == team.Id }; session.Players.Add(player); var ballCount = UsePlayerTurns ? team.NumberOfBallz : 1; var ballNames = TeamNames.GetBallNames(team.Country, ballCount); for (var i = 0; i < ballCount; ++i) { var playerBall = new Ball { Name = ballNames[i], Position = spawnPoints[currBallCreating], Velocity = new Vector2(0, 0), IsAiming = true, Player = player, HoldingWeapon = "Bazooka", IsStatic = false }; player.OwnedBalls.Add(playerBall); ++currBallCreating; session.World.AddEntity(playerBall); BallControl controller; if (team.ControlledByAI) controller = new AIControl(game, session, playerBall); else controller = new UserControl(game, session, playerBall); session.SessionLogic.BallControllers[playerBall] = controller; } player.ActiveBall = player.OwnedBalls.FirstOrDefault(); session.SessionLogic.ActiveControllers[player] = session.SessionLogic.BallControllers[player.ActiveBall]; } return session; }
public DebugRenderer(Ballz _game) : base(_game) { Game = _game; WaterRenderer = new WaterRenderer(_game); }
protected override void ImplInitializeSession(Ballz game, GameSession.Logic.GameSettings settings) { var mapTexture = MapName == "Generated" ? TerrainGenerator.GenerateTerrain(width,height): game.Content.Load<Texture2D>("Worlds/" + MapName); settings.MapName = MapName; settings.MapTexture = mapTexture; }
public abstract Session StartSession(Ballz game);
public Waterbomb(Ball ball, Ballz game) : base(ball, game) { }
public AIControl(Ballz game, Session match, Ball ball) : base(game, match, ball) { pistol = new Pistol(ball, game); bazoo = new Bazooka(ball, game); }
public Pistol(Ball ball, Ballz game) : base(ball, game) { }
public GameRenderer(Ballz game) : base(game) { WaterRenderer = new WaterRenderer(game); TeamTextures = new Dictionary<string, Texture2D>(); }