def calc_boss1_collision_rect(player_rect): rects = [] w = player_rect.w * .8 h = player_rect.h * .3 x = player_rect.x + player_rect.w *.1 y = player_rect.y + player_rect.h * 0.3 rects.append(mygame.Rect(x,y,w,h)) w = player_rect.w * .4 h = player_rect.h * .3 x = player_rect.x + player_rect.w *.3 y = player_rect.y rects.append(mygame.Rect(x,y,w,h)) w = player_rect.w * .6 h = player_rect.h * .3 x = player_rect.x + player_rect.w *.2 y = player_rect.y + player_rect.h * 0.6 rects.append(mygame.Rect(x,y,w,h)) return rects
def draw_line_centered(self, text, y, screen): w = self.__word_length(text) indent = SCREEN_X / 2 - w / 2 my_rect = mygame.Rect(indent, y, SCREEN_X - indent, self.large_font_height) self.set_text(text, my_rect) self.draw(screen)
def __init__(self, map_max_x, map_max_y): self.static_columns = [] #Split the map up into sections and keep units in these columns #reduces the aamount of searching we must do when testing for collisions self.num_rows = 0 num_sections = 0 if CHOP_VERTICALLY: step = UNIT_SCENE_SIZE else: step = int(map_max_y) for y in range(0, int(map_max_y), step): y_width = step self.num_columns = 0 for x in range(0, int(map_max_x), UNIT_SCENE_SIZE): r = mygame.Rect(x, y, UNIT_SCENE_SIZE, y_width) s = LevelUnitSetRect(r) self.static_columns.append(s) print_debug("Created column %d,%d,%d,%d" %(r.x, r.y, r.w, r.h),3) self.num_columns+=1 num_sections +=1 print_debug("Number of sections for unit sets %d (%d,%d,%d)" %(num_sections, self.num_columns, self.num_rows, map_max_x),3) self.static_units = [] #complete list self.moveable_units = [] #complete list self.alien_prototypes = dict({}) self.gun_flare_unit = None self.player = None self.bullet_prototypes = dict({}) self.small_explosion_prototype = None self.units_by_name = dict({}) self.lifts = [] self.doors = []
def calc_boss2_collision_rect(player_rect): rects = [] w = player_rect.w * .6 h = player_rect.h * .6 x = player_rect.x + player_rect.w *.2 y = player_rect.y rects.append(mygame.Rect(x,y,w,h)) w = player_rect.w * .2 h = player_rect.h * .2 x = player_rect.x + player_rect.w *.4 y = player_rect.y + player_rect.h * .7 rects.append(mygame.Rect(x,y,w,h)) return rects
def calc_collision_rect(player_rect): f = .8 o = .1 w = player_rect.w *f h = player_rect.h *f x = player_rect.x + player_rect.w*o y = player_rect.y + player_rect.h*o return mygame.Rect(x,y,w,h)
def __init__(self,level, refresh_rate, my_game): self.view = mygame.Rect(0,0,0,0) self.level = level self.border_ratio = 5 self.hud = Hud(level.get_player().get_player_stats(), level.my_game) self.refresh_rate = refresh_rate self.countdown_overlay = None self.debug_alien_path = None self.palette_switched = False self.my_game = my_game
def start(self): self.ticker = True self.img,self.x,self.y,TEXT_X,TEXT_Y,TEXT_W,TEXT_H = self.__get_screen_data() self.font_rect = mygame.Rect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H) self.font.set_ticker_text(self.text, self.font_rect) self.delay = 500 self.pause_time = 0 self.start_time = None if not Cheats.getNoAudio(): self.background_sound.play(-1)
def start(self): self.ticker = True self.img, self.x,self.y,TEXT_X,TEXT_Y,TEXT_W,TEXT_H,LIFT_X = self.__get_screen_data() self.font_rect = mygame.Rect(TEXT_X, TEXT_Y, TEXT_W, TEXT_H) self.font.set_ticker_text(self.text_loader.get_mission_text(), self.font_rect) self.delay = 2000 self.pause_time = 0 self.initial_skip_delay = 4000 self.start_time = None self.menu.start() if not self.__is_first_level(): self.deck_man = DeckMan(LIFT_X, self.y, self.my_game.get_mixer()) else: self.deck_man = None
def start(self): #Reload image resources nw we are in correct palette self.menu_cursor = self.menu_controller.menu_cursor self.ticker_font = IntexTickerFont(self.mixer) self.menu_font = self.menu_controller.menu_font if not Cheats.getNoAudio(): self.comp_start_sound.play() self.font_rect = mygame.Rect(IntexIntro.TEXT_X, IntexIntro.TEXT_Y, IntexIntro.TEXT_W, IntexIntro.TEXT_H) text = load_text_file_as_string(get_config_pathname(INTEXT_INTRO_TEXT)) self.ticker_font.set_ticker_text(text.upper(), self.font_rect) self.ticker_font.delay = 0 self.ticker_font.char_increment = 8 self.in_ticker = False
def move_until_first_unit_hit(self, player_unit, scroll_x, scroll_y, pp, collided_map, time): #Check for unit collisions within distance moved... unit_collisions = self.unit_collision2.get_unit_collisions(player_unit, mygame.Rect(pp.tl.v.x + scroll_x, pp.tl.v.y + scroll_y, pp.w, pp.h)) #process all non-blocking collisions up until first blocking (solid) collision closest_blocking_unit = None for unit in unit_collisions: player_unit.collide_unit(unit[1], unit[3], time) if unit[1].is_blocking_collision(player_unit): closest_blocking_unit = unit break if closest_blocking_unit: scroll_x=0 scroll_y=0 #unit is to right of player, scroll to unit left position - player right edge if unit[2].x > pp.tr.v.x: scroll_x = unit[2].x - pp.tr.v.x if (unit[2].x + unit[2].w) < pp.tl.v.x: #unit to left, scroll to unit right edge scroll_x = -(pp.tl.v.x - (unit[2].x + unit[2].w)) if unit[2].y > pp.bl.v.y: #unit below player scroll_y = unit[2].y - pp.bl.v.y if unit[2].y + unit[2].h < pp.tl.v.y: #unit below player scroll_y = -(pp.tl.v.y - (unit[2].y + unit[2].h)) #scroll_x = unit[2].x - pp.tl.v.x #scroll_y = unit[2].y - pp.tl.v.y #print_debug("hit unit at %d,%d" %(unit[2].x, unit[2].y),2) else: #not blocked by unit, perhaps by map obstruction if collided_map: # let subclasses know we collided with the map self.collided_map(player_unit, scroll_x, scroll_y, time) return scroll_x, scroll_y, closest_blocking_unit
def plot_big_ticks(self, s, hud_y, start_x, num, max): x = start_x num_ticks = num plot_plus = False if num_ticks > max: num_ticks = max plot_plus = True for l in range(0, num_ticks): s.blit(self.hud_gold_big_blip, (x, hud_y)) x += self.big_tick_x_increment if plot_plus: #this image is too wide - it has white space in second half... s.blit_part( self.hud_gold_plus, (x, hud_y), mygame.Rect(0, self.hud_gold_plus.get_rect().y, self.hud_gold_plus.get_rect().w / 2, self.hud_gold_plus.get_rect().h))
def __init__(self, my_game): self.background_sound = my_game.get_mixer().Music(get_sound_pathname(MENU_BACKGROUND_SOUND)) self.star = StarField(mygame.Rect(0,0,SCREEN_X, SCREEN_Y)) self.my_game=my_game self.playing = False
def set_pos(self, x, y, unit): unit_state = unit.unit_state unit_state.rect = mygame.Rect(x, y, self.tile_width, self.tile_height) unit_state.collision_rects = self.calc_collision_rects(unit)