Example #1
0
    def __init__(self, game):

        self.bg_list = [
            constants.load_image("main_bg1.jpg").convert(),
            constants.load_image("main_bg2.jpg").convert(),
            constants.load_image("main_bg3.jpg").convert()
        ]
        self.bg_no = 0
        self.bg = self.bg_list[0]
        self.speaker = models.Speaker(screen, 700, 20,
                                      constants.MUSIC_LIST[constants.MAIN])
        self.gamejolt = models.Gj(screen, 55, 30)
        new_key = models.MenuItem("newgame_text.png", True, (295, 209),
                                  (275, 185))
        con_key = models.MenuItem("continue_text.png", False, (300, 305),
                                  (275, 280), True)
        high_score = models.MenuItem("high_score_text.png", False, (295, 398),
                                     (275, 375))
        ex_key = models.MenuItem("exit_text.png", False, (350, 490),
                                 (275, 470))
        self.menu = models.Menu(screen, [new_key, con_key, high_score, ex_key])
        self.cursor = Display.cursor
        self.game = game
        self.title = constants.load_image("tetris.png")
        pygame.time.set_timer(25, 500)
Example #2
0
 def __init__(self):
     self.bg_list = [constants.load_image("main_bg1.jpg").convert(), constants.load_image("main_bg2.jpg").convert(), constants.load_image("main_bg3.jpg").convert()]
     self.bg_no = 0
     self.bg = self.bg_list[0]
     back_key = models.MenuItem("back_text.png", False, (335,500), (275,480) )
     self.menu = models.Menu(screen, [ back_key ])
     self.cursor = Display.cursor
     self.score_block_img = constants.load_image("score_block.png")
     pygame.time.set_timer(25, 500)  
Example #3
0
 def __init__(self):
     self.bg_list = [
         constants.load_image("main_bg1.jpg").convert(),
         constants.load_image("main_bg2.jpg").convert(),
         constants.load_image("main_bg3.jpg").convert()
     ]
     self.bg_no = 0
     self.bg = self.bg_list[0]
     back_key = models.MenuItem("back_text.png", False, (335, 500),
                                (275, 480))
     self.menu = models.Menu(screen, [back_key])
     self.cursor = Display.cursor
     self.score_block_img = constants.load_image("score_block.png")
     pygame.time.set_timer(25, 500)
Example #4
0
 def __init__(self, **options):
     """ Options: x, y, font, color, restricted, maxlength, prompt """
     self.options = Config(options, ['x', '0'], ['y', '0'], ['font', 'pygame.font.Font(None, 32)'],
                           ['color', '(0,0,0)'], ['restricted', '\'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#$%&\\\'()*+,-./:;<=>?@[\]^_`{|}~\''],
                           ['maxlength', '-1'], ['prompt1', '\'\''], ['prompt2', '\'\''])
     self.x = self.options.x; self.y = self.options.y
     self.font = self.options.font
     self.color = self.options.color
     self.restricted = self.options.restricted
     self.maxlength = self.options.maxlength
     self.prompt1 = self.options.prompt1
     self.prompt2 = self.options.prompt2
     self.values = ['','']
     self.no = 0
     self.shifted = False
     self.box = [constants.load_image("text_box.png"), constants.load_image("text_box2.png")]
Example #5
0
 def __init__(self, game): 
         
     self.bg_list = [constants.load_image("main_bg1.jpg").convert(), constants.load_image("main_bg2.jpg").convert(), constants.load_image("main_bg3.jpg").convert()]
     self.bg_no = 0
     self.bg = self.bg_list[0]
     self.speaker = models.Speaker(screen, 700, 20, constants.MUSIC_LIST[constants.MAIN])
     self.gamejolt = models.Gj(screen, 55, 30)
     new_key = models.MenuItem("newgame_text.png", True, (295,209), (275, 185) )
     con_key = models.MenuItem("continue_text.png", False, (300,305), (275, 280), True )
     high_score = models.MenuItem("high_score_text.png", False, (295,398), (275, 375) )
     ex_key = models.MenuItem("exit_text.png", False, (350,490), (275,470) )
     self.menu = models.Menu(screen, [ new_key, con_key, high_score, ex_key ])
     self.cursor = Display.cursor
     self.game = game
     self.title = constants.load_image("tetris.png")
     pygame.time.set_timer(25, 500)
Example #6
0
	def __init__(self, model):
		self.character_bg = load_image(MISC, 'character')
		self.name = 'choose'

		self.model = model
		self.bg =  pygame.image.load(os.path.join(BGS, 'choose.png'))
		imgs = load_animation('marker', 4)		
		self.marker = Animation(imgs, 400)
		
		gold_opts = [1] * 4
		
		val = 1
		while val < model.game_state['gold']:
			gold_opts.append(int(val))
			val *= 1.8
		gold_opts = gold_opts[-3:]
		gold_opts.append(model.game_state['gold'])
		self.gold_opts = gold_opts
		self.step = 0
		self.choices =  [
				{ 'name' : 'small', 'method' : self.gold},
				{ 'name' : 'medium', 'method' : self.gold},
				{ 'name' : 'large', 'method' : self.gold},
				{ 'name' : 'all_in', 'method' : self.gold},
				]

		self.choice = 0
		self.current_bet = 0
		self.current_hero = 0
		model.boss = Enemy(enemy_type = 'boss', level = model.game_state['level'])
		model.boss.loot = []
		model.boss.hp = model.game_state['hp']
		model.boss.defense = model.game_state['defense']
Example #7
0
 def __init__(self, file, btn_high,text_pos, btn_pos, disabled = False):
     self.text = constants.load_image(file)
     self.text_position = text_pos
     self.btn_position = btn_pos
     self.disabled = disabled
     if btn_high :
         self.btn = MenuItem.highlighted_btn
     else:
         self.btn = MenuItem.btn
Example #8
0
	def __init__(self, model):
		self.character_bg = load_image(MISC, 'character')
		self.name = 'dungeon'
		self.bg = pygame.image.load(os.path.join(BGS,'dungeon.png'))
		self.treasure = load_image(MISC, 'treasure')
		self.path_img = load_image(MISC, 'path')
		self.field = [
			 '##################',
			 '#................#',
			 '#................#',
			 '#................#',
			 '#......##........#',
			 '#......##........#',
			 '#................#',
			 '#................#',
			 '#................#',
			 '##################']

		self.enemies = {}
		self.spawn = (16,8)
		self.divel_pos = (1,1)

		self.inactive_minions = []
		for i in range(1, 10):
			self.inactive_minions.append(Enemy(level=randrange(1, 5)))

		self.heroes = []
		self.start_time = pygame.time.get_ticks()
		self.model = model
		self.choice = 0
		self.old_msg = []
		self.pos = (1,1)	
		self.treasure_pos = (1,1)
		self.divel = load_image(MISC, 'enemy_boss')
		self.console_messages = []
		self.show_minions = False
		self.add_hero()
		self.chosen_inactive = 0
		self.chosen_item = 0
		self.items = model.game_state['inventory']
		self.bet = 10
Example #9
0
	def __init__(self, model):
		self.character_bg = load_image(MISC, 'character')
		self.name = 'post'

		self.model = model

		#self.gained_gold = model.game_state['gained_gold']
		#model.game_state['gold']  = model.game_state['gold']  + self.gained_gold
		s = model.game_state

			

		self.bg =  pygame.image.load(os.path.join(BGS, 'choose.png'))
Example #10
0
 def __init__(self):
           
     self.speaker = models.Speaker(screen, 615, 290, constants.MUSIC_LIST[constants.NEW])
     self.bg = constants.load_image("game_bg.jpg").convert()
     self.block1 = constants.load_image("block1.png")
     self.block2 = constants.load_image("block2.png")
     self.block3 = constants.load_image("block3.png")
     self.next_text = constants.load_image("next_text.png")
     self.cursor = Display.cursor
     self.score_text = constants.load_image("score.png")
     self.block_controler = models.BlockControler()
     self.block_controler.initiate()
     self.puase_img = constants.load_image("puase.png")
     self.lost_img = constants.load_image("lost.png")
     self.status = None
Example #11
0
 def __init__(self, **options):
     """ Options: x, y, font, color, restricted, maxlength, prompt """
     self.options = Config(options, ['x', '0'], ['y', '0'], [
         'font', 'pygame.font.Font(None, 32)'
     ], ['color', '(0,0,0)'], [
         'restricted',
         '\'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"#$%&\\\'()*+,-./:;<=>?@[\]^_`{|}~\''
     ], ['maxlength', '-1'], ['prompt1', '\'\''], ['prompt2', '\'\''])
     self.x = self.options.x
     self.y = self.options.y
     self.font = self.options.font
     self.color = self.options.color
     self.restricted = self.options.restricted
     self.maxlength = self.options.maxlength
     self.prompt1 = self.options.prompt1
     self.prompt2 = self.options.prompt2
     self.values = ['', '']
     self.no = 0
     self.shifted = False
     self.box = [
         constants.load_image("text_box.png"),
         constants.load_image("text_box2.png")
     ]
Example #12
0
    def __init__(self):

        self.speaker = models.Speaker(screen, 615, 290,
                                      constants.MUSIC_LIST[constants.NEW])
        self.bg = constants.load_image("game_bg.jpg").convert()
        self.block1 = constants.load_image("block1.png")
        self.block2 = constants.load_image("block2.png")
        self.block3 = constants.load_image("block3.png")
        self.next_text = constants.load_image("next_text.png")
        self.cursor = Display.cursor
        self.score_text = constants.load_image("score.png")
        self.block_controler = models.BlockControler()
        self.block_controler.initiate()
        self.puase_img = constants.load_image("puase.png")
        self.lost_img = constants.load_image("lost.png")
        self.status = None
Example #13
0
	def __init__(self, hero_type, level):
		self.generator = NameGen('name_gen_file.txt')
		self.name = self.generate_name(hero_type) + " (Lvl " + str(level) + ")"
		self.level = level
		if hero_type == 'fighter':
			self.small_img = load_image(CHARACTERS, 'small_fighter')
			self.hp = level * 3 + randrange(0, level)
			self.max_hp = self.hp
			self.defense = level*1.5
		self.loot = []
		self.gold = random.randrange(1, level*2)
		self.hero_type = hero_type
		self.pos = (16, 8)
		self.path = deque()
Example #14
0
class MenuItem():
    
    dis = prepare_alpha(constants.load_image("button_disable.png"),  200)
    highlighted_btn = prepare_alpha(constants.load_image("highlighted_button.png"),  200)
    btn  = prepare_alpha(constants.load_image("button.png"),  200)
    
    def __init__(self, file, btn_high,text_pos, btn_pos, disabled = False):
        self.text = constants.load_image(file)
        self.text_position = text_pos
        self.btn_position = btn_pos
        self.disabled = disabled
        if btn_high :
            self.btn = MenuItem.highlighted_btn
        else:
            self.btn = MenuItem.btn
            
    def draw(self, screen):
        screen.blit(self.btn, self.btn_position)
        screen.blit(self.text, self.text_position)
        if self.disabled :
            screen.blit(MenuItem.dis, self.btn_position)
        
    def unhighlight(self):
        self.btn = MenuItem.btn
    def highlight(self):
        self.btn = MenuItem.highlighted_btn
    def disable(self):
        self.disabled = True
    def enable(self):
        self.disabled = False
    def hover(self, x, y):
        if self.disabled :
            return False
        size = self.btn.get_rect().size
        pos = self.btn_position
        return (x >= pos[0] and x <= pos[0] + size[0] and 
                  y >= pos[1] and y <= pos[1] + size[1])
Example #15
0
class Display():
    cursor = constants.load_image("cursor1.png")

    def __init__(self):
        pass

    def left_mousebtn(self):
        pass

    def key_down(self):
        pass

    def key_up(self):
        pass

    def key_right(self):
        pass

    def key_left(self):
        pass

    def key_enter(self):
        pass

    def key_down_upd(self):
        pass

    def draw(self):
        pass

    def logic(self):
        pass

    def key_esc(self):
        pass

    def timer_event(self):
        pass

    def p_key(self):
        pass

    def speaker_event(self):
        pass

    def update_music(self):
        pass
Example #16
0
	def __init__(self, level, enemy_type = None):
		self.name = enemy_type
		self.level = level
		self.loot = []

		cands = []
		for e in enemy_data:
			if e['minlvl'] <= level and e['maxlvl'] >= level:
				cands.append(e)
		random.shuffle(cands)
		enemy = cands[0]
		self.img = load_image(MISC, 'enemy_' + enemy['name'])

		self.hp = level * pow(2, enemy['hp'])
		self.maxhp = self.hp
		self.defense = level*enemy['def']
		self.loot.append(Loot('gold', random.randrange(1, level*enemy['rich'])))

		dmga = randrange(level*enemy['attack'], level*pow(enemy['attack'], 2))
		dmgb = randrange(level*enemy['attack'], level*pow(enemy['attack'], 2))
		self.mindmg = min(dmga, dmgb)
		self.maxdmg = max(dmga, dmgb) + 1

		self.name = enemy['name']
Example #17
0
	def __init__(self, model):
		self.name = 'town'
		if not hasattr(model, 'game_state') or model.game_state is None:
			model.game_state = GameData.gen_new_player()

		self.character_bg = load_image(MISC, 'character')
		model.places = {'places' : ['store', 'dungeons', 'something']}

		model.target_selection = target_selection = 0

		self.model = model
		self.bg =  pygame.image.load(os.path.join(BGS, 'town.png'))
		self.marker = pygame.image.load(os.path.join(MISC, 'menu_choice.png'))
		
		path = os.path.join(SOUND, 'cozy_melacholy.wav')

		song = pygame.mixer.Sound(path)
		model.song = song

		if PLAY_SOUND:
			model.song.play(loops=-1)
		
		self.choices =  [
				{ 'name' : 'start dungeon', 'method' : self.start_dungeon},
				{ 'name' : 'shop', 'method' : self.shop},
				{ 'name' : 'train', 'method' : self.train},
				{ 'name' : 'exit', 'method' : self.exit},
				]
		self.choice = 0
		imgs = load_animation('marker', 4)		
		self.marker = Animation(imgs, 400)

		self.cave_text = pygame.image.load(os.path.join(MISC, 'cave_text.png'))
		self.shop_text = pygame.image.load(os.path.join(MISC, 'shop_text.png'))
		self.workout_text = pygame.image.load(os.path.join(MISC, 'workout_text.png'))
		self.main_menu = pygame.image.load(os.path.join(MISC, 'main_menu_text.png'))
Example #18
0
        game_key_repeat()
        
    elif display.screen_no == constants.CONTINUE and current_display != display_game :
        current_display = display_game
        current_display.update_music()
        game_key_repeat()
        
    if display.screen_no == constants.SCORE and current_display != display_score :
            current_display = display_score
        
    elif display.screen_no == constants.EXIT:
        done = True
        
        
    # --- Game logic should go here
    current_display.logic()
    
    display.screen.fill(constants.OFF_WHITE)
 
    current_display.draw()
    if fail > 0:
        display.screen.blit(constants.load_image("failed.png"), (285,550))
        fail -= 1
    pygame.display.flip()
    
    # --- Limit to 60 frames per second
    clock.tick(60)
    
pygame.quit()

Example #19
0
        current_display = display_game
        current_display.update_music()
        game_key_repeat()

    elif display.screen_no == constants.CONTINUE and current_display != display_game:
        current_display = display_game
        current_display.update_music()
        game_key_repeat()

    if display.screen_no == constants.SCORE and current_display != display_score:
        current_display = display_score

    elif display.screen_no == constants.EXIT:
        done = True

    # --- Game logic should go here
    current_display.logic()

    display.screen.fill(constants.OFF_WHITE)

    current_display.draw()
    if fail > 0:
        display.screen.blit(constants.load_image("failed.png"), (285, 550))
        fail -= 1
    pygame.display.flip()

    # --- Limit to 60 frames per second
    clock.tick(60)

pygame.quit()
Example #20
0
class Gj():
    logo = constants.load_image("gj_logo.png")
    btn = constants.load_image("gj_b1.png")
    btnh = constants.load_image("gj_b2.png")
    ov = constants.load_image("ov1.png")
    def __init__(self, screen, x, y):
        self.screen = screen
        self.x_logo = x
        self.y_logo = y
        self.x_btn = x-30
        self.y_btn = y+70
        self.font = constants.load_font("LithosPro", 20)
        self.y_t = self.y_btn+10
        d = shelve.open('info')
        try :
            self.user, self.token = d['user'] 
        except:
            self.user, self.token = ('','')
        d.close()
        self.api = gjapi.GameJoltTrophy(self.user, self.token, constants.GAME_ID, constants.PRIVATE_KEY)
        #if self.api.authenticateUser():
            #self.logged = True
            #self.api.openSession()
            #self.btn =  Gj.btnh
            #self.text = self.font.render(self.user, 1, constants.BLACK) 
            #pygame.time.set_timer(27, 35000)            
        #else:
        self.logged = False
        self.btn = Gj.btn
        self.text = self.font.render("Offline", 1, constants.BLACK)
        _thread.start_new_thread(self.login, (self.user, self.token))
        self.opened = False
        options = {'x':150, 'y':200, 'font':self.font, 'color':constants.DLIGHT_BLUE,
                   'maxlength':25, 'prompt1':"Username:  "******"Token:  "}
        self.txtbx = eztext.Input(**options)
        self.tip1 = self.font.render("- Tab to switch between text boxes", 1, constants.OFF_WHITE)
        self.tip2 = self.font.render("- Enter to login", 1, constants.OFF_WHITE)
        self.tip3 = self.font.render("- Esc to go back", 1, constants.OFF_WHITE)
        
    def draw(self):
        self.x_t = self.x_btn+60-self.text.get_rect().size[0]/2
        self.screen.blit(Gj.logo, (self.x_logo,self.y_logo))
        self.screen.blit(self.btn, (self.x_btn, self.y_btn))
        self.screen.blit(self.text, (self.x_t, self.y_t ))
        if self.opened:
            self.screen.blit(Gj.ov, (0,0)) 
            self.screen.fill(constants.BLACK, [150,400, 500, 70])
            self.screen.blit(self.tip1, (160, 405 ))
            self.screen.blit(self.tip2, (160, 425 ))
            self.screen.blit(self.tip3, (160, 445 ))
            self.txtbx.draw(self.screen)
            
    def logic(self, events):
        self.txtbx.update(events) 
    
    def key_enter(self):
        self.user, self.token = self.txtbx.get_text()
        _thread.start_new_thread(self.login, (self.user, self.token))
        
    def login(self, user, token):
        self.api.changeUsername(user)
        self.api.changeUserToken(token)
        if self.api.authenticateUser():
            d = shelve.open('info')
            d['user'] = (user, token)
            d.close()
            self.api.openSession()
            self.logged = True
            self.opened = False
            self.btn =  Gj.btnh
            self.text = self.font.render(self.user, 1, constants.BLACK) 
            pygame.time.set_timer(27, 35000)
        else:
            pygame.event.post(pygame.event.Event(28))
        
    def check_mouse(self, pos):
        x, y = pos
        x2, y2 = Gj.btn.get_rect().size
        con1 = x > self.x_btn
        con2 = x <= self.x_btn + x2
        con3 = y > self.y_btn
        con4 = y <= self.y_btn + y2
        if con1 and con2 and con3 and con4 :
            self.click()  
            
    def click(self):
        if self.logged:
            self.logged = False
            d = shelve.open('info')
            d['user'] = ('', '')
            d.close()            
            self.btn =  Gj.btn
            self.text = self.font.render("Offline", 1, constants.BLACK)            
        else:
            self.opened = True
Example #21
0
class Speaker():
    active = [constants.load_image("speaker1.png"), constants.load_image("speaker2.png")]
    mute = constants.load_image("speaker3.png")
    def __init__(self, screen, x, y, music):
        self.screen = screen
        self.x_pos = x
        self.y_pos = y
        self.music = music
        
        d = shelve.open('info')
        try:
            self.playing = d['sound']
        except:
            self.playing = True
        d.close()
        self.img_no = 0
        if self.playing:
            self.img = Speaker.active[0]
            #self.update_music()
            pygame.time.set_timer(26, 500)
        else:
            self.img = Speaker.mute

    def draw(self):
        self.screen.blit(self.img, (self.x_pos,self.y_pos))
    
    def logic(self):
        pass
    
    def check_mouse(self, pos):
        x, y = pos
        x2, y2 = Speaker.mute.get_rect().size
        con1 = x > self.x_pos
        con2 = x <= self.x_pos + x2
        con3 = y > self.y_pos
        con4 = y <= self.y_pos + y2
        if con1 and con2 and con3 and con4 :
            self.click()
        
    
    def update_music(self):
        d = shelve.open('info')
        try:
            self.playing = d['sound']
        except:
            pass
        d.close()        
        if self.playing:
            self.img = Speaker.active[0]
            pygame.mixer.music.load(self.music)
            pygame.mixer.music.play(-1) 
            pygame.time.set_timer(26, 500)            
        else:
            self.img = Speaker.mute
            pygame.mixer.music.stop()    
            
    def click(self):
        self.playing = not self.playing
        d = shelve.open('info')
        d['sound'] = self.playing
        d.close()        
        self.update_music()
        
    def timer(self):
        if self.playing:
            self.img_no = (self.img_no + 1) % 2
            self.img = Speaker.active[self.img_no]
            pygame.time.set_timer(26, 500)
Example #22
0
class Block():
    # Frames for explosion animation
    explode_img = [constants.load_image("frame8.png").convert(), constants.load_image("frame7.png").convert(), 
                   constants.load_image("frame6.png").convert(), constants.load_image("frame5.png").convert(), 
                   constants.load_image("frame4.png").convert(), constants.load_image("frame3.png").convert(), 
                   constants.load_image("frame2.png").convert(), constants.load_image("frame1.png").convert() ]
    
    def __init__(self, x, y, img, y_spd, s = False):
        self.x_pos = x
        self.y_pos = y
        self.img = img
        self.y_spd = y_spd
        self.ori_spd = y_spd
        self.special = s
      
    # Check if the block entered the playing area or not yet  
    def drawable(self):
        return self.y_pos >= y_low_limit    
    # Bilt the block to screen
    def draw(self, screen, x = None, y = None):
        if x == None :
            x = self.x_pos
        if y == None :
            y = self.y_pos
        screen.blit(self.img, [x, y])
        
    # Update block's position using it's speed
    def update_pos(self):
        self.y_pos += self.y_spd
        
    # Change block's speed
    def update_speed(self, y):
        self.y_spd = y
    
    # Restore the original speed given to the block at it's creation
    def restore_speed(self):
        self.y_spd = self.ori_spd
    
    # Stop the block
    def stop(self):
        self.update_speed(0)
    
    # Draw the block with a frame of the explosion
    def explode(self,screen, n):
        screen.blit(Block.explode_img[n], [self.x_pos, self.y_pos])
    
    # Move the block one step right    
    def move_right(self):
        self.x_pos += x_s
    
    # Move the block one step left
    def move_left(self):
        self.x_pos -= x_s
    
    # Get X position of the block    
    def get_x(self):
        return self.x_pos
    
    # Get Y position of the block 
    def get_y(self):
        return self.y_pos
    # Set the position of X
    def set_x(self, x):
        self.x_pos = x
    # Change X's position with a magnitude    
    def trans_x(self, x):
        self.x_pos += x
    # Set the position of Y
    def set_y(self, y):
        self.y_pos = y
    # Change Y's position with a magnitude    
    def trans_y(self, y):
        self.y_pos += y
Example #23
0
class BlockObject():
    # Images used to create blocks
    i_block1 = constants.load_image("i_block.png").convert()
    j_block1 = constants.load_image("j_block.png").convert()
    o_block1 = constants.load_image("o_block.png").convert()
    z_block1 = constants.load_image("z_block.png").convert()
    t_block1 = constants.load_image("t_block.png").convert()
    sp_block1 = constants.load_image("special_block.png").convert()
    
    # Block objects images for instant blit on the screen
    next_block = [constants.load_image("i_next.png").convert(), constants.load_image("j_next.png"),
                  constants.load_image("o_next.png").convert(), constants.load_image("z_next.png"),
                  constants.load_image("t_next.png"), constants.load_image("special_block.png").convert()] 
    
    def __init__(self):
        self.next_list = []
        self.moving_list = []
        self.variation = None
        self.rtype = None
        self.ntype = None
        self.special = None
        # Mapping functions to spawn objects using type and variation of the object
        self.dic = {0: {0:self.add_i_v1, 1:self.add_i_v2 ,2:self.add_i_v1 ,3:self.add_i_v2},
                    1: {0:self.add_j_v1, 1:self.add_j_v2 ,2:self.add_j_v3 ,3:self.add_j_v4},
                    2: {0:self.add_o, 1:self.add_o, 2:self.add_o, 3:self.add_o},
                    3: {0:self.add_z_v1, 1:self.add_z_v2 ,2:self.add_z_v1 ,3:self.add_z_v2},
                    4: {0:self.add_t_v1, 1:self.add_t_v2 ,2:self.add_t_v3 ,3:self.add_t_v4}} 
        # Mapping functions to help replace variotaions
        self.pos = {0: self.get_i, 1: self.get_j, 2: self.get_o, 3: self.get_z, 4: self.get_t}         

    # This current moving object is taken from the 'previous' next object, the next object
    # gets a new random object
    def new_object(self):
        # Spawn a special block object with 1/2o chance
        if random.randint(0,20) == 20:
            self.rtype = self.ntype
            self.ntype = 5
            self.variation = 0
            self.moving_list = self.next_list
            self.next_list = [Block( x_midpoint, y_low_limit , BlockObject.sp_block1, speed)]  
        # Spawn a typical block object
        else: 
            temp = random.randint(0, 4)
            self.rtype = self.ntype
            self.ntype = temp
            self.variation = 0
            self.moving_list = self.next_list
            self.next_list = self.dic[self.ntype][0]()
        self.special = (self.rtype == 5)
          
    # Functions to add 'I' Blocks and it's vartiations
    def add_i_v1(self, x= x_midpoint, y= y_low_limit - y_s): 
        blocks = [0,0,0,0]
        for i in range(4):
            blocks[i] = Block( x, y -(i*y_s) , BlockObject.i_block1, speed)
        return blocks
    def add_i_v2(self, x = (x_midpoint - (2 * x_s) ), y= y_low_limit): 
        blocks = [0,0,0,0]
        for i in range(4):
            blocks[i] = Block( x + (i * x_s), y, BlockObject.i_block1, speed)
        return blocks      
    
    # Functions to add 'J' Blocks and it's vartiations
    def add_j_v1(self, x = x_midpoint - x_s, y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.j_block1, speed)
        for i in range(3):
            blocks[i+1] = Block( x + x_s , y-(i*y_s), BlockObject.j_block1, speed)
        return blocks
    def add_j_v2(self, x = x_midpoint - x_s, y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        for i in range(3):
            blocks[i] = Block( x + (i* x_s) , y, BlockObject.j_block1, speed)
        blocks[3] = Block( x , y - y_s, BlockObject.j_block1, speed)
        return blocks    
    def add_j_v3(self, x = x_midpoint - x_s, y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        for i in range(3):
            blocks[i] = Block( x , y-(i*y_s), BlockObject.j_block1, speed)
        blocks[3] = Block( x + x_s , y - 2 * y_s, BlockObject.j_block1, speed)
        return blocks
    def add_j_v4(self, x = x_midpoint - x_s, y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        for i in range(3):
            blocks[i+1] = Block( x - (i* x_s) , y, BlockObject.j_block1, speed)
        blocks[0] = Block( x , y+y_s, BlockObject.j_block1, speed)
        return blocks             

    # Functions to add 'O' Blocks and no variations OBVIOUSLY
    def add_o(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.o_block1, speed)
        blocks[1] = Block( x - x_s , y, BlockObject.o_block1, speed)
        blocks[2] = Block( x , y - y_s, BlockObject.o_block1, speed) 
        blocks[3] = Block( x - x_s , y - y_s, BlockObject.o_block1, speed) 
        return blocks     
    
    # Functions to add 'Z' Blocks and it's vartiations    
    def add_z_v1(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x + x_s , y, BlockObject.z_block1, speed)
        blocks[1] = Block( x , y, BlockObject.z_block1, speed)
        blocks[2] = Block( x , y - y_s, BlockObject.z_block1, speed) 
        blocks[3] = Block( x - x_s, y - y_s, BlockObject.z_block1, speed) 
        return blocks 
    def add_z_v2(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.z_block1, speed)
        blocks[1] = Block( x , y - y_s, BlockObject.z_block1, speed)
        blocks[2] = Block( x + x_s, y - y_s, BlockObject.z_block1, speed) 
        blocks[3] = Block( x + x_s, y - 2*y_s, BlockObject.z_block1, speed) 
        return blocks    
    
    # Functions to add 'T' Blocks and it's vartiations
    def add_t_v1(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.t_block1, speed)
        blocks[1] = Block( x , y - y_s, BlockObject.t_block1, speed)
        blocks[2] = Block( x - x_s, y - y_s, BlockObject.t_block1, speed) 
        blocks[3] = Block( x + x_s, y - y_s, BlockObject.t_block1, speed) 
        return blocks   
    def add_t_v2(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.t_block1, speed)
        blocks[1] = Block( x , y - y_s, BlockObject.t_block1, speed)
        blocks[2] = Block( x , y - 2*y_s, BlockObject.t_block1, speed) 
        blocks[3] = Block( x - x_s, y - y_s, BlockObject.t_block1, speed) 
        return blocks     
    def add_t_v3(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.t_block1, speed)
        blocks[1] = Block( x + x_s, y, BlockObject.t_block1, speed)
        blocks[2] = Block( x - x_s, y, BlockObject.t_block1, speed) 
        blocks[3] = Block( x , y - y_s, BlockObject.t_block1, speed) 
        return blocks     
    def add_t_v4(self, x = x_midpoint , y = y_low_limit - y_s): 
        blocks = [0,0,0,0]
        blocks[0] = Block( x , y, BlockObject.t_block1, speed)
        blocks[1] = Block( x , y - y_s, BlockObject.t_block1, speed)
        blocks[2] = Block( x , y - 2*y_s, BlockObject.t_block1, speed) 
        blocks[3] = Block( x + x_s, y - y_s, BlockObject.t_block1, speed) 
        return blocks
    
    # Update the positions of the current moving object
    def update(self):
        for b in self.moving_list:
            b.update_pos()  
    # Return the list of the blocks of the current moving object   
    def get_list(self):
        return self.moving_list
    
    # Stop the object, 
    #if it had already crossed a line bring it back and STOP IT
    def stop(self):
        for b in self.moving_list :
            b.stop()
            
    def transfer(self, x, y):
        for b in self.moving_list:
            b.trans_y(y)
            b.trans_x(x)
            
    # Blit an image of the next coming object in the 'Next' Area        
    def draw_next(self, screen):
        img = BlockObject.next_block[self.ntype]
        s = img.get_rect().size
        x = 650 - s[0]/2
        y = 175 - s[1]/2
        screen.blit(img , [x , y])    
        
    # Cuased by the down arrow key
    # Makes the object move faster
    def move_down(self):
            for b in self.moving_list:
                b.update_speed(speed*5)  
                
    # Cuased by releasing the down arrow key
    # Makes the objects move at it's own pace, peacefully
    def restore_spd(self):
        for b in self.moving_list:
            b.restore_speed()  
    
    # Move object one step right
    def move_right(self):
        for b in self.moving_list:
            b.move_right()
            
    # Move object one step left
    def move_left(self):
        for b in self.moving_list:
            b.move_left()    

    # Cuased by up arrow key
    # Try to transform object into next variation, pass results to Controler
    def change_v(self):
        if self.special:
            return (self.moving_list, self.variation)
        pos = self.pos[self.rtype]()
        v = (self.variation + 1) % 4
        l = self.dic[self.rtype][v](*pos)
        return (l,v)
    
    # If it's cool with the controler, it's cool with me!
    def ok(self, l, v):
        self.variation = v
        self.moving_list = l

    # Helper for I's transformations
    def get_i(self):
        if self.variation == 0 or self.variation == 2 :
            x = self.moving_list[0].get_x() - 2 * x_s
            y = self.moving_list[0].get_y()
        else:
            x = self.moving_list[0].get_x() + 2 * x_s
            y = self.moving_list[3].get_y()   
        return (x, y) 
    
    # Helper for J's transformations
    def get_j(self):
        if self.variation == 0:
            x = self.moving_list[0].get_x() -  x_s
            y = self.moving_list[0].get_y()
        elif self.variation == 1:
            x = self.moving_list[0].get_x() + 2 * x_s
            y = self.moving_list[0].get_y()   
        elif self.variation == 2:
            x = self.moving_list[0].get_x() + x_s
            y = self.moving_list[0].get_y()   
        elif self.variation == 3:
            x = self.moving_list[0].get_x() - 2 * x_s
            y = self.moving_list[0].get_y()           
        return (x, y)  
    
    # Do nothing, just make O objects feel not so deficient
    def get_o(self):
        return (self.moving_list[0].get_x(), self.moving_list[0].get_y())
    
    # Helper for Z's transformations
    def get_z(self):
        if self.variation == 0 or self.variation == 2 :
            x = self.moving_list[3].get_x() + x_s
            y = self.moving_list[0].get_y()
        else:
            x = self.moving_list[0].get_x() 
            y = self.moving_list[0].get_y()   
        return (x, y) 
    
    # Just like O's Helper
    def get_t(self):
        return (self.moving_list[0].get_x(), self.moving_list[0].get_y())