Пример #1
0
func (self *fire) Tick() {
	self.Life = self.Life - 1
	if self.Life > 0 {
		self.Position[0] = self.Position[0] + self.Direction[0]*self.Speed
		self.Position[1] = self.Position[1] + self.Direction[1]*self.Speed
	} else {
		self.destroy()
		return
	}
	if self.sector != nil {
		poly := self.Poly()
		for player := range self.sector.players {
			if player != nil {
				_, err := g.PolyIntersectsPoly(poly, player.Poly())
				if err == nil {
					player.hit(self.player, self.hitValue)
					if self.player != nil {
						self.player.addPoints(player.hitValue)
					}
					self.Life = 0
				}
			}
		}
	}
}
Пример #2
0
func (self *player) collidesWithPlayer(other *player) ([]*g.Point, error) {
	a := self.Poly()
	b := other.Poly()
	points, err := g.PolyIntersectsPoly(a, b)
	if err == nil {
		return points, nil
	}
	return points, err
}
Пример #3
0
func (self *powerup) Tick() {
	if self.Life <= 0 {
		self.destroy()
		return
	}
	if self.sector != nil {
		poly := self.Poly()
		for player := range self.sector.players {
			if player != nil {
				_, err := g.PolyIntersectsPoly(poly, player.Poly())
				if err == nil {
					// Intercepts player
					switch self.Item.Kind {

					case POWERUP_BEAM_1X:
						player.bulletType = BULLET_1X
					case POWERUP_BEAM_2X:
						player.bulletType = BULLET_2X
					case POWERUP_BEAM_3X:
						player.bulletType = BULLET_3X

					case POWERUP_BONUS_1X:
						player.addPoints(BONUS_POINTS * 1)
					case POWERUP_BONUS_2X:
						player.addPoints(BONUS_POINTS * 2)
					case POWERUP_BONUS_3X:
						player.addPoints(BONUS_POINTS * 3)

					case POWERUP_RECOVER_1X:
						player.addLife(LIFE_POINTS * 1)
					case POWERUP_RECOVER_2X:
						player.addLife(LIFE_POINTS * 2)
					case POWERUP_RECOVER_3X:
						player.addLife(LIFE_POINTS * 3)
					case POWERUP_RECOVER_FULL:
						player.addLife(LIFE_POINTS * 10)

					case POWERUP_SPEED_1X:
						player.speedFactor = 1.0
					case POWERUP_SPEED_2X:
						player.speedFactor = 2.0
					case POWERUP_SPEED_3X:
						player.speedFactor = 3.0

					}
					self.Life = self.Life - 1
					return
				}
			}
		}
	}
}
Пример #4
0
func (self *player) isFree() bool {
	var poly *g.Poly

	if self.sector != nil {
		for other := range self.sector.players {
			if self.sameAs(other) == false {
				poly = self.Poly()
				_, err := g.PolyIntersectsPoly(poly, other.Poly())
				if err == nil {
					return false
				}
			}
		}
	}
	return true
}
Пример #5
0
func (self *player) Tick() {
	var t float64

	t = playerTurnSpeed

	if self.control.Y > 0 {
		self.Speed = -playerMaxSpeed
	} else if self.control.Y < 0 {
		self.Speed = playerMaxSpeed
	} else {
		self.Speed = 0.0
	}

	self.Speed = self.Speed * self.speedFactor

	if self.control.X < 0 {
		t = -t
	} else if self.control.X == 0 {
		t = 0.0
	}

	x := self.Direction[0]
	y := self.Direction[1]

	self.Direction[0] = x*math.Cos(t) - y*math.Sin(t)
	self.Direction[1] = x*math.Sin(t) + y*math.Cos(t)

	// Attempt to move.
	self.Position[0] = self.Position[0] + self.Direction[0]*self.Speed
	self.Position[1] = self.Position[1] + self.Direction[1]*self.Speed

	// Boundary checking
	if int64(self.Position[0]) > self.sector.bounds[0] {
		self.Position[0] = float64(self.sector.bounds[0])
	}

	if int64(self.Position[0]) < -self.sector.bounds[0] {
		self.Position[0] = float64(-self.sector.bounds[0])
	}

	if int64(self.Position[1]) > self.sector.bounds[1] {
		self.Position[1] = float64(self.sector.bounds[1])
	}

	if int64(self.Position[1]) < -self.sector.bounds[1] {
		self.Position[1] = float64(-self.sector.bounds[1])
	}

	// Collision check
	poly := self.Poly()
	for other, _ := range self.sector.players {
		if self.sameAs(other) == false {
			_, err := g.PolyIntersectsPoly(poly, other.Poly())
			if err == nil {
				self.hit(nil, 1)
			}
		}
	}

	if self.control.S > 0 {
		self.shoot()
	}

}