def run(self): while self.running: self.windowSurface.fill((0, 0, 0)) me = self.data.players[self.data.myPLI] view = polygon.getRectangle(me.position.toTuple(), self.ww, self.wh, me.rotation) self.drawPolygon(self.MAP, view, (255, 255, 255)) playersInView = self.getPlayersInView(view) for player in playersInView: self.drawPlayer(player, view) pygame.display.update()
def setup(self, data, windowWidth, windowHeight, windowSurface): # Perspective reads the main data object self.data = data self.IMG_player_idle = pygame.transform.smoothscale( pygame.image.load("images/player.png").convert_alpha(), (40, 40) ) self.ww, self.wh = windowWidth, windowHeight self.playerImgRadius = math.sqrt(math.pow(40, 2) + math.pow(40, 2)) self.running = True self.windowSurface = windowSurface self.MAP = polygon.getRectangle((MAPWIDTH / 2, MAPHEIGHT / 2), MAPWIDTH, MAPHEIGHT, 0.0)
def __init__(self, position, rotation, name, mapWidth, mapHeight): #self.collisionBox = polygon.getRectangle((position), 10, 20, 0, (255, 0, 0)) self.collisionBox = circle.Circle(position, 10) self.perspective = polygon.getRectangle(position, 800, 600, rotation, (0,255,0)) self.facing = float(rotation) self.velocity = vector.Vector(0,0) self.baseAcc = 4.0 self.topSpeed = 7.0 self.moveRight = False self.moveLeft = False self.moveUp = False self.moveDown = False self.name = name self.mw = mapWidth self.mh = mapHeight
import socket, threading, time, random import player, receiver, vector, test, polygon CONCODE, MSG, CLIENTS = 0,1,2 NUMBEROFPLAYERS = 64 MAPWIDTH, MAPHEIGHT = 800, 600 MAP = polygon.getRectangle((MAPWIDTH/2,MAPHEIGHT/2), MAPWIDTH, MAPHEIGHT, 0) class Client: def __init__(self, ip, sendPort, recvPort, playerListIndex): self.ip = ip self.sendPort = sendPort #from the clients POV self.recvPort = recvPort self.pli = playerListIndex class Data: def __init__(self): self.players = [] #tuple met (poort, positie) for i in range(NUMBEROFPLAYERS): self.players.append(None) self.clients = [] self.waitingForConfirmation = [] #messages that need confirmation of reception from the client #format: [(conCode, message, listOfClients(indexnumbers)), ... ] self.confirmationCode = 0 self.immobileObjects = [] def addClient(self, ip, sendPort, recvPort, name): playerListIndex = self.getAvailablePLI() self.clients.append(Client(ip, sendPort, recvPort, playerListIndex)) self.addPlayer(playerListIndex, name) self.toBeSentAndConfirmed("PLU" + self.positionsToString([playerListIndex]) + name) for pli in range(0, len(self.players)-1): if self.players[pli] is not None:
def randomRect(mapWidth, mapHeight): center = (random.randint(0,mapWidth), random.randint(0,mapHeight)) width = random.randint(10, 100) height = random.randint(10, 100) rotation = random.random() * math.pi return polygon.getRectangle(center, width, height, rotation, randomColor())