本文整理汇总了Golang中github.com/awesomegroupidunno/game-server/state.GameState.GetVehicle方法的典型用法代码示例。如果您正苦于以下问题:Golang GameState.GetVehicle方法的具体用法?Golang GameState.GetVehicle怎么用?Golang GameState.GetVehicle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/awesomegroupidunno/game-server/state.GameState
的用法示例。
在下文中一共展示了GameState.GetVehicle方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
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)
}
示例2: Run
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)
}
示例3: Run
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
}
示例4: Run
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
}
}
示例5: Run
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
}
}