def __init__(self): self.all_sprites = pygame.sprite.Group()#cenario, aqui é o grupo do cenario self.all_cube = pygame.sprite.Group()#jogador self.all_enemy = pygame.sprite.Group()#inimigo self.all_meteor = pygame.sprite.Group()#meteor #cenario self.bg = Obj("Assets/Background2.png", 0, 0, self.all_sprites) #jogador self.cube = Cube("Assets/Player2.png", 640, 360, self.all_sprites, self.all_cube) random_x = random.randint(100, 1000) #inimigo self.enemy = Enemy("Assets/enemy2.png", random_x, -750, self.all_sprites, self.all_enemy) self.enemy = Enemy("Assets/enemy2.png", 500, -750, self.all_sprites, self.all_enemy) self.enemy = Enemy("Assets/enemy2.png", 500, -750, self.all_sprites, self.all_enemy) self.enemy = Enemy("Assets/enemy2.png", 500, -750, self.all_sprites, self.all_enemy) self.enemy = Enemy("Assets/enemy2.png", 500, -750, self.all_sprites, self.all_enemy) #obstaculos self.meteor = Meteor("Assets/meteor.png", 100, 1000, self.all_sprites, self.all_meteor) #cenario self.hud = Obj("Assets/hud_black.png", 10, 10, self.all_sprites) self.lifes_1 = Obj("Assets/life_3.png", 107, 14, self.all_sprites) self.lifes_2 = Obj("Assets/life_3.png", 116, 14, self.all_sprites) self.lifes_3 = Obj("Assets/life_3.png", 125, 14, self.all_sprites)
def generateData(self, id): obj_size = util.Constants.OBJECT_SIZE if id == 1: self.color = util.Colors.GREEN self.dir = right for i in range((snake_len + 1) * obj_size, obj_size, -obj_size): self.pos.append(Obj(obj_size, i, self.color)) elif id == 2: self.color = util.Colors.RED self.dir = left for i in range(width - obj_size - snake_len * obj_size, width - obj_size, obj_size): self.pos.append(Obj(height - obj_size, i, self.color)) elif id == 3: self.color = util.Colors.BLUE self.dir = up for i in range(height - obj_size - snake_len * obj_size, height - obj_size, obj_size): self.pos.append(Obj(i, obj_size, self.color)) elif id == 4: self.color = util.Colors.YELLOW self.dir = down for i in range((snake_len + 1) * obj_size, obj_size, -obj_size): self.pos.append(Obj(i, width - obj_size, self.color)) else: pass
def __init__(self): self.tela = Window(1280, 720, "Pong Futeball") self.bg = Obj("assets/field.png", 0, 0) self.tela.add_obj(self.bg.drawing(self.tela.window)) self.player1 = Obj("assets/player1.png", 50, 300) self.tela.add_obj(self.player1.drawing(self.tela.window))
def __init__(self): self.room_objects = [ Obj(Vector2D(self.view.pos.x + 5, 1), load_texture("other", 1), style=colorama.Style.BRIGHT), Obj(Vector2D(self.view.pos.x + 5, 10), load_texture("other", 4)), Obj(Vector2D(self.view.pos.x + 5, 15), load_texture("other", 4)), Obj(Vector2D(self.view.pos.x + 5 + 3, 12), "Retry"), Obj(Vector2D(self.view.pos.x + 5 + 3, 17), "Exit") ]
def gameLoop(): # init variables # set room to porch # sprList is list of objects in the room gameExit = False #loadObj{ box1 = Obj('../art/obj1.png', "obj1") box2 = Obj('../art/obj2.png', "obj2") #} uniqueObj = pygame.sprite.Group() #load obj { uniqueObj.add(box1) uniqueObj.add(box2) #} #loadRooms{ intro = Room("porch", BLUE) intro.addObj("obj1", "obj1", (0, 0), 0) intro.addObj("obj2", "obj2", (200, 200), 0) while not gameExit: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() # if event.type == pygame.MOUSEBUTTONDOWN: # pos = event.pos # # for sprite in uniqueObj: # if sprite.rect.collidepoint(pos): # print("OPEN") #stuff happens here print(event) #displayRoom{ #change bg colour showObjList = pygame.sprite.Group() gameDisplay.fill(intro.col) for o in intro.roomObj: print() print("ST - ", o) for s in uniqueObj.sprites(): print("ST2 - ", s.name) if o.startswith(s.name): print("FOUND") s.rect.x, s.rect.y = intro.roomObj[o] s.update() s.draw(gameDisplay) break #} pygame.display.update() clock.tick(60)
def __init__(self): self.bg = Obj("assets/bg.png", 0, 0) self.bg2 = Obj("assets/bg.png", 0, -640) self.spider = Obj("assets/spider1.png", random.randrange(0, 320), -50) self.flower = Obj("assets/florwer1.png", random.randrange(0, 320), 200) self.bee = Bee("assets/bee1.png", 150, 600) self.change_scene = False self.score = Text(120, "0") self.lifes = Text(60, "3")
def glLoad(self, filename,translate, scale): model = Obj(filename) c=0 for face in model.faces: if c >8939: self.glColor(1,1,1) elif c < 8939 and c>6060: self.glColor(0,0,1) else: self.glColor(1,0,0) c+=1 vcount = len(face) for j in range(vcount): f1 = face[j][0] f2 = face[(j + 1) % vcount][0] v1 = model.vertices[f1 - 1] v2 = model.vertices[f2 - 1] x1 = round((v1[0] + translate[0]) * scale[0]) y1 = round((v1[1] + translate[1]) * scale[1]) x2 = round((v2[0] + translate[0]) * scale[0]) y2 = round((v2[1] + translate[1]) * scale[1]) self.glLine(x1, y1, x2, y2)
def test_directional_sensors(): a = Animat() lx, ly = 0.5, 0.5 # obj position o = Obj(lx, ly, 'default') a.add_obj(o) res = np.linspace(0, 1, 50) mesh = np.meshgrid(res, res) def f(coords): a.x = coords[0] a.y = coords[1] a.update_sensors() return a.sensors['default'][Sides.LEFT] zs = np.apply_along_axis(f, 0, mesh) imshow(zs, extent=[0, 1, 0, 1], origin='lower') plot(lx, ly, 'wo', label='object') xlabel('animat position') ylabel('animat position') title('Animat is facing to the right') legend() show()
def load(self, filename, translate=(0, 0), scale=(1, 1)): """ Loads an obj file in the screen wireframe only Input: filename: the full path of the obj file translate: (translateX, translateY) how much the model will be translated during render scale: (scaleX, scaleY) how much the model should be scaled """ model = Obj(filename) for face in model.vfaces: vcount = len(face) for j in range(vcount): f1 = face[j][0] f2 = face[(j + 1) % vcount][0] v1 = model.vertices[f1 - 1] v2 = model.vertices[f2 - 1] scaleX, scaleY = scale translateX, translateY = translate x1 = round((v1[0] + translateX) * scaleX) y1 = round((v1[1] + translateY) * scaleY) x2 = round((v2[0] + translateX) * scaleX) y2 = round((v2[1] + translateY) * scaleY) self.line((x1, y1), (x2, y2))
def glLoadObjWireFrame(self, filename, translateX, translateY, scaleX, scaleY): # Se instancia la clase Obj obj = Obj(filename) for face in obj.faces: # Se establece la cantidad de vertices en cada cara vertexCount = len(face) for i in range(vertexCount): # Para hacer una linea se toma el vertice que indica i y el siguiente despues de i f1 = face[i] - 1 nextVertex = i + 1 # Si i es el ultimo vertice se conectara con el primero if nextVertex >= vertexCount: nextVertex -= vertexCount f2 = face[nextVertex] - 1 # Se encuentran las coordenadas de los vertices de la linea v1 = obj.vertices[f1] v2 = obj.vertices[f2] # Se establecen los puntos inicial y final de la linea, se aplica la traslacion y la escala x1 = (v1[0] + translateX) * scaleX y1 = (v1[1] + translateY) * scaleY x2 = (v2[0] + translateX) * scaleX y2 = (v2[1] + translateY) * scaleY # Se dibuja la linea self.glLine(x1, y1, x2, y2)
def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1), rotate=(0, 0, 0)): self.loadModelMatrix(translate, scale, rotate) model = Obj(filename) vertex_buffer_object = [] for face in model.faces: for facepart in face: try: vertex = self.transform(V3(*model.vertices[facepart[0]])) vertex_buffer_object.append(vertex) except Exception as e: continue if self.active_texture: for facepart in face: try: tvertex = V3(*model.tvertices[facepart[1]]) vertex_buffer_object.append(tvertex) except Exception as e: continue for facepart in face: try: nvertex = V3(*model.normals[facepart[2]]) vertex_buffer_object.append(nvertex) except Exception as e: continue self.active_vertex_array = iter(vertex_buffer_object)
def loadGame(self, gameName): gamePath = './saved_games/' + gameName + '/game_state.txt' if os.path.exists(gamePath) == False: return -1 inputGame = open(gamePath, 'r') for line in inputGame: if 'currentRoom' in line: words = re.split("[:]+", line) words = [x.strip() for x in words] gameStateData = Room() gameStateData.loadRoom(gameName, words[1]) elif 'inventory' in line: words = re.split("[:,]+", line) words = [x.strip() for x in words] gameStateData = [] if len(words) > 1 and words[1] != '': for x in words[1:]: myObject = Obj() myObject.loadObject(gameName, x) gameStateData.append(myObject) else: words = re.split("[:]+", line) words = [x.strip() for x in words] gameStateData = words[1] setattr(self, words[0], gameStateData)
def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1), texture=None): """ Loads an obj file in the screen Input: filename: the full path of the obj file translate: (translateX, translateY) how much the model will be translated during render scale: (scaleX, scaleY) how much the model should be scaled texture: texture file to use """ model = Obj(filename) vertex_buffer_object = [] for face in model.vfaces: vcount = len(face) for v in range(vcount): vertex = self.transform(model.vertices[face[v][0]], translate, scale) vertex_buffer_object.append(vertex) if self.active_texture: for v in range(vcount): tvertex = V3(*model.tvertices[face[v][1]]) vertex_buffer_object.append(tvertex) self.active_vertex_array = iter(vertex_buffer_object)
def glLoadOld(filename,translate=(0,0),scale=(1,1)): global my_bitmap model = Obj(filename) for face in model.vfaces: vcount = len(face) #print(vcount) for j in range(vcount): f1 = face[j][0] f2 = face[(j+1)%vcount][0] v1 = model.vertices[f1-1] v2 = model.vertices[f2-1] scaleX,scaleY = scale translateX,translateY = translate x1 = round((v1[0] + translateX) * scaleX) x1 = round(x1/(my_bitmap.width/2),2) y1 = round((v1[1] + translateY) * scaleY) y1 = round(y1/(my_bitmap.height/2),2) x2 = round((v2[0] + translateX) * scaleX) x2 = round(x2/(my_bitmap.width/2),2) y2 = round((v2[1] + translateY) * scaleY) y2 = round(y2/(my_bitmap.height/2),2) #print(x1,x2,y1,y2) glLine(x1,y1,x2,y2,0.004)
def move_flower(self): self.flower.sprite.rect[1] += 2 if self.flower.sprite.rect[1] > 640: self.flower.sprite.kill() self.flower = Obj("assets/florwer1.png", random.randrange(0, 320), -10)
def move_spiders(self): self.spider.sprite.rect[1] += 11 if self.spider.sprite.rect[1] > 640: self.spider.sprite.kill() self.spider = Obj("assets/spider1.png", random.randrange(0, 320), -50)
def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1)): """ Loads an obj file in the screen wireframe only Input: filename: the full path of the obj file translate: (translateX, translateY) how much the model will be translated during render scale: (scaleX, scaleY) how much the model should be scaled """ model = Obj(filename) light = V3(0,0,1) for face in model.vfaces: vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 a = self.transform(model.vertices[f1], translate, scale) b = self.transform(model.vertices[f2], translate, scale) c = self.transform(model.vertices[f3], translate, scale) normal = norm(cross(sub(b, a), sub(c, a))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue self.triangle(a, b, c, color(grey, grey, grey)) else: # assuming 4 f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 vertices = [ self.transform(model.vertices[f1], translate, scale), self.transform(model.vertices[f2], translate, scale), self.transform(model.vertices[f3], translate, scale), self.transform(model.vertices[f4], translate, scale) ] normal = norm(cross(sub(vertices[0], vertices[1]), sub(vertices[1], vertices[2]))) # no necesitamos dos normales!! intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue # dont paint this face # vertices are ordered, no need to sort! # vertices.sort(key=lambda v: v.x + v.y) A, B, C, D = vertices self.triangle(A, B, C, color(grey, grey, grey)) self.triangle(A, C, D, color(grey, grey, grey))
def glLoad(filename,translate=(0,0,0),scale=(1,1,1),texture=None,shader=None,normalmap=None): #print(texture) global my_bitmap model = Obj(filename) my_bitmap.light = V3(0,0,1) my_bitmap.texture = texture my_bitmap.shader = shader my_bitmap.normalmap = normalmap for face in model.vfaces: vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 a = glTransform(model.vertices[f1], translate, scale) b = glTransform(model.vertices[f2], translate, scale) c = glTransform(model.vertices[f3], translate, scale) n1 = face[0][2] - 1 n2 = face[1][2] - 1 n3 = face[2][2] - 1 nA = V3(*model.normals[n1]) nB = V3(*model.normals[n2]) nC = V3(*model.normals[n3]) t1 = face[0][1] - 1 t2 = face[1][1] - 1 t3 = face[2][1] - 1 tA = V3(*model.tvertices[t1]) tB = V3(*model.tvertices[t2]) tC = V3(*model.tvertices[t3]) triangle(a,b,c,texture_coords=(tA,tB,tC),varying_normals=(nA,nB,nC)) else: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 vertices = [ glTransform(model.vertices[f1],translate,scale), glTransform(model.vertices[f2],translate,scale), glTransform(model.vertices[f3],translate,scale), glTransform(model.vertices[f4],translate,scale) ] normal = norm(cross(sub(vertices[0], vertices[1]), sub(vertices[1], vertices[2]))) intensity = dot(normal,my_bitmap.light) grey = round(255 * intensity) if grey < 0: continue A,B,C,D = vertices #if not texture: triangle(A, B, C, color(grey, grey, grey)) triangle(A, C, D, color(grey, grey, grey))
def load(self, filename, translate=(0, 0, 0), scale=(1, 1, 1), texture=None, shader=None, normalmap=None): model = Obj(filename) self.light = V3(0,0,1) self.texture = texture self.shader = shader self.normalmap = normalmap for face in model.faces: vcount = len(face) if vcount==3: f1 = face[0][0]-1 f2 = face[1][0]-1 f3 = face[2][0]-1 a= self.transform(model.vertices[f1],translate,scale) b= self.transform(model.vertices[f2],translate,scale) c= self.transform(model.vertices[f3],translate,scale) n1 = face[0][2] -1 n2 = face[1][2] -1 n3 = face[2][2] -1 nA = V3(*model.normals[n1]) nB = V3(*model.normals[n2]) nC = V3(*model.normals[n3]) t1 = face[0][1]-1 t2 = face[1][1]-1 t3 = face[2][1]-1 tA = V3(*model.tvertices[t1]) tB = V3(*model.tvertices[t2]) tC = V3(*model.tvertices[t3]) self.triangle(a,b,c, texture_coords=(tA,tB,tC),varying_normals=(nA,nB,nC)) else: f1 = face[0][0]-1 f2 = face[1][0]-1 f3 = face[2][0]-1 f4 = face[3][0]-1 vertices = [ self.transform(model.vertices[f1],translate,scale), self.transform(model.vertices[f2],translate,scale), self.transform(model.vertices[f3],translate,scale), self.transform(model.vertices[f4],translate,scale) ] normal = norm(cross(sub(vertices[0],vertices[1]),sub(vertices[1],vertices[2]))) intensity = dot(normal,self.light) grey = round(255*intensity) if grey<0: continue A,B,C,D = vertices self.triangle(A, B, C, color(grey, grey, grey)) self.triangle(A, C, D, color(grey, grey, grey))
def loadModel(self, filename, translate=V3(0, 0, 0), scale=V3(1, 1, 1), rotate=V3(0, 0, 0), isWireframe=False): model = Obj(filename) modelMatrix = self.createObjectMatrix(translate, scale, rotate) rotationMatrix = self.createRotationMatrix(rotate) for face in model.faces: vertCount = len(face) v0 = model.vertices[face[0][0] - 1] v1 = model.vertices[face[1][0] - 1] v2 = model.vertices[face[2][0] - 1] if vertCount > 3: v3 = model.vertices[face[3][0] - 1] v0 = self.transform(v0, modelMatrix) v1 = self.transform(v1, modelMatrix) v2 = self.transform(v2, modelMatrix) if vertCount > 3: v3 = self.transform(v3, modelMatrix) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0, 0) vt1 = V2(0, 0) vt2 = V2(0, 0) vt3 = V2(0, 0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] vn0 = self.dirTransform(vn0, rotationMatrix) vn1 = self.dirTransform(vn1, rotationMatrix) vn2 = self.dirTransform(vn2, rotationMatrix) if vertCount > 3: vn3 = model.normals[face[3][2] - 1] vn3 = self.dirTransform(vn3, rotationMatrix) self.triangle_bc(v0, v1, v2, texcoords=( vt0, vt1, vt2), normals=(vn0, vn1, vn2)) if vertCount > 3: # asumamos que 4, un cuadrado self.triangle_bc(v0, v2, v3, texcoords=( vt0, vt2, vt3), normals=(vn1, vn2, vn3))
def glLoadModel_texture(self, filename, translate = V3(0,0,0), scale = V3(1,1,1), texture = None): model = Obj(filename) light = V3(0,0,1) for face in model.faces: vertCount = len(face) v0 = model.vertices[ face[0][0] - 1 ] v1 = model.vertices[ face[1][0] - 1 ] v2 = model.vertices[ face[2][0] - 1 ] if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v0 = self.transform_original(v0,translate, scale) v1 = self.transform_original(v1,translate, scale) v2 = self.transform_original(v2,translate, scale) if vertCount > 3: v3 = self.transform_original(v3,translate, scale) if texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0,0) vt1 = V2(0,0) vt2 = V2(0,0) vt3 = V2(0,0) s1 = V3((v1.x - v0.x), (v1.y - v0.y), (v1.z - v0.z)) s2 = V3((v2.x - v0.x), (v2.y - v0.y), (v2.z - v0.z)) normal = V3(((s1.y * s2.z)- (s2.y * s1.z)), -((s1.x * s2.z)- (s2.x * s1.z)), ((s1.x * s2.y)- (s2.x * s1.y))) try: norm_normal = ( abs(normal.x)**2 + abs(normal.y)**2 + abs(normal.z)**2 )**(1/2) normal = V3((normal.x / norm_normal), (normal.y / norm_normal), (normal.z / norm_normal)) intensity = (normal.x * light.x) + (normal.y * light.y) + (normal.z * light.z) if intensity >=0: self.triangle_bc_texture(v0,v1,v2, texture = texture, texcoords = (vt0,vt1,vt2), intensity = intensity ) if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v3 = self.transform_original(v3,translate, scale) self.triangle_bc_texture(v0,v2,v3, texture = texture, texcoords = (vt0,vt2,vt3), intensity = intensity) except: pass
def glLoadModel(self, filename, translate = V3(0,0,0), scale = V3(1,1,1), rotate=V3(0,0,0)): model = Obj(filename) mMatrix = modelMatrix(translate, scale, rotate) rMatrix = rotationMatrix(rotate) for face in model.faces: vertCount = len(face) v0 = model.vertices[ face[0][0] - 1 ] v1 = model.vertices[ face[1][0] - 1 ] v2 = model.vertices[ face[2][0] - 1 ] if vertCount > 3: v3 = model.vertices[ face[3][0] - 1 ] v0 = self.transform(v0, mMatrix) v1 = self.transform(v1, mMatrix) v2 = self.transform(v2, mMatrix) if vertCount > 3: v3 = self.transform(v3, mMatrix) if self.active_texture: vt0 = model.texcoords[face[0][1] - 1] vt1 = model.texcoords[face[1][1] - 1] vt2 = model.texcoords[face[2][1] - 1] vt0 = V2(vt0[0], vt0[1]) vt1 = V2(vt1[0], vt1[1]) vt2 = V2(vt2[0], vt2[1]) if vertCount > 3: vt3 = model.texcoords[face[3][1] - 1] vt3 = V2(vt3[0], vt3[1]) else: vt0 = V2(0,0) vt1 = V2(0,0) vt2 = V2(0,0) vt3 = V2(0,0) vn0 = model.normals[face[0][2] - 1] vn1 = model.normals[face[1][2] - 1] vn2 = model.normals[face[2][2] - 1] vn0 = self.dirTransform(vn0, rMatrix) vn1 = self.dirTransform(vn1, rMatrix) vn2 = self.dirTransform(vn2, rMatrix) if vertCount > 3: vn3 = model.normals[face[3][2] - 1] vn3 = self.dirTransform(vn3, rMatrix) try: self.triangle_bc(v0,v1,v2, texcoords = (vt0,vt1,vt2), normals = (vn0,vn1,vn2)) if vertCount > 3: self.triangle_bc(v0,v2,v3, texcoords = (vt0,vt2,vt3), normals = (vn0,vn2,vn3)) except: pass
def init_grid(dimension): grid = [] for row in range(dimension): grid.append([]) for col in range(dimension): piece = Obj(row, col) grid[row].append(piece) return grid
def generateFood(self): row = None col = None while True: row = random.randint(0, util.Constants.GAME_WINDOW_HEIGHT) col = random.randint(0, util.Constants.GAME_WINDOW_WIDTH) if self.board[row][col] == None: self.food = Obj(row, col, util.Constants.FOOD_COLOR) self.placeObj(self.food) return self.food
def __init__(self, filename, texture_name, scale): self.model = Obj(filename) self.createVertBuffer() self.texture_surface = pygame.image.load(texture_name) self.texture_data = pygame.image.tostring(self.texture_surface, "RGB", 1) self.texture = glGenTextures(1) self.position = glm.vec3(0, 0, 0) self.rotation = glm.vec3(0, 0, 0) self.scale = scale
def detect_bounce(msg): analysis = lamson.bounce.detect(Obj(base=lamson.encoding.from_message(msg))) print('Lamson bounce analysis: {}'.format(analysis.__dict__)) if analysis.is_hard(): print('Hard bounce.') return ResponseType.hard if analysis.is_soft(): print('Soft bounce.') return ResponseType.soft # TODO: detect complaints return ResponseType.unknown
def draw(self): temp_objects = [] if (self.score_window): self.draw_score() else: if (self.run): for i in self.sector[0].enemies: for j in i.laser: if (j.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(j) if (i.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(i) for i in self.sector[0].obstacles: if (i.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(i) for i in self.sector[0].powerups: if (i.hitbox.check_hitbox(self.view.hitbox)): temp_objects.append(i) temp_objects.append(self.player) for i in self.player.laser: temp_objects.append(i) hud = [ Obj(Vector2D(self.view.pos.x + 1, 2), Graphics.draw_hline(148, 1)), Obj(Vector2D(self.view.pos.x + 1, 1), "HP:[" + "█" * (self.player.hp * 2) + " " * (10 - self.player.hp * 2) + "]", fore_color=colorama.Fore.RED, bg_color=colorama.Back.BLACK, style=colorama.Style.BRIGHT), Obj( Vector2D(self.view.pos.x + 135, 1), "Score:[" + " " * (6 - len(str(self.score))) + str(self.score) + "]") ] self.last_matrix = Graphics.draw(temp_objects, self.view, matrix=self.last_matrix, hud=hud)
def Model(self, filename, translate, scale): modelo = Obj(filename) for face in modelo.faces: vertCount = len(face) for vert in range(vertCount): v0 = modelo.vertices[face[vert][0] - 1] v1 = modelo.vertices[face[(vert + 1) % vertCount][0] - 1] x0 = int(v0[0] * scale[0] + translate[0]) y0 = int(v0[1] * scale[1] + translate[1]) x1 = int(v1[0] * scale[0] + translate[0]) y1 = int(v1[1] * scale[1] + translate[1]) self.glLine(x0, y0, x1, y1)
def push_the_objects(self): tmi_values = tmi.values() for i in range(config['height'] // 8): for j in range(config['width'] // 8): data = pyxel.tilemap(self.current_tm).get( j + self.tm_offsetX, i + self.tm_offsetY) if data in tmi_values: self.world.push( Obj(j * 8, i * 8, 8, 8, get_key(tmi, data)[0]))
def load(self, filename, translate, scale, texture=None): model = Obj(filename) light = V3(0, 0, 1) for face in model.faces: vcount = len(face) vertices = [] tvertices = [] for j in range(vcount): f1 = face[j][0] - 1 v1 = model.vertices[f1] x1 = round((v1[0] + translate[0]) * scale[0]) y1 = round((v1[1] + translate[1]) * scale[1]) z1 = round((v1[2] + translate[2]) * scale[2]) # self.glLine(V2(x1, y1), V2(x2, y2), glColor(random.randint(0,255),random.randint(0,255),random.randint(0,255))) vertices.append(V3(x1, y1, z1)) f1t = face[j][1] - 1 v1t = model.tvertices[f1t] tvertices.append(V2(v1t[0], v1t[1])) randomColor = glColor(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) A = vertices[0] B = vertices[1] C = vertices[2] normal = norm(cross(sub(B, A), sub(C, A))) intensity = dot(normal, light) grey = round(255 * intensity) if grey < 0: continue # intensityColor = glColor(grey,grey,grey) tA = vertices[0] tB = vertices[1] tC = vertices[2] self.triangle(vertices=(A, B, C), tvertices=(tA, tB, tC), texture=texture # intensityColor )