本文整理汇总了Golang中github.com/awesomegroupidunno/game-server/state.GameState类的典型用法代码示例。如果您正苦于以下问题:Golang GameState类的具体用法?Golang GameState怎么用?Golang GameState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GameState类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
示例2: 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
示例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: 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
示例5: 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
示例6: 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
示例7: 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
示例8: SpawnPowerup
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)
}
开发者ID:awesomegroupidunno,项目名称:game-server,代码行数:16,代码来源:physics.go
注:本文中的github.com/awesomegroupidunno/game-server/state.GameState类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论