--- BubbMan2-DX.old/lib/game.py +++ BubbMan2-DX/lib/game.py @@ -6,10 +6,10 @@ from engine import * rgl.util.set_global_sound_volume(0.6) -def get_time(lvl): +def get_time (lvl, cfgdir): time = 10000.0 - if os.path.exists("data/level%d.high" % lvl): - score = open("data/level%d.high" % lvl, "rU").read() + if os.path.exists (cfgdir + "/level%d.high" % lvl): + score = open (cfgdir + "/level%d.high" % lvl, "rU").read() time = float(score.split("\n")[0]) return time @@ -26,7 +26,11 @@ self.water = rgl.gameobject.Group() self.spikes = rgl.gameobject.Group() self.bombs = rgl.gameobject.Group() - + + self.cfgdir = os.path.expanduser ("~/.bubbman2") + if not os.path.exists(self.cfgdir): + os.mkdir (self.cfgdir) + Player.groups = [self.objects, self.players] Player.non_stationary = self.non_stationary Platform.groups = [self.objects] @@ -105,8 +109,13 @@ pos = 0 rgl.clock.tick() rgl.button.handle_input() - if rgl.button.is_pressed(START): + + if rgl.button.is_pressed (START) or \ + rgl.button.is_pressed (SELECT) or \ + rgl.button.is_pressed (A_BUTTON) or \ + rgl.button.is_pressed (B_BUTTON): break + surface = rgl.display.get_surface() surface.blit(self.end_capture, (0, 0)) surface.blit(self.end_screen, (pos, 0)) @@ -118,9 +127,9 @@ self.render_text(surface, "Total: %06d" % self.total_score, (128-pos, 170), 1) self.render_text(surface, "Press Start!", (128-pos, 200), 1) rgl.display.update() - t = get_time(self.level) + t = get_time (self.level, self.cfgdir) if self.time < t: - open("data/level%d.high" % self.level, "wb").write(str(self.time)) + open (self.cfgdir + "/level%d.high" % self.level, "wb").write(str(self.time)) pygame.mixer.music.stop() def restart(self): @@ -208,7 +217,7 @@ TextMessage(self.engine, "+25", f.rect.center) rgl.util.play_sound("data/powerup.ogg") self.score += 25 - self.player.energy += 15 + self.player.energy += 50 if self.player.energy > 50: self.player.energy = 50 for b in self.baddies: @@ -221,22 +230,32 @@ if b.rect.colliderect(self.player.rect) and not self.player.dying: self.player.die() b.kill() - if self.player.dx > 0: - self.oldguy.speed = 2 - if self.player.dx > 2: - self.oldguy.speed = 3 + +#ifdef NOTDEF +# if self.player.dx > 0: +# self.oldguy.speed = 2 +# if self.player.dx > 2: +# self.oldguy.speed = 3 +#else + self.oldguy.speed = 1 +#endif + margin = 24 if self.boss_fight == True: margin = -64 if self.oldguy.rect.right < self.player.rect.left-128-margin: - self.oldguy.speed = 4 + self.oldguy.speed = 2 if self.first_time: self.oldguy.speed -= 1 if self.player.rect.left < 48: self.oldguy.speed = 0 if self.boss_fight == True: - if self.oldguy.speed < 3: - self.oldguy.speed += 1 +#ifdef NOTDEF +# if self.oldguy.speed < 3: +# self.oldguy.speed += 1 +#else + self.oldguy.speed = 1 +#endif if len(self.bombs) < 5 and not random.randrange(15): Bomb(self.engine, self.oldguy.rect.topleft) if self.checkpoint: @@ -259,7 +278,7 @@ self.player.decelerate(self.player.decel, 0) else: self.player.decelerate(0.999, 0) - self.player.energy -= abs(self.player.dx)*0.075 + self.player.energy -= abs(self.player.dx)*0.010 if rgl.button.is_pressed(A_BUTTON): self.player.jump() @@ -272,18 +291,29 @@ if rgl.button.is_held(A_BUTTON) and rgl.button.is_pressed(SELECT) and rgl.button.is_held(B_BUTTON): self.passed_checkpoint = True self.restart() - + + self.try_again = False + if not self.player.alive() and not self.won: + if rgl.button.is_pressed (START) or \ + rgl.button.is_pressed (A_BUTTON) or \ + rgl.button.is_pressed (B_BUTTON): + self.try_again = True if rgl.button.is_pressed(SELECT): + self.try_again = True + + if self.try_again: if self.paused: self.running = False else: self.restart() - if rgl.button.is_pressed(START) and self.player.alive(): - self.paused ^= 1 - if self.paused: - self.ptime = time.time() - else: - self.start_time -= self.ptime-time.time() + else: + if rgl.button.is_pressed(START) and self.player.alive(): + self.paused ^= 1 + if self.paused: + self.ptime = time.time() + else: + self.start_time -= self.ptime-time.time() + if self.player.energy <= 0: self.player.energy = 0 self.player.die() --- BubbMan2-DX.old/lib/intro.py +++ BubbMan2-DX/lib/intro.py @@ -48,7 +48,7 @@ for x in range(256/24 + 2): p = self.pos % 256 screen.blit(self.ground, (((x*24 - 24) + p % 24), 240-24)) - if rgl.button.is_pressed(START) or rgl.button.is_pressed(A_BUTTON): + if rgl.button.is_pressed(START) or rgl.button.is_pressed(A_BUTTON) or rgl.button.is_pressed(B_BUTTON): self.running = False bframe = 0 oframe = 0 --- BubbMan2-DX.old/lib/menu.py +++ BubbMan2-DX/lib/menu.py @@ -27,12 +27,12 @@ self.help_text = [ "Controls:", "", - "A Button = Z Key ", - "B Button = X Key ", + "Jump = Space ", + "Throw = L. CTRL ", "Start = Enter ", "Select = R. Shift", "", - "Press start!", + "Press Enter", ] def start_game(self): @@ -72,7 +72,7 @@ if rgl.button.is_pressed(UP): self.menu1.move_cursor(-1) rgl.util.play_sound("data/throw.ogg") - if rgl.button.is_pressed(A_BUTTON) or rgl.button.is_pressed(START): + if rgl.button.is_pressed(A_BUTTON) or rgl.button.is_pressed(B_BUTTON) or rgl.button.is_pressed(START): rgl.util.play_sound("data/jump.ogg") if self.menu1.option == 0: self.start_game() --- BubbMan2-DX.old/lib/worldmap.py +++ BubbMan2-DX/lib/worldmap.py @@ -23,11 +23,17 @@ self.map = load_image("data/worldmap.png") self.logo = load_image("data/world-logo.png") self.frame = 0 - if not os.path.exists("data/prog.sav"): + + self.cfgdir = os.path.expanduser ("~/.bubbman2") + if not os.path.exists(self.cfgdir): + os.mkdir (self.cfgdir) + + self.progsav = self.cfgdir + "/save.dat" + if not os.path.exists(self.progsav): self.unlocked = 1 - open("data/prog.sav", "wb").write(str(self.unlocked)) + open (self.progsav, "wb").write(str(self.unlocked)) else: - self.unlocked = int(open("data/prog.sav", "rU").read()) + self.unlocked = int(open(self.progsav, "rU").read()) self.num_levels = 0 for i in range(8): if os.path.exists("data/level%d.png" % (i+1)): @@ -66,7 +72,7 @@ credits.Credits().loop() if self.pos >= self.unlocked and self.pos < self.num_levels: self.unlocked += 1 - open("data/prog.sav", "wb").write(str(self.unlocked)) + open (self.progsav, "wb").write(str(self.unlocked)) self.first_time = False else: self.pos -= 1 @@ -82,15 +88,15 @@ self.pos -= 1 rgl.util.play_sound("data/throw.ogg") if rgl.button.is_pressed(RIGHT): - if self.pos < self.unlocked-1: + if self.pos < 7: self.pos += 1 rgl.util.play_sound("data/throw.ogg") - if rgl.button.is_pressed(A_BUTTON) or rgl.button.is_pressed(START): + if rgl.button.is_pressed(A_BUTTON) or \ + rgl.button.is_pressed(START) or \ + rgl.button.is_pressed(B_BUTTON) or \ + rgl.button.is_pressed(SELECT): rgl.util.play_sound("data/jump.ogg") self.start_game() - if rgl.button.is_pressed(B_BUTTON) or rgl.button.is_pressed(SELECT): - rgl.util.play_sound("data/spring.ogg") - self.running = False self.frame += 1 self.spot = self.spot_imgs[self.frame/12%2] @@ -102,8 +108,7 @@ screen.blit(self.logo, (0, 0)) self.render_text(screen, "Level %d" % (self.pos+1), (128, 210), 1) - - time = game.get_time(self.pos+1) + time = game.get_time (self.pos+1, self.cfgdir) if time >= 10000.0: time = "---" else: --- BubbMan2-DX.old/retrogamelib/button.py +++ BubbMan2-DX/retrogamelib/button.py @@ -14,10 +14,11 @@ self.pressed = {} self.held = {"key": [], "joy": [], "dpad": []} - self.bind_key(A_BUTTON, pygame.K_z) self.bind_key(A_BUTTON, 2) - self.bind_key(B_BUTTON, pygame.K_x) + self.bind_key(A_BUTTON, pygame.K_SPACE) self.bind_key(B_BUTTON, 1) + self.bind_key(B_BUTTON, pygame.K_LCTRL) + self.bind_key(START, pygame.K_RETURN) self.bind_key(START, 8) self.bind_key(SELECT, pygame.K_RSHIFT) @@ -48,7 +49,8 @@ pygame.quit() quit() if e.type == pygame.KEYDOWN: - if e.key == pygame.K_ESCAPE: + if (e.key == pygame.K_ESCAPE) or \ + (e.key == pygame.K_q): pygame.quit() quit() self.pressed["key"].append(e.key) --- BubbMan2-DX.old/retrogamelib/display.py +++ BubbMan2-DX/retrogamelib/display.py @@ -1,12 +1,21 @@ import sys import os +import Tkinter as tk + +root = tk.Tk() +screen_width = root.winfo_screenwidth() +screen_height = root.winfo_screenheight() import pygame from pygame.locals import * from constants import * -SCALE = 1.0 +SCALE_TO = (640, 480) +if screen_width >= 1280 and screen_height >= 1024: + SCALE_TO = (1024, 768) + +SCALE = 8.0 screen = None surface = None resolution = None @@ -14,7 +23,7 @@ def init(scale=2.0, caption="NES Game", res=NESRES): """Initialise the SDL display -> return None """ - + global SCALE, screen, surface, resolution resolution = res SCALE = scale @@ -23,12 +32,9 @@ pygame.init() pygame.display.set_caption(caption) - screen = pygame.display.set_mode(( - int(resolution[0]*SCALE), - int(resolution[1]*SCALE))) + screen = pygame.display.set_mode (SCALE_TO) surface = pygame.Surface(NESRES) update() - pygame.mouse.set_visible(0) def update(): @@ -36,15 +42,12 @@ """ global surface, resolution - surface = pygame.transform.scale(surface, - (int(resolution[0]*SCALE), int(resolution[1]*SCALE))) + surface = pygame.transform.scale (surface, SCALE_TO) screen.blit(surface, (0, 0)) surface = pygame.transform.scale(surface, resolution) - pygame.display.flip() def get_surface(): """Get the surface to draw to -> return pygame.Surface """ - return surface