def __init__(self): self.walkers = [] self.clients = self. walkers terrain.walkers = self.walkers #fixme i dont think i need or want this line #but should improve the gamestate class, give it some funcs #oh, and fix the freaking networking so its good! self.walkers.append(player.playerclass(self, "The server", None))
def addClient(self, cname, netdata): for c in self.clients: if c.netdata == None: continue if c.netdata[0] == netdata[0]: return None newplayer = player.playerclass(self.gamestate, cname, netdata) print( (cname, netdata), "joined") self.clients.append(newplayer) return newplayer
def handleEvent(self, event, cplayer): if event.type == pygame.QUIT: sys.exit() elif event.type == pgl.VIDEORESIZE: print(event.dict['size']) display.resize(event.dict['size'][0], event.dict['size'][1]) pygame.display.flip() elif simplenet.isClient: ne = netevent() ne.type = event.type if event.type == 2 or event.type == 3: if event.key == pgl.K_ESCAPE: sys.exit() ne.key = event.key simplenet.sendserv("event", ne) elif event.type == pgl.MOUSEMOTION: ne.pos = [event.pos[0], event.pos[1]] simplenet.sendserv("event", ne) elif event.type == pgl.MOUSEBUTTONDOWN: ne.button = event.button ne.pos = [event.pos[0], event.pos[1]] simplenet.sendserv("event", ne) elif event.type == pgl.MOUSEBUTTONUP: ne.button = event.button ne.pos = [event.pos[0], event.pos[1]] simplenet.sendserv("event", ne) return if event.type == 2:#keypress if event.key == pgl.K_DELETE: if len(self.walkers) > 0:self.walkers.remove(self.walkers[0]) if event.key == pgl.K_w: #for i in range(0, len(self.walkers)):self.walkers[i].upkey = 1 cplayer.upkey = 1 if event.key == pgl.K_ESCAPE: sys.exit() if event.key == pgl.K_m: self.menu.runMenu() if event.key == pgl.K_s: cplayer.dnkey = 1 if event.key == pgl.K_a: cplayer.ltkey = 1 if event.key == pgl.K_d: cplayer.rtkey = 1 if event.key == pgl.K_SPACE: cplayer.jumpkey = 1 if event.key == pgl.K_LCTRL: cplayer.crouchkey = 1 if event.key == pgl.K_v: cplayer.digkey = 1 if event.key == pgl.K_q: cplayer.changegun(1) if event.key == pgl.K_e: cplayer.changegun(-1) if event.type == 3:#keyrelease if event.key == pgl.K_n: newplayer = player.playerclass(self.gamestate, "A Bot " + str(len(self.gamestate.clients)), None) newplayer.isbot = 1#int(random()*2) newplayer.jumpkey = int(random()*2) newplayer.x = cplayer.gmx newplayer.y = cplayer.gmy self.walkers.append(newplayer) if event.key == pgl.K_w: cplayer.upkey = 0 if event.key == pgl.K_s: cplayer.dnkey = 0 if event.key == pgl.K_a: cplayer.ltkey = 0 if event.key == pgl.K_d: cplayer.rtkey = 0 if event.key == pgl.K_SPACE: cplayer.jumpkey = 0 if event.key == pgl.K_LCTRL: cplayer.crouchkey = 0 if event.key == pgl.K_v: cplayer.digkey = 0 if event.type == pgl.MOUSEMOTION or event.type == pgl.MOUSEBUTTONUP or event.type == pgl.MOUSEBUTTONDOWN: cplayer.msinx = event.pos[0] cplayer.msiny = event.pos[1] #print event.type if event.type == pgl.MOUSEBUTTONUP: if event.button == 1: cplayer.unshoot()#jumpkey = 1 if event.button == 3: cplayer.altunshoot()#jumpkey = 1 if event.type == pgl.MOUSEBUTTONDOWN: #print event.button if event.button == 4: cplayer.changegun(1) if event.button == 5: cplayer.changegun(-1) if event.button == 3: cplayer.altshoot() #terrain.explode(cplayer.gmx, cplayer.gmy, 90, 255) if event.button == 1: cplayer.shoot()#jumpkey = 1