<commit_before>#!/usr/bin/python

import math
import pygame
import Globals
from Globals import UnitType, Debug
import Effects

class Projectile(pygame.sprite.Sprite):
	""" All projectiles will inherit this class for a basic projectile. """
	def __init__(self, d=None, l=-1):
		pygame.sprite.Sprite.__init__(self)
		self.Degrees = d
		self.Speed = 6		# Movement per tick
		self.Life = l		## Anything higher than -1 will determine how many 
							## ticks the projectile is alive.
		
		self.image = None
		self.rect = None
		
		self.realX = 0.0
		self.realY = 0.0
		
	def calculate_path(self):
		if self.Degrees is None:
			self.Degrees = 0.0
			
		self.Radian = (self.Degrees - 90.0) * (math.pi / 180.0)
		
		## Distance the projectile travels per tick, given the angle above.
		self.StepX = self.Speed * math.cos(self.Radian)
		self.StepY = self.Speed * math.sin(self.Radian)
		#Debug(">> Radian: " + str(self.Radian) + "\nStep: " + str((self.StepX, self.StepY)))
	
	def update(self, nobounds=False):
		## This will despawn the projectile once it leaves play.
		"""if not nobounds:
			if not self.check_bounds():
				self.kill()"""
		
		## Move the projectile keeping in mind the direction.
		self.rect.x += self.StepX
		self.rect.y += self.StepY
		
	
	def check_bounds(self):
		vars = Globals.Vars()
		bounds = vars.Bounds
		if self.Type == UnitType.ENEMY:
			bounds = vars.ScreenSize
		
		if self.Life > -1:
			if self.Life == 0:
				return False
			else:
				self.Life -= 1
		
		if bounds.contains(self.rect):
			return True
		return False

class Bullet(Projectile):
	def __init__(self, t, x, y, d=None, l=-1):
		Projectile.__init__(self, d, l)
		
		self.Type = t
		
		## Defaults given the unit type that fired the projectile.
		if self.Degrees == None:
			if self.Type == UnitType.PLAYER:
				self.Degrees = 0.0
			elif self.Type == UnitType.ENEMY:
				self.Degrees = 180.0
			else:
				self.Degrees = 90.0
		
		## Load the correct image.
		if self.Type == UnitType.PLAYER:
			self.image = pygame.transform.rotate(Globals.LoadImage('png/Lasers/laserGreen02.png'), (self.Degrees * -1))
			self.Speed = 15
		else:
			self.image = pygame.transform.rotate(Globals.LoadImage('png/Lasers/laserRed02.png'), (self.Degrees * -1))
		
		self.rect = self.image.get_rect()
		self.rect.x = x
		self.rect.y = y
		
		self.calculate_path()

class BulletBomb(Bullet):
	def __init__(self, t, x, y, group, d=0, l=90):
		Bullet.__init__(self, t, x, y, d, l)
		self.Fuse = 20
		self.Speed = 1
		self.Group = group
	
	def detonate(self):
		shrapnel = 8
		for n in range(shrapnel):
			self.Group.add(BulletBomb(self.Type, self.rect.centerx, self.rect.centery, self.Group, (n * (360.0 / shrapnel)), self.Life - 20))
		self.Group.add(Effects.Explosion(self.Type, (self.rect.centerx, self.rect.centery)))
		self.kill()<commit_msg>Fixed BulletBomb issue.<commit_after>#!/usr/bin/python

import math
import pygame
import Globals
from Globals import UnitType, Debug
import Effects

class Projectile(pygame.sprite.Sprite):
	""" All projectiles will inherit this class for a basic projectile. """
	def __init__(self, d=None, l=-1):
		pygame.sprite.Sprite.__init__(self)
		self.Degrees = d
		self.Speed = 6		# Movement per tick
		self.Life = l		## Anything higher than -1 will determine how many 
							## ticks the projectile is alive.
		
		self.image = None
		self.rect = None
		
		self.realX = 0.0
		self.realY = 0.0
		
	def calculate_path(self):
		if self.Degrees is None:
			self.Degrees = 0.0
			
		self.Radian = (self.Degrees - 90.0) * (math.pi / 180.0)
		
		## Distance the projectile travels per tick, given the angle above.
		self.StepX = self.Speed * math.cos(self.Radian)
		self.StepY = self.Speed * math.sin(self.Radian)
		#Debug(">> Radian: " + str(self.Radian) + "\nStep: " + str((self.StepX, self.StepY)))
	
	def update(self, nobounds=False):
		## This will despawn the projectile once it leaves play.
		"""if not nobounds:
			if not self.check_bounds():
				self.kill()"""
		
		## Move the projectile keeping in mind the direction.
		self.rect.x += self.StepX
		self.rect.y += self.StepY
		
	
	def check_bounds(self):
		vars = Globals.Vars()
		bounds = vars.Bounds
		if self.Type == UnitType.ENEMY:
			bounds = vars.ScreenSize
		
		# TODO: Move this somewhere else.
		if self.Life > -1:
			if self.Life == 0:
				return False
			else:
				self.Life -= 1
		
		if bounds.contains(self.rect):
			return True
		return False

class Bullet(Projectile):
	def __init__(self, t, x, y, d=None, l=-1):
		Projectile.__init__(self, d, l)
		
		self.Type = t
		
		## Defaults given the unit type that fired the projectile.
		if self.Degrees == None:
			if self.Type == UnitType.PLAYER:
				self.Degrees = 0.0
			elif self.Type == UnitType.ENEMY:
				self.Degrees = 180.0
			else:
				self.Degrees = 90.0
		
		## Load the correct image.
		if self.Type == UnitType.PLAYER:
			self.image = pygame.transform.rotate(Globals.LoadImage('png/Lasers/laserGreen02.png'), (self.Degrees * -1))
			self.Speed = 15
		else:
			self.image = pygame.transform.rotate(Globals.LoadImage('png/Lasers/laserRed02.png'), (self.Degrees * -1))
		
		self.rect = self.image.get_rect()
		self.rect.x = x
		self.rect.y = y
		
		self.calculate_path()
	
	def update(self):
		if not self.check_bounds():
			self.kill()
		else:
			Projectile.update(self)

class BulletBomb(Bullet):
	def __init__(self, t, x, y, group, d=0, l=90):
		Bullet.__init__(self, t, x, y, d, l)
		self.Fuse = 20
		self.Speed = 1
		self.Group = group
	
	def detonate(self):
		shrapnel = 8
		for n in range(shrapnel):
			self.Group.add(BulletBomb(self.Type, self.rect.centerx, self.rect.centery, self.Group, (n * (360.0 / shrapnel)), self.Life - 20))
		self.Group.add(Effects.Explosion(self.Type, (self.rect.centerx, self.rect.centery)))
		self.kill()
{'fraction_non_alphanumeric': 0.13668690372940157, 'fraction_numerical': 0.017346053772766695, 'mean_word_length': 3.1156316916488223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2196705', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2084, 'n_words': 538}