def __init__(self, pos=None): FlyingObject.__init__(self) self.spaceship, self.rect = Utils.loadImage("spaceship.png") self.flame = [Utils.loadImage("flame_red_00.png")[0], Utils.loadImage("flame_red_01.png")[0], Utils.loadImage("flame_red_02.png")[0]] self.flameRect = self.flame[0].get_rect() self.rect.h += self.flameRect.h self.flameRect.bottom = self.rect.h-self.flameRect.h self.flameRect.left = 0 self.image = pygame.Surface((self.rect.w, self.rect.h)) self.image.fill(Color(255,0,255)) self.image.blit(self.spaceship, (0,0)) self.spaceship = self.image.copy() self.spaceship.set_colorkey(Color(255,0,255)) self.accel = False self.flameCounter = 0 self.direction = 0 self.turning = 0 if pos == None: self.pos = [Settings.map_size[0]//2, Settings.map_size[1]//2] else: self.pos = pos self.snd_engine = Utils.loadSound("engine.ogg") self.snd_engine_channel = None
def __init__(self, pos, direction, speed, lifespan, init_move=[0,0]): FlyingObject.__init__(self) self.image, self.rect = Utils.loadImage("missisle_basic.png") self.move = [math.sin(math.radians(-direction))*speed, -math.cos(math.radians(direction))*speed] self.move[0] += init_move[0] self.move[1] += init_move[1] self.pos = pos#position of the center of the missisle, in floats [rect keeps it in ints] #rotate image self.image = pygame.transform.rotozoom(self.image, direction, 1) self.rect = self.image.get_rect() self.rect.center = pos self.lifespan = lifespan snd = Utils.loadSound("missisle_basic.ogg") vol_r = pos[0]/Settings.screen_size[0] vol_l = 1-vol_r try: snd.play().set_volume(vol_l,vol_r) except AttributeError: pass #not enaught channels
def __init__(self, size=200, pos=None, direction=None, speed=None): FlyingObject.__init__(self) self.size = size self.image = pygame.Surface((size, size)) self.image.fill(Color(255,0,255)) self.image.set_colorkey(Color(255,0,255)) pointlist = [] for i in range(random.randint(7,12)):#how much verticles x = random.randint(0,size//2) y1 = (size//2)**2 - x**2 y1 = int(math.sqrt(y1)) y2 = (size//4)**2 - x**2 try: y2 = int(math.sqrt(y2)) except ValueError: y2 = 0 y = random.randint(y2, y1) y = random.choice([-1,1])*y x = random.choice([-1,1])*x y+=size//2 x+=size//2 pointlist += [(x,y)] s=size//2 def cmp(a,b): if a==b: return 0 if a[1] >= s and b[1] >= s: if a[0] > b[0]: return 1 else: return -1 if a[1] < s and b[1] < s: if a[0] > b[0]: return -1 else: return 1 if a[1] < s and b[1] >= s: return 1 else: return -1 pointlist.sort(cmp) #print pointlist self.rect = pygame.draw.polygon(self.image, Color(40,40,40), pointlist) self.rect = pygame.draw.polygon(self.image, Color(200,200,200), pointlist,3) #self.image, self.rect = Utils.loadImage("spaceship.png") if not pos: #random position site = random.randint(0,1) br_pos = [0,0] br_pos[site] = 0 br_pos[not site] = random.randint(0,Settings.map_size[not site]) self.rect.bottomright = br_pos self.pos[0], self.pos[1] = self.rect.center#position of the center of the asteroid, in floats [rect keeps it in ints] else: self.pos = pos self.rect.center = pos if not direction: #random direction directions = range(360) del(directions[0]) del(directions[90]) del(directions[180]) direction = random.choice(directions) if not speed: #random speed speed = random.randint(1,2) self.move = [math.sin(math.radians(-direction))*speed, -math.cos(math.radians(direction))*speed] self.mask = pygame.mask.from_surface(self.image)