示例#1
0
func (p *Physics) DamageShieldGenerator(b *state.Bullet, s *state.ShieldGenerator) bool {
	s.CurrentHealth -= p.BulletDamage
	b.ShouldRemove = true
	if s.CurrentHealth <= 0 {
		s.Shield.IsEnabled = false
		s.CurrentHealth = 0
		return true
	}
	return false

}
func TestBox2dShieldGen(t *testing.T) {
	shieldGen := state.ShieldGenerator{
		Point: state.Point{X: 10,
			Y: 20},
		Sized: state.Sized{Width: 15,
			Height: 15}}
	Convey("Proper Box Shield Generator", t, func() {
		So(shieldGen.AngleDegrees(), ShouldAlmostEqual, 0, .001)
		x, y := shieldGen.Position()
		w, h := shieldGen.Size()

		So(x, ShouldAlmostEqual, shieldGen.X, .001)
		So(y, ShouldAlmostEqual, shieldGen.Y, .001)
		So(w, ShouldAlmostEqual, shieldGen.Height, .001)
		So(h, ShouldAlmostEqual, shieldGen.Width, .001)

	})
}
示例#3
0
func (p *Physics) NewGameState() state.GameState {

	bases := []*state.Base{}

	b1 := state.Base{
		Point:         state.NewPoint(p.BaseOffset, p.WorldHeight-p.BaseOffset),
		Sized:         state.NewSized(p.BaseWidth, p.BaseWidth),
		CurrentHealth: p.BaseHealth,
		MaxHealth:     p.BaseHealth,
		TeamId:        0}

	b2 := state.Base{
		Point:         state.NewPoint(p.WorldWidth-p.BaseOffset, p.BaseOffset),
		Sized:         state.NewSized(p.BaseWidth, p.BaseWidth),
		CurrentHealth: p.BaseHealth,
		MaxHealth:     p.BaseHealth,
		TeamId:        1}

	bases = append(bases, &b1, &b2)

	shields := []*state.Shield{}

	s1 := state.Shield{
		Point:     state.NewPoint(p.WorldWidth-p.BaseOffset, p.BaseOffset),
		Sized:     state.NewSized(p.BaseWidth*1.5, p.BaseWidth*1.5),
		IsEnabled: true,
		TeamId:    1}

	s2 := state.Shield{
		Point:     state.NewPoint(p.BaseOffset, p.WorldHeight-p.BaseOffset),
		Sized:     state.NewSized(p.BaseWidth*1.5, p.BaseWidth*1.5),
		IsEnabled: true,
		TeamId:    0}

	shields = append(shields, &s1, &s2)

	generators := []*state.ShieldGenerator{}
	g1 := state.ShieldGenerator{
		Point:         state.NewPoint(p.WorldWidth-p.ShieldOffset, p.WorldHeight-p.BaseOffset),
		Sized:         state.NewSized(p.ShieldWidth, p.ShieldWidth),
		CurrentHealth: p.ShieldGeneratorHealth,
		MaxHealth:     p.ShieldGeneratorHealth,
		TeamId:        0,
		RespawnTime:   time.Now()}

	g1.Shield = &s2

	g2 := state.ShieldGenerator{
		Point:         state.NewPoint(p.ShieldOffset, p.ShieldOffset),
		Sized:         state.NewSized(p.ShieldWidth, p.ShieldWidth),
		CurrentHealth: p.ShieldGeneratorHealth,
		MaxHealth:     p.ShieldGeneratorHealth,
		TeamId:        1,
		RespawnTime:   time.Now()}

	g2.Shield = &s1
	generators = append(generators, &g1, &g2)

	state := state.GameState{
		Val:              "",
		Vehicles:         []*state.Vehicle{},
		Bases:            bases,
		ShieldGenerators: generators,
		GameOver:         -1,
		Bullets:          []*state.Bullet{},
		Shields:          shields,
		Rockets:          []*state.Rocket{},
		PowerUps:         []*state.Powerup{},
		SecToRestart:     -1,
	}
	return state
}