lastFrame = time.time() timeStep = 1.0 / 160 vel_iters, pos_iters = 6, 2 borrar_bullet = [] borrar_asteroids = [] updateFPS() t_delta = getDelta() bullet = [] asteroids_dic = dict() myListener = myContactListener(borrar_bullet) myDestructor = myDestructionListener() world=b2World(gravity=(0,0),contactListener=myListener, destructorListener=myDestructor) mapa = chunk(0,0,world) #generate asteroids for ids in range(10): asteroids_dic[ids] = asteroids(world, [randint(-10000,10000)/100,randint(-10000,10000)/100], borrar_asteroids, ids) # Se prepara el servidor #server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server = socket.socket(socket.SOCK_DGRAM) global clientes clientes = [] maestro = mainProcess(clientes, bullet, borrar_bullet, borrar_asteroids, asteroids_dic) maestro.start() try: server_name = sys.argv[1] except: server_name = "Default name" thread_updateLobby = updateLobby(clientes, 8003, server_name) thread_updateLobby.start() server.bind(("", 8003))
def create_box(self): tmp = asteroids(self.world.CreateDynamicBody(position=(self.pos_init[0]*size_tile,self.pos_init[1]*size_tile), angularDamping=10.0, linearDamping= 5.0), 2, 50000, [6.0,3.0]) #print tmp.get_body() return tmp
def load_map(self): #MatrixT = [[0 for x in xrange(30)] for x in xrange(400)] import csv mapa = list(csv.reader(open('assets/mapa.tmx'))) estado = 0 x = -1 y = 29 capa = -1 #for taa in range(int(50)): # self.items.append([]) for pepe in mapa: if "orientation" in pepe[0]: pos_tmp = pepe[0].find('width="') string_tmp = pepe[0][pos_tmp + 7:] pos_tmp = string_tmp.find('"') self.total_x = int(string_tmp[:pos_tmp]) pos_tmp = pepe[0].find('height="') string_tmp = pepe[0][pos_tmp + 8:] pos_tmp = string_tmp.find('"') self.total_y = int(string_tmp[:pos_tmp]) y = self.total_y - 1 print self.total_x, self.total_y xasd = 0 MatrixT = [[0 for xasd in xrange(self.total_y)] for xasd in xrange(self.total_x)] print "matrixt generado" for taa in range(int(self.total_x / 8)): self.items.append([]) self.itemsDisplayList.append((glGenLists(1))) if pepe[0] == ' <data encoding="csv">': capa += 1 if (capa < 2): glNewList(self.chunkDisplayList + capa, GL_COMPILE) estado = 1 elif pepe[0] == '</data>': if (capa < 2): glEndList() estado = 0 self.Matrix.append(copy.deepcopy(MatrixT)) x = -1 y = self.total_y - 1 elif estado == 1: for taa in pepe: if taa != "": x += 1 if (capa == 2 and int(taa) - 1 != -1): tmpe = casilla( int(taa) - 1, objetos(int(taa) - 1, 1)) else: tmpe = casilla(int(taa) - 1) if (int(taa) - 1 != -1): if (capa < 2): self.create_tile(x, y, int(taa) - 1) if (capa == 2): self.items[int(x / 20)].append([x, y, tmpe]) MatrixT[x][y] = tmpe else: y -= 1 x = -1 shape = [] tmp_v = 0 for taa in self.items: self.regenerate_items(tmp_v) tmp_v += 1 posible_shape = [(-1, -1), (-1, -1)] for y in range(self.total_y): for x in range(self.total_x): s_y = (self.total_y - 1) - int(y) tile = self.Matrix[0][x][y].get_tile() if (tile != -1): if posible_shape[0][0] != -1 and posible_shape[0][ 0] != -1 and posible_shape[1][ 0] != -1 and posible_shape[1][1] != -1: shape.append(posible_shape) if posible_shape[0][0] != -1 and posible_shape[0][ 0] != -1 and posible_shape[1][ 0] == -1 and posible_shape[1][0] == -1: posible_shape[1] = posible_shape[0] shape.append(posible_shape) posible_shape = [(-1, -1), (-1, -1)] #if (tile == 4): # self.create_colision_triangle((x,y),True) #if (tile == 5): # self.create_colision_triangle((x,y),False) else: if posible_shape[0][0] == -1 and posible_shape[0][1] == -1: posible_shape[0] = (x, y) else: posible_shape[1] = (x, y) #create dynamic bodys tile = self.Matrix[3][x][y].get_tile() if (tile != -1): # pass self.dynamics.append( asteroids(self.worlds.CreateDynamicBody( position=(x * size_tile, y * size_tile), angularDamping=10.0, linearDamping=10.0), tile, dl=self.global_DL)) self.create_colision(shape)