diff --git a/README b/README index 9636bc9..be28934 100644 --- a/README +++ b/README @@ -12,6 +12,9 @@ at http://github.com/ryanakca/slingshot See http://github.com/ryanakca/slingshot/commits/master for a detailed listing. +v0.9r1: + - Fix bug in network games (disappearing planets) + v0.9: - Fix deprecation Python warnings and errors - Introduce networking support @@ -63,6 +66,7 @@ Copyright: Copyright (C) 2007 Bart Mak Copyright (C) 2009 Marcus Dreier Copyright (C) 2010 Ryan Kavanagh + Copyright (C) 2019 H. A. L. (contributions to v0.9r1) slingshot/data/FreeSansBold.ttf: Copyright (C) 2002, 2003, 2005, 2008 Free Software Foundation diff --git a/src/bin/slingshot b/src/bin/slingshot index 68185fb..9e4ef87 100644 --- a/src/bin/slingshot +++ b/src/bin/slingshot @@ -371,8 +371,9 @@ class Game: result.add(Planet(result, self.background)) else: for p in planetlist: - if p[0] > Settings.MAX_PLANETS: - # Numbers above Settings.MAX_PLANETS are + if p[0] > Settings.NUM_PLANET_SPRITES: + # Numbers above + # Settings.NUM_PLANET_SPRITES are # allocated to blackholes. result.add(Blackhole(None, self.background, p[0], p[1], p[2], p[3])) else: @@ -1033,7 +1034,8 @@ class Game: if ret is not False: packet = (self.bounce, self.fixed_power, self.invisible, self.random, self.max_planets, self.timeout, self.max_rounds, self.max_blackholes) - if not self.net.send(packet): + if self.net.send(packet) is False: + print "ERROR in host_game_init when sending" self.menu = self.net_error_menu self.net.close() return @@ -1041,6 +1043,7 @@ class Game: self.save_settings() self.game_init(net_host=True) else: + print "ERROR in host_game_init in connecting" self.menu = self.net_error_menu self.net.close() @@ -1052,7 +1055,7 @@ class Game: if self.net.cnct(hostname) is not False: packet = self.net.recv() - if not packet: + if packet == False: self.menu = self.net_error_menu self.net.close() return @@ -1068,6 +1071,7 @@ class Game: self.menu = None self.save_settings() + print "client_game_init succeded" self.game_init(net_client=True) else: self.menu = self.net_error_menu @@ -1081,22 +1085,24 @@ class Game: y_coordlist = (self.players[1].get_rect_y_coord(), self.players[2].get_rect_y_coord()) packet = (planetlist, y_coordlist) - if not self.net.send(packet): + if self.net.send(packet) is False: + print "ERROR in host_round_init " self.menu = self.net_error_menu self.net.close() def client_round_init(self): ret = self.net.recv() - if not ret: + if ret == False: self.menu = self.net_error_menu self.net.close() + return None return ret - def use_fullscreen(self): - pygame.display.set_mode((0, 0), pygame.FULLSCREEN | pygame.NOFRAME) + def use_fullscreen(self): + pygame.display.set_mode((0, 0), pygame.FULLSCREEN | pygame.NOFRAME) - def use_window(self): - pygame.display.set_mode((800, 600)) + def use_window(self): + pygame.display.set_mode((800, 600)) def main(): @@ -1107,7 +1113,9 @@ def main(): path = os.path.expanduser("~") + "/.slingshot" if not os.path.exists(path): os.mkdir(path) - path += "/logfile.txt" + # randomize name of logfile for debugging, since multiple instances might be + # running for the same user + path += "/logfile" + str(randint(1,10000)) + ".txt" sys.stderr = open(path, "w") sys.stdout = sys.stderr game = Game() diff --git a/src/slingshot/planet.py b/src/slingshot/planet.py index a6da9db..af11c2f 100644 --- a/src/slingshot/planet.py +++ b/src/slingshot/planet.py @@ -60,7 +60,7 @@ def __init__(self, planets, background, n=None, radius=None, mass=None, pos=None unique = False while not unique: unique = True - self.n = randint(1, 8) + self.n = randint(1, Settings.NUM_PLANET_SPRITES) for p in planets: if self.n == p.get_n(): unique = False @@ -143,7 +143,8 @@ def __init__(self, planets, background, n=None, radius=None, mass=None, pos=None unique = False while not unique: unique = True - self.n = randint(Settings.MAX_PLANETS + 1, Settings.MAX_PLANETS + Settings.MAX_BLACKHOLES + 1) + self.n = randint(Settings.NUM_PLANET_SPRITES + + 1, Settings.NUM_PLANET_SPRITES + Settings.MAX_BLACKHOLES + 1) for p in planets: if self.n == p.get_n(): unique = False diff --git a/src/slingshot/settings.py b/src/slingshot/settings.py index 799fa7b..733605f 100644 --- a/src/slingshot/settings.py +++ b/src/slingshot/settings.py @@ -26,7 +26,7 @@ class Settings: - VERSION = '0.9' + VERSION = '0.9r1' g = 120 # gravity MAXPOWER = 350 @@ -52,6 +52,10 @@ class Settings: MAX_FLIGHT = 750 MAX_PLANETS = 4 + # MAX_PLANTES_SPRITES is the number of planet sprites, hence the maximal + # number for any Planet.n and we can identify BHs by haveing an n > + # NUM_PLANET_SPRITES + NUM_PLANET_SPRITES = 8 MAX_BLACKHOLES = 0 HITSCORE = 1500