Beispiel #1
0
func (sp *CameraController) Update() {
	t := sp.GameObject().Transform()

	if input.KeyDown('A') {
		t.Translatef(float32(-sp.Speed*engine.DeltaTime()), 0)
	}
	if input.KeyDown('D') {
		t.Translatef(float32(sp.Speed*engine.DeltaTime()), 0)
	}
	if input.KeyDown('S') {
		t.Translatef(0, float32(-sp.Speed*engine.DeltaTime()))
	}
	if input.KeyDown('W') {
		t.Translatef(0, float32(sp.Speed*engine.DeltaTime()))
	}
	if input.KeyDown('E') {
		engine.CurrentCamera().SetSize(engine.CurrentCamera().Size() + float32(engine.DeltaTime()))
	}
	if input.KeyDown('Q') {
		engine.CurrentCamera().SetSize(engine.CurrentCamera().Size() - float32(engine.DeltaTime()))
	}

	if input.KeyDown('Z') {
		a := t.Angle()
		t.SetWorldRotationf(a + float32(engine.DeltaTime())*10)
	}
	if input.KeyDown('X') {
		a := t.Angle()
		t.SetWorldRotationf(a - float32(engine.DeltaTime())*10)
	}
}
Beispiel #2
0
func (sp *SmoothFollow) LateUpdate() {
	camera := engine.CurrentCamera()
	if camera != nil {
		myPos := sp.Target.Transform().Position()
		camPos := camera.Transform().Position()

		if sp.Speed > 0 {
			camPos = engine.Lerp(camPos, myPos, float32(engine.DeltaTime())*sp.Speed)
			disX := camPos.X - myPos.X
			disY := camPos.Y - myPos.Y
			if float32(math.Abs(float64(disX))) > sp.MaxDis {
				if disX < 0 {
					camPos.X = myPos.X - sp.MaxDis
				} else {
					camPos.X = myPos.X + sp.MaxDis
				}
			}
			if float32(math.Abs(float64(disY))) > sp.MaxDis {
				if disY < 0 {
					camPos.Y = myPos.Y - sp.MaxDis
				} else {
					camPos.Y = myPos.Y + sp.MaxDis
				}
			}
		} else {
			camPos = myPos
		}
		camera.Transform().SetPosition(camPos)
	}
}
Beispiel #3
0
func (b *back) Update() {
	camera := engine.GetScene().SceneBase().Camera
	if camera != nil {
		myPos := engine.Vector{b.Transform().Position().X - float32(engine.Width/2), b.Transform().Position().Y - float32(engine.Height/2), 0}
		camPos := camera.Transform().Position()

		myPos = engine.Lerp(myPos, camPos, float32(engine.DeltaTime())*5)
		disX := myPos.X - camPos.X
		disY := myPos.Y - camPos.Y
		var MaxDis float32 = 300
		if float32(math.Abs(float64(disX))) > MaxDis {
			if disX < 0 {
				myPos.X = MaxDis - myPos.X
			} else {
				myPos.X = myPos.X + MaxDis
			}
		}
		if float32(math.Abs(float64(disY))) > MaxDis {
			if disY < 0 {
				myPos.Y = MaxDis - myPos.Y
			} else {
				myPos.Y = myPos.Y + MaxDis
			}
		}

		b.Transform().SetPosition(camPos)
	}
}
Beispiel #4
0
func (m *ResizeScript) Update() {
	delta := float32(engine.DeltaTime())
	if m.State == 0 {
		sx := (rand.Float32() * m.MaxX) + m.MinX
		sy := (rand.Float32() * m.MaxY) + m.MinY
		sx = m.MinX
		sy = m.MinY
		m.Transform().SetScalef(sx, sy)
		m.State = 1
	} else if m.State == 1 {
		deltaX := m.MaxX - m.MinX
		deltaY := m.MaxY - m.MinY
		s := m.Transform().Scale()
		s.X, s.Y = s.X+(deltaX*m.Speed*delta), s.Y+(deltaY*m.Speed*delta)
		m.Transform().SetScale(s)
		if s.X > m.MaxX || s.Y > m.MaxY {
			m.State = 2
		}
	} else if m.State == 2 {
		deltaX := m.MaxX - m.MediumX
		deltaY := m.MaxY - m.MediumY
		s := m.Transform().Scale()
		s.X, s.Y = s.X-(deltaX*m.Speed*delta), s.Y-(deltaY*m.Speed*delta)
		m.Transform().SetScale(s)
		if s.X < m.MediumX || s.Y < m.MediumY {
			m.State = 3
		}
	} else if m.State == 3 {
		deltaX := m.MaxX - m.MediumX
		deltaY := m.MaxY - m.MediumY
		s := m.Transform().Scale()
		s.X, s.Y = s.X+(deltaX*m.Speed*delta), s.Y+(deltaY*m.Speed*delta)
		m.Transform().SetScale(s)
		if s.X > m.MaxX || s.Y > m.MaxY {
			m.State = 2
		}
	}
}
func (sp *ShipController) Update() {
	delta := float32(engine.DeltaTime())
	r2 := sp.Transform().DirectionTransform(engine.Up)
	r3 := sp.Transform().DirectionTransform(engine.Left)
	ph := sp.GameObject().Physics
	rx, ry := r2.X*delta, r2.Y*delta
	rsx, rsy := r3.X*delta, r3.Y*delta

	jet := false
	back := false

	if input.KeyDown('W') {
		ph.Body.AddForce(sp.Speed*rx, sp.Speed*ry)
		jet = true
	}

	if input.KeyDown('S') {
		ph.Body.AddForce(-sp.Speed*rx, -sp.Speed*ry)
		jet = true
		back = true
	}

	rotSpeed := sp.RotationSpeed
	if input.KeyDown(input.KeyLshift) {
		rotSpeed = 100
	}

	if sp.UseMouse {
		v := engine.GetScene().SceneBase().Camera.MouseWorldPosition()
		v = v.Sub(sp.Transform().WorldPosition())
		v.Normalize()
		angle := float32(math.Atan2(float64(v.Y), float64(v.X))) * engine.DegreeConst

		angle = engine.LerpAngle(sp.Transform().Rotation().Z, float32(int((angle - 90))), delta*rotSpeed/50)
		sp.Transform().SetRotationf(angle)

		ph.Body.SetAngularVelocity(0)
		ph.Body.SetTorque(0)

		if input.KeyDown('D') || input.KeyDown('E') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(-sp.Speed*rsx, -sp.Speed*rsy)
			jet = true
			back = true
		}
		if input.KeyDown('A') || input.KeyDown('Q') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(sp.Speed*rsx, sp.Speed*rsy)
			jet = true
			back = true
		}
	} else {
		r := sp.Transform().Rotation()
		if input.KeyDown('D') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			sp.Transform().SetRotationf(r.Z - rotSpeed*delta)
			jet = true
			back = true
		}
		if input.KeyDown('A') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			sp.Transform().SetRotationf(r.Z + rotSpeed*delta)
			jet = true
			back = true
		}

		if input.KeyDown('E') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(-sp.Speed*rsx, -sp.Speed*rsy)
			jet = true
			back = true
		}
		if input.KeyDown('Q') {
			ph.Body.SetAngularVelocity(0)
			ph.Body.SetTorque(0)
			ph.Body.AddForce(sp.Speed*rsx, sp.Speed*rsy)
			jet = true
			back = true
		}
	}

	if input.MouseDown(input.MouseLeft) {
		if time.Now().After(sp.lastShoot) {
			sp.Shoot()
			sp.lastShoot = time.Now().Add(time.Millisecond * 200)
		}
	}

	if input.KeyPress('P') {
		engine.EnablePhysics = !engine.EnablePhysics
	}
	if input.KeyPress('T') {
		sp.UseMouse = !sp.UseMouse
	}

	if jet {
		for _, resize := range sp.JetFirePool {
			if back {
				resize.SetValues(0.1, 0.1, 0.2, 0.0, 0.2, 0.3)
			} else {
				resize.SetValues(0.2, 0.2, 0.3, 0.0, 0.6, 0.8)
			}
		}
		if !sp.JetFireParent.IsActive() {
			sp.JetFireParent.SetActive(true)
			for _, resize := range sp.JetFirePool {
				resize.State = 0
				if back {
					resize.SetValues(0.1, 0.1, 0.2, 0.0, 0.2, 0.3)
				} else {
					resize.SetValues(0.2, 0.2, 0.3, 0.0, 0.6, 0.8)
				}
			}
		}
	} else {
		sp.JetFireParent.SetActive(false)
	}
}