Skip to content

Commit

Permalink
Fix shooting and add server info to clients
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed May 13, 2019
1 parent 160bac7 commit 3e385af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
10 changes: 6 additions & 4 deletions game/src/Game/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ def draw(self):
self.window.erase()
self.window.border(0) # Draw border

self.window.addstr(0, 2, f' Text MOBA – {self.address[0]}:{self.address[1]} ')

for bullet in self.game['bullets']: # Bullets
self.window.addch(bullet['pos']['y'], bullet['pos']['x'], '.')

for index in range(0, len(self.game['players'])): # Players
player = self.game['players'][index]

if not player == None:
self.window.addch(player['pos']['y'], player['pos']['x'], player['c'])
self.window.addstr(0, 2 + (index * 14), f' Player {index + 1}: {player["s"]} ')

for bullet in self.game['bullets']: # Bullets
self.window.addch(bullet['pos']['y'], bullet['pos']['x'], '.')
self.window.addstr(self.size[0] - 1, 2 + (index * 14), f' Player {player["c"]}: {player["s"]} ')

for wall in self.walls:
self.window.addch(wall[1], wall[0], '▓')
22 changes: 12 additions & 10 deletions server/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,24 @@ def listenToPlayer(clientsocket, playerid):
pos['x'] -= 1

if action == 's':
if payload == 0: # Up
game['bullets'].append({'pos': { 'x': pos['x'], 'y': pos['y'] - 1 }, 'dir': payload, 'id': playerid})
if payload == 1: # Right
game['bullets'].append({'pos': { 'x': pos['x'] + 1, 'y': pos['y'] }, 'dir': payload, 'id': playerid})
if payload == 2: # Down
game['bullets'].append({'pos': { 'x': pos['x'], 'y': pos['y'] + 1 }, 'dir': payload, 'id': playerid})
if payload == 3: # Left
game['bullets'].append({'pos': {'x': pos['x'] - 1, 'y': pos['y'] }, 'dir': payload, 'id': playerid})
game['bullets'].append({'pos': { 'x': pos['x'], 'y': pos['y'] }, 'dir': payload, 'id': playerid})

# if payload == 0: # Up
# game['bullets'].append({'pos': { 'x': pos['x'], 'y': pos['y'] - 1 }, 'dir': payload, 'id': playerid})
# if payload == 1: # Right
# game['bullets'].append({'pos': { 'x': pos['x'] + 1, 'y': pos['y'] }, 'dir': payload, 'id': playerid})
# if payload == 2: # Down
# game['bullets'].append({'pos': { 'x': pos['x'], 'y': pos['y'] + 1 }, 'dir': payload, 'id': playerid})
# if payload == 3: # Left
# game['bullets'].append({'pos': {'x': pos['x'] - 1, 'y': pos['y'] }, 'dir': payload, 'id': playerid})
except:
pass

threading.Thread(target = acceptClients, daemon = True).start()

while True: # Update clients
try:
for bullet in game['bullets']:
for bullet in game['bullets']: # Move bullets
if not bullet == -1:
if bullet['dir'] == 0:
bullet['pos']['y'] -= 1
Expand All @@ -160,7 +162,7 @@ def listenToPlayer(clientsocket, playerid):
player = game['players'][index]
if not player == None:
for bullet in game['bullets']:
if player['pos'] == bullet['pos']:
if player['pos'] == bullet['pos'] and not bullet['id'] == index:
bulletid = bullet['id']

game['players'][index]['pos'] = {
Expand Down

0 comments on commit 3e385af

Please sign in to comment.