Read the score database in MenuState.
This commit is contained in:
7
database.py
Normal file
7
database.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
############################################
|
||||||
|
# Created on 1-13-2013. Miguel Angel Astor #
|
||||||
|
############################################
|
||||||
|
import sqlite3
|
||||||
|
|
||||||
|
scores = sqlite3.connect('db/scores.db')
|
||||||
|
cursor = scores.cursor()
|
BIN
db/scores.db
BIN
db/scores.db
Binary file not shown.
15
intro.py
15
intro.py
@@ -24,14 +24,14 @@ class IntroState(BaseState):
|
|||||||
self.count = 0
|
self.count = 0
|
||||||
self.next_transition = VALID_STATES['STAY']
|
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')
|
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')
|
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')
|
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 = 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.
|
# 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
|
# 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.
|
# in 20 seconds. We divide by 60 to obtain the speed in pixels per frame.
|
||||||
@@ -53,6 +53,16 @@ class IntroState(BaseState):
|
|||||||
self.oneoop_logo.set_position([10 + (image3.get_width() / 2),
|
self.oneoop_logo.set_position([10 + (image3.get_width() / 2),
|
||||||
pygame.display.Info().current_h - 10 - (image3.get_height() / 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:
|
if game.DEBUG:
|
||||||
print "Velocity: " + str(self.sine_movement.get_velocity())
|
print "Velocity: " + str(self.sine_movement.get_velocity())
|
||||||
print "Position: " + str(self.sine_movement.get_position())
|
print "Position: " + str(self.sine_movement.get_position())
|
||||||
@@ -100,5 +110,6 @@ class IntroState(BaseState):
|
|||||||
def render(self, canvas):
|
def render(self, canvas):
|
||||||
canvas.fill(self.background_color)
|
canvas.fill(self.background_color)
|
||||||
self.oneoop_logo.draw(canvas)
|
self.oneoop_logo.draw(canvas)
|
||||||
|
self.text.draw(canvas)
|
||||||
self.submarine.draw(canvas)
|
self.submarine.draw(canvas)
|
||||||
self.particle_system.draw(canvas)
|
self.particle_system.draw(canvas)
|
||||||
|
3
main.py
3
main.py
@@ -9,6 +9,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
android = None
|
android = None
|
||||||
|
|
||||||
|
import database
|
||||||
from game import Game
|
from game import Game
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -18,6 +19,7 @@ def main():
|
|||||||
|
|
||||||
# Init PyGame.
|
# Init PyGame.
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
pygame.font.init()
|
||||||
|
|
||||||
if android:
|
if android:
|
||||||
# Init pgs4a and map Android's back button to PyGame's escape key.
|
# Init pgs4a and map Android's back button to PyGame's escape key.
|
||||||
@@ -38,6 +40,7 @@ def main():
|
|||||||
game.game_loop()
|
game.game_loop()
|
||||||
|
|
||||||
# Cleanly terminate PyGame.
|
# Cleanly terminate PyGame.
|
||||||
|
database.scores.close()
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
|
||||||
# Required by pgs4a.
|
# Required by pgs4a.
|
||||||
|
62
menu.py
62
menu.py
@@ -1,12 +1,15 @@
|
|||||||
############################################
|
###########################################
|
||||||
# Created on 1-7-2013. Miguel Angel Astor #
|
# 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
|
import pygame
|
||||||
try:
|
try:
|
||||||
import android
|
import android
|
||||||
except ImportError:
|
except ImportError:
|
||||||
android = None
|
android = None
|
||||||
|
|
||||||
|
import database
|
||||||
from constants import DEBUG
|
from constants import DEBUG
|
||||||
from imloader import cached_image_loader
|
from imloader import cached_image_loader
|
||||||
from actor import BaseActor
|
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),
|
self.back_button.set_position([self.scoreboard.get_position()[0] + image.get_width() - (image.get_width() // 10),
|
||||||
pygame.display.Info().current_h // 2])
|
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):
|
def input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@@ -85,8 +99,22 @@ class MenuState(BaseState):
|
|||||||
if self.current_menu == MENUS['MAIN']:
|
if self.current_menu == MENUS['MAIN']:
|
||||||
if self.quit_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
if self.quit_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
||||||
self.next_transition = VALID_STATES['QUIT']
|
self.next_transition = VALID_STATES['QUIT']
|
||||||
|
|
||||||
elif self.scr_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
elif self.scr_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
||||||
self.current_menu = MENUS['SCORE']
|
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):
|
elif self.new_button.rect.collidepoint(self.cursor_x, self.cursor_y):
|
||||||
self.current_menu = MENUS['INTRO']
|
self.current_menu = MENUS['INTRO']
|
||||||
|
|
||||||
@@ -114,3 +142,29 @@ class MenuState(BaseState):
|
|||||||
elif self.current_menu == MENUS['SCORE']:
|
elif self.current_menu == MENUS['SCORE']:
|
||||||
self.scoreboard.draw(canvas)
|
self.scoreboard.draw(canvas)
|
||||||
self.back_button.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)
|
||||||
|
Reference in New Issue
Block a user