Exemplo n.º 1
0
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)

}
Exemplo n.º 2
0
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)

}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
func (t *PowerupCommandProcessor) placeWell(v *state.Vehicle, g *state.GameState) {
	v.StoredPowerup = NO_POWERUP
	r := state.GravityWell{
		Point:   state.NewPoint(v.X, v.Y),
		Sized:   state.NewSized(10, 10),
		Owner:   v.Owner,
		Expires: time.Now().Add(5 * time.Second),
	}

	g.GravityWells = append(g.GravityWells, &r)
}
Exemplo n.º 5
0
func (t *PowerupCommandProcessor) fireRocket(v *state.Vehicle, g *state.GameState) {
	v.StoredPowerup = NO_POWERUP
	targetedVehicle := targetVehicle(v, g)
	r := state.Rocket{
		Point:    state.NewPoint(v.X, v.Y),
		Sized:    state.NewSized(t.Physics.BulletWidth*3, t.Physics.BulletWidth*1.25),
		Target:   targetedVehicle,
		Velocity: t.Physics.BulletVelocity * .75,
	}

	g.Rockets = append(g.Rockets, &r)
}
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
	}
}
Exemplo n.º 7
0
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
	}

}
Exemplo n.º 8
0
func (p *Physics) SpawnPowerup(g *state.GameState) {
	powerupType := rand.Intn(NUM_POWERUPS) + 1
	powerupType = (powerupsSpawned % NUM_POWERUPS) + 1
	powerupsSpawned++

	size := state.Sized{30, 30}

	newPowerup := state.Powerup{
		Point:        p.findSpace(size, *g),
		Sized:        size,
		ShouldRemove: false,
		PowerupType:  powerupType,
	}

	g.PowerUps = append(g.PowerUps, &newPowerup)
}