Assorted scoring related fixes.
This commit is contained in:
1
TODO
1
TODO
@@ -2,3 +2,4 @@ Stuff left:
|
|||||||
1) Add sound and music.
|
1) Add sound and music.
|
||||||
2) Implement the defeat condition with the enemies.
|
2) Implement the defeat condition with the enemies.
|
||||||
3) Center the letters in ScoreState and the story labels in MenuState.
|
3) Center the letters in ScoreState and the story labels in MenuState.
|
||||||
|
4) Add time to player after scoring.
|
||||||
|
BIN
db/scores.db
BIN
db/scores.db
Binary file not shown.
38
ingame.py
38
ingame.py
@@ -16,6 +16,7 @@ import player
|
|||||||
import background
|
import background
|
||||||
import imloader
|
import imloader
|
||||||
import actor
|
import actor
|
||||||
|
import database
|
||||||
from state import BaseState, VALID_STATES
|
from state import BaseState, VALID_STATES
|
||||||
|
|
||||||
class InGameState(BaseState):
|
class InGameState(BaseState):
|
||||||
@@ -435,6 +436,7 @@ class InGameState(BaseState):
|
|||||||
npc.make_invisible()
|
npc.make_invisible()
|
||||||
self.create_explosion(npc.get_position())
|
self.create_explosion(npc.get_position())
|
||||||
player.PLAYERS[1].inc_score_by_one()
|
player.PLAYERS[1].inc_score_by_one()
|
||||||
|
self.time_left += 1
|
||||||
|
|
||||||
# If the npc exploded this turn, remove it.
|
# If the npc exploded this turn, remove it.
|
||||||
if not npc.is_visible():
|
if not npc.is_visible():
|
||||||
@@ -470,8 +472,10 @@ class InGameState(BaseState):
|
|||||||
self.npcs.clear()
|
self.npcs.clear()
|
||||||
|
|
||||||
player.PLAYERS[1].revive()
|
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']
|
self.next_transition = VALID_STATES['SCORE']
|
||||||
else:
|
else:
|
||||||
self.next_transition = VALID_STATES['MENU']
|
self.next_transition = VALID_STATES['MENU']
|
||||||
@@ -508,25 +512,25 @@ class InGameState(BaseState):
|
|||||||
# Blit everything to the bacground.
|
# Blit everything to the bacground.
|
||||||
# Sort npcs by Y coordinate and draw.
|
# Sort npcs by Y coordinate and draw.
|
||||||
# The idea is to draw npcs near the bottom edge of the screen last.
|
# The idea is to draw npcs near the bottom edge of the screen last.
|
||||||
#npc_list = list(self.npcs)
|
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)
|
|
||||||
|
|
||||||
if player.PLAYERS[1].is_alive():
|
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.
|
# Same idea here.
|
||||||
#expl_list = list(self.explosions)
|
expl_list = list(self.explosions)
|
||||||
#sorted(expl_list, key = lambda explosion: explosion.get_position()[1])
|
expl_list = sorted(expl_list, key = lambda explosion: explosion.get_position()[1])
|
||||||
#for explosion in expl_list:
|
for explosion in expl_list:
|
||||||
# explosion.draw(self.game_area)
|
|
||||||
for explosion in self.explosions:
|
|
||||||
explosion.draw(self.game_area)
|
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.fill((128, 128, 128))
|
||||||
self.text_box.blit(self.score_text, (5, 5))
|
self.text_box.blit(self.score_text, (5, 5))
|
||||||
|
18
menu.py
18
menu.py
@@ -9,6 +9,7 @@ except ImportError:
|
|||||||
android = None
|
android = None
|
||||||
|
|
||||||
import database
|
import database
|
||||||
|
import player
|
||||||
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
|
||||||
@@ -146,17 +147,22 @@ class MenuState(BaseState):
|
|||||||
|
|
||||||
def reload_scores(self):
|
def reload_scores(self):
|
||||||
# Reload the scores from the database.
|
# Reload the scores from the database.
|
||||||
for row in database.cursor.execute('SELECT * FROM score ORDER BY _id'):
|
database.cursor.execute('SELECT * FROM score ORDER BY _id')
|
||||||
if row[0] == 1:
|
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))
|
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))
|
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))
|
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))
|
self.score_4 = self.font.render("4) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0))
|
||||||
else:
|
else:
|
||||||
self.score_5 = self.font.render("5) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0))
|
self.score_5 = self.font.render("5) " + row[1] + " . . . . . . . . . " + str(max(row[2], 0)), True, (0, 0, 0))
|
||||||
|
i += 1
|
||||||
|
|
||||||
def input(self):
|
def input(self):
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
@@ -182,6 +188,8 @@ class MenuState(BaseState):
|
|||||||
if android is None:
|
if android is None:
|
||||||
pygame.mouse.set_visible(True)
|
pygame.mouse.set_visible(True)
|
||||||
|
|
||||||
|
player.PLAYERS[1].reset_score()
|
||||||
|
|
||||||
if self.next_transition != VALID_STATES['QUIT']:
|
if self.next_transition != VALID_STATES['QUIT']:
|
||||||
if self.next_transition != VALID_STATES['STAY']:
|
if self.next_transition != VALID_STATES['STAY']:
|
||||||
# Set next_transition to STAY if the game gets to this state from ScoreState.
|
# Set next_transition to STAY if the game gets to this state from ScoreState.
|
||||||
|
9
score.py
9
score.py
@@ -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 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.
|
# 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('SELECT * FROM score ORDER BY score ASC')
|
||||||
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)
|
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()
|
database.scores.commit()
|
||||||
player.PLAYERS[1].reset_score()
|
|
||||||
# Don't forget to reset the initials list.
|
# Don't forget to reset the initials list.
|
||||||
self.player_init = []
|
self.player_init = []
|
||||||
self.letter_index = 0
|
self.letter_index = 0
|
||||||
|
Reference in New Issue
Block a user