diff -ruN a/lib/animation.py b/lib/animation.py --- a/lib/animation.py +++ b/lib/animation.py @@ -85,7 +85,7 @@ self.finished = True else: self.i = 0 - if Animation.cached_frames.has_key(self.cache_name + str(self.i)): + if self.cache_name + str(self.i) in Animation.cached_frames: self.image = Animation.cached_frames[self.cache_name + str(self.i)] else: self.image = (self.frames[self.i]).get_image() diff -ruN a/lib/blob.py b/lib/blob.py --- a/lib/blob.py +++ b/lib/blob.py @@ -5,14 +5,14 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from object import DynamicObject -from sound import play_sound -from animation import Animation -from particle import Particle +from .object import DynamicObject +from .sound import play_sound +from .animation import Animation +from .particle import Particle class Blob(DynamicObject): diff -ruN a/lib/game.py b/lib/game.py --- a/lib/game.py +++ b/lib/game.py @@ -4,21 +4,22 @@ import pygame from pygame.locals import * +import asyncio import os import random -from locals import * -from player import Player -from spider import Spider -from particle import Particle -from level import Level -from sound import play_sound -from util import * -from variables import variables -from log import error_message -from trigger import Trigger -from visibleobject import flip_direction_from_position -import data +from .locals import * +from .player import Player +from .spider import Spider +from .particle import Particle +from .level import Level +from .sound import play_sound +from .util import * +from .variables import variables +from .log import error_message +from .trigger import Trigger +from .visibleobject import flip_direction_from_position +from . import data # Fix this ugly hack @@ -124,7 +125,7 @@ return inputs -def run(screen, level_name="w0-l0", score_mod=0, score=None, joystick=None): +async def run(screen, level_name="w0-l0", score_mod=0, score=None, joystick=None): done = False objects = [] particles = [] @@ -205,7 +206,7 @@ trigger = None if scripted_event_on: - if inputs.has_key("JUMP") or inputs.has_key("DOWN"): + if "JUMP" in inputs or "DOWN" in inputs: cleared = True moved = False @@ -395,7 +396,7 @@ player.orientation = current_scripted_event_element.orientation current_scripted_event_element.finished = True elif current_scripted_event_element.event_type == "change_level": - score.score += (5 + score_mod) * ((player.life + 4) / 5 + 12) + score.score += (5 + score_mod) * ((player.life + 4) // 5 + 12) score.levels += 1 current_scripted_event_element.finished = True if player.current_animation != "gone": @@ -434,6 +435,7 @@ pygame.display.flip() clock.tick(FPS) + await asyncio.sleep(0) #Main game loop finished diff -ruN a/lib/level.py b/lib/level.py --- a/lib/level.py +++ b/lib/level.py @@ -1,7 +1,8 @@ import os import codecs -import pytmx +import xml.etree.ElementTree as ET + import pygame from pygame.locals import * @@ -39,6 +40,27 @@ raise UnknownTileException(path) +def load_tmx(path): + """ + Minimal reader for the Tiled maps of this game (one CSV tile layer and one external + tileset of single-image tiles), in place of the pytmx library the original used. + Returns the tileset name and a list of (x, y, tile type). + """ + tmx = ET.parse(path).getroot() + tileset = tmx.find('tileset') + firstgid = int(tileset.get('firstgid')) + tsx = ET.parse(os.path.join(os.path.dirname(path), tileset.get('source'))).getroot() + sources = {int(t.get('id')) + firstgid: t.find('image').get('source') for t in tsx.findall('tile')} + layer = tmx.find('layer') + width = int(layer.get('width')) + gids = [int(g) for g in layer.find('data').text.replace('\n', '').split(',') if g.strip()] + tiles = [] + for i, gid in enumerate(gids): + if gid: + tiles.append((i % width, i // width, get_tile_type(sources[gid]))) + return tsx.get('name'), tiles + + class Level: def __init__(self, screen, character, level_name="w0-l0"): self.screen = screen @@ -116,11 +138,10 @@ # Parse a TMX path = filepath(line.split(None, 1)[1].strip()) - tmx = pytmx.pytmx.TiledMap(path) - for x, y, image in tmx.layers[0].tiles(): - tile_type = get_tile_type(image[0]) + tileset_name, tmx_tiles = load_tmx(path) + for x, y, tile_type in tmx_tiles: self.add_tile(tile_type, (x, y)) - self.set = tmx.tilesets[0].name + self.set = tileset_name continue @@ -154,8 +175,8 @@ self.bg_animations["default"] = Animation(self.set + "_background", "static") self.current_animation = "default" self.rect = (self.bg_animations[self.current_animation].update_and_get_image()).get_rect() - self.rect.centerx = SCREEN_WIDTH / 2 - self.rect.centery = SCREEN_HEIGHT / 2 + self.rect.centerx = SCREEN_WIDTH // 2 + self.rect.centery = SCREEN_HEIGHT // 2 self.reset_active_tiles() return @@ -340,8 +361,8 @@ the area currently visible. """ for t in self.active_tiles: - if t.rect.collidepoint(coords[0] * TILE_DIM + TILE_DIM / 2, - coords[1]*TILE_DIM + TILE_DIM / 2): + if t.rect.collidepoint(coords[0] * TILE_DIM + TILE_DIM // 2, + coords[1]*TILE_DIM + TILE_DIM // 2): self.active_tiles.remove(t) self.tiles.remove(t) self.edited = True diff -ruN a/lib/locals.py b/lib/locals.py --- a/lib/locals.py +++ b/lib/locals.py @@ -2,7 +2,7 @@ GAME_NAME_SHORT = "wwiu2" -MULTIPLIER = float(raw_input('Enter a resolution multiplier (1): ') or 1) +MULTIPLIER = 1.0 MULT = lambda x: x.__class__(x * MULTIPLIER) SCREEN_WIDTH = MULT(520) @@ -21,8 +21,8 @@ TILE_DIM = MULT(40) -PLAY_AREA_CENTER_X = (-FULL_TILES_HOR / 2 + TILES_HOR) * TILE_DIM -PLAY_AREA_CENTER_Y = (-FULL_TILES_VER / 2 + TILES_VER) * TILE_DIM +PLAY_AREA_CENTER_X = (-FULL_TILES_HOR // 2 + TILES_HOR) * TILE_DIM +PLAY_AREA_CENTER_Y = (-FULL_TILES_VER // 2 + TILES_VER) * TILE_DIM GRAVITY = MULT(1.0) GRAVITY_PARTICLE = MULT(0.5) @@ -112,14 +112,13 @@ TOTAL_LEVELS = 7 -MENU_QUIT = -6 -MENU_SOUND = -5 -MENU_DIALOGUE = -4 -MENU_FULLSCREEN = -3 -MENU_CHARACTER = -2 -MENU_WORLD = -1 +# The menu items before the level list: Quit, Sound, Dialogue (the original also had +# fullscreen, character and world choices, left out of this web version) +MENU_QUIT = -3 +MENU_SOUND = -2 +MENU_DIALOGUE = -1 -MENU_OFFSET = 6 +MENU_OFFSET = 3 MENU_MAX_VISIBLE = 7 @@ -131,7 +130,8 @@ FADE_STATE_NONE = 0 #World names must also correspond to the text file names in the levels directory (.txt is added) -WORLDS = ["Quest For The Keys", "The Other Side", "A Piece of Cake"] +# The other two worlds of the original lack some of their pictures in this version of the game +WORLDS = ["Quest For The Keys"] CHARACTERS = [('Guy', 'guy'), ('Dude', 'guy')] #How many old log lines are kept in the log file when the log is updated diff -ruN a/lib/log.py b/lib/log.py --- a/lib/log.py +++ b/lib/log.py @@ -16,7 +16,7 @@ """Add a message to the message log, which can be written on disk later.""" #Multiple messages of the same type aren't added to the log: - if variables.vdict.has_key("last_log_message"): + if "last_log_message" in variables.vdict: if string == variables["last_log_message"]: return diff -ruN a/lib/main.py b/lib/main.py --- a/lib/main.py +++ b/lib/main.py @@ -5,6 +5,7 @@ The actual gameplay code is in game.py. """ +import asyncio import os import sys @@ -22,7 +23,7 @@ from .sound import play_sound -def main(): +async def main(): # Parsing level from parameters and parsing main config: parse_config() @@ -67,7 +68,6 @@ caption = caption + " - developer mode" pygame.display.set_caption(caption) - apply_fullscreen_setting(screen) if (pygame.joystick.get_count() > 0): joystick = pygame.joystick.Joystick(0) @@ -97,12 +97,12 @@ while not done: if end_trigger == END_NEXT_LEVEL: if user_supplied_level: - end_trigger = game.run(screen, level_name, world.level_index, score, joystick) + end_trigger = await game.run(screen, level_name, world.level_index, score, joystick) if end_trigger == END_NEXT_LEVEL: user_supplied_level = False end_trigger = END_WIN else: - end_trigger = game.run(screen, level_name, world.level_index, score, joystick) + end_trigger = await game.run(screen, level_name, world.level_index, score, joystick) if end_trigger == END_NEXT_LEVEL: if world.is_next_level(): level_name = world.get_level() @@ -123,8 +123,11 @@ menu_choice = 0 bgscreen = screen.copy() elif end_trigger == END_QUIT or end_trigger == END_HARD_QUIT: - done = True + # There is nothing to quit to on a web page: back to the menu + end_trigger = END_MENU + continue elif end_trigger == END_MENU: + write_config() prev_score = score.score prev_time = score.time prev_levels = score.levels @@ -133,7 +136,7 @@ menu = Mainmenu(screen, prev_score, world, bgscreen, prev_time, prev_levels) else: menu = Mainmenu(screen, None, world, bgscreen) - menu_choice = menu.run(menu_choice) + menu_choice = await menu.run(menu_choice) if menu_choice == MENU_QUIT: end_trigger = END_QUIT elif menu_choice == MENU_SOUND: @@ -142,22 +145,6 @@ elif menu_choice == MENU_DIALOGUE: variables["dialogue"] = not variables["dialogue"] end_trigger = END_MENU - elif menu_choice == MENU_FULLSCREEN: - variables["fullscreen"] = not variables["fullscreen"] - end_trigger = END_MENU - apply_fullscreen_setting(screen) - elif menu_choice == MENU_CHARACTER: - cur_char = variables['character'] + 1 - if cur_char >= len(CHARACTERS): - cur_char = 0 - variables['character'] = cur_char - end_trigger = END_MENU - elif menu_choice == MENU_WORLD: - world_index += 1 - if world_index >= len(WORLDS): - world_index = 0 - world = World(world_index) - end_trigger = END_MENU else: level_name = world.get_level(menu_choice) end_trigger = END_NEXT_LEVEL diff -ruN a/lib/mainmenu.py b/lib/mainmenu.py --- a/lib/mainmenu.py +++ b/lib/mainmenu.py @@ -3,14 +3,14 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from util import Util, Score, render_text, bool_to_str -from variables import variables -from level import Level -from menu import Menu +from .util import Util, Score, render_text, bool_to_str +from .variables import variables +from .level import Level +from .menu import Menu class Mainmenu: @@ -26,17 +26,14 @@ self.world = world return - def run(self, menu_choice=0): + async def run(self, menu_choice=0): done = False #Static menu part menu_items = ["Quit", "Sound: " + bool_to_str(variables["sound"]), - "Dialogue: " + bool_to_str(variables["dialogue"]), - "Fullscreen mode: " + bool_to_str(variables["fullscreen"]), - 'Choose character: %s' % CHARACTERS[variables['character']][0], - "Choose world: " + str(self.world.number) + "Dialogue: " + bool_to_str(variables["dialogue"]) ] #Adds levels to the menu @@ -79,19 +76,19 @@ menu_image = render_text("World " + str(self.world.number) + ": " + self.world.name, COLOR_GUI) rect = menu_image.get_rect() - rect.centerx = SCREEN_WIDTH / 2 + rect.centerx = SCREEN_WIDTH // 2 rect.top = GUI_MENU_TOP - 75 self.bgscreen.blit(menu_image, rect) menu_image = render_text(score_text, COLOR_GUI) rect = menu_image.get_rect() - rect.centerx = SCREEN_WIDTH / 2 + rect.centerx = SCREEN_WIDTH // 2 rect.top = GUI_MENU_TOP - 50 self.bgscreen.blit(menu_image, rect) menu_image = render_text(time_text, COLOR_GUI) rect = menu_image.get_rect() - rect.centerx = SCREEN_WIDTH / 2 + rect.centerx = SCREEN_WIDTH // 2 rect.top = GUI_MENU_TOP - 30 self.bgscreen.blit(menu_image, rect) @@ -99,7 +96,7 @@ menu = Menu(self.screen, menu_items, self.bgscreen, "Which way is up?") - menu_choice = menu.run(menu_choice + MENU_OFFSET) + menu_choice = await menu.run(menu_choice + MENU_OFFSET) #Quit (-3) gets special treatment, because it's returned as a constant when the player presses ESC #If offset would be applied to it, it would turn up -6 diff -ruN a/lib/menu.py b/lib/menu.py --- a/lib/menu.py +++ b/lib/menu.py @@ -31,16 +31,17 @@ import pygame import os +import asyncio from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from util import Util, render_text -from variables import variables +from .util import Util, render_text +from .variables import variables -from sound import play_sound +from .sound import play_sound class Menu: @@ -53,7 +54,7 @@ self.heading_text = heading_text return - def run(self, menu_choice = 0): + async def run(self, menu_choice = 0): done = False clock = pygame.time.Clock() @@ -91,14 +92,14 @@ menu_bg = pygame.image.load(data.picpath("menu", "bg")).convert_alpha() rect = menu_bg.get_rect() - rect.centerx = SCREEN_WIDTH / 2 + rect.centerx = SCREEN_WIDTH // 2 rect.top = GUI_MENU_TOP self.screen.blit(menu_bg, rect) if self.heading_text != None: menu_head = render_text(self.heading_text) rect = menu_head.get_rect() - rect.centerx = SCREEN_WIDTH / 2 + rect.centerx = SCREEN_WIDTH // 2 rect.top = GUI_MENU_TOP + 50 + menu_offset self.screen.blit(menu_head, rect) @@ -120,7 +121,7 @@ else: menu_image = render_text(m, COLOR_GUI) rect = menu_image.get_rect() - rect.centerx = SCREEN_WIDTH / 2 + rect.centerx = SCREEN_WIDTH // 2 rect.top = GUI_MENU_TOP + 60 + (menu_visible + 1) * 20 + menu_offset self.screen.blit(menu_image, rect) current_menu_index += 1 @@ -131,5 +132,6 @@ pygame.display.flip() clock.tick(FPS) + await asyncio.sleep(0) return menu_choice diff -ruN a/lib/object.py b/lib/object.py --- a/lib/object.py +++ b/lib/object.py @@ -9,16 +9,16 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from variables import variables -from particle import Particle -from visibleobject import VisibleObject, screen_coords_to_tile_coords +from .variables import variables +from .particle import Particle +from .visibleobject import VisibleObject, screen_coords_to_tile_coords -from sound import play_sound -from log import log_message +from .sound import play_sound +from .log import log_message class DynamicObject(VisibleObject): @@ -34,7 +34,7 @@ self.initial_y = y self.gravity = gravity self.colliding = colliding - self.active = (self.x + self.rect.width / 2 > 0) and (self.y + self.rect.height / 2 > 0) + self.active = (self.x + self.rect.width // 2 > 0) and (self.y + self.rect.height // 2 > 0) self.on_ground = False @@ -75,7 +75,7 @@ VisibleObject.update(self) if self.flip_finished and self.itemclass != "player": - self.active = (self.x + self.rect.width / 2 > 0) and (self.y + self.rect.height / 2 > 0) + self.active = (self.x + self.rect.width // 2 > 0) and (self.y + self.rect.height // 2 > 0) if self.flipping or not self.active: return @@ -112,18 +112,18 @@ self.on_ground = False - if self.x < 0 + self.rect.width / 2: - self.x = 0 + self.rect.width / 2 + if self.x < 0 + self.rect.width // 2: + self.x = 0 + self.rect.width // 2 self.dx = 0 collision_type = 0 - if self.x > PLAY_AREA_WIDTH - self.rect.width / 2: - self.x = PLAY_AREA_WIDTH - self.rect.width / 2 + if self.x > PLAY_AREA_WIDTH - self.rect.width // 2: + self.x = PLAY_AREA_WIDTH - self.rect.width // 2 self.dx = 0 collision_type = 0 - if self.y > PLAY_AREA_HEIGHT - self.rect.height / 2: - self.y = PLAY_AREA_HEIGHT - self.rect.height / 2 + if self.y > PLAY_AREA_HEIGHT - self.rect.height // 2: + self.y = PLAY_AREA_HEIGHT - self.rect.height // 2 self.dy = 0 self.on_ground = True collision_type = 0 diff -ruN a/lib/particle.py b/lib/particle.py --- a/lib/particle.py +++ b/lib/particle.py @@ -7,9 +7,9 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data class Particle: def __init__(self, screen, life = 30, x = None, y = None, dx = None, dy = None, random_move = 0, color = COLOR_DUST, radius = 3, gravity = False): @@ -28,9 +28,9 @@ self.radius = radius self.gravity = gravity if (self.x == None): - self.x = SCREEN_WIDTH / 2 + self.x = SCREEN_WIDTH // 2 if (self.y == None): - self.y = SCREEN_HEIGHT / 2 + self.y = SCREEN_HEIGHT // 2 if (self.dx == None): self.dx = 0.0 if (self.dy == None): diff -ruN a/lib/player.py b/lib/player.py --- a/lib/player.py +++ b/lib/player.py @@ -6,14 +6,14 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from object import DynamicObject -from sound import play_sound -from animation import Animation -from log import log_message +from .object import DynamicObject +from .sound import play_sound +from .animation import Animation +from .log import log_message class Player(DynamicObject): @@ -77,7 +77,7 @@ blood = [] - if collision_type > 0: + if collision_type is not None and collision_type > 0: blood = self.take_damage(collision_type) if self.current_animation != "dying": self.dy -= collision_type*PLAYER_JUMP_ACC / 4.5 diff -ruN a/lib/projectile.py b/lib/projectile.py --- a/lib/projectile.py +++ b/lib/projectile.py @@ -5,13 +5,13 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from object import DynamicObject -from sound import play_sound -from animation import Animation +from .object import DynamicObject +from .sound import play_sound +from .animation import Animation class Projectile(DynamicObject): diff -ruN a/lib/scripted_event.py b/lib/scripted_event.py --- a/lib/scripted_event.py +++ b/lib/scripted_event.py @@ -3,15 +3,15 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from util import dir_from_str +from .util import dir_from_str -from log import log_message +from .log import log_message -from variables import variables +from .variables import variables class Scripted_event_element: def __init__(self, event_type, text="", orientation=RIGHT, animation=""): diff -ruN a/lib/spider.py b/lib/spider.py --- a/lib/spider.py +++ b/lib/spider.py @@ -4,18 +4,18 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from object import DynamicObject -from sound import play_sound -from animation import Animation -from projectile import Projectile - -from util import cycle_clockwise, cycle_counter_clockwise, get_direction, str_from_dir -from sound import play_sound -from log import log_message +from .object import DynamicObject +from .sound import play_sound +from .animation import Animation +from .projectile import Projectile + +from .util import cycle_clockwise, cycle_counter_clockwise, get_direction, str_from_dir +from .sound import play_sound +from .log import log_message class Spider(DynamicObject): diff -ruN a/lib/spikes.py b/lib/spikes.py --- a/lib/spikes.py +++ b/lib/spikes.py @@ -3,12 +3,12 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from tile import Tile -from animation import Animation +from .tile import Tile +from .animation import Animation class Spikes(Tile): def __init__(self, screen, tilex, tiley, set = "brown"): diff -ruN a/lib/tile.py b/lib/tile.py --- a/lib/tile.py +++ b/lib/tile.py @@ -3,14 +3,14 @@ from pygame.locals import * -from locals import * +from .locals import * -import data +from . import data -from visibleobject import VisibleObject -from animation import Animation +from .visibleobject import VisibleObject +from .animation import Animation -from log import log_message +from .log import log_message class Tile(VisibleObject): def __init__(self, screen, tilex, tiley, set = "brown", tileclass = "wall"): @@ -47,8 +47,8 @@ def realign(self): self.rect.centerx = self.x self.rect.centery = self.y - self.x = round((float(self.rect.right)/float(TILE_DIM)), 0)*TILE_DIM - self.rect.width / 2 - self.y = round((float(self.rect.bottom)/float(TILE_DIM)), 0)*TILE_DIM - self.rect.height / 2 + self.x = round((float(self.rect.right)/float(TILE_DIM)), 0)*TILE_DIM - self.rect.width // 2 + self.y = round((float(self.rect.bottom)/float(TILE_DIM)), 0)*TILE_DIM - self.rect.height // 2 if self.rect.height % 2 == 1: self.y -= 1 if self.rect.width % 2 == 1: diff -ruN a/lib/util.py b/lib/util.py --- a/lib/util.py +++ b/lib/util.py @@ -12,11 +12,11 @@ import pygame from pygame.locals import * -from locals import * -import data -from sound import play_sound -from variables import variables -from log import error_message, log_message +from .locals import * +from . import data +from .sound import play_sound +from .variables import variables +from .log import error_message, log_message class Score: @@ -50,6 +50,11 @@ under the data directory instead. """ path_name = '' + if os.path.isdir('/saves'): + # On the web (pygbag) /saves is the folder the page keeps in the browser (play/pygame.html) + path_name = '/saves/' + GAME_NAME_SHORT + os.makedirs(path_name, exist_ok=True) + return path_name try: path_name = os.path.join(os.environ['HOME'], '.' + GAME_NAME_SHORT) except KeyError: @@ -118,13 +123,13 @@ try: conffile = codecs.open(file_path, 'w', 'utf_8') for world in WORLDS: - print >> conffile, 'unlocked\t%(world)s\t%(unlocked)s' % {'world': world, 'unlocked': variables.vdict['unlocked' + world]} - print >> conffile, 'hiscore\t%(world)s\t%(hiscore)s' % {'world': world, 'hiscore': variables.vdict['hiscore' + world]} - print >> conffile, 'besttime\t%(world)s\t%(besttime)s' % {'world': world, 'besttime': variables.vdict['besttime' + world]} - print >> conffile, 'sound\t%s' % bool_to_str(variables.vdict['sound']) - print >> conffile, 'dialogue\t%s' % bool_to_str(variables.vdict['dialogue']) - print >> conffile, 'fullscreen\t%s' % bool_to_str(variables.vdict['fullscreen']) - print >> conffile, 'character\t%s' % variables.vdict['character'] + print('unlocked\t%(world)s\t%(unlocked)s' % {'world': world, 'unlocked': variables.vdict['unlocked' + world]}, file=conffile) + print('hiscore\t%(world)s\t%(hiscore)s' % {'world': world, 'hiscore': variables.vdict['hiscore' + world]}, file=conffile) + print('besttime\t%(world)s\t%(besttime)s' % {'world': world, 'besttime': variables.vdict['besttime' + world]}, file=conffile) + print('sound\t%s' % bool_to_str(variables.vdict['sound']), file=conffile) + print('dialogue\t%s' % bool_to_str(variables.vdict['dialogue']), file=conffile) + print('fullscreen\t%s' % bool_to_str(variables.vdict['fullscreen']), file=conffile) + print('character\t%s' % variables.vdict['character'], file=conffile) except Exception: error_message('Could not write configuration file to ' + file_path) return False @@ -143,13 +148,13 @@ count += 1 if count > MAX_OLD_LOG_LINES: break - if variables.vdict.has_key('log'): + if 'log' in variables.vdict: try: conffile = codecs.open(file_path, 'w', 'utf_8') - print >> conffile, 'Log updated ' + str(datetime.date.today()) - print >> conffile, variables.vdict['log'] - print >> conffile, '' - print >> conffile, old_log + print('Log updated ' + str(datetime.date.today()), file=conffile) + print(variables.vdict['log'], file=conffile) + print('', file=conffile) + print(old_log, file=conffile) except: error_message('Could not write log file to ' + file_path) return False @@ -174,7 +179,7 @@ The constant colors can be found from locals.py. """ - if Util.cached_text_images.has_key(string + str(color) + str(bgcolor)): + if (string + str(color) + str(bgcolor)) in Util.cached_text_images: final_image = Util.cached_text_images[string + str(color) + str(bgcolor)] else: text_image_bg = Util.smallfont.render(string, True, bgcolor) @@ -210,8 +215,8 @@ rendered_string = string[0:phase] string_image = render_text(rendered_string) string_rect = string_image.get_rect() - string_rect.centerx = SCREEN_WIDTH / 2 - string_rect.centery = SCREEN_HEIGHT / 2 + string_rect.centerx = SCREEN_WIDTH // 2 + string_rect.centery = SCREEN_HEIGHT // 2 if key == 'p': skip_image = Util.cached_images['key_p'] @@ -219,7 +224,7 @@ skip_image = Util.cached_images['key_z'] skip_rect = skip_image.get_rect() - skip_rect.centerx = SCREEN_WIDTH / 2 + skip_rect.centerx = SCREEN_WIDTH // 2 skip_rect.top = string_rect.bottom + 5 bg_rect = pygame.Rect(string_rect.left - 10, string_rect.top - 5, string_rect.width + 20, string_rect.height + skip_rect.height + 15) diff -ruN a/lib/visibleobject.py b/lib/visibleobject.py --- a/lib/visibleobject.py +++ b/lib/visibleobject.py @@ -23,9 +23,9 @@ self.x = x self.y = y if (self.x == None): - self.x = SCREEN_WIDTH / 2 + self.x = SCREEN_WIDTH // 2 if (self.y == None): - self.y = SCREEN_HEIGHT / 2 + self.y = SCREEN_HEIGHT // 2 self.flipping = False self.flipcounter = 0 @@ -118,7 +118,7 @@ def die(self): """Make the object die - if the object has a death animation, it will be played first.""" - if self.animations.has_key("dying"): + if "dying" in self.animations: self.current_animation = "dying" else: self.dead = True diff -ruN a/main.py b/main.py --- a/main.py +++ b/main.py @@ -0,0 +1,8 @@ +import asyncio + +# pygbag reads the imports of this file to install pygame-ce before the game's own modules load +import pygame + +from lib import main + +asyncio.run(main.main())