当前位置: 首页>>代码示例>>Golang>>正文


Golang GameState.GetVehicle方法代码示例

本文整理汇总了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)

}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:32,代码来源:connect.go

示例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)

}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:32,代码来源:fire.go

示例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
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:16,代码来源:turn.go

示例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
	}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:22,代码来源:acceleration.go

示例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
	}

}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:24,代码来源:powerup.go


注:本文中的github.com/awesomegroupidunno/game-server/state.GameState.GetVehicle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。