aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilly Brown2017-12-02 20:58:40 +0000
committerBilly Brown2017-12-02 20:58:40 +0000
commit9cb172d9097b1cd4ba429f476ae1cf146e64a218 (patch)
tree0a73791e016b7a3674c22d2b6ee7515eb4648878
parent1 (diff)
downloadlongpong-9cb172d9097b1cd4ba429f476ae1cf146e64a218.tar.gz
longpong-9cb172d9097b1cd4ba429f476ae1cf146e64a218.zip

x

-rw-r--r--client/events.py6
-rw-r--r--client/game.py49
2 files changed, 31 insertions, 24 deletions
diff --git a/client/events.py b/client/events.py
index 74d1e34..2835c86 100644
--- a/client/events.py
+++ b/client/events.py
@@ -59,6 +59,12 @@ class Events:
def has_num(self):
return self.has(self.is_num)
+ def is_n(self, event):
+ return event.type == sdl2.SDL_KEYUP and event.key.keysym.sym == sdl2.SDLK_n
+
+ def has_n(self):
+ return self.has(self.is_n)
+
def get_nums(self):
return list(map(self.get_num, self.matching(self.is_num)))
diff --git a/client/game.py b/client/game.py
index a4ca325..c6448f9 100644
--- a/client/game.py
+++ b/client/game.py
@@ -92,7 +92,6 @@ class Game:
def loop(self):
self.running = True
- self.was_n_down = False
c_time = time.time()
while self.running:
self.client.listen()
@@ -121,34 +120,36 @@ class Game:
if 'size' in msg:
ball.size = (msg['size']['x'], msg['size']['y'])
else:
- self.ball_list[msg['ball_id']] = Ball(msg[0]['pos'],msg[0]['vel'],msg[0]['size'])
+ self.ball_list[msg['ball_id']] = Ball(msg['pos'],msg['vel'],msg['size'])
+ ball = self.ball_list[msg['ball_id']]
touched[msg['ball_id']] = True
l_deltaT = c_time - msg['time']
ball.move(l_deltaT)
- if self.events.has_key(sdl2.SDLK_n):
- if not self.was_n_down:
- t = 0
- for x in range(0, 10**10):
- if x not in self.ball_list:
- t = x
- msg = {
- 'ball_id': x,
- 'vel': {
- 'x': 1,
- 'y': 1
- },
- 'pos': {
- 'x': self.renderer.get_rightmost_edge(),
- 'y': 0.5
- },
- 'time': c_time
- }
- self.client.send_ballchange(msg)
- self.was_n_down = True
- else:
- self.was_n_down = False
+ if self.events.has_n():
+ t = 0
+ for x in range(0, 10**10):
+ if x not in self.ball_list:
+ t = x
+ break
+ msg = {
+ 'ball_id': x,
+ 'vel': {
+ 'x': 1,
+ 'y': 1
+ },
+ 'pos': {
+ 'x': self.width / 2,
+ 'y': 0.5
+ },
+ 'size': {
+ 'x': 0.05,
+ 'y': 0.05
+ },
+ 'time': c_time
+ }
+ self.client.send_ballchange(msg)
balls_to_remove = []
for i, ball in self.ball_list.items():