func (t *ConnectCommandProcessor) Run(g *state.GameState, c cmd.GameCommand) { command := c.(*cmd.ConnectCommand) // if the user already has a vehicle, ignore vehicle := g.GetVehicle(command.UserId) if vehicle != nil { return } // For now, randomly join team 0 or 1 teamNum := len(g.Vehicles) % 2 size := state.NewSized(t.Physics.VehicleWidth, t.Physics.VehicleHeight) pt := t.Physics.findSpace(size, *g) newVehicle := state.Vehicle{ Point: pt, Sized: size, Velocity: 0.0, Angle: 0, TeamId: teamNum, MaxHealth: t.Physics.VehicleHealth, CurrentHealth: t.Physics.VehicleHealth, Owner: command.UserId, Mass: 10, IsAlive: true, ActivePowerup: NO_POWERUP, StoredPowerup: NO_POWERUP, OverRideSpeedTill: time.Now().Add(-5 * time.Second)} g.Vehicles = append(g.Vehicles, &newVehicle) }
func (t *FireCommandProcessor) Run(g *state.GameState, c cmd.GameCommand) { if t.lastFired == nil { t.lastFired = make(map[string]time.Time) } command := c.(*cmd.FireCommand) vehicle := g.GetVehicle(command.UserId) if vehicle == nil || !vehicle.IsAlive { return } last := t.lastFired[vehicle.Owner] diff := time.Now().Sub(last) if diff < t.Physics.BulletDelay { return } t.lastFired[vehicle.Owner] = time.Now() b := state.Bullet{ Point: state.NewPoint(vehicle.X, vehicle.Y), Sized: state.NewSized(t.Physics.BulletWidth, t.Physics.BulletWidth), Velocity: t.Physics.BulletVelocity, Angle: vehicle.Angle, OwnerId: vehicle.Owner, } g.Bullets = append(g.Bullets, &b) }
func (t *TurnCommandProcessor) Run(g *state.GameState, c cmd.GameCommand) { command := c.(*cmd.TurnCommand) vehicle := g.GetVehicle(command.UserId) if vehicle == nil || !vehicle.IsAlive { return } temp := vehicle temp.Angle = math.Mod(temp.Angle-(command.Value*t.Physics.TurnCommandModifier), 360) if temp.Angle < 0 { temp.Angle += 360 } vehicle = temp }
func (t *AccelerationCommandProcessor) Run(g *state.GameState, c cmd.GameCommand) { command := c.(*cmd.AccelerationCommand) vehicle := g.GetVehicle(command.UserId) if vehicle == nil || !vehicle.IsAlive { return } powerupOn := vehicle.ActivePowerup == SPEEDUP && vehicle.OverRideSpeedTill.After(time.Now()) if powerupOn { t.Physics.AccelerationCommandModifier *= 2 t.Physics.MaxVehicleVelocity *= 2 } t.accelerateVehicle(vehicle, command) if powerupOn { t.Physics.AccelerationCommandModifier /= 2 t.Physics.MaxVehicleVelocity /= 2 } }
func (t *PowerupCommandProcessor) Run(g *state.GameState, c cmd.GameCommand) { command := c.(*cmd.PowerupCommand) vehicle := g.GetVehicle(command.UserId) if vehicle == nil || !vehicle.IsAlive { return } switch vehicle.StoredPowerup { case HEAL: t.healVehicle(vehicle) return case SPEEDUP: t.applySpeedPowerUp(vehicle) return case ROCKET: t.fireRocket(vehicle, g) return case GRAVITY_WELL: t.placeWell(vehicle, g) return } }