aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/client.py12
-rw-r--r--client/game.py17
-rw-r--r--client/longpong.py2
-rw-r--r--client/render.py16
4 files changed, 21 insertions, 26 deletions
diff --git a/client/client.py b/client/client.py
index 17567c2..3da7a3a 100644
--- a/client/client.py
+++ b/client/client.py
@@ -10,11 +10,11 @@ class Client:
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((ip,port))
self.n = n
- self.client_sock.setblocking(False)
+ self.sock.setblocking(False)
def listen(self):
try:
- msg = client_sock.recv(4096)
+ msg = self.sock.recv(4096)
jsonMSG = json.loads(msg)
print(jsonMSG)
if 'command' in data:
@@ -41,22 +41,22 @@ class Client:
inp = {}
inp['nValue'] = self.n;
inp['screenSize'] = str(screen)
- self.client_sock.send(str(json.dumps(inp)))
+ self.sock.sendall(str(json.dumps(inp)).encode())
def send_start(self):
msg ={'command':'start'}
jsonVal = json.dumps(msg)
- self.client_sock.send(str(jsonVal))
+ self.sock.sendall(str(jsonVal).encode())
def send_stop(self):
msg ={'command':'stop'}
jsonVal = json.dumps(msg)
- self.client_sock.send(str(jsonVal))
+ self.sock.sendall(str(jsonVal).encode())
def send_ballchange(self,message):
msg['command'] = "bchange"
jsonVal = json.dumps(msg)
- self.client_sock.send(str(jsonVal))
+ self.sock.sendall(str(jsonVal).encode())
def has_started(self):
return self.started
diff --git a/client/game.py b/client/game.py
index 485a874..8a7a031 100644
--- a/client/game.py
+++ b/client/game.py
@@ -2,13 +2,6 @@ import time
import sdl2
import sdl2.ext
-class Rect:
- def __init__(self, x, y, width, height):
- self.x = x
- self.y = y
- self.width = width
- self.height = height
-
class Ball:
def __init__(self, pos, vel, size):
self.pos = pos
@@ -45,7 +38,7 @@ class Game:
def start(self):
self.place_windows()
# Tell the server how wide the screen is
- full_width = sum(self.renderer.get_screen_widths)
+ full_width = sum(self.renderer.get_screen_widths())
self.client.send_init(full_width)
# Wait for a start event
while not self.client.has_started():
@@ -84,8 +77,10 @@ class Game:
if self.events.has_quit() or self.client.has_stopped():
self.running = False
break
- self.update(None)
- self.renderer.render(None, None)
+ p_time = time
+ time = time.time()
+ self.update(time, p_time)
+ self.renderer.render(ball_list, paddle_list, (0, 0))
def update(self, time, p_time):
deltaT = time - p_time
@@ -128,7 +123,7 @@ class Game:
'x': ball.pos[0],
'y': ball.pos[1]
},
- 'time': time.time()
+ 'time': time
}
self.client.send_ballchange(msg)
diff --git a/client/longpong.py b/client/longpong.py
index 62ce4d1..afdfb36 100644
--- a/client/longpong.py
+++ b/client/longpong.py
@@ -3,7 +3,7 @@ import sys
from client import Client
from events import Events
-from game import Game, Rect
+from game import Game
from render import Renderer
def main(args):
diff --git a/client/render.py b/client/render.py
index 0885e65..8e4b0eb 100644
--- a/client/render.py
+++ b/client/render.py
@@ -59,18 +59,18 @@ class Renderer:
def draw_ball(self, screen, offset, ball):
if ball != None:
- rect = sdl2.SDL_Rect(int((ball.x - offset) * screen.height),
- int(ball.y * screen.height),
- int(ball.width * screen.height),
- int(ball.height * screen.height))
+ rect = sdl2.SDL_Rect(int((ball.pos[0] - offset) * screen.height),
+ int(ball.pos[1] * screen.height),
+ int(ball.size[0] * screen.height),
+ int(ball.size[1] * screen.height))
sdl2.SDL_RenderFillRect(screen.renderer.sdlrenderer, rect)
def draw_paddle(self, screen, offset, paddle):
if paddle != None:
- rect = sdl2.SDL_Rect(int((paddle.x - offset) * screen.height),
- int(paddle.y * screen.height),
- int(paddle.width * screen.height),
- int(paddle.height * screen.height))
+ rect = sdl2.SDL_Rect(int((paddle.pos[0] - offset) * screen.height),
+ int(paddle.pos[1] * screen.height),
+ int(paddle.size[0] * screen.height),
+ int(paddle.size[1] * screen.height))
sdl2.SDL_RenderFillRect(screen.renderer.sdlrenderer, rect)
def draw_score(self, screen, scores):