def __init__(self, score): sfx_enter.play() # Screen shake self.offset = repeat((0,0)) self.offset = shake(10,5) self.score = score if self.score > game_data.high_score: game_data.high_score = self.score # Images self.img_background = load_png("background.png", IMG_DIR, 8) # Sprites self.sprites = pygame.sprite.Group() self.bubbles = pygame.sprite.Group() # Texts self.text_go = Text(WIN_SZ[0]/2, WIN_SZ[1]/2 - 198, "Game", GAME_FONT, 96, PALETTE["WHITE"]) self.text_go2 = Text(WIN_SZ[0]/2, WIN_SZ[1]/2 - 96, "Over", GAME_FONT, 96, PALETTE["WHITE"]) self.text_score = Text(WIN_SZ[0]/2, WIN_SZ[1]/2, f"Score: {self.score}", GAME_FONT, 32, PALETTE["WHITE"]) self.text_comment = Text(WIN_SZ[0]/2, WIN_SZ[1]/1.6, self.generate_comment(self.score), GAME_FONT, 32, PALETTE["WHITE"]) self.text_return = Text(WIN_SZ[0]/2, WIN_SZ[1]/1.4, "[RETURN]", GAME_FONT, 32, PALETTE["WHITE"]) self.sprites.add(self.text_go) self.sprites.add(self.text_go2) self.sprites.add(self.text_score) self.sprites.add(self.text_comment) self.sprites.add(self.text_return)
def __init__(self): sfx_enter.play() # Screen shake self.offset = repeat((0,0)) self.offset = shake(10,5) # Stats area self.stats_area = pygame.Surface((WIN_SZ[0] - 64,500)) self.stats_area.fill(BG_COLOR) self.stats_area.set_colorkey(BG_COLOR) # Sprite groups self.stats_texts = pygame.sprite.Group() self.bubbles = pygame.sprite.Group() # Images self.img_background = load_png("background.png", IMG_DIR, 8) # Texts self.text_statsheader = Text(self.stats_area.get_width() / 2,64, "STATS", GAME_FONT, 44, PALETTE['WHITE']) self.text_highscore = Text(16,128, f"Hi-score: {game_data.high_score}", GAME_FONT, 24, PALETTE['WHITE'], False) self.text_timespressed = Text(16, 184, f"Presses: {game_data.times_pressed}", GAME_FONT, 24, PALETTE['WHITE'], False) # Compute time minutes = round(game_data.play_time / 1000) // 60 seconds = round(game_data.play_time / 1000) % 60 time = f"{minutes}m{seconds}s" self.text_playtime = Text(16, 240, f"Play time: {time}", GAME_FONT, 22, PALETTE['WHITE'], False) self.text_exitbutton = Text(self.stats_area.get_width() / 2, self.stats_area.get_height() * 0.9, "[ESC]", GAME_FONT, 24, PALETTE['WHITE']) self.stats_texts.add(self.text_statsheader) self.stats_texts.add(self.text_highscore) self.stats_texts.add(self.text_timespressed) self.stats_texts.add(self.text_playtime) self.stats_texts.add(self.text_exitbutton)
def __init__(self): # Screen shake sfx_enter.play() self.offset = repeat((0,0)) self.offset = shake(10,5) # Menu self.img_logo = load_png("logo.png", IMG_DIR, 8) self.menu_area = pygame.Surface((300,400)) self.selector_width = self.menu_area.get_width() * 0.9 self.selector_height = 56 self.selector_x = self.menu_area.get_width() / 2 - self.selector_width / 2 self.selector_y = 32 self.menu_texts_size = 32 self.menu_texts_y = 64 self.selected_option = 0 self.menu_options = [ ClassicGameScene, StatsScene ] # Sprite groups self.sprites = pygame.sprite.Group() self.bubbles = pygame.sprite.Group() self.menu_texts = pygame.sprite.Group() # Images self.img_background = load_png("background.png", IMG_DIR, 8) # Color of the objects self.color = PALETTE["CYAN"] self.color_palette = PALETTE["CYAN_PAL"] # Texts #self.text_title1 = Text(WIN_SZ[0]/2, WIN_SZ[1]/4, "low key", GAME_FONT, 64, PALETTE["WHITE"]) #=self.text_title2 = Text(WIN_SZ[0]/2, WIN_SZ[1]/4, "", GAME_FONT, 48, PALETTE["WHITE"]) self.text_developer = Text(WIN_SZ[0]/2, WIN_SZ[1]/4 + 128, "by Zyenapz", GAME_FONT, 28, PALETTE["WHITE"]) self.text_play = Text(self.menu_area.get_width() / 2, self.menu_texts_y * 1, "Play", GAME_FONT, self.menu_texts_size, PALETTE["WHITE"]) #self.text_shop = Text(self.menu_area.get_width() / 2, self.menu_texts_y * 2, "Shop", GAME_FONT, self.menu_texts_size, PALETTE["WHITE"]) self.text_stats = Text(self.menu_area.get_width() / 2, self.menu_texts_y * 2, "Stats", GAME_FONT, self.menu_texts_size, PALETTE["WHITE"]) #self.text_credits = Text(self.menu_area.get_width() / 2, self.menu_texts_y * 4, "Credits", GAME_FONT, self.menu_texts_size, PALETTE["WHITE"]) self.text_quit = Text(self.menu_area.get_width() / 2, self.menu_texts_y * 3, "Quit", GAME_FONT, self.menu_texts_size, PALETTE["WHITE"]) #self.sprites.add(self.text_title1) #self.sprites.add(self.text_title2) self.sprites.add(self.text_developer) self.menu_texts.add(self.text_play) #self.menu_texts.add(self.text_shop) self.menu_texts.add(self.text_stats) #self.menu_texts.add(self.text_credits) self.menu_texts.add(self.text_quit)
def __init__(self): # Booleans self.help_available = False self.stats_available = False # Surfaces self.menu_area = pygame.Surface((256, 280)) self.menu_area_rect = self.menu_area.get_rect() self.menu_area_rect.centerx = WIN_SZ[0] / 2 self.menu_area_rect.y = 200 self.logo_img = load_png("logo.png", IMG_DIR, 4) self.help_area = pygame.Surface((300, 450)) self.help_img = load_png("help.png", IMG_DIR, 4) self.stats_area = pygame.Surface((300, 450)) self.dev_img = load_png("dev_info.png", IMG_DIR, 4) self.bg_layer1_x = 0 self.bg_layer2_x = 0 self.bg_layer3_x = 0 self.bg_layer1_img = load_png("title_bg_layer1.png", IMG_DIR, 4) self.bg_layer1_rect = self.bg_layer1_img.get_rect() self.bg_layer2_img = load_png("title_bg_layer2.png", IMG_DIR, 4) self.bg_layer2_rect = self.bg_layer2_img.get_rect() self.bg_layer3_img = load_png("title_bg_layer3.png", IMG_DIR, 4) self.bg_layer3_rect = self.bg_layer3_img.get_rect() # Selector self.y_offset = 32 self.selector_width = 6 self.selector_y = -self.selector_width + self.y_offset self.cur_sel = 0 # Sprite groups self.statstexts = pygame.sprite.Group() self.helptexts = pygame.sprite.Group() self.optiontexts = pygame.sprite.Group() # Texts for menu #self.text_title = Text(self.menu_area.get_width() / 2, self.menu_area.get_height () / 8, "CAFFEINE", GAME_FONT, 48, 'white') self.text_play = Text(self.menu_area.get_width() / 2, 0 + self.y_offset, "PLAY", GAME_FONT, 34, 'white') self.text_shop = Text(self.menu_area.get_width() / 2, 45 + self.y_offset, "SHOP", GAME_FONT, 32, 'yellow') self.text_stats = Text(self.menu_area.get_width() / 2, 90 + self.y_offset, "STATS", GAME_FONT, 32, 'white') self.text_help = Text(self.menu_area.get_width() / 2, 135 + self.y_offset, "HELP", GAME_FONT, 32, 'white') self.text_quit = Text(self.menu_area.get_width() / 2, 180 + self.y_offset, "QUIT", GAME_FONT, 32, 'white') #self.texts.add(self.text_title) self.optiontexts.add(self.text_play) self.optiontexts.add(self.text_shop) self.optiontexts.add(self.text_stats) self.optiontexts.add(self.text_help) self.optiontexts.add(self.text_quit) # Texts for help area self.text_help = Text(0, 0, "HELP", GAME_FONT, 32, 'white') self.text_help.rect = (16, 16) self.helptexts.add(self.text_help) # Texts for stats area self.text_statslabel = Text(0, 0, "STATS", GAME_FONT, 32, 'white') self.text_statslabel.rect = (16, 16) self.text_highscore = Text(0, 0, f"Hi-score: {game_data.highscore}", GAME_FONT, 14, 'yellow') self.text_highscore.rect = (16, 64) self.text_coins = Text(0, 0, f"Coins: {game_data.coins}", GAME_FONT, 14, 'white') self.text_coins.rect = (16, 94) self.text_timesdied = Text(0, 0, f"Times died: {game_data.times_died}", GAME_FONT, 14, 'white') self.text_timesdied.rect = (16, 124) self.text_timeshit = Text(0, 0, f"Times hit: {game_data.times_hit}", GAME_FONT, 14, 'white') self.text_timeshit.rect = (16, 154) self.text_timesfuel = Text( 0, 0, f"Fuel pickups: {game_data.times_fuelpickup}", GAME_FONT, 14, 'white') self.text_timesfuel.rect = (16, 184) self.text_timesshield = Text( 0, 0, f"Shield pickups: {game_data.times_shieldpickup}", GAME_FONT, 14, 'white') self.text_timesshield.rect = (16, 214) self.text_playtime = Text(0, 0, f"Play time: {game_data.play_time}s", GAME_FONT, 14, 'white') self.text_playtime.rect = (16, 244) self.statstexts.add(self.text_statslabel) self.statstexts.add(self.text_highscore) self.statstexts.add(self.text_coins) self.statstexts.add(self.text_timesdied) self.statstexts.add(self.text_timeshit) self.statstexts.add(self.text_timesfuel) self.statstexts.add(self.text_timesshield) self.statstexts.add(self.text_playtime)
def __init__(self): # Settings self.offset = repeat((0, 0)) # For screen shake self.orig_gxspeed = 0 self.global_xspeed = 3 self.bg_layer1_x = 0 self.bg_layer2_x = 0 self.bg_layer3_x = 0 self.moon_x = 0 self.score = 0 self.coins = 0 self.max_enemies = 2 self.max_powerups = 1 self.difficulty_ticks = 0 self.difficulty_increase_delay = 7500 self.difficulty_level = 0 self.debug_mode = False self.start_delay = 3000 self.exit_ticks = 0 self.can_exit = False self.cur_playtime = 0 img_sc = 4 # Load Images ============================= # Play area and stats area and other crap self.play_area = pygame.Surface((536, 440)) self.stats_area = pygame.Surface((156, 440)) self.color_correction = pygame.Surface( (self.play_area.get_width(), self.play_area.get_height())) self.color_correction.set_alpha(10) self.border_img = load_png("border.png", IMG_DIR, img_sc) # Background self.bg_layer1_img = load_png("bg_layer1.png", IMG_DIR, img_sc) self.bg_layer1_rect = self.bg_layer1_img.get_rect() self.bg_layer2_img = load_png("bg_layer2.png", IMG_DIR, img_sc) self.bg_layer2_rect = self.bg_layer2_img.get_rect() self.bg_layer3_img = load_png("bg_layer3.png", IMG_DIR, img_sc) self.bg_layer3_rect = self.bg_layer3_img.get_rect() # Player player_imgs = { "NORMAL": { "MOVRIGHT": load_png("player1.png", IMG_DIR, img_sc), "IDLE": load_png("player2.png", IMG_DIR, img_sc), "MOVLEFT": load_png("player3.png", IMG_DIR, img_sc) }, "SHIELDED": { "MOVRIGHT": load_png("player_shielded1.png", IMG_DIR, img_sc), "IDLE": load_png("player_shielded2.png", IMG_DIR, img_sc), "MOVLEFT": load_png("player_shielded3.png", IMG_DIR, img_sc) } } if game_data.equipped_pet != "none": pet_ing = load_png(game_data.equipped_pet, IMG_DIR, 3) if game_data.equipped_hat != "none": hat_img = load_png(game_data.equipped_hat, IMG_DIR, img_sc) # Obstacles kid_obstacle_imgs = [ load_png("obstacle_kid1.png", IMG_DIR, img_sc), load_png("obstacle_kid2.png", IMG_DIR, img_sc) ] heli_obstacle_imgs = [ load_png("obstacle_heli1.png", IMG_DIR, img_sc), load_png("obstacle_heli2.png", IMG_DIR, img_sc) ] obstacle_bird_imgs = [ load_png("obstacle_bird1.png", IMG_DIR, img_sc), load_png("obstacle_bird2.png", IMG_DIR, img_sc) ] barry_obstacle_imgs = [ load_png("obstacle_barry1.png", IMG_DIR, img_sc), load_png("obstacle_barry2.png", IMG_DIR, img_sc) ] crate_obstacle_imgs = [ load_png("obstacle_crate1.png", IMG_DIR, img_sc), load_png("obstacle_crate2.png", IMG_DIR, img_sc) ] parasol_obstacle_img = [ load_png("obstacle_parasol1.png", IMG_DIR, img_sc) ] self.obstacle_imgs = [ kid_obstacle_imgs, heli_obstacle_imgs, obstacle_bird_imgs, barry_obstacle_imgs, parasol_obstacle_img, crate_obstacle_imgs ] # CoffeeOMeter coffee_meter_imgs = { "100": load_png("CoffeeOMeter1.png", IMG_DIR, img_sc), "90": load_png("CoffeeOMeter2.png", IMG_DIR, img_sc), "80": load_png("CoffeeOMeter3.png", IMG_DIR, img_sc), "70": load_png("CoffeeOMeter4.png", IMG_DIR, img_sc), "60": load_png("CoffeeOMeter5.png", IMG_DIR, img_sc), "50": load_png("CoffeeOMeter6.png", IMG_DIR, img_sc), "40": load_png("CoffeeOMeter7.png", IMG_DIR, img_sc), "30": load_png("CoffeeOMeter8.png", IMG_DIR, img_sc), "20": load_png("CoffeeOMeter9.png", IMG_DIR, img_sc), "10": load_png("CoffeeOMeter10.png", IMG_DIR, img_sc), } # ShieldOMeter shield_meter_imgs = { "2": load_png("ShieldOMeter1.png", IMG_DIR, img_sc), "1": load_png("ShieldOMeter2.png", IMG_DIR, img_sc), "0": load_png("ShieldOMeter3.png", IMG_DIR, img_sc) } # Powerup self.powerup_imgs = { "fuel": load_png("powerup_fuel.png", IMG_DIR, img_sc), "shield": load_png("powerup_shield.png", IMG_DIR, img_sc), "coin": load_png("powerup_coin.png", IMG_DIR, img_sc) } # Sprite groups self.sprites = pygame.sprite.Group() self.enemies = pygame.sprite.Group() self.texts = pygame.sprite.Group() self.texts_pa = pygame.sprite.Group() self.powerups = pygame.sprite.Group() self.particles = pygame.sprite.Group() self.trails = pygame.sprite.Group() self.moving_stuff = pygame.sprite.Group( ) # this group is just for detecting overlapping sprites in the spawning functions # Player self.player = Player(player_imgs) if game_data.equipped_pet != "none": self.pet = Pet(pet_ing, self.player) if game_data.equipped_hat != "none": self.hat = Hat(hat_img, self.player, img_sc, img_sc * 6) # Stats texts self.text_stats = Text(self.stats_area.get_width() / 2, 0, "Stats", GAME_FONT, 28, 'white') self.coffee_o_meter = CoffeeOMeter(coffee_meter_imgs, (16, 0), "100", "10") self.text_scorelabel = Text(self.stats_area.get_width() / 2, self.stats_area.get_height() / 3.8, "Score", GAME_FONT, 28, 'white') self.text_score = Text(self.stats_area.get_width() / 2, self.stats_area.get_height() / 3, f"{str(self.score).zfill(5)}", GAME_FONT, 28, 'white') self.shield_o_meter = CoffeeOMeter(shield_meter_imgs, (16, WIN_SZ[1] / 2.8), "2", "0", False) self.text_coinslabel = Text(self.stats_area.get_width() / 2, self.stats_area.get_height() / 1.4, "Coins", GAME_FONT, 28, 'yellow') self.text_coins = Text(self.stats_area.get_width() / 2, self.stats_area.get_height() / 1.27, f"{str(self.coins).zfill(5)}", GAME_FONT, 28, 'yellow') self.texts.add(self.text_stats) self.texts.add(self.text_scorelabel) self.texts.add(self.text_score) self.texts.add(self.text_coinslabel) self.texts.add(self.text_coins) # Play area text(s) self.text_gameover = Text(self.play_area.get_width() / 2, self.play_area.get_height() / 4, "GAME OVER!", GAME_FONT, 48, 'white', False) self.text_finalscore = Text(self.play_area.get_width() / 2, self.play_area.get_height() / 2.4, "SCORE 00000", GAME_FONT, 32, 'white', False) self.text_finalcoin = Text(self.play_area.get_width() / 2, self.play_area.get_height() / 2, "COINS 00000", GAME_FONT, 32, 'white', False) self.text_exitbutton = Text(self.play_area.get_width() / 2, self.play_area.get_height() / 1.4, "[X] Exit", GAME_FONT, 32, 'white', False) self.texts_pa.add(self.text_gameover) self.texts_pa.add(self.text_finalscore) self.texts_pa.add(self.text_finalcoin) self.texts_pa.add(self.text_exitbutton)
def __init__(self): #print(game_data.highscore, game_data.coins) self.coins = 1000 self.init_x = 16 self.init_y = 16 self.x_offset = 64 + self.init_x self.y_offset = 64 + self.init_y self.pet_files = [ 'pet_cat.png', 'pet_chiki.png', 'pet_coffee.png', 'pet_dog.png', 'pet_fish.png', 'pet_skull.png', 'pet_stealbucks.png' ] self.hat_files = [ 'hat_dimadome.png', 'hat_howl.png', 'hat_leprechaun.png', 'hat_phony.png', 'hat_santa.png', 'hat_swag.png', 'hat_ushanka.png' ] self.pet_imgs = self.load_items(self.pet_files) self.hat_imgs = self.load_items(self.hat_files) #print(self.hat_imgs) self.selector_x = 16 self.selector_y = 16 if game_data.equipped_pet != "none": self.pet_equipped_x = 16 + ( 80 * self.pet_files.index(game_data.equipped_pet)) #self.row_break = len(self.all_pets) // 2 if game_data.equipped_hat != "none": self.hat_equipped_x = 16 + ( 80 * self.hat_files.index(game_data.equipped_hat)) self.cur_pet = 0 self.cur_hat = 0 self.item_cost = 30 self.debug_mode = False # Surfaces self.pets_area = pygame.Surface((WIN_SZ[0] / 1.33, 96)) self.hats_area = pygame.Surface((WIN_SZ[0] / 1.33, 96)) self.cur_shop = self.pets_area self.bg_layer1_img = load_png("title_bg_layer1.png", IMG_DIR, 4) self.bg_layer1_rect = self.bg_layer1_img.get_rect() self.bg_layer2_img = load_png("title_bg_layer2.png", IMG_DIR, 4) self.bg_layer2_rect = self.bg_layer2_img.get_rect() self.bg_layer3_img = load_png("title_bg_layer3.png", IMG_DIR, 4) self.bg_layer3_rect = self.bg_layer3_img.get_rect() self.bg_layer1_x = 0 self.bg_layer2_x = 0 self.bg_layer3_x = 0 # Sprite groups self.texts = pygame.sprite.Group() # Texts self.text_shoplabel = Text(WIN_SZ[0] / 5, 64, "Shop", GAME_FONT, 48, 'white') self.text_coins = Text(WIN_SZ[0] / 1.4, 75, f"C{game_data.coins}", GAME_FONT, 32, 'yellow') self.text_isbought = Text(WIN_SZ[0] / 1.5, 400, "Bought", GAME_FONT, 32, 'white', False) self.text_entbutton = Text(WIN_SZ[0] / 1.5, 360, "[ENT]", GAME_FONT, 32, 'white') self.text_cost = Text(WIN_SZ[0] / 1.5, 400, f"Cost {self.item_cost}", GAME_FONT, 32, 'white', False) self.text_exitbutton = Text(WIN_SZ[0] / 4.2, 400, "[ESC]", GAME_FONT, 32, 'white') self.texts.add(self.text_shoplabel) self.texts.add(self.text_coins) self.texts.add(self.text_isbought) self.texts.add(self.text_cost) self.texts.add(self.text_exitbutton) self.texts.add(self.text_entbutton)
def __init__(self): sfx_enter.play() # Game variables self.score = 0 self.offset = repeat((0,0)) # For screen shake self.offset = shake(10,5) self.cur_ticks = 0 self.timer = 25 * 1000 + self.cur_ticks # n * 1000. Default: n = 20, Debug: n = 5 self.rem_time = round((self.timer-self.cur_ticks) / 1000) self.is_paused = False self.choose_mash_ticks = 0 self.choose_mash_delay = 5000 self.mash_duration = 3000 self.mash_ticks = 0 self.mash_reward = 2 self.selected_letter = "none" self.mash_reward_score = 2 self.get_ready_ticks = 0 self.get_ready_delay = 4000 self.is_ready = False self.play_ready_sfx_ticks = 0 # Sprite groups self.sprites = pygame.sprite.Group() self.key_sprites = pygame.sprite.Group() self.particles = pygame.sprite.Group() self.bubbles = pygame.sprite.Group() self.ready_texts = pygame.sprite.Group() # Images self.img_background = load_png("background.png", IMG_DIR, 8) # Color of the objects self.color = PALETTE["CYAN"] self.color_palette = PALETTE["CYAN_PAL"] # Keys self.K_SIZE = 32 # key size self.letters = ["1234567890-=", "QWERTYUIOP[]", "ASDFGHJKL;'", "ZXCVBNM,./"] self.key_shape = "roundrect" # rect, roundrect, round, arc self.chars = list() load_keys(self.letters, self.sprites, self.key_sprites, self.K_SIZE, self.color, GAME_FONT, self.key_shape) # Texts for the game self.text_readytime = PulsatingText(WIN_SZ[0]/2, 300, "Get Ready", GAME_FONT, 48, self.color) self.text_scorelabel = Text(WIN_SZ[0]/2, 60, "Score", GAME_FONT, 64, self.color) self.text_score = PulsatingText(WIN_SZ[0]/2, 100, self.score, GAME_FONT, 64, self.color) timer_text = f"T{self.rem_time}" self.text_time = PulsatingText(WIN_SZ[0]/2, 200, timer_text, GAME_FONT, 48, PALETTE["WHITE"]) #self.sprites.add(self.text_scorelabel) self.sprites.add(self.text_score) self.sprites.add(self.text_time) self.sprites.add(self.text_readytime) self.ready_texts.add(self.text_readytime) # Texts for the pause screen self.paused_texts = pygame.sprite.Group() txt_paused = Text(WIN_SZ[0]/2, WIN_SZ[1]/2, "PAUSED", GAME_FONT, 48, PALETTE["WHITE"]) txt_resume = Text(WIN_SZ[0]/2, WIN_SZ[1]/1.65, "[ESC] Resume", GAME_FONT, 24, PALETTE["WHITE"]) txt_exit = Text(WIN_SZ[0]/2, WIN_SZ[1]/1.50, "[X] Exit", GAME_FONT, 24, PALETTE["WHITE"]) self.paused_texts.add(txt_paused) self.paused_texts.add(txt_resume) self.paused_texts.add(txt_exit)