• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang state.Vehicle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.Printer类代码示例发布时间:2022-05-24
下一篇:
Golang state.GameState类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap