-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartClient.py
More file actions
58 lines (48 loc) · 1.78 KB
/
StartClient.py
File metadata and controls
58 lines (48 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding:utf-8 -*-
import pygame, os, json
import Render, Phisics
from socket import *
##############Клиент############
host = 'localhost'
port = 9090
addr = (host, port)
Data = 256
################################
wi = 1200
hi = 800
screen2 = pygame.display.set_mode((wi, hi))
pygame.display.set_caption('Battle tank client') #name window
loc = os.getcwd()+'/img/'
Pz5 = Render.Render(loc+'Pz-5corpM.png', 50, 50, 300, screen2, 0)
TurmPz5 = Render.Render(loc+'TurmPz5MC.png', 500, 250, 300, screen2, 0)
Pz5USSR = Render.Render(loc+'Pz-5corpUSSR.png', 50, 50, 300, screen2, 0)
TurmPz5USSR = Render.Render(loc+'TurmPz5USSR.png', 500, 250, 300, screen2, 0)
Xmark = Render.Render(loc+'X.png', TurmPz5.x, TurmPz5.y, 0, screen2, 0, 150)
Shell = Render.Render(loc+'Shellmini3.png', 50, 50, 0, screen2, 0, None, 0, 0)
clock = pygame.time.Clock()
while True:
#Phisics.phisics(Pz5, TurmPz5, Xmark, Shell)
screen2.fill((50, 50, 0)) #color field
Pz5.render
TurmPz5.x, TurmPz5.y = Pz5.x, Pz5.y
TurmPz5.render
Shell.render
Xmark.render
################################################
tcp_socket = socket(AF_INET, SOCK_STREAM)
tcp_socket.connect(addr)
toServeData = Data
toServeData = [Pz5.x, Pz5.y, Pz5.angle,TurmPz5.angle]
toServeData = json.dumps(toServeData, ensure_ascii=False).encode()
tcp_socket.send(toServeData)
response = tcp_socket.recv(4096)
response = json.loads(response.decode())
Pz5USSR.x, Pz5USSR.y, Pz5USSR.angle, TurmPz5USSR.angle = response[0], response[1], response[2], response[3]
Pz5USSR.render
TurmPz5USSR.x, TurmPz5USSR.y = Pz5USSR.x, Pz5USSR.y
TurmPz5USSR.render
Shell.render
Xmark.render
Phisics.phisics(Pz5, TurmPz5, Xmark, Shell)
clock.tick(100)
pygame.display.update()