Assorted scoring related fixes.

This commit is contained in:
2013-01-22 23:45:58 -04:30
parent 5c2254d762
commit 22c0846592
5 changed files with 41 additions and 25 deletions

1
TODO
View File

@@ -2,3 +2,4 @@ Stuff left:
1) Add sound and music.
2) Implement the defeat condition with the enemies.
3) Center the letters in ScoreState and the story labels in MenuState.
4) Add time to player after scoring.

Binary file not shown.

View File

@@ -16,6 +16,7 @@ import player
import background
import imloader
import actor
import database
from state import BaseState, VALID_STATES
class InGameState(BaseState):
@@ -435,6 +436,7 @@ class InGameState(BaseState):
npc.make_invisible()
self.create_explosion(npc.get_position())
player.PLAYERS[1].inc_score_by_one()
self.time_left += 1
# If the npc exploded this turn, remove it.
if not npc.is_visible():
@@ -470,8 +472,10 @@ class InGameState(BaseState):
self.npcs.clear()
player.PLAYERS[1].revive()
if not self.cancel:
# Register scores only if the game ended cleanly.
database.cursor.execute('SELECT * FROM score ORDER BY score ASC')
row = database.cursor.fetchone()
if player.PLAYERS[1].get_score() > row[2]:
self.next_transition = VALID_STATES['SCORE']
else:
self.next_transition = VALID_STATES['MENU']
@@ -508,25 +512,25 @@ class InGameState(BaseState):
# Blit everything to the bacground.
# Sort npcs by Y coordinate and draw.
# The idea is to draw npcs near the bottom edge of the screen last.
#npc_list = list(self.npcs)
#if player.PLAYERS[1].is_alive():
# npc_list.append(self.player)
#sorted(npc_list, key = lambda npc: npc.get_position()[1])
#for npc in npc_list:
# npc.draw(self.game_area)
for npc in self.npcs:
npc.draw(self.game_area)
npc_list = list(self.npcs)
if player.PLAYERS[1].is_alive():
self.player.draw(self.game_area)
npc_list.append(self.player)
npc_list = sorted(npc_list, key = lambda npc: npc.get_position()[1])
for npc in npc_list:
npc.draw(self.game_area)
#for npc in self.npcs:
# npc.draw(self.game_area)
#if player.PLAYERS[1].is_alive():
# self.player.draw(self.game_area)
# Same idea here.
#expl_list = list(self.explosions)
#sorted(expl_list, key = lambda explosion: explosion.get_position()[1])
#for explosion in expl_list:
# explosion.draw(self.game_area)
for explosion in self.explosions:
expl_list = list(self.explosions)
expl_list = sorted(expl_list, key = lambda explosion: explosion.get_position()[1])
for explosion in expl_list:
explosion.draw(self.game_area)
#for explosion in self.explosions:
# explosion.draw(self.game_area)
self.text_box.fill((128, 128, 128))
self.text_box.blit(self.score_text, (5, 5))

18
menu.py
View File

@@ -9,6 +9,7 @@ except ImportError:
android = None
import database
import player
from constants import DEBUG
from imloader import cached_image_loader
from actor import BaseActor
@@ -146,17 +147,22 @@ class MenuState(BaseState):
def reload_scores(self):
# Reload the scores from the database.
for row in database.cursor.execute('SELECT * FROM score ORDER BY _id'):
if row[0] == 1:
database.cursor.execute('SELECT * FROM score ORDER BY _id')
rows = database.cursor.fetchall()
rows = sorted(rows, key = lambda row: row[2], reverse = True)
i = 1
for row in rows:
if i == 1:
self.score_1 = self.font.render("1) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0))
elif row[0] == 2:
elif i == 2:
self.score_2 = self.font.render("2) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0))
elif row[0] == 3:
elif i == 3:
self.score_3 = self.font.render("3) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0))
elif row[0] == 4:
elif i == 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))
i += 1
def input(self):
for event in pygame.event.get():
@@ -182,6 +188,8 @@ class MenuState(BaseState):
if android is None:
pygame.mouse.set_visible(True)
player.PLAYERS[1].reset_score()
if self.next_transition != VALID_STATES['QUIT']:
if self.next_transition != VALID_STATES['STAY']:
# Set next_transition to STAY if the game gets to this state from ScoreState.

View File

@@ -119,10 +119,13 @@ class ScoreState(BaseState):
if self.done_button.is_visible() and self.done_button.test_collision_with_point((self.cursor_x, self.cursor_y)):
# If the user clicked on the done button, insert the score in the database and go to the main menu.
score = (str(self.player_init[0] + self.player_init[1] + self.player_init[2]), player.PLAYERS[1].get_score())
database.cursor.execute('UPDATE score SET player_name = ?, score = ? WHERE _id IN (SELECT _id FROM score WHERE score IN (SELECT MIN(score) FROM score))', score)
database.cursor.execute('SELECT * FROM score ORDER BY score ASC')
row = database.cursor.fetchone()
score = (str(self.player_init[0] + self.player_init[1] + self.player_init[2]),
player.PLAYERS[1].get_score(),
row[0])
database.cursor.execute('UPDATE score SET player_name = ?, score = ? WHERE _id = ?', score)
database.scores.commit()
player.PLAYERS[1].reset_score()
# Don't forget to reset the initials list.
self.player_init = []
self.letter_index = 0