diff --git a/database.py b/database.py new file mode 100644 index 0000000..aa1464e --- /dev/null +++ b/database.py @@ -0,0 +1,7 @@ +############################################ +# Created on 1-13-2013. Miguel Angel Astor # +############################################ +import sqlite3 + +scores = sqlite3.connect('db/scores.db') +cursor = scores.cursor() diff --git a/db/scores.db b/db/scores.db index ff9aad3..adf54c8 100644 Binary files a/db/scores.db and b/db/scores.db differ diff --git a/intro.py b/intro.py index 4aa3c6d..4a26603 100644 --- a/intro.py +++ b/intro.py @@ -24,14 +24,14 @@ class IntroState(BaseState): self.count = 0 self.next_transition = VALID_STATES['STAY'] - self.screen_vertical_half = pygame.display.Info().current_h / 2 + self.screen_vertical_half = pygame.display.Info().current_h / 3 image = imloader.cached_image_loader.get_image_to_screen_percent('gfx/burbuja.png') image2 = imloader.cached_image_loader.get_image_to_screen_percent('gfx/submarino1.png') image3 = imloader.cached_image_loader.get_image_to_screen_percent('gfx/oneoop.png') self.sine_movement = actor.BulletActor(0, image, "SineMovement", False, True, False) - self.sine_movement.set_position([-(image2.get_width() / 2 + 10), pygame.display.Info().current_h / 2]) + self.sine_movement.set_position([-(image2.get_width() / 2 + 10), pygame.display.Info().current_h / 4]) # The next line calculates the horizontal velocity of sine_movement. # We want it to cover the width of the screen plus the width of the submarine sprite # in 20 seconds. We divide by 60 to obtain the speed in pixels per frame. @@ -52,6 +52,16 @@ class IntroState(BaseState): self.oneoop_logo = actor.BaseActor(2, image3, "1-Oop logo", False, True, False) self.oneoop_logo.set_position([10 + (image3.get_width() / 2), pygame.display.Info().current_h - 10 - (image3.get_height() / 2)]) + + screen_prop = (25.0 / 768.0) + screen_fract = (float(pygame.display.Info().current_h) * screen_prop) / 768.0 + scale_factor = screen_fract / screen_prop + + font = pygame.font.Font('font/PressStart2P/PressStart2P.ttf', int(25.0 * scale_factor)) + text_surf = font.render("1-OOP Presenta", True, (0, 0, 0)) + self.text = actor.BaseActor(2, text_surf, "Text", False, True, False) + self.text.set_position([self.oneoop_logo.get_position()[0] + image3.get_width() + (text_surf.get_width() // 2) + 10, + pygame.display.Info().current_h - 10 - (image3.get_height() / 2)]) if game.DEBUG: print "Velocity: " + str(self.sine_movement.get_velocity()) @@ -100,5 +110,6 @@ class IntroState(BaseState): def render(self, canvas): canvas.fill(self.background_color) self.oneoop_logo.draw(canvas) + self.text.draw(canvas) self.submarine.draw(canvas) self.particle_system.draw(canvas) diff --git a/main.py b/main.py index 8cf1497..ca0aa40 100755 --- a/main.py +++ b/main.py @@ -9,6 +9,7 @@ try: except ImportError: android = None +import database from game import Game def main(): @@ -18,6 +19,7 @@ def main(): # Init PyGame. pygame.init() + pygame.font.init() if android: # Init pgs4a and map Android's back button to PyGame's escape key. @@ -38,6 +40,7 @@ def main(): game.game_loop() # Cleanly terminate PyGame. + database.scores.close() pygame.quit() # Required by pgs4a. diff --git a/menu.py b/menu.py index 817bf68..754b408 100644 --- a/menu.py +++ b/menu.py @@ -1,12 +1,15 @@ -############################################ +########################################### # 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 except ImportError: android = None +import database from constants import DEBUG from imloader import cached_image_loader from actor import BaseActor @@ -57,9 +60,20 @@ 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]) - # Load story screen sprites. + screen_prop = (42.0 / 768.0) + screen_fract = (float(pygame.display.Info().current_h) * screen_prop) / 768.0 + scale_factor = screen_fract / screen_prop - # Add sound support. + self.font = pygame.font.Font('font/ProfaisalEliteRiqa/Profaisal-EliteRiqaV1.0.ttf', int(42.0 * scale_factor)) + self.score_1 = None + self.score_2 = None + self.score_3 = None + self.score_4 = None + self.score_5 = None + + self.score_text_x = int(float(image.get_width()) * 0.183) + self.scoreboard.rect.left + 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) def input(self): for event in pygame.event.get(): @@ -85,8 +99,22 @@ class MenuState(BaseState): if self.current_menu == MENUS['MAIN']: if self.quit_button.rect.collidepoint(self.cursor_x, self.cursor_y): self.next_transition = VALID_STATES['QUIT'] + elif self.scr_button.rect.collidepoint(self.cursor_x, self.cursor_y): self.current_menu = MENUS['SCORE'] + # Reload the scores from the database. + for row in database.scores.execute('SELECT * FROM score ORDER BY _id'): + if row[0] == 1: + self.score_1 = self.font.render("1) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0)) + elif row[0] == 2: + self.score_2 = self.font.render("2) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0)) + elif row[0] == 3: + self.score_3 = self.font.render("3) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0)) + elif row[0] == 4: + 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): self.current_menu = MENUS['INTRO'] @@ -114,3 +142,29 @@ class MenuState(BaseState): elif self.current_menu == MENUS['SCORE']: self.scoreboard.draw(canvas) self.back_button.draw(canvas) + + if self.score_1 is not None: + rect = self.score_1.get_rect() + rect.top = self.score_text_1_y + rect.left = self.score_text_x + canvas.blit(self.score_1, rect) + if self.score_2 is not None: + rect = self.score_2.get_rect() + rect.top = self.score_text_1_y + self.score_text_inc + rect.left = self.score_text_x + canvas.blit(self.score_2, rect) + if self.score_3 is not None: + rect = self.score_3.get_rect() + rect.top = self.score_text_1_y + (2 * self.score_text_inc) + rect.left = self.score_text_x + canvas.blit(self.score_3, rect) + if self.score_4 is not None: + rect = self.score_4.get_rect() + rect.top = self.score_text_1_y + (3 * self.score_text_inc) + rect.left = self.score_text_x + canvas.blit(self.score_4, rect) + if self.score_5 is not None: + rect = self.score_5.get_rect() + rect.top = self.score_text_1_y + (4 * self.score_text_inc) + rect.left = self.score_text_x + canvas.blit(self.score_5, rect)