コード例 #1
0
ファイル: guppy.py プロジェクト: nevilc/Sammy-the-Salmon
    def flock(self, l, delta):

        v1 = vector.muls(self.cohesion(l), self.__cohesion_factor)
        v2 = vector.muls(self.separation(l), self.__separation_factor)
        v3 = vector.muls(self.rate(l), self.__rate_factor)

        self.velocity = vector.add(self.velocity, v1, v2, v3)

        self.velocity = vector.maxs(vector.mins(self.velocity, self.__velocity_max), -self.__velocity_max)

        self.direction = vector.dir(vector.add(self.velocity, (0, 192 / 6)))
        self.set_rotation(-math.degrees((self.direction - math.radians(90)) % math.radians(360)))
コード例 #2
0
ファイル: boss.py プロジェクト: nevilc/Sammy-the-Salmon
	def update(self, delta, view):
		super(Boss, self).update(delta)
		
		if self.rect.colliderect(view):
			if not self.active:
				self.active = True
				self.sound_announce.play()
		
			if self.idle > 0:
				self.idle -= delta
			else:
				if self.whirl:
					v = (self.target.centerx - self.rect.centerx, self.target.centery - self.rect.centery)
					mag = vector.mag(v)
					if mag < 300 * delta:
						self.rect.center = self.target.center
						self.whirl = False
						self.target = None
						self.idle = self.__whirlsecs
						self.charging = False
					else:
						v = vector.muls(vector.divs(v, vector.mag(v)), 300 * delta)
						self.move(v)
				else:
					if self.charging:
						self.move((0, self.__charge_speed * delta))
						self.rect.bottom = min(self.rect.bottom, view.bottom)
						if self.rect.bottom == view.bottom:
							self.charging = False
							self.set_animation(self.sprite_swim, 4)
					elif self.target:
						v = (self.target.centerx - self.rect.centerx, self.target.centery - self.rect.centery)
						mag = vector.mag(v)
						if mag < self.__speed * delta:
							self.rect.center = self.target.center
							self.set_animation(self.sprite_swim, 4)
							self.target = None
						else:
							v = vector.muls(vector.divs(v, vector.mag(v)), self.__speed * delta)
							self.move(v)
					else:
						if random.random() < self.__charge_chance:
							self.charging = True
							self.set_animation(self.sprite_charge, 4)
							self.sound_charge.play()
						else:
							self.target = pygame.Rect((self.rect.left + random.randint(-self.__range, self.__range), self.rect.top + random.randint(-self.__range, self.__range)), (137, 274))
							
							self.target.left = max(self.target.left, 144)
							self.target.right = min(self.target.right, 768 - 144)
							self.target.top = max(self.target.top, view.top)
							self.target.bottom = min(self.target.bottom, view.top + (864 * 0.75))
コード例 #3
0
ファイル: guppy.py プロジェクト: nevilc/Sammy-the-Salmon
    def update(self, delta, view):
        """Updates Location"""
        super(Guppy, self).update(delta)

        # Move based on School
        if self.whirl:
            v = (self.target.centerx - self.rect.centerx, self.target.centery - self.rect.centery)
            mag = vector.mag(v)
            if mag < 300 * delta:
                self.rect.center = self.target.center
            else:
                v = vector.muls(vector.divs(v, vector.mag(v)), 300 * delta)
                self.move(v)
        else:
            self.rect.center = vector.add(self.rect.center, vector.muls(self.velocity, delta))
コード例 #4
0
ファイル: whirlpool.py プロジェクト: nevilc/Sammy-the-Salmon
	def update(self, delta, view):
		super(Whirlpool, self).update(delta)
		if not self.__windup:
			if self.__traveled < self.__distance:
				self.move(vector.muls(self.__velocity, delta))
				self.move((self.__speed * delta * math.cos(self.__direction), self.__speed * delta * math.sin(self.__direction)))
				self.__traveled += self.__speed * delta
			elif self.__created_hitbox == False:
				WHitbox((self.rect.topleft[0] - self.rect.w, self.rect.topleft[1] - self.rect.h))
				self.__created_hitbox = True
			else:
				self.__time_alive += delta
		
		if self.__time_alive >= self.__life_max:
			self.destroy = True
			if WHitbox.list:
				for wh in WHitbox.list:
					wh.destroy = True
			
		#if self.rect.topleft[1] >= view.bottom:
		#	self.destroy = True
		
		self.rect.top = max(self.rect.top, view.top)
		self.rect.left = max(self.rect.left, 144)
		self.rect.right = min(self.rect.right, view.right - 144)
コード例 #5
0
ファイル: guppy.py プロジェクト: nevilc/Sammy-the-Salmon
    def rate(self, list):
        mean = (0, 0)
        for i in list:
            mean = vector.add(mean, i.velocity)

        mean = vector.divs(mean, len(list))

        meandist = vector.mag(mean)
        if meandist > self.__force_max:
            mean = vector.muls(vector.divs(mean, meandist), self.__force_max)

        return mean
コード例 #6
0
ファイル: guppy.py プロジェクト: nevilc/Sammy-the-Salmon
    def steer(self, v):
        diff = vector.sub(v, self.rect.center)
        dist = vector.mag(diff)

        if dist > 0:
            diff = vector.divs(diff, dist)

            damp = 64.0
            if dist < damp:
                diff = vector.muls(diff, self.__velocity_max * (dist / damp))
            else:
                diff = vector.muls(diff, self.__velocity_max)

            vec = vector.sub(diff, self.velocity)
            vecdist = vector.mag(vec)
            if vecdist > self.__force_max:
                vec = vector.muls(vector.divs(vec, vecdist), self.__force_max)
        else:
            vec = (0, 0)

        return vec
コード例 #7
0
ファイル: bubble.py プロジェクト: nevilc/Sammy-the-Salmon
	def update(self, delta, view):
		super(Bubble, self).update(delta)
		
		self.move(vector.muls(self.__velocity, delta))
		self.move((self.__speed_base * math.cos(self.__direction) * delta, self.__speed_base * math.sin(self.__direction) * delta))
		
		#self.move((self.__velocity[0] * delta, self.__velocity[1] * delta))
		#self.move((self.__speed * delta * math.cos(math.radians(self.__dir)), self.__speed * delta * math.sin(math.radians(self.__dir))))
		
		# Destroy bubbles once they are outside of view
		if not self.is_in(view):
			self.destroy = True
					
コード例 #8
0
ファイル: catfish.py プロジェクト: nevilc/Sammy-the-Salmon
	def update(self, delta, view):
		super(Catfish, self).update(delta)
		
		if self.rect.colliderect(view):
			if self.whirl:
				v = (self.target.centerx - self.rect.centerx, self.target.centery - self.rect.centery)
				mag = vector.mag(v)
				if mag < 300 * delta:
					self.rect.center = self.target.center
				else:
					v = vector.muls(vector.divs(v, vector.mag(v)), 300 * delta)
					self.move(v)
			else:
				if self.bound.colliderect(self.target):
					if self.rect.centerx < self.target.centerx:
						self.move((self.__chase_speed * delta, 0))
						self.rect.centerx = min(self.rect.centerx, self.target.centerx)
						self.rect.right = min(self.rect.right, self.bound.right)
					elif self.rect.centerx > self.target.centerx:
						self.move((-self.__chase_speed * delta, 0))
						self.rect.centerx = max(self.rect.centerx, self.target.centerx)
						self.rect.left = max(self.rect.left, self.bound.left)
					
				self.move(vector.muls(self.__velocity, delta))
コード例 #9
0
ファイル: guppy.py プロジェクト: nevilc/Sammy-the-Salmon
    def bound(self, area):
        v = (0, 0)
        diff = area.left - self.rect.left
        if diff > 0:
            v = vector.add(v, (diff, 0))
        diff = self.rect.right - area.right
        if diff > 0:
            v = vector.sub(v, (diff, 0))
        diff = area.top - self.rect.top
        if diff > 0:
            v = vector.add(v, (0, diff))
        diff = self.rect.bottom - area.bottom
        if diff > 0:
            v = vector.sub(v, (0, diff))

        self.velocity = vector.add(self.velocity, vector.muls(v, self.__bound_factor))
コード例 #10
0
ファイル: fish.py プロジェクト: nevilc/Sammy-the-Salmon
	def update(self, delta, view):
		super(Fish, self).update(delta)
		
		# Only drift if on screen
		#if self.rect.colliderect(view):
		#	self.rect.top += self.__drift_speed * delta
		
		#if whirlpool hits do not allow fish to target salmon
		if self.target == None:
			self.move((0, self.__drift_speed * delta))
		else:
			if not self.whirl:
				self.move((self.__velocity[0] * delta, self.__velocity[1] * delta ))
			else:
				v = (self.target.centerx - self.rect.centerx, self.target.centery - self.rect.centery)
				mag = vector.mag(v)
				if mag < 300 * delta:
					self.rect.center = self.target.center
				else:
					v = vector.muls(vector.divs(v, vector.mag(v)), 300 * delta)
					self.move(v)