Exemplo n.º 1
0
func (p *Physics) MoveRocket(rocket *state.Rocket, duration time.Duration) {

	t := rocket.Target
	if t == nil {
		rocket.ShouldRemove = true
		return
	}

	dx := t.X - rocket.X
	dy := t.Y - rocket.Y
	rocket.Angle = math.Atan2(dy, dx) * RadToDeg
	x, y := p.move2d(rocket.X, rocket.Y, rocket.Angle, rocket.Velocity, duration)

	rocket.X = x
	rocket.Y = y

	if collision.Collides(rocket, t) {
		rocket.ShouldRemove = true
		p.damageVehicle(t, p.BulletDamage*20)
	}
}
Exemplo n.º 2
0
func TestBox2dRocket(t *testing.T) {
	rocket := state.Rocket{
		Point: state.Point{X: 10,
			Y: 20},
		Sized: state.Sized{Width: 15,
			Height: 15}}
	Convey("Proper Box Rocket", t, func() {
		So(rocket.AngleDegrees(), ShouldAlmostEqual, rocket.Angle, .001)
		x, y := rocket.Position()
		w, h := rocket.Size()

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

	})
}