Ejemplo n.º 1
0
def init():
    global background,title,clock
    #Initialize Everything
    pygame.init()
    gfx.init()   
    # load some global images
    background,back_rect = gfx.load_image("background.png")
    title,title_rect = gfx.load_image("title.png")
    gfx.screen.blit(background,(0,0))
    gfx.screen.blit(title,(120,20))
    pygame.display.flip()
    # load and set some defaults
    game_state = 0
    clock = pygame.time.Clock()
    #load some global sounds

    # load some music

    # wait till mouse is clicked or loops interates 1000 times
    i = 0
    while 1:
        clock.tick(60)
        if i==200: return
        for event in pygame.event.get():
            if event.type == QUIT:
                return
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return
            elif event.type == MOUSEBUTTONDOWN:
                return                
        gfx.screen.blit(background,(0,0))
        gfx.screen.blit(title,(120,20))
        pygame.display.flip()
        i = i + 1
Ejemplo n.º 2
0
    def __init__(self, x, y, mobtype):
        pygame.sprite.Sprite.__init__(self)
        self.projectileTimer = 0
        self.currentAnimationFrame = 0
        self.currentAnimationType = 'static'
        self.framecounter = 0
        self.dx = 0
        self.dy = 0

        self.moving = True #Don't know if we need this but I'll keep this in here in case we want mobs to stand still
        self.forced = 0

        self.direction = 'up'
        self.rect = pygame.Rect(x,y,64,64)
        self.projectiles = pygame.sprite.Group()
        self.mobtype = mobtype
        self.setDir()

        self.hp=0
        if(mobtype=='art'):
            self.image,null = gfx.load_image('Enemy-1/down-attack/Animation-Down0001.png',-1)

            self.hp=15
        elif(mobtype=='football'):
            self.hp=15
            self.image,null = gfx.load_image('Enemy-2/down-attack/Animation0001.png',-1)
        elif(mobtype=='commerce'):
            self.image,null = gfx.load_image('Enemy-3/Down-attack/Animation0001.png',-1)
Ejemplo n.º 3
0
    def __init__(self, driver):
        super(BasicMatch, self).__init__(driver)
        self.background = gfx.load_image("images/bkgd-crop.png")[0]
        self.buff = gfx.load_image("images/bkgd-crop.png")[0]
        self.banner_image = \
            gfx.load_image_with_colorkey("images/fight_banner_border.png")

        self.input_lock = False
Ejemplo n.º 4
0
    def __init__(self, driver):
        super(BasicMatch, self).__init__(driver)
        self.background = gfx.load_image("images/bkgd-cropblack.png")[0]
        self.buff = gfx.load_image("images/bkgd-cropblack.png")[0]
        self.banner_image = \
            gfx.load_image_with_colorkey("images/fight_banner_border.png")

        self.input_lock = False
Ejemplo n.º 5
0
 def __init__(self):
     pg.sprite.Sprite.__init__(self)
     self.images = []
     self.images.append(gfx.load_image("POWERUP/powerup_a.png"))
     self.images.append(gfx.load_image("POWERUP/powerup_b.png"))
     self.images.append(gfx.load_image("POWERUP/powerup_c.png"))
     self.next_anim_frame = 0
     self.index = 0
     self.image = self.images[self.index]
     self.rect = pg.Rect(0, 0, 40, 40)
     self.rect.x = randrange(40, SCREEN_WIDTH - 40)
     self.rect.y = 1
Ejemplo n.º 6
0
    def __init__(self,level,bg):

        self.leveltimer = 0
        
        self.level = level #int, which level we are currently on.
        self.obstacles = []
        self.fg = False
        #### MOBS ####
        # 1. Art Student
        # 2. Commerce Student
        # 3. Health Sci Student
        # 4. Football Player
        # 5. All of the above

        #### BOSS ####
        # 1. Angry Art Student
        # 2. Dr. Fleisig
        # 3. Dr. McLean
        # 4. Football Coach
        # 5. Dr. Smith

        self.spawnRate = 0
        self.spawnPoints = []

        
        if 1==level:
            self.bg,null = gfx.load_image("level-1-bg.png",-1)
            self.fg,null = gfx.load_image("level-1-fg.png",-1)
            
            self.obstacles.append(pygame.Rect(312,440,80,55))
            self.obstacles.append(pygame.Rect(106,197,65,62))
            self.obstacles.append(pygame.Rect(372,197,65,62))
            self.obstacles.append(pygame.Rect(634,197,65,62))

            self.mobType='art'
            self.spawnRate = 2
            self.spawnPoints = [(800,600),(0,600),(300,600)]
            
        if 2==level:
            self.bg,null = gfx.load_image("Level-2.png",-1)
            self.mobType = 'football'
            self.spawnRate = 5
            self.spawnPoints = [(-250,-250),(800,0),(300,600),(-250,300),(-250,800),(1000,1000)]
        if 3==level:
            self.bg,null = gfx.load_image("Level-3.png",-1)
            self.mobType = 'commerce'
            self.spawnRate = 1
            self.spawnPoints = [(800,600),(0,600),(300,600)]
        if 4==level:
            pass
        if 5==level:
            pass
Ejemplo n.º 7
0
 def setDir(self,direction):
     # 1. Set player's direction
     # 2. Change player's image to match direction
     self.dir = direction
     
     if self.currentAnimationType==0:
         if direction == 'down':
             self.image,null = gfx.load_image('player-melee-down/frame1.png',-1)
         elif direction == 'left':
             self.image,null = gfx.load_image('player-melee-left/frame1.png',-1)
         elif direction == 'right':
             self.image,null = gfx.load_image('player-melee-left/frame8.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif direction == 'up':
             self.image,null = gfx.load_image('player-melee-up/frame1.png',-1)
         elif direction == 'downleft':
             self.image,null = gfx.load_image('player-melee-downleft/frame1.png',-1)
         elif direction == 'downright':
             self.image,null = gfx.load_image('player-melee-downleft/frame8.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif direction == 'upleft':
             self.image,null = gfx.load_image('player-melee-upleft/frame1.png',-1)
         elif direction == 'upright':
             self.image,null = gfx.load_image('player-melee-upleft/frame8.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif direction == 'static':
             pass
def get_masks_from_image(file_name):
    """
    attempt to load a mask file and get hit boxes from it.

    hitboxes in the image can touch, but cannot overlap.
    they must be rectangles with straight edges.
    a dict defining the colors to search for can be passed.

    """

    if os.access(file_name, os.F_OK) == False:
        return

    mask, rect = gfx.load_image(file_name, use_cache=False)
    pxarray = pygame.PixelArray(mask)

    width, height = rect.size
    height = height - 1

    # could be slow, but idk another way
    y = 0
    rects = []
    while y <= height:
        rect        = None
        last_color  = None
        for x in range(0, width):
            color = mask.unmap_rgb(pxarray[x][y])[:3]

            if last_color != color:
                if (rect == None) and (color != (0,0,0)):
                    rect = [x,y,None,None,color]
                elif rect != None:
                    existing = False
                    rect[2] = x - 1
                    for r in rects:
                        if r[3] == None:
                            if (r[0] == rect[0]) and (r[1] == rect[1] - 1) and (r[2] == rect[2]) and (r[4] == rect[4]):
                                r[3] = y
                                existing = True
                        elif (r[0] == rect[0]) and (r[3] == rect[1] - 1) and (r[2] == rect[2]) and (r[4] == rect[4]):
                            r[3] = y
                            existing = True

                    if existing == False:
                        #print r, rect, x, y
                        rects.append(rect)
                    if color != (0,0,0):
                        rect = [x,y,None,None,color]

            last_color = color
        y += 1
   
    if rect != None:
        rect[2] = x - 1
        for r in rects:
            if r[3] == None:
                if (r[0] == rect[0]) and (r[1] == rect[1] - 1) and (r[2] == rect[2]) and (r[4] == rect[4]):
                    r[3] = y
            elif (r[0] == rect[0]) and (r[3] == rect[1] - 1) and (r[2] == rect[2]) and (r[4] == rect[4]):
                r[3] = y
Ejemplo n.º 9
0
def display():
    clock = pygame.time.Clock()
    i = 0
    for button in buttons:
        tmp_image,tmp_rect = gfx.load_image(button)
        if i==0:
            button_image = [tmp_image]
            button_rect = [tmp_rect]
        else :
            button_image.append(tmp_image)
            button_rect.append(tmp_rect)
            
        gfx.screen.blit(button_image[i],hotspots[i])
        pygame.display.flip()
        i = i + 1
    while 1:
        clock.tick(60)
        pygame.time.delay(20)
        for event in pygame.event.get():
            if event.type == QUIT:
                return 'exit'
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return 'exit'
            elif event.type == MOUSEBUTTONDOWN:
                # check for hotspots and preform the action
                j = 0
                for button in button_rect:
                    button.topleft = hotspots[j]
                    if hit_hotspot(button,pygame.mouse.get_pos()):
                        return actions[j]                
                    j = j + 1
Ejemplo n.º 10
0
 def __init__(self):
     pygame.sprite.Sprite.__init__(self) #call Sprite intializer
     self.image, self.rect = gfx.load_image('thetofu.bmp', -1)
     screen = pygame.display.get_surface()
     self.area = screen.get_rect()
     self.rect.topleft = 30, 30
     self.move = 2
     self.stopped = 0
Ejemplo n.º 11
0
 def die(self):
     for i in range(9):
         pg.display.update(
                 gfx.explosion(self.center[0] + randrange(-100, 100, 20), self.center[1] + randrange(-100, 100, 20)))
         snd.load_sound("explode.wav")
     self.image = pg.transform.scale2x(gfx.load_image("explosion_last.png"))
     snd.load_sound("blow_up.wav")
     pg.display.update()
     snd.play_song("saturns_folly.ogg")
     self.kill()
Ejemplo n.º 12
0
def init_game():
    global score,time, last_ttime, level,picture,hints,background,small_title
    global exit,exit_rect,score_time,level_img,hint_bar,hint_x,num_correct
    #global first,second,third,fourth,fifth
    num_correct = [1,2,3,4,5]
    score = 0
    time = 1250
    last_ttime = datetime.now()
    "load picture list "
    picture = pictures.Pictures()
    
    level = 1
    hints = 3
    "load up the images"
    small_title,small_title_rect = gfx.load_image("small_title.png")
    exit,exit_rect = gfx.load_image("menu.png")
    score_time,score_time_rect = gfx.load_image("score_time.png")
    level_img,level_img_rect = gfx.load_image("level.png")
    hint_bar,hint_bar_rect = gfx.load_image("hint_bar.png")
    hint_x,hint_x_rect = gfx.load_image("hint_x.png")
    
    "draw everything"
    gfx.screen.blit(background,(0,0))
    gfx.screen.blit(small_title,(20,20))
    gfx.screen.blit(exit,(580,500))
    gfx.screen.blit(score_time,(530,30))
    gfx.screen.blit(level_img,(350,30))
    gfx.screen.blit(hint_bar,(530,115))
    picture.get_pic()
    picture.draw_pics()
Ejemplo n.º 13
0
 def reset(self):
     self.style = None           # 1v1, 2v1, 2v2, tag, etc
     self.rounds = 3
     self.fighter = []
     self.controller = []
     self.finished = False
     self.quit = False
     self.defeat = None
     self.current_round = 1
     self.next_match = (False, False)
     self.arena = None
     self.post_round_pause = False
     self.world = engine.StaticWorld(self._driver.get_size())
     self.world.view.set_background(gfx.load_image("images/bkgd-crop.png")[0])
Ejemplo n.º 14
0
    def __init__(self, X, Y):
        self.currentAnimationFrame = 1
        self.currentAnimationType = 'static'
        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = gfx.load_image('swish-down/frame1.png',-1)

        self.dir = 'down'
        self.proj_type = 'swish'
        self.canDoDamage = True
        
        self.rect = pygame.Rect(X,Y,128,128)
        fullname = os.path.join('sprites', 'swish-down/frame1.png')
        self.image = pygame.image.load(fullname)
        self.image.convert()
Ejemplo n.º 15
0
 def reset(self):
     self.style = None  # 1v1, 2v1, 2v2, tag, etc
     self.rounds = 3
     self.fighter = []
     self.controller = []
     self.finished = False
     self.quit = False
     self.defeat = None
     self.current_round = 1
     self.next_match = (False, False)
     self.arena = None
     self.post_round_pause = False
     self.world = engine.StaticWorld(self._driver.get_size())
     self.world.view.set_background(
         gfx.load_image("images/bkgd-cropblack.png")[0])
Ejemplo n.º 16
0
    def __init__(self, X, Y):

        self.attacking = False
        self.currentAnimationFrame = 0
        self.currentAnimationType = 0
        self.moving = False

        self.dir = 'down'
        self.dx = 0
        self.dy = 0

        pygame.sprite.Sprite.__init__(self)
        self.image, self.rect = gfx.load_image('player-melee-down/frame1.png', -1)
        self.rect = pygame.Rect(X,Y,64,64)
        self.canAttack = True
        self.health = 100

        return
Ejemplo n.º 17
0
 def __init__(self, X, Y):
     pygame.sprite.Sprite.__init__(self)
     self.image, null = gfx.load_image('health/pack.png',-1)
     self.rect = pygame.Rect(X,Y,50,50)
Ejemplo n.º 18
0
def load_resources():
    for i in range(11):
        images.append(gfx.load_image('ring/ring{}.png'.format(i)))
 def reactivate(self):
     self._driver.get_screen().blit(gfx.load_image("images/bkgd-crop.png")[0], (0,0))
     pass
Ejemplo n.º 20
0
def get_masks_from_image(file_name):
    """
    attempt to load a mask file and get hit boxes from it.

    hitboxes in the image can touch, but cannot overlap.
    they must be rectangles with straight edges.
    a dict defining the colors to search for can be passed.

    """

    if os.access(file_name, os.F_OK) == False:
        return

    mask, rect = gfx.load_image(file_name, use_cache=False)
    pxarray = pygame.PixelArray(mask)

    width, height = rect.size
    height = height - 1

    # could be slow, but idk another way
    y = 0
    rects = []
    while y <= height:
        rect = None
        last_color = None
        for x in range(0, width):
            color = mask.unmap_rgb(pxarray[x][y])[:3]

            if last_color != color:
                if (rect == None) and (color != (0, 0, 0)):
                    rect = [x, y, None, None, color]
                elif rect != None:
                    existing = False
                    rect[2] = x - 1
                    for r in rects:
                        if r[3] == None:
                            if (r[0]
                                    == rect[0]) and (r[1] == rect[1] - 1) and (
                                        r[2] == rect[2]) and (r[4] == rect[4]):
                                r[3] = y
                                existing = True
                        elif (r[0] == rect[0]) and (r[3] == rect[1] - 1) and (
                                r[2] == rect[2]) and (r[4] == rect[4]):
                            r[3] = y
                            existing = True

                    if existing == False:
                        #print r, rect, x, y
                        rects.append(rect)
                    if color != (0, 0, 0):
                        rect = [x, y, None, None, color]

            last_color = color
        y += 1

    if rect != None:
        rect[2] = x - 1
        for r in rects:
            if r[3] == None:
                if (r[0] == rect[0]) and (r[1] == rect[1] - 1) and (
                        r[2] == rect[2]) and (r[4] == rect[4]):
                    r[3] = y
            elif (r[0] == rect[0]) and (r[3] == rect[1] - 1) and (
                    r[2] == rect[2]) and (r[4] == rect[4]):
                r[3] = y
Ejemplo n.º 21
0
 def setDir(self):
     
     
     if self.currentAnimationType==0 and self.mobtype == 'art':
         if self.direction == 'down':
             self.image,null = gfx.load_image('Enemy-1/down-attack/Animation-Down0001.png',-1)
         elif self.direction == 'left':
             self.image,null = gfx.load_image('Enemy-1/left-attack/Animation-Left0001.png',-1)
         elif self.direction == 'right':
             self.image,null = gfx.load_image('Enemy-1/left-attack/Animation-Left0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'up':
             self.image,null = gfx.load_image('Enemy-1/up-attack/Animation-Up0001.png',-1)
         elif self.direction == 'downleft':
             self.image,null = gfx.load_image('Enemy-1/down-left-attack/Animation-down-left0001.png',-1)
         elif self.direction == 'downright':
             self.image,null = gfx.load_image('Enemy-1/down-left-attack/Animation-down-left0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'upleft':
             self.image,null = gfx.load_image('Enemy-1/up-left-attack/Animation-up-left0001.png',-1)
         elif self.direction == 'upright':
             self.image,null = gfx.load_image('Enemy-1/up-left-attack/Animation-up-left0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'static':
             pass
     if self.currentAnimationType==0 and self.mobtype == 'football':
         if self.direction == 'down':
             self.image,null = gfx.load_image('Enemy-2/down-attack/Animation0001.png',-1)
         elif self.direction == 'left':
             self.image,null = gfx.load_image('Enemy-2/left-attack/Animation0001.png',-1)
         elif self.direction == 'right':
             self.image,null = gfx.load_image('Enemy-2/left-attack/Animation0001.png',-1)
         elif self.direction == 'up':
             self.image,null = gfx.load_image('Enemy-2/up-attack/Animation0001.png',-1)
         elif self.direction == 'downleft':
             self.image,null = gfx.load_image('Enemy-2/down-left-attack/Animation0001.png',-1)
         elif self.direction == 'downright':
             self.image,null = gfx.load_image('Enemy-2/down-left-attack/Animation0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'upleft':
             self.image,null = gfx.load_image('Enemy-2/up-left-attack/Animation0001.png',-1)
         elif self.direction == 'upright':
             self.image,null = gfx.load_image('Enemy-2/up-left-attack/Animation0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'static':
             pass
     if (self.currentAnimationType==0 or self.currentAnimationType=='static') and self.mobtype == 'commerce':
         if self.direction == 'down':
             self.image,null = gfx.load_image('Enemy-3/Down-attack/Animation0001.png',-1)
         elif self.direction == 'left':
             self.image,null = gfx.load_image('Enemy-3/Right-attack/Animation0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'right':
             self.image,null = gfx.load_image('Enemy-3/Right-attack/Animation0001.png',-1)
         elif self.direction == 'up':
             self.image,null = gfx.load_image('Enemy-3/Up-attack/Animation0001.png',-1)
         elif self.direction == 'downleft':
             self.image,null = gfx.load_image('Enemy-3/Down-right-attack/Animation0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'downright':
             self.image,null = gfx.load_image('Enemy-3/Down-right-attack/Animation0001.png',-1)
         elif self.direction == 'upleft':
             self.image,null = gfx.load_image('Enemy-3/Up-right-attack/Animation0001.png',-1)
             self.image = pygame.transform.flip(self.image,True,False)
         elif self.direction == 'upright':
             self.image,null = gfx.load_image('Enemy-3/Up-right-attack/Animation0001.png',-1)
         elif self.direction == 'static':
             pass
Ejemplo n.º 22
0
 def load_image(self, filename):
     self.image, self.rect = gfx.load_image(filename)
Ejemplo n.º 23
0
def load_resources():
    for i in range(8):
        images.append(gfx.load_image('glow/glow{}.png'.format(i)))
Ejemplo n.º 24
0
    def update(self):
        self.tickcount+=1
        if(self.moving):
            self.placeholder[0] += self.dx
            self.placeholder[1] += self.dy
            self.rect.move_ip(int(self.placeholder[0]),int(self.placeholder[1]))

            if(int(self.placeholder[0])!=0):
                if(self.placeholder[0]>0):
                    self.placeholder[0] -= int(self.placeholder[0])
                else:
                    self.placeholder[0] -= int(self.placeholder[0])
                    
            if(int(self.placeholder[1])!=0):
                if(self.placeholder[1]>0):
                    self.placeholder[1] -= int(self.placeholder[1])
                else:
                    self.placeholder[1] -= int(self.placeholder[1])
            if self.rect.left == self.destination[0] and self.rect.top == self.destination[1]:
                self.moving = False
        if(self.level == 1):
            if(self.livingfor ==10 and not self.moving):
                self.walkTo(500,250)
            if(self.hp >=250):
                self.currentphase = 1
                # Phase 1
                if (self.livingfor - self.lastattack)>=self.nextattack:
                    self.nextattack = random.randrange(3,8,1)
                    self.lastattack = self.livingfor
                    self.attacking=True
            elif(self.hp >=150):
                self.currentphase = 2
                # Phase 2
                if (self.livingfor - self.lastattack)>=self.nextattack:
                    self.nextattack = random.randrange(3,8,1)
                    self.lastattack = self.livingfor
                    self.attacking = True
                pass
            elif(self.hp >=50):
                if(self.currentphase ==2):
                    ## red,orange,yellow,green,blue,purple,black,white
                    self.next_tiny = [0,0,0,0,0,0,0,0]
                    self.last_tiny = [0,0,0,0,0,0,0,0]
                    self.curr_tiny = [0,0,0,0,0,0,0,0]
                self.currentphase = 3
                self.curr_tiny = [0,0,0,0,0,0,0,0]
                for i in range(8):
                    if(self.livingfor-self.last_tiny[i])>=self.next_tiny[i]:
                        self.next_tiny[i] = random.randrange(3,8,1)
                        self.last_tiny[i] = self.livingfor
                        self.curr_tiny[i] = 1
                        self.attacking = True
                # Phase 3
                pass
            elif(self.hp > 0):
                if(self.currentphase == 3):
                    self.attacking=True
                    pass
                self.currentphase = 4
                if(self.tickcount-self.lastattack)>20:
                    self.attack_4 = True
                    self.lastattack = self.tickcount
                # Phase 4
            else:
                if not self.currentphase==5:
                    self.attacking=True
                self.currentphase = 5
        elif(self.level == 2):
            if(self.livingfor==10 and not self.moving):
                self.walkTo(500,250)
            if(self.hp >= 250):
                self.currentphase = 1
                if (self.livingfor - self.lastattack)>=self.nextattack:
                    self.nextattack = random.randrange(3,8,1)
                    self.lastattack = self.livingfor
                    self.attacking=True
            elif(self.hp >=150):
                self.currentphase = 2
                if (self.livingfor - self.lastattack)>=self.nextattack:
                    self.nextattack = random.randrange(3,8,1)
                    self.lastattack = self.livingfor
                    self.attacking=True
            elif(self.hp > 0):
                self.currentphase = 3
                if (self.livingfor - self.lastattack)>=self.nextattack:
                    self.nextattack = random.randrange(8,15,1)
                    self.lastattack = self.livingfor
                    self.attacking=True
            else:
                if(self.currentphase ==4):
                    pass
        elif(self.level ==3):
            if(self.livingfor==10 and not self.moving):
                self.walkTo(100,300)
            if(self.hp > 0):
                self.currentphase = 1
                if (self.livingfor - self.lastattack)>=self.nextattack:
                    self.nextattack = random.randrange(6,10,1)
                    self.lastattack = self.livingfor
                    self.attacking=True
                    self.attack_4 = False
        if(self.attacking):
            if(self.level ==1):
                if 1==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,1)
                    if self.currentAnimationFrame==5:
                        self.attacking=False
                        self.attack_1=True
                        self.currentAnimationFrame=0
                elif 2==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,2)
                    if self.currentAnimationFrame==10:
                        self.attacking=False
                        self.attack_2=True
                        self.currentAnimationFrame=0
                elif 3==self.currentphase:
                    self.attacking=False
                    self.attack_3=True
                    self.currentAnimationFrame=0
                elif 4==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,4)
                    if self.currentAnimationFrame==10:
                        self.attacking=False
                        self.currentAnimationFrame=0
                elif 5==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,5)
                    print self.currentAnimationFrame
                    if self.currentAnimationFrame==9:
                        self.die()
                        self.attacking = False
            elif(self.level==2):
                if 1==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,1)
                    if(self.currentAnimationFrame==10):
                        self.attacking=False
                        self.attack_1=True
                        self.currentAnimationFrame=0
                elif 2==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,1)
                    if(self.currentAnimationFrame==10):
                        self.attacking=False
                        self.attack_2=True
                        self.currentAnimationFrame=0
                elif 3==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,1)
                    self.attacking=False
                    self.attack_3=True
                    self.currentAnimationFrame=0
            elif(self.level==3):
                if 1==self.currentphase:
                    self.currentAnimationFrame+=1
                    gfx.animate(self,1)
                    if(self.currentAnimationFrame==60):
                        self.attacking=False
                        self.attack_1=True
                        self.currentAnimationFrame=0
        
        if(self.takingdmg):
            if self.level==1 and self.currentphase is not 5:
                self.counter+=1
                if self.counter%5==0:
                    if 4==self.currentphase:
                        self.image,null = gfx.load_image("boss-art/rage/rage00010.png",-1)
                    else:
                        self.image,null = gfx.load_image("boss-art/throw0005.png",-1)
                elif self.counter%5==1:
                    if 4==self.currentphase:
                        self.image,null = gfx.load_image("boss-art/rage/takingdmg.png",-1)
                    else:
                        self.image,null = gfx.load_image("boss-art/takingdmg.png",-1)
                if(self.counter==60):
                    self.takingdmg= False
            elif self.level==2 and self.currentphase is not 5:
                self.counter+=1
                if self.counter%5==0:
                    self.image,null = gfx.load_image("coach-art/boss.png",-1)
                elif self.counter%5==1:
                    self.image,null = gfx.load_image("coach-art/boss-hit.png",-1)
                if(self.counter==60):
                    self.takingdmg = False
            elif self.level==3:
                self.counter+=1
                if self.counter%5==0:
                    self.image,null = gfx.load_image("boss-fleisig/boss.png",-1)
                elif self.counter%5==1:
                    self.image,null = gfx.load_image("boss-fleisig/takingdmg.png",-1)
                if(self.counter==60):
                    self.takingdmg = False
Ejemplo n.º 25
0
def game_loop():
    global clock,last_ttime, score,time,level,picture,hints,background,small_title
    global exit,exit_rect,score_time,level_img,hint_bar,hint_x
    #global first,second,third,fourth,fifth
    " play tofuhunt, it rocks :) "
    
    init_game()

    while 1:
        clock.tick(60)
        if hints == 0:
            gfx.screen.blit(hint_x,(602,132))
            gfx.screen.blit(hint_x,(654,132))
            gfx.screen.blit(hint_x,(708,132))
        elif hints == 1:
            gfx.screen.blit(hint_x,(654,132))
            gfx.screen.blit(hint_x,(708,132))
        elif  hints == 2:  
            gfx.screen.blit(hint_x,(708,132))

        # draw level and score and time
        gfx.screen.blit(score_time,(530,30))
        if pygame.font:            
            font = pygame.font.Font("data/fonts/font.ttf", 18)
            text = font.render(str(level), 1, (255, 10, 10))
            gfx.screen.blit(text, (391,70))
            font = pygame.font.Font("data/fonts/font.ttf", 14)
            text = font.render(str(score), 1, (255, 10, 10))
            gfx.screen.blit(text, ((740-(len(str(score))*5)),50))

        ttime = datetime.now()
        ttime = int((ttime.hour*60*60)+(ttime.minute*60)+ttime.second)
        lttime = int((last_ttime.hour*60*60)+(last_ttime.minute*60)+last_ttime.second)
                
        time_delta = ttime - lttime 
        
        j = 0
        while j<(time/10):
            red_bar,red_bar_rect= gfx.load_image("bar.png")        
            gfx.screen.blit(red_bar,(625+j,82))
            
            j = j + 1
            
        if_hit = 0
        
        pygame.display.flip()
        for event in pygame.event.get():
            if event.type == QUIT:
                return 'exit' 
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                return 'main_menu'
            elif event.type == MOUSEBUTTONDOWN:
                if picture.is_diff(pygame.mouse.get_pos()):
                    score = score + 100;
                    if_hit = 1
                    break
                elif hit_hint(pygame.mouse.get_pos()):
                    if_hit = 1
                    # draw the hint pics
                    if hints>0:
                        if hints == 1:
                            gfx.screen.blit(hint_x,(602,132))
                            hints = hints - 1
                        elif hints == 2:
                            gfx.screen.blit(hint_x,(654,132))
                            hints = hints - 1
                        elif hints == 3:
                            gfx.screen.blit(hint_x,(708,132))
                            hints = hints - 1
                            
                        picture.next_diff()
                    break
                elif hit_exit(exit_rect,pygame.mouse.get_pos()):
                    return 'main_menu'
        if if_hit == 0:
            time = time - time_delta
        else :
            if_hit = 0
        last_ttime = datetime.now()
        if picture.num_correct == 5:
            great,great_rect = gfx.load_image("great.png",(10,10,10))
            gfx.screen.blit(great,(325,230))
            pygame.display.flip()
            pygame.time.delay(1000)
            next_level()
            continue

        if time <= 0:  
            game_over,go_rect = gfx.load_image("game_over.png",(10,10,10))
            gfx.screen.blit(game_over,(325,230))
            pygame.display.flip()
            pygame.time.delay(800)
            for event in pygame.event.get():
                if event.type == MOUSEBUTTONDOWN:
                    return 'main_menu'
        else :
            time = time - (level+time_delta)
    
    
        # draw level and score and time
        gfx.screen.blit(score_time,(530,30))
        if pygame.font:            
            font = pygame.font.Font("data/fonts/font.ttf", 18)
            text = font.render(str(level), 1, (255, 10, 10))
            gfx.screen.blit(text, (391,70))
            font = pygame.font.Font("data/fonts/font.ttf", 14)
            text = font.render(str(score), 1, (255, 10, 10))
            gfx.screen.blit(text, ((740-(len(str(score))*5)),50))
                
        j = 0
        while j<(time/10):
            red_bar,red_bar_rect= gfx.load_image("bar.png")        
            gfx.screen.blit(red_bar,(625+j,82))
            #pygame.display.update(625+j,82,red_bar_rect.width,red_bar_rect.height)
            j = j + 1
        
        pygame.display.flip()
        pygame.time.delay(1)
Ejemplo n.º 26
0
 def __init__(self,X,Y,level):
     self.livingfor = 0
     self.currentAnimationType=0
     self.currentAnimationFrame=0
     self.tickcount = 0
     self.lastattack = 0
     self.nextattack=5
     self.moving = False
     self.dx = 0
     self.dy = 0
     self.attacking = False
     self.takingdmg = False
     self.attack_1 = False #This is so main.py can throw the ball instead of level.py
     self.attack_2 = False
     self.attack_3 = False
     self.attack_4 = False
     self.attack_5 = False
     if(level==1):
         self.level = level
         #### ANGRY ART STUDENT ####
         # Phase 1 (350-250)
         ## - Throw paint balls of various colours at the player (explode once they hit the ground)
         ## - 3-8 seconds between each ball
         # Phase 2 (250-150)
         ## - Throw palette (boomerang style)
         # Phase 3 (150-50)
         ## - Shoot tiny paint balls (slow, lots of them)
         # Phase 4 (50-0)
         ## - Paint balls fall from the sky
         self.hp = 350
         self.damage = 15
         self.currentphase = 0
         pygame.sprite.Sprite.__init__(self)
         self.image,self.rect = gfx.load_image("boss-art/boss.png",-1)
         self.rect = pygame.Rect(X,Y,250,250)
     if(level==2):
         self.level = level
         #### FOOTBALL COACH ####
         # Phase 1
         ## Throw football
         # Phase 2
         ## Summon players
         # Phase 3
         ## Yell
         self.hp = 350
         self.damage = 15
         self.currentphase = 0
         pygame.sprite.Sprite.__init__(self)
         self.image,self.rect = gfx.load_image("coach-art/boss.png",-1)
         self.rect = pygame.Rect(X,Y,150,150)
     if(level==3):
         #### DR. FLEISIG ####
         # Phase 1
         ## Shoot Fire
         self.level = level
         self.hp = 200
         self.damage = 15
         self.currentphase= 0
         pygame.sprite.Sprite.__init__(self)
         self.image,self.rect = gfx.load_image("boss-fleisig/boss.png",-1)
         self.rect = pygame.Rect(X,Y,209,182)
Ejemplo n.º 27
0
 def load_image(self, filename):
     self.image, self.rect = gfx.load_image(filename)
Ejemplo n.º 28
0
    def game_loop(self):
        #for x in range(10000):
        #    pass
        self.running = True #If running is true, the game will play
        self.framecount = 0 #how many frames have elapsed (resets every second)
        self.total_frames = 0 #Total frames since start

        #gfx.preloadedgfx.loadbasic()
        #print gfx.preloadedgfx.swish_down

        
        
        while self.running:
            tick_timer.tick(GAME_SETTINGS.GAME_SPEED) #tick
            self.framecount+=1 #Count frames

            ### DRAW ORDER ###
            ## This code makes sure that the background is drawn first, then the foreground
            ## The foreground should have transparent pixels, these pixels should be set 
            ##  to a color (rgb), where that colour in the image file is assumed to be 
            ##  transparent. Which colour is transparent should be held in the (0,0) pixel
            ##  (for example, if the transparent color is red, the top-left-most pixel should be
            ##  set to rgb(255,0,0)
            self.screen.blit(self.background, (0, 0)) #Draw background
            self.all_sprites.draw(self.screen)        #Draw sprites
            #COULD CLEAN THIS UP^^
            self.screen.blit(self.foreground, (0, 0)) #Draw foreground
            self.projectiles.draw(self.screen)
            colorkey =self.foreground.get_at((0,0))   #Set transparent color
            self.foreground.set_colorkey(colorkey)
            pygame.display.flip()                     #Make it happen
            
            #Check for inputs
            for event in pygame.event.get():
                if event.type == pygame.QUIT or event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
                    self.running = False #Quit Game
                    pygame.quit()
                    return False
                elif event.type == pygame.KEYDOWN:  # check for key presses          
                    if event.key == pygame.K_LEFT:        # left arrow turns left
                        self.pressed_left = True
                    elif event.key == pygame.K_RIGHT:     # right arrow turns right
                        self.pressed_right = True
                    elif event.key == pygame.K_UP:        # up arrow goes up
                        self.pressed_up = True
                    elif event.key == pygame.K_DOWN:      # down arrow goes down
                        self.pressed_down = True
                    elif event.key == pygame.K_s:
                        self.boss = level.Boss(1000,-250,self.currentLevel.level)
                        self.boss.add(pygame.sprite.RenderPlain(self.boss))
                        self.all_sprites.add(pygame.sprite.RenderPlain(self.boss))
                        self.boss.walkTo(700,250)
                        self.bossHealthBar = pygame.sprite.Sprite()
                        pygame.sprite.Sprite.__init__(self.healthBar)
                        self.bossHealthBar.image, null = gfx.load_image('health/10.png',-1)
                        self.bossHealthBar.rect = (550,550,100,20)
                        self.all_sprites.add(pygame.sprite.RenderPlain(self.bossHealthBar))
                        self.bossHealthChanged = False
                    elif event.key == pygame.K_SPACE:
                        self.pressed_leftmouse = True
                        
                elif event.type == pygame.KEYUP:    # check for key releases
                    if event.key == pygame.K_LEFT:        # left arrow turns left
                        self.pressed_left = False
                    elif event.key == pygame.K_RIGHT:     # right arrow turns right
                        self.pressed_right = False
                    elif event.key == pygame.K_UP:        # up arrow goes up
                        self.pressed_up = False
                    elif event.key == pygame.K_DOWN:      # down arrow goes down
                        self.pressed_down = False
                    elif event.key == pygame.K_SPACE:
                        self.pressed_leftmouse = False
                
                elif (event.type == pygame.MOUSEBUTTONDOWN and event.button==1): #Click
                    self.pressed_leftmouse = True
                elif(event.type == pygame.MOUSEBUTTONDOWN and event.button==3) and self.currentLevel.level > 2 and self.fireballCount > 0:
                     self.pressed_rightmouse = True
                     new_projectile = projectile.Projectile(self.guy.rect.center,pygame.mouse.get_pos(),'fireball',1)
                     self.all_sprites.add(pygame.sprite.RenderPlain(new_projectile))
                     self.fireballs.add(pygame.sprite.RenderPlain(new_projectile))
                     self.fireballCount += -1
                     self.fireballsChanged = True
                elif event.type == pygame.MOUSEBUTTONUP and event.button==1:
                     self.pressed_leftmouse = False
                elif event.type == pygame.MOUSEBUTTONUP and event.button==3:
                     self.pressed_rightmouse = False


            ###########################################
            ### DIRECTIONS                          ###
            ### 1: down        _       _            ### If a number must be substituted
            ### 2: left       |   / \   |           ###  for a direction, use this.
            ### 3: right        7  4  8             ###
            ### 4: up        <  2     3  >          ###
            ### 5: downleft     5  1  6             ###
            ### 6: downright  |_  \ /  _|           ###
            ### 7: upleft                           ###
            ### 8: upright                          ###
            ###########################################

            #Change player's direction based on input
            self.guy.moving = True #Assume guy is going to be moving
            if self.pressed_down and not self.pressed_up:
                if self.pressed_left: self.guy.setDir('downleft')
                elif self.pressed_right: self.guy.setDir('downright')
                else: self.guy.setDir('down')
            elif self.pressed_up and not self.pressed_down:
                if self.pressed_left: self.guy.setDir('upleft')
                elif self.pressed_right: self.guy.setDir('upright')
                else: self.guy.setDir('up')
            elif self.pressed_left:
                self.guy.setDir('left')
            elif self.pressed_right:
                self.guy.setDir('right')
            else:
                self.guy.moving = False #Guy is not moving


            #Draw fireballs
            if self.fireballsChanged:
                if self.fireballCount == 4:
                    self.fireball5.kill()
                if self.fireballCount == 3:
                    self.fireball4.kill()
                if self.fireballCount == 2:
                    self.fireball3.kill()
                if self.fireballCount == 1:
                    self.fireball2.kill()
                if self.fireballCount == 0:
                    self.fireball1.kill()
                self.fireballsChanged = False
            if self.addFireball:
                if self.fireballCount == 4:
                    self.fireball5 = pygame.sprite.Sprite()
                    pygame.sprite.Sprite.__init__(self.fireball5)
                    self.fireball5.image,null = gfx.load_image('engfireball.png',-1)
                    self.fireball5.rect = (400,550,32,32)
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball5))
                    self.fireballCount += 1
                if self.fireballCount == 3:
                    self.fireball4 = pygame.sprite.Sprite()
                    pygame.sprite.Sprite.__init__(self.fireball4)
                    self.fireball4.image,null = gfx.load_image('engfireball.png',-1)
                    self.fireball4.rect = (350,550,32,32)
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball4))
                    self.fireballCount += 1
                if self.fireballCount == 2:
                    self.fireball3 = pygame.sprite.Sprite()
                    pygame.sprite.Sprite.__init__(self.fireball3)
                    self.fireball3.image,null = gfx.load_image('engfireball.png',-1)
                    self.fireball3.rect = (300,550,32,32)
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball3))
                    self.fireballCount += 1
                if self.fireballCount == 1:
                    self.fireball2 = pygame.sprite.Sprite()
                    pygame.sprite.Sprite.__init__(self.fireball2)
                    self.fireball2.image,null = gfx.load_image('engfireball.png',-1)
                    self.fireball2.rect = (250,550,32,32)
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball2))
                    self.fireballCount += 1
                if self.fireballCount == 0:
                    self.fireball1 = pygame.sprite.Sprite()
                    pygame.sprite.Sprite.__init__(self.fireball5)
                    self.fireball1.image,null = gfx.load_image('engfireball.png',-1)
                    self.fireball1.rect = (200,550,32,32)
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball1))
                    self.fireballCount += 1
                self.addFireball = False
                    
                
            #Make player attack(), make a swish animation, make a swish collision box
            if self.pressed_leftmouse and not self.guy.attacking and self.guy.canAttack == True:
                self.guy.attack()
                self.swish = player.Swish(self.guy.rect.topleft[0]-32,self.guy.rect.topleft[1]-32)
                self.all_sprites.add(pygame.sprite.RenderPlain(self.swish))
                self.guy.canAttack = False
            #If a swish exists, make sure its direction matches the players direction
            
            if self.guy.attacking:
                self.swish.dir = self.guy.dir
                self.swish.rect.topleft = (self.guy.rect.topleft[0] -32,self.guy.rect.topleft[1] -32)

                ### SWISH HITBOX ###
                # enable this to see the swish hitbox
##              sbb = self.swish.createSwishBox()
##              self.obstacle = pygame.Surface((sbb.height,sbb.width))
##              self.obstacle = self.obstacle.convert()
##              self.obstacle.fill((0, 255, 0))
##              self.background.blit(self.obstacle, (sbb.x,sbb.y))


            #Update movement of all sprites in the game
            self.all_sprites.update()
            
            #Check for physics collisions with player
            if self.guy.moving and self.Physics.bodyCanMoveToLocation(self.guy, self.guy.dx, self.guy.dy):
                self.guy.didMove(self.guy.dx,self.guy.dy)
                self.guy.dx,self.guy.dy = 0,0
            elif self.guy.moving and self.Physics.bodyCanMoveToLocation(self.guy, 0, self.guy.dy):
                self.guy.didMove(0,self.guy.dy)
                self.guy.dx,self.guy.dy = 0,0
            elif self.guy.moving and self.Physics.bodyCanMoveToLocation(self.guy,self.guy.dx,0):
                self.guy.didMove(self.guy.dx,0)
                self.guy.dx,self.guy.dy = 0,0

            #AI movement
            for enemy in self.mobs:

                #If the player's attack hits the enemy, take damage
                if(self.guy.attacking and enemy.rect.colliderect(self.swish.createSwishBox())):
                    if(enemy.takedamage(5)):
                        self.killCount += 1
                    
                #enemy.move sets the enemy's dx,dy, and direction
                enemy.move(self.guy)

                #Deal with collisions in the game
                if enemy.moving and self.Physics.bodyCanMoveToLocation(enemy, enemy.dx, enemy.dy):
                    #Mob is moving freely
                    enemy.didMove(enemy.dx,enemy.dy)
                    enemy.forced = 0
                    
                elif enemy.moving and self.Physics.bodyCanMoveToLocation(enemy, 0, enemy.dy):
                    if enemy.forced:
                        enemy.didMove(0,enemy.forced)
                    elif not enemy.forced: #If walking into a wall and also not moving
                        num = random.randrange(-2,3,4)
                        enemy.forced =  num #Pick a direction and move
                        
                elif enemy.moving and self.Physics.bodyCanMoveToLocation(enemy,enemy.dx,0):
                    if enemy.forced:
                        enemy.didMove(enemy.forced,0)
                    elif not enemy.forced: #If walking into a wall and also not moving
                        num = random.randrange(-2,3,4)
                        enemy.forced =  num #Pick a direction and move
                        
                elif enemy.moving and self.Physics.bodyCanMoveToLocation(enemy, 0, 2):
                    enemy.didMove(0,2)
                elif enemy.moving and self.Physics.bodyCanMoveToLocation(enemy, -2, 0):
                    enemy.didMove(2,0)
                else:
                    enemy.didMove(0,2)
            #Boss stuff
            if(self.currentLevel.level==1 and not self.spawnMobs):
                if(self.boss.attack_1): #Throwing ball
                    colors = ['red','orange','yellow','green','blue','purple','black','white']
                    playerPos = [self.guy.rect.x, self.guy.rect.y]
                    selfPos = [self.boss.rect.x+125, self.boss.rect.y+125]
                    paintball = projectile.Projectile(playerPos,selfPos,'paint',colors[random.randrange(0,8,1)])
                    self.all_sprites.add(paintball)
                    self.projectiles.add(paintball)
                    self.boss.attack_1= False
                elif(self.boss.attack_2): #Boomerang
                    playerPos = [self.guy.rect.x, self.guy.rect.y]
                    selfPos = [self.boss.rect.x+125, self.boss.rect.y+125]
                    boomer = projectile.Projectile(playerPos,selfPos,'boomer',0)
                    self.all_sprites.add(boomer)
                    self.projectiles.add(boomer)
                    self.boss.attack_2= False
                elif(self.boss.attack_3): #Shoot tiny
                    key = ['red','orange','yellow','green','blue','purple','black','white']
                    loc_key = {'red':[56,128],'orange':[30,132],'yellow':[17,142],'green':[8,155],'blue':[5,170],'purple':[1,189],'black':[12,200],'white':[28,205]}
                    fire = []
                    for i in range(8):
                        if(self.boss.curr_tiny[i]):
                            fire.append(key[i])
                    playerPos = [self.guy.rect.x, self.guy.rect.y]
                    for color in fire:
                        selfPos = [self.boss.rect.x+loc_key[color][0], self.boss.rect.y+loc_key[color][1]]
                        tiny = projectile.Projectile(playerPos,selfPos,'tiny',color)
                        self.all_sprites.add(tiny)
                        self.projectiles.add(tiny)
                        self.boss.attack_3= False
                elif(self.boss.attack_4): #Drop paint
                    colors = ['red','orange','yellow','green','blue','purple','black','white']
                    randcolor = colors[random.randrange(0,8,1)]
                    randtype = random.randrange(0,2,1)
                    randx = random.randrange(10,790,1)
                    randy = random.randrange(10,590,1)
                    paintdrop = projectile.Projectile([randx,randy],[randx,0],'drop_paint',[randtype,randcolor])
                    self.all_sprites.add(paintdrop)
                    self.projectiles.add(paintdrop)
                    self.boss.attack_4 = False

                    #shadow
                    shadow = projectile.Projectile([randx,randy],[randx,randy],'shadow',[randtype,(randy+32)/1.5])
                    self.all_sprites.add(shadow)
                        
                if(self.guy.attacking and self.boss.rect.colliderect(self.swish.createSwishBox())):
                    self.boss.takeDamage(50)
                    self.bossHealthChanged = True
                    
            elif(self.currentLevel.level==2 and not self.spawnMobs):
                if(self.boss.attack_1):
                    #Throwing football
                    playerPos = [self.guy.rect.x,self.guy.rect.y]
                    selfPos = [self.boss.rect.x+50,self.boss.rect.y+50]
                    football = projectile.Projectile(playerPos,selfPos,'boss_football',0)
                    self.all_sprites.add(football)
                    self.projectiles.add(football)
                    self.boss.attack_1 = False
                elif(self.boss.attack_2):
                    #Summoning players
                    for i in range(random.randrange(10)):
                        spawnloc = self.currentLevel.spawnPoints[random.randrange(len(self.currentLevel.spawnPoints))]
                        self.newmob = ai.Mob(spawnloc[0],spawnloc[1], self.currentLevel.mobType)
                        self.mobs.add(pygame.sprite.RenderPlain(self.newmob))
                        self.all_sprites.add(pygame.sprite.RenderPlain(self.newmob))
                    self.boss.attack_2 = False
                elif(self.boss.attack_3):
                    yelltype = random.randrange(2)
                    #Yelling
                    bossPos = [self.boss.rect.x-128,self.boss.rect.y-64]
                    yell = projectile.Projectile(bossPos,bossPos,'yell',yelltype)
                    self.all_sprites.add(yell)
                    self.projectiles.add(yell)
                    self.boss.attack_3 = False
                    self.boss.attack_4 = yelltype
                    self.boss.attack_5 = True

                if self.boss.attack_5: #attack_4 :: 0 = stop moving, 1 = keep moving
                    if (not(self.boss.attack_4) and (self.guy.moving or self.guy.attacking)) or (self.boss.attack_4 and not(self.guy.moving)):
                        self.guy.tookDamage(1)
                        self.healthChanged = True
                    else:
                        pass
                
                if(self.guy.attacking and self.boss.rect.colliderect(self.swish.createSwishBox())):
                    self.boss.takeDamage(50)
                    self.bossHealthChanged = True
                    
            elif(self.currentLevel.level==3 and not self.spawnMobs):
                if(self.boss.attack_1):
                    #Remove all seeds
                    for seed in self.flameseeds:
                        seed.kill()
                    attack_type = self.boss.attack_3
                    ## LEGEND
                    # 0 : flames go right in 3 lines
                    # 1 : flames go left in 3 lines
                    # 2 : flames go from the bottom right and bottom left to opposite corners
                    # 3 : flames go from the top right and top left to opposite corners
                    # 4 : flames go in a huge line down the center left to right
                    # 5 : flames go in a huge line down the center right to left
                    # 6 : flames go up in 3 lines
                    # 7 : flames go down in 3 lines
                    # 8 : flames go in two huge lines right
                    # 9 : flames go in two huge lines left
                    if 0==attack_type: #l>r
                        numflames = 6
                        flamePos = [[0,100],[0,132],[0,300],[0,332],[0,450],[0,482]]
                        flameDir = [[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]
                    elif 1==attack_type: #r>l
                        numflames = 6
                        flamePos = [[800,100],[800,132],[800,300],[800,332],[800,450],[800,482]]
                        flameDir = [[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]]
                    elif 2==attack_type: #diag
                        numflames = 4
                        flamePos = [[0,580],[20,600],[800,580],[780,600]]
                        flameDir = [[1,-1],[1,-1],[-1,-1],[-1,-1]]
                    elif 3==attack_type: #diag
                        numflames = 4
                        flamePos = [[0,20],[20,0],[800,20],[780,0]]
                        flameDir = [[1,1],[1,1],[-1,1],[-1,1]]
                    elif 4==attack_type:
                        numflames = 6
                        flamePos = [[0,200],[0,240],[0,280],[0,320],[0,360],[0,400]]
                        flameDir = [[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]
                    elif 5==attack_type:
                        numflames = 6
                        flamePos = [[800,200],[800,240],[800,280],[800,320],[800,360],[800,400]]
                        flameDir = [[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]]
                    elif 6==attack_type:
                        numflames = 6
                        flamePos = [[100,0],[132,0],[400,0],[432,0],[650,0],[682,0]]
                        flameDir = [[0,1],[0,1],[0,1],[0,1],[0,1],[0,1]]
                    elif 7==attack_type:
                        numflames = 6
                        flamePos = [[100,600],[132,600],[400,600],[432,600],[650,600],[682,600]]
                        flameDir = [[0,-1],[0,-1],[0,-1],[0,-1],[0,-1],[0,-1]]
                    elif 8==attack_type:
                        numflames = 6
                        flamePos = [[0,100],[0,132],[0,164],[0,500],[0,468],[0,436]]
                        flameDir = [[1,0],[1,0],[1,0],[1,0],[1,0],[1,0]]
                    elif 9==attack_type:
                        numflames = 6
                        flamePos = [[800,100],[800,132],[800,164],[800,500],[800,468],[800,436]]
                        flameDir = [[-1,0],[-1,0],[-1,0],[-1,0],[-1,0],[-1,0]]
                        
                    for i in range(numflames):
                        flame = projectile.Projectile(flamePos[i],flamePos[i],'fire',flameDir[i])
                        self.all_sprites.add(flame)
                        self.fire.add(flame)
                    self.boss.attack_1 = False
                elif self.boss.attacking and not self.boss.attack_4:
                    self.boss.attack_3 = random.randrange(0,10)
                    attack_type = self.boss.attack_3
                    
                    if 0==attack_type:
                        numseeds = 3
                        flamePos = [[0,100],[0,300],[0,450]]
                    elif 1==attack_type:
                        numseeds = 3
                        flamePos = [[800,100],[720,300],[720,450]]
                    elif 2==attack_type:
                        numseeds = 2
                        flamePos = [[0,520],[720,520]]
                    elif 3==attack_type:
                        numseeds = 2
                        flamePos = [[0,20],[720,20]]
                    elif 4==attack_type:
                        numseeds = 4
                        flamePos = [[0,200],[0,250],[0,300],[0,350]]
                    elif 5==attack_type:
                        numseeds = 4
                        flamePos = [[720,200],[720,250],[720,300],[720,350]]
                    elif 6==attack_type:
                        numseeds = 3
                        flamePos = [[100,0],[400,0],[650,0]]
                    elif 7==attack_type:
                        numseeds = 3
                        flamePos = [[100,520],[400,520],[650,520]]
                    elif 8==attack_type:
                        numseeds = 2
                        flamePos = [[0,100],[0,500]]
                    elif 9==attack_type:
                        numseeds = 2
                        flamePos = [[720,100],[720,500]]
                        
                    for i in range(numseeds):
                        flameseed = projectile.Projectile(flamePos[i],flamePos[i],'fireseed',0)
                        self.all_sprites.add(flameseed)
                        self.flameseeds.add(flameseed)
                    self.boss.attack_4 = True
                if(self.guy.attacking and self.boss.rect.colliderect(self.swish.createSwishBox())):
                    self.boss.takeDamage(50)
                    self.bossHealthChanged = True


            
            if self.bossHealthChanged:
                healthStr = str(self.boss.hp/35)
                self.bossHealthBar.image, null = gfx.load_image('health/'+healthStr+'.png',-1)
                self.bossHealthChanged = False
                if self.boss.hp <= 0:
                    self.boss.kill()
                    self.menuScreen = menu.deathScreen(False,self.currentLevel.level)
                    self.running = False
                    if self.menuScreen.screen_loop(MainObject.screen):
                        restartGame(self.currentLevel.level+1)
                        return
                    else:
                        pygame.quit()                                        #This recreates the entire main object and loads the next level.
            #Boss 3 Flames
            for flame in self.fire:
                #Fire "extra" value
                ## extra[0] : change in x value each time
                ## extra[1] : change in y value each time
                newpos = [flame.rect.x+(flame.extra[0]*16),flame.rect.y+(flame.extra[1]*16)]
                if(newpos[0]<800 and newpos[0]>0 and newpos[1]<600 and newpos[1]>0):
                    newflame = projectile.Projectile(newpos,newpos,'fire',flame.extra)
                    self.fire.remove(flame)
                    self.projectiles.add(flame)
                    self.all_sprites.add(newflame)
                    self.fire.add(newflame)

            
            #Testing player projectile collisions
            for fireball in self.fireballs:
                for mob in self.mobs:
                    if fireball.rect.colliderect(mob.rect):
                        if(mob.takedamage(5)):
                            self.killCount+=1
                if((not self.spawnMobs) and self.boss.rect.colliderect(fireball.rect)):
                        self.boss.takeDamage(50)
                        fireball.kill()
                        self.bossHealthChanged = True

            #Testing enemy projectile collisions
            if not self.spawnMobs:
                self.boss.attack_5 = False
            for proj in self.projectiles:
                if(proj.proj_type=='yell'):
                    self.boss.attack_5 = True
                self.projRect = pygame.Rect(proj.rect.left, proj.rect.top, proj.rect.width,proj.rect.height)
                if(proj.proj_type=='boomer'):
                    self.projRect = pygame.Rect(proj.rect.left+50,proj.rect.top+40,175,175)
                self.playerRect = pygame.Rect(self.guy.rect.left, self.guy.rect.top, 64, 64)
                
##                self.obstacle = pygame.Surface((self.projRect.width,self.projRect.height))
##                self.obstacle = self.obstacle.convert()
##                self.obstacle.fill((0, 255, 0))
##                self.foreground.blit(self.obstacle, (self.projRect.x,self.projRect.y))
                
                if self.projRect.colliderect(self.playerRect):
                    if proj.proj_type == 'art':
                        proj.die()
                        self.guy.tookDamage(10)
                        self.healthChanged = True
                    elif proj.proj_type == 'paint':
                        self.guy.tookDamage(1)
                        self.healthChanged = True
                        pass
                    elif proj.proj_type == 'boomer':
                        self.guy.tookDamage(2)
                        self.healthChanged = True
                    elif proj.proj_type == 'tiny':
                        self.guy.tookDamage(3)
                        self.healthChanged = True
                        proj.die()
                    elif proj.proj_type == 'drop_paint' and proj.dy==0 and self.playerRect.colliderect(pygame.Rect(self.projRect.x,self.projRect.y+40,self.projRect.width,10)):
                        self.guy.tookDamage(1)
                        self.healthChanged = True
                    elif proj.proj_type == 'commerce':
                        self.guy.tookDamage(10)
                        self.healthChanged = True
                        proj.die()
                    elif proj.proj_type == 'fire':
                        self.guy.tookDamage(2)
                        self.healthChanged = True
                    elif proj.proj_type == 'football':
                        self.guy.tookDamage(10)
                        self.healthChanged = True
                        proj.die()
                    elif proj.proj_type == 'boss_football':
                        self.guy.tookDamage(5)
                        self.healthChanged = True
                if proj.proj_type == "boomer" and proj.extra == "back" and proj.rect.colliderect(pygame.Rect(self.boss.rect.x+200,self.boss.rect.y+130,50,50)):
                    proj.die()
                for solid in self.Physics.collisionRects:
                    
##                    self.obstacle = pygame.Surface((solid.width,solid.height))
##                    self.obstacle = self.obstacle.convert()
##                    self.obstacle.fill((0, 255, 0))
##                    self.foreground.blit(self.obstacle, (solid.x,solid.y))
                    
                    if proj.proj_type is not 'paint' and proj.proj_type is not 'boomer' and proj.proj_type is not 'drop_paint' and self.projRect.colliderect(solid) :
                        proj.die()

                        
            #Testing healthpack collisions
            for pack in self.health:
                
                if pack.rect.colliderect(self.guy.rect):
                    pack.kill()
                    self.guy.tookDamage(-50)
                    self.healthChanged = True
                    self.spawnHealth = True
                
            #Tick level
            self.currentLevel.tick()

            #Health bar logic

            if self.healthChanged:
                if self.guy.health > 100:
                    self.guy.health = 100
                elif self.guy.health < 0:
                    self.guy.health = 0
                healthStr = str(self.guy.health/10)
                self.healthBar.image, null = gfx.load_image('health/'+healthStr+'.png',-1)
                self.healthChanged = False

            #Death conditions
                
                if healthStr == '0':
                    self.deathScreen = menu.deathScreen(True,self.currentLevel.level)
                    self.running = False
                    if self.deathScreen.screen_loop(MainObject.screen):
                        restartGame(self.currentLevel.level)
                        return
                    else:
                        pygame.quit()
                        

            self.fireballTimer += 1
            
            #If something needs to be done every second, put it here
            if (self.framecount == 30 or self.framecount == 60):
                self.guy.canAttack = True
                print self.fireballCount

            if self.fireballTimer == 300 and not self.fireballCount == 5:
                self.addFireball = True
                self.fireballTimer = 0

            
                
                
            
            if(self.framecount==60):
                self.secondsPassed += 1
                if self.secondsPassed%self.healthSpawnRate==0 and self.spawnHealth:
                    X = random.randint(50,750)
                    Y = random.randint(50,550)
                    pack = player.Healthpack(X,Y)
                    self.all_sprites.add(pygame.sprite.RenderPlain(pack))
                    self.health.add(pygame.sprite.RenderPlain(pack))
                    self.spawnHealth = False
                    

                

                
                if(self.killCount>=2 and self.spawnMobs):
                    self.spawnMobs=False
                    self.boss = level.Boss(1000,-250,self.currentLevel.level)
                    self.boss.add(pygame.sprite.RenderPlain(self.boss))
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.boss))
                    self.boss.walkTo(700,250)
                    self.bossHealthBar = pygame.sprite.Sprite()
                    pygame.sprite.Sprite.__init__(self.healthBar)
                    self.bossHealthBar.image, null = gfx.load_image('health/10.png',-1)
                    self.bossHealthBar.rect = (550,550,100,20)
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.bossHealthBar))
                    self.bossHealthChanged = False
                self.framecount=0
                self.total_frames += 1
                self.currentLevel.leveltimer +=1
                self.mobs.update()
                try:
                    self.boss.livingfor+=1
                except AttributeError as e:
                    pass
            #Enemy projectile spawning/attacking
                for enemy in self.mobs:
                        playerPos = [self.guy.rect.x, self.guy.rect.y]
                        selfPos = [enemy.rect.x, enemy.rect.y]
                        proj = projectile.Projectile(playerPos, selfPos, self.currentLevel.mobType,enemy.direction)
                        enemy.currentAnimationType = 1
                        enemy.currentAnimationFrame = 0
                        self.projectiles.add(proj)
                        self.all_sprites.add(proj)

                    

                if self.spawnMobs and (self.currentLevel.leveltimer==self.currentLevel.spawnRate):
                    #Spawn a Mob
                    self.currentLevel.leveltimer=0
                    spawnloc = self.currentLevel.spawnPoints[random.randrange(len(self.currentLevel.spawnPoints))]
                    self.newmob = ai.Mob(spawnloc[0],spawnloc[1], self.currentLevel.mobType)
                    self.mobs.add(pygame.sprite.RenderPlain(self.newmob))
                    self.all_sprites.add(pygame.sprite.RenderPlain(self.newmob))
Ejemplo n.º 29
0
    def __init__(self,levelNumber):
        pygame.init() #Initialize PyGame

        #Initialize Displays
        self.screen = pygame.display.set_mode((GAME_SETTINGS.WINDOW_WIDTH,GAME_SETTINGS.WINDOW_HEIGHT)) #Initialize Screen
        
        self.background = pygame.Surface(self.screen.get_size()) #Set Background
        self.background = self.background.convert()
        self.background.fill((0,0,0))
        
        self.foreground = pygame.Surface(self.screen.get_size())
        self.foreground = self.foreground.convert()

        #Load title screen
        self.titlescreen = menu.TitleScreen((GAME_SETTINGS.WINDOW_WIDTH,GAME_SETTINGS.WINDOW_HEIGHT))

        #Initialize Physics.py
        self.Physics = physics.Physics(self.background)

        #Sprites
        self.guy = player.Player(300,300) #Create Player object
        self.all_sprites = pygame.sprite.RenderPlain(self.guy) #Every Sprite goes here
        self.projectiles = pygame.sprite.Group() #Projectiles
        self.solids = pygame.sprite.Group() #Solids
        self.mobs = pygame.sprite.Group() #Mobs
        self.health = pygame.sprite.Group() #Health packs
        self.fireballs = pygame.sprite.Group() # Player projectiles
        self.fire = pygame.sprite.Group() #Fire, used for boss #3
        self.flameseeds = pygame.sprite.Group() #Fire starter, used for boss #3

        #Font
        #self.kill_text = pygame.font.Font.render("0",1,(255,255,255))
        
        #inputs
        self.pressed_down = False
        self.pressed_up = False
        self.pressed_left = False
        self.pressed_right = False
        self.pressed_leftmouse = False
        self.pressed_rightmouse = False

        self.fireballCount = 5
        self.fireballsChanged = False
        self.addFireball = False
        self.fireballTimer = 0


        #Level set up
        self.currentLevel = level.Level(levelNumber,self.background)
        for obstacle in self.currentLevel.obstacles:
            obstacle.height-=48
            self.Physics.addBody(obstacle)
        self.background.blit(self.currentLevel.bg,(0,0))
        if self.currentLevel.fg:                        #Only blit the foreground if there actually is one
            self.foreground.blit(self.currentLevel.fg,(0, 0))

        #Health set up

        self.bossHealthChanged = False
        self.killCount = 0
        self.spawnMobs = True
        self.healthBar = pygame.sprite.Sprite()
        pygame.sprite.Sprite.__init__(self.healthBar)
        self.healthBar.image, null = gfx.load_image('health/10.png',-1)
        self.healthBar.rect = (50,550,100,20)
        self.all_sprites.add(pygame.sprite.RenderPlain(self.healthBar))
        self.healthChanged = False

        if self.currentLevel.level > 2:
            self.fireball1 = pygame.sprite.Sprite()
            self.fireball2 = pygame.sprite.Sprite()
            self.fireball3 = pygame.sprite.Sprite()
            self.fireball4 = pygame.sprite.Sprite()
            self.fireball5 = pygame.sprite.Sprite()
            pygame.sprite.Sprite.__init__(self.fireball1)
            pygame.sprite.Sprite.__init__(self.fireball2)
            pygame.sprite.Sprite.__init__(self.fireball3)
            pygame.sprite.Sprite.__init__(self.fireball4)
            pygame.sprite.Sprite.__init__(self.fireball5)

            self.fireball1.image,null = gfx.load_image('engfireball.png',-1)
            self.fireball2.image,null = gfx.load_image('engfireball.png',-1)
            self.fireball3.image,null = gfx.load_image('engfireball.png',-1)
            self.fireball4.image,null = gfx.load_image('engfireball.png',-1)
            self.fireball5.image,null = gfx.load_image('engfireball.png',-1)
            self.fireball1.rect = (200,550,32,32)
            self.fireball2.rect = (250,550,32,32)
            self.fireball3.rect = (300,550,32,32)
            self.fireball4.rect = (350,550,32,32)
            self.fireball5.rect = (400,550,32,32)
            self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball1))
            self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball2))
            self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball3))
            self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball4))
            self.all_sprites.add(pygame.sprite.RenderPlain(self.fireball5))


        #Health pack set up
        
        self.healthSpawnRate = 3   #Every x seconds, a pack is spawned (only if the previous pack has been picked up)
        self.spawnHealth = True
        self.secondsPassed = 0

        #gfx testing
        self.preloaded_gfx = gfx.preloadedgfx()
        gfx.preloaded_gfx = self.preloaded_gfx
        #Sounds

        self.Sounds = pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
        self.musicChannel = pygame.mixer.Channel(0)
        self.soundsChannel1 = pygame.mixer.Channel(1)
        self.soundsChannel2 = pygame.mixer.Channel(2)
        self.musicSound = pygame.mixer.music.load('sounds/Kalimba.mp3')
        pygame.mixer.music.play()
Ejemplo n.º 30
0
 def draw_pics(self):
     self.diff_image,self.diff_rect = gfx.load_image("pics/diff/"+self.image)
     self.reg_image,self.reg_rect = gfx.load_image("pics/"+self.image)
     gfx.screen.blit(self.reg_image,(20,200))
     gfx.screen.blit(self.diff_image,(403,200))