diff --git a/gfx/ForeverAlone/Idle_Front_face_hidden.png b/gfx/ForeverAlone/Idle_Front_face_hidden.png new file mode 100644 index 0000000..9604cff Binary files /dev/null and b/gfx/ForeverAlone/Idle_Front_face_hidden.png differ diff --git a/menu.py b/menu.py index 754b408..7030c4f 100644 --- a/menu.py +++ b/menu.py @@ -1,8 +1,7 @@ +# -*- coding: latin-1 -*- ########################################### # Created on 1-7-2013. Miguel Angel Astor # ########################################### -# Update score database: -# UPDATE score SET player_name = ?, score = ? WHERE _id IN (SELECT _id FROM score WHERE score IN (SELECT MIN(score) FROM score)) import pygame try: import android @@ -23,8 +22,8 @@ class MenuState(BaseState): self.next_transition = VALID_STATES['STAY'] self.current_menu = MENUS['MAIN'] - self.intro_time = 0 - self.intro_max_time = 5000 # Miliseconds. + self.story_time = 0 + self.story_timeout = 7000 # 7 seconds. self.then = 0 self.cursor_x = 0 @@ -60,21 +59,89 @@ class MenuState(BaseState): self.back_button.set_position([self.scoreboard.get_position()[0] + image.get_width() - (image.get_width() // 10), pygame.display.Info().current_h // 2]) - screen_prop = (42.0 / 768.0) + font_size = 42 + screen_prop = (float(font_size) / 768.0) screen_fract = (float(pygame.display.Info().current_h) * screen_prop) / 768.0 scale_factor = screen_fract / screen_prop + self.font = pygame.font.Font('font/ProfaisalEliteRiqa/Profaisal-EliteRiqaV1.0.ttf', int(font_size * scale_factor)) - self.font = pygame.font.Font('font/ProfaisalEliteRiqa/Profaisal-EliteRiqaV1.0.ttf', int(42.0 * scale_factor)) + # Score labels. self.score_1 = None self.score_2 = None self.score_3 = None self.score_4 = None self.score_5 = None + + # Story labels. + font_size = 22 + screen_prop = (float(font_size) / 768.0) + screen_fract = (float(pygame.display.Info().current_h) * screen_prop) / 768.0 + scale_factor = screen_fract / screen_prop + font_small = pygame.font.Font('font/ProfaisalEliteRiqa/Profaisal-EliteRiqaV1.0.ttf', int(font_size * scale_factor)) + + self.story_1 = font_small.render("Este es Moncho, nuestro heroe...", True, (0, 0, 0)) + self.story_2 = font_small.render("Moncho ama a toda la gente, gente como esta...", True, (0, 0, 0)) + self.story_3 = font_small.render("Ama tanto a la gente que solo quiere abrazarlos...", True, (0, 0, 0)) + self.story_5 = font_small.render("Aunque, tal vez Moncho no ame a TODA la gente...", True, (0, 0, 0)) + + font_size = 35 + screen_prop = (float(font_size) / 768.0) + screen_fract = (float(pygame.display.Info().current_h) * screen_prop) / 768.0 + scale_factor = screen_fract / screen_prop + font_big = pygame.font.Font('font/ProfaisalEliteRiqa/Profaisal-EliteRiqaV1.0.ttf', int(font_size * scale_factor)) + + self.story_4 = font_big.render("ĦĦĦABRAZARLOS HASTA QUE EXPLOTEN!!!", True, (255, 0, 0)) - self.score_text_x = int(float(image.get_width()) * 0.183) + self.scoreboard.rect.left + self.interrogation = font_big.render("?", True, (0, 0, 0)) + + self.player_label_1 = cached_image_loader.get_image_to_screen_percent('gfx/Player/player_idle_front.png') + self.player_label_2 = cached_image_loader.get_image_to_screen_percent('gfx/Player/player_idle_front_HUG.png') + + self.he_huggable_1 = cached_image_loader.get_image_to_screen_percent('gfx/HeHuggable/Idle_front.png') + self.he_huggable_2 = cached_image_loader.get_image_to_screen_percent('gfx/HeHuggable/Walking_front_1_scared.png') + + self.she_huggable_1 = cached_image_loader.get_image_to_screen_percent('gfx/SheHuggable/Idle_front.png') + self.she_huggable_2 = cached_image_loader.get_image_to_screen_percent('gfx/SheHuggable/Walking_front_2_scared.png') + + self.explosion = cached_image_loader.get_image_to_screen_percent('gfx/Explosion2.png') + self.mystery_guy = cached_image_loader.get_image_to_screen_percent('gfx/ForeverAlone/Idle_Front_face_hidden.png') + + self.score_text_x = int(float(image.get_width()) * 0.183) + self.scoreboard.rect.left # image holds the scoreboard graphic. self.score_text_1_y = int(float(image.get_height()) * 0.300) + self.scoreboard.rect.top self.score_text_inc = int(float(image.get_height()) * 0.112) + self.story_1_x = int((float(pygame.display.Info().current_w) * 177.0 ) / 1024.0) + self.story_1_y = int((float(pygame.display.Info().current_h) * 109.0 ) / 768.0) + self.story_2_x = int((float(pygame.display.Info().current_w) * 211.0 ) / 1024.0) + self.story_2_y = int((float(pygame.display.Info().current_h) * 223.0 ) / 768.0) + self.story_3_x = int((float(pygame.display.Info().current_w) * 240.0 ) / 1024.0) + self.story_3_y = int((float(pygame.display.Info().current_h) * 346.0 ) / 768.0) + self.story_4_x = int((float(pygame.display.Info().current_w) * 38.0 ) / 1024.0) + self.story_4_y = int((float(pygame.display.Info().current_h) * 517.0 ) / 768.0) + self.story_5_x = int((float(pygame.display.Info().current_w) * 244.0 ) / 1024.0) + self.story_5_y = int((float(pygame.display.Info().current_h) * 710.0 ) / 768.0) + self.interr_x = int((float(pygame.display.Info().current_w) * 173.0 ) / 1024.0) + self.interr_y = int((float(pygame.display.Info().current_h) * 650.0 ) / 768.0) + + self.moncho_1_x = int((float(pygame.display.Info().current_w) * 49.0 ) / 1024.0) + self.moncho_1_y = int((float(pygame.display.Info().current_h) * 49.0 ) / 768.0) + self.moncho_2_x = int((float(pygame.display.Info().current_w) * 98.0 ) / 1024.0) + self.moncho_2_y = int((float(pygame.display.Info().current_h) * 293.0 ) / 768.0) + self.hug_male_1_x = int((float(pygame.display.Info().current_w) * 834.0 ) / 1024.0) + self.hug_male_1_y = int((float(pygame.display.Info().current_h) * 193.0 ) / 768.0) + self.hug_male_2_x = int((float(pygame.display.Info().current_w) * 702.0 ) / 1024.0) + self.hug_male_2_y = int((float(pygame.display.Info().current_h) * 495.0 ) / 768.0) + self.hug_female_1_x = int((float(pygame.display.Info().current_w) * 738.0 ) / 1024.0) + self.hug_female_1_y = int((float(pygame.display.Info().current_h) * 184.0 ) / 768.0) + self.hug_female_2_x = int((float(pygame.display.Info().current_w) * 797.0 ) / 1024.0) + self.hug_female_2_y = int((float(pygame.display.Info().current_h) * 457.0 ) / 768.0) + self.explosion_x = int((float(pygame.display.Info().current_w) * 705.0 ) / 1024.0) + self.explosion_y = int((float(pygame.display.Info().current_h) * 428.0 ) / 768.0) + self.mystery_x = int((float(pygame.display.Info().current_w) * 117.0 ) / 1024.0) + self.mystery_y = int((float(pygame.display.Info().current_h) * 706.0 ) / 768.0) + + self.user_click = False + def input(self): for event in pygame.event.get(): if android: @@ -84,12 +151,16 @@ class MenuState(BaseState): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.next_transition = VALID_STATES['QUIT'] + if self.current_menu == MENUS['INTRO']: + self.user_click = True if event.type == pygame.QUIT: self.next_transition = VALID_STATES['QUIT'] # Catch the position of a mouse click (or tap). if event.type == pygame.MOUSEBUTTONDOWN: (self.cursor_x, self.cursor_y) = event.pos + if self.current_menu == MENUS['INTRO']: + self.user_click = True def update(self): if android is None: @@ -97,10 +168,12 @@ class MenuState(BaseState): if self.next_transition != VALID_STATES['QUIT']: if self.current_menu == MENUS['MAIN']: + # Check for mouse (tap) collisions with the main menu buttons. if self.quit_button.rect.collidepoint(self.cursor_x, self.cursor_y): + # Collision with the quit button. self.next_transition = VALID_STATES['QUIT'] - elif self.scr_button.rect.collidepoint(self.cursor_x, self.cursor_y): + # Collision with the high scores button. self.current_menu = MENUS['SCORE'] # Reload the scores from the database. for row in database.scores.execute('SELECT * FROM score ORDER BY _id'): @@ -114,17 +187,32 @@ class MenuState(BaseState): self.score_4 = self.font.render("4) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0)) else: self.score_5 = self.font.render("5) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0)) - elif self.new_button.rect.collidepoint(self.cursor_x, self.cursor_y): + # Collision with the new game button. self.current_menu = MENUS['INTRO'] - + self.then = pygame.time.get_ticks() elif self.current_menu == MENUS['SCORE']: + # Check for mouse (tap) collisions with the high scores menu buttons. if self.back_button.rect.collidepoint(self.cursor_x, self.cursor_y): + # Collision with the go back button. self.current_menu = MENUS['MAIN'] - elif self.current_menu == MENUS['INTRO']: - pass + # Wait for a timeout before going to the game. + now = pygame.time.get_ticks() + delta_t = now - self.then + self.story_time += delta_t + if self.user_click: + # If the user taps or presses a key before the timeout, go to the game. + self.next_transition = VALID_STATES['IN_GAME'] + elif self.story_time >= self.story_timeout: + # After the timeout, reset the time counter and go to the game. + self.story_time = 0 + self.next_transition = VALID_STATES['IN_GAME'] + else: + # Keep tracking time. + self.then = now + # Recenter the mouse pointer. self.cursor_x = 0 self.cursor_y = 0 @@ -168,3 +256,74 @@ class MenuState(BaseState): rect.top = self.score_text_1_y + (4 * self.score_text_inc) rect.left = self.score_text_x canvas.blit(self.score_5, rect) + + elif self.current_menu == MENUS['INTRO']: + rect = self.story_1.get_rect() + rect.top = self.story_1_y + rect.left = self.story_1_x + canvas.blit(self.story_1, rect) + + rect = self.story_2.get_rect() + rect.top = self.story_2_y + rect.left = self.story_2_x + canvas.blit(self.story_2, rect) + + rect = self.story_3.get_rect() + rect.top = self.story_3_y + rect.left = self.story_3_x + canvas.blit(self.story_3, rect) + + rect = self.story_4.get_rect() + rect.top = self.story_4_y + rect.left = self.story_4_x + canvas.blit(self.story_4, rect) + + rect = self.story_5.get_rect() + rect.top = self.story_5_y + rect.left = self.story_5_x + canvas.blit(self.story_5, rect) + + rect = self.player_label_1.get_rect() + rect.top = self.moncho_1_y + rect.left = self.moncho_1_x + canvas.blit(self.player_label_1, rect) + + rect = self.player_label_2.get_rect() + rect.top = self.moncho_2_y + rect.left = self.moncho_2_x + canvas.blit(self.player_label_2, rect) + + rect = self.she_huggable_1.get_rect() + rect.top = self.hug_female_1_y + rect.left = self.hug_female_1_x + canvas.blit(self.she_huggable_1, rect) + + rect = self.he_huggable_1.get_rect() + rect.top = self.hug_male_1_y + rect.left = self.hug_male_1_x + canvas.blit(self.he_huggable_1, rect) + + rect = self.explosion.get_rect() + rect.top = self.explosion_y + rect.left = self.explosion_x + canvas.blit(self.explosion, rect) + + rect = self.she_huggable_2.get_rect() + rect.top = self.hug_female_2_y + rect.left = self.hug_female_2_x + canvas.blit(self.she_huggable_2, rect) + + rect = self.he_huggable_2.get_rect() + rect.top = self.hug_male_2_y + rect.left = self.hug_male_2_x + canvas.blit(self.he_huggable_2, rect) + + rect = self.mystery_guy.get_rect() + rect.top = self.mystery_y + rect.left = self.mystery_x + canvas.blit(self.mystery_guy, rect) + + rect = self.interrogation.get_rect() + rect.top = self.interr_y + rect.left = self.interr_x + canvas.blit(self.interrogation, rect) diff --git a/score.py b/score.py index 5651d7b..da6e8e6 100644 --- a/score.py +++ b/score.py @@ -1,5 +1,8 @@ -# Miguel Angel Astor Romero. Created on 7-1-2013. # -################################################### +########################################### +# Created on 1-7-2013. Miguel Angel Astor # +########################################### +# Update score database: +# UPDATE score SET player_name = ?, score = ? WHERE _id IN (SELECT _id FROM score WHERE score IN (SELECT MIN(score) FROM score)) import pygame try: