Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disappearing planets in network games (they turned into BHs) #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,6 +66,7 @@ Copyright:
Copyright (C) 2007 Bart Mak
Copyright (C) 2009 Marcus Dreier <[email protected]>
Copyright (C) 2010 Ryan Kavanagh <[email protected]>
Copyright (C) 2019 H. A. L. <[email protected]> (contributions to v0.9r1)
slingshot/data/FreeSansBold.ttf:
Copyright (C) 2002, 2003, 2005, 2008 Free Software Foundation

Expand Down
30 changes: 19 additions & 11 deletions src/bin/slingshot
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -1033,14 +1034,16 @@ 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
self.menu = None
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()

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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():
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions src/slingshot/planet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/slingshot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class Settings:

VERSION = '0.9'
VERSION = '0.9r1'

g = 120 # gravity
MAXPOWER = 350
Expand All @@ -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
Expand Down