本文整理汇总了Golang中github.com/awesomegroupidunno/game-server/state.Vehicle类的典型用法代码示例。如果您正苦于以下问题:Golang Vehicle类的具体用法?Golang Vehicle怎么用?Golang Vehicle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Vehicle类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: VehicleKnockback
// Creates knockback for a vehicle
func (p *Physics) VehicleKnockback(vehicle *state.Vehicle, kbAngle, kbVelocity float64) {
// Get vehicle velocity vectors
vehAngleX, vehAngleY := splitComponent(vehicle.Angle)
vehVectorX := vehAngleX * vehicle.Velocity
vehVectorY := vehAngleY * vehicle.Velocity
// Get knockback velocity vectors
kbAngleX, kbAngleY := splitComponent(kbAngle)
kbVectorX := kbAngleX * kbVelocity
kbVectorY := kbAngleY * kbVelocity
// Combine vectors
vectorX := vehVectorX + kbVectorX
vectorY := vehVectorY + kbVectorY
vehVelocity := combineComponents(vectorX, vectorY)
// Calculate angle perpendicularity as a percent
angleFactor := math.Mod(math.Abs(vehicle.Angle-kbAngle+90), 180) / 90.0
// Set vehicle velocity
if math.Signbit(vehicle.Velocity) == math.Signbit(vehVelocity) {
vehicle.Velocity = -vehVelocity * angleFactor
} else {
vehicle.Velocity = vehVelocity * angleFactor
}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:27,代码来源:physics.go
示例2: VehicleBounding
func (p *Physics) VehicleBounding(v *state.Vehicle) {
shouldStop := v.X < 0
if shouldStop {
v.X = 2
}
if v.Y < 0 {
shouldStop = true
v.Y = 2
}
if v.Y > p.WorldHeight {
shouldStop = true
v.Y = p.WorldHeight - 2
}
if v.X > p.WorldWidth {
shouldStop = true
v.X = p.WorldWidth - 2
}
if shouldStop {
v.Velocity = 0
}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:25,代码来源:physics.go
示例3: accelerateVehicle
func (t *AccelerationCommandProcessor) accelerateVehicle(v *state.Vehicle, c *cmd.AccelerationCommand) {
v.Velocity = v.Velocity + (c.Value * t.Physics.AccelerationCommandModifier)
if v.Velocity >= t.Physics.MaxVehicleVelocity {
v.Velocity = t.Physics.MaxVehicleVelocity
}
if (v.Velocity) <= (-1 * t.Physics.MaxVehicleVelocity) {
v.Velocity = -1 * t.Physics.MaxVehicleVelocity
}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:11,代码来源:acceleration.go
示例4: damageVehicle
func (p *Physics) damageVehicle(v *state.Vehicle, amount int) bool {
if v.IsAlive {
v.CurrentHealth -= amount
if v.CurrentHealth <= 0 {
v.CurrentHealth = 0
v.IsAlive = false
v.TimeDestroyed = time.Now()
return true
}
}
return false
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:12,代码来源:physics.go
示例5: VehicleFrictionSlow
func (p *Physics) VehicleFrictionSlow(vehicle *state.Vehicle, duration time.Duration) {
speedLoss := p.FrictionSpeedLoss * duration.Seconds()
if vehicle.Velocity > 0 {
vehicle.Velocity = float64(vehicle.Velocity) - float64(speedLoss)
if vehicle.Velocity < 0 {
vehicle.Velocity = 0
}
} else {
vehicle.Velocity = float64(vehicle.Velocity) + float64(speedLoss)
if vehicle.Velocity > 0 {
vehicle.Velocity = 0
}
}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:14,代码来源:physics.go
示例6: placeWell
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)
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:11,代码来源:powerup.go
示例7: fireRocket
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)
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:12,代码来源:powerup.go
示例8: RespawnVehicle
func (p *Physics) RespawnVehicle(v *state.Vehicle, g state.GameState) bool {
if !v.IsAlive {
if time.Now().After(v.TimeDestroyed.Add(p.VehicleRespawn)) {
v.IsAlive = true
loc := p.findSpace(v.Sized, g)
v.Y = loc.Y
v.X = loc.X
v.Angle = 0
v.CurrentHealth = v.MaxHealth
v.ActivePowerup = NO_POWERUP
v.StoredPowerup = NO_POWERUP
}
}
return false
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:15,代码来源:physics.go
示例9: TestBox2dVehicle
func TestBox2dVehicle(t *testing.T) {
vehicle := state.Vehicle{
Point: state.NewPoint(10, 20),
Sized: state.NewSized(15, 40),
Angle: 3}
Convey("Proper Box Vehicle", t, func() {
So(vehicle.AngleDegrees(), ShouldAlmostEqual, vehicle.Angle, .001)
x, y := vehicle.Position()
w, h := vehicle.Size()
So(x, ShouldAlmostEqual, vehicle.X, .001)
So(y, ShouldAlmostEqual, vehicle.Y, .001)
So(w, ShouldAlmostEqual, vehicle.Height, .001)
So(h, ShouldAlmostEqual, vehicle.Width, .001)
})
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:17,代码来源:state_test.go
示例10: applySpeedPowerUp
func (t *PowerupCommandProcessor) applySpeedPowerUp(v *state.Vehicle) {
v.ActivePowerup = SPEEDUP
v.StoredPowerup = NO_POWERUP
v.OverRideSpeedTill = time.Now().Add(10 * time.Second)
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:5,代码来源:powerup.go
示例11: healVehicle
func (t *PowerupCommandProcessor) healVehicle(v *state.Vehicle) {
v.CurrentHealth = v.MaxHealth
v.StoredPowerup = NO_POWERUP
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:4,代码来源:powerup.go
示例12: PickupPowerUp
func (p *Physics) PickupPowerUp(v1 *state.Vehicle, power *state.Powerup) {
if v1.IsAlive && !power.ShouldRemove {
power.ShouldRemove = true
v1.StoredPowerup = power.PowerupType
}
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:6,代码来源:physics.go
示例13: MoveVehicle
func (p *Physics) MoveVehicle(vehicle *state.Vehicle, duration time.Duration) {
x, y := p.move2d(vehicle.X, vehicle.Y, vehicle.Angle, vehicle.Velocity, duration)
vehicle.X = x
vehicle.Y = y
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:6,代码来源:physics.go
注:本文中的github.com/awesomegroupidunno/game-server/state.Vehicle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论