def collide(self, player, cpu): """ Checks if ball has hit a paddle """ if collide.collide(self, cpu) == True: self.x_speed = -self.x_speed if collide.collide(self, player): self.x_speed = -self.x_speed
def objectObjectCollisions(self,object,object2): if isinstance(object,RigidObjectModel): try: object = [o for o in xrange(self.world.numRigidObjects()) if self.world.rigidObject(o).getID()==object.getID()][0] except IndexError: raise RuntimeError("RigidObject "+object.getName()+" is not found in the world!") if isinstance(object2,RigidObjectModel): try: object2 = [o for o in xrange(self.world.numRigidObjects()) if self.world.rigidObject(o).getID()==object2.getID()][0] except IndexError: raise RuntimeError("RigidObject "+object2.getName()+" is not found in the world!") if object2 == None: #test all terrains for o in xrange(len(self.rigidObjects)): for c in self.objectObjectCollisions(objectot): yield c return oindex = self.rigidObjects[object] oindex2 = self.rigidObjects[object2] if oindex < 0: return if oindex2 < 0: return if oindex not in self.mask[oindex2]: return self.updateFrame(*self.geomList[oindex]) self.updateFrame(*self.geomList[oindex2]) if collide.collide(self.geomList[oindex][1],self.geomList[oindex2][1]): yield (self.geomList[oindex][0],self.geomList[oindex2][0]) return
def objectTerrainCollisions(self,object,terrain=None): if isinstance(object,RigidObjectModel): try: object = [o for o in xrange(self.world.numRigidObjects()) if self.world.rigidObject(o).getID()==object.getID()][0] except IndexError: raise RuntimeError("RigidObject "+object.getName()+" is not found in the world!") if isinstance(terrain,TerrainModel): try: terrain = [t for t in xrange(self.world.numTerrains()) if self.world.terrain(t).getID()==terrain.getID()][0] except IndexError: raise RuntimeError("Terrain "+robot.getName()+" is not found in the world!") if terrain == None: #test all terrains for t in xrange(len(self.terrains)): for c in self.objectTerrainCollisions(object,t): yield c return oindex = self.rigidObjects[object] tindex = self.terrains[terrain] if oindex < 0: return if tindex < 0: return if tindex not in self.mask[oindex]: return self.updateFrame(*self.geomList[oindex]) if collide.collide(self.geomList[oindex][1],self.geomList[tindex][1]): q = collide.makeCollQuery(self.geomList[oindex][1],self.geomList[tindex][1]) coll = collide.queryCollide(q) d = collide.queryDistance(q,0,0) (cp1,cp2) = collide.queryClosestPoints(q) #print "Coll",coll,"dist",d,"Cps:",(se3.apply(self.geomList[oindex][0].getTransform(),cp1),cp2) collide.destroyCollQuery(q) yield (self.geomList[oindex][0],self.geomList[tindex][0]) return
def robotTerrainCollisions(self,robot,terrain=None): """Given robot and terrain indices, tests all collisions between robot links and the terrain""" if isinstance(robot,RobotModel): try: robot = [r for r in xrange(self.world.numRobots()) if self.world.robot(r).getID()==robot.getID()][0] except IndexError: raise RuntimeError("Robot "+robot.getName()+" is not found in the world!") if isinstance(terrain,TerrainModel): try: terrain = [t for t in xrange(self.world.numTerrains()) if self.world.terrain(t).getID()==terrain.getID()][0] except IndexError: raise RuntimeError("Terrain "+robot.getName()+" is not found in the world!") if terrain == None: #test all terrains for t in xrange(len(self.terrains)): for c in self.robotTerrainCollisions(robot,t): yield c return rindices = self.robots[robot] tindex = self.terrains[terrain] if tindex < 0: return self.updateFrame(*self.geomList[tindex]) for i in rindices: if i < 0: continue if tindex not in self.mask[i]: continue self.updateFrame(*self.geomList[i]) if collide.collide(self.geomList[tindex][1],self.geomList[i][1]): yield (self.geomList[i][0],self.geomList[tindex][0])
def robotObjectCollisions(self,robot,object=None): """Given robot and object indices, tests all collisions between robot links and the object. If object is not provided, all objects are tested""" if isinstance(robot,RobotModel): try: robot = [r for r in xrange(self.world.numRobots()) if self.world.robot(r).getID()==robot.getID()][0] except IndexError: raise RuntimeError("Robot "+robot.getName()+" is not found in the world!") if isinstance(object,RigidObjectModel): try: object = [o for o in xrange(self.world.numRigidObjects()) if self.world.rigidObject(o).getID()==object.getID()][0] except IndexError: raise RuntimeError("RigidObject "+object.getName()+" is not found in the world!") if object == None: #test all objects for o in xrange(len(self.rigidObjects)): for c in self.robotObjectCollisions(robot,o): yield c return rindices = self.robots[robot] oindex = self.rigidObjects[object] if oindex < 0: return self.updateFrame(*self.geomList[oindex]) for i in rindices: if i < 0: continue if oindex not in self.mask[i]: continue self.updateFrame(*self.geomList[i]) if collide.collide(self.geomList[oindex][1],self.geomList[i][1]): yield (self.geomList[i][0],self.geomList[oindex][0])
def robotSelfCollisions(self,robot=None): """Given robot, tests all self collisions. If robot is None, all robots are tested. If robots is an index or a RobotModel object only collisions for that robot are tested""" if isinstance(robot,RobotModel): try: robot = [r for r in xrange(self.world.numRobots()) if self.world.robot(r).getID()==robot.getID()][0] except IndexError: raise RuntimeError("Robot "+robot.getName()+" is not found in the world!") if robot == None: #test all robots for r in xrange(len(self.robots)): for c in self.robotSelfCollisions(r): yield c return rindices = self.robots[robot] for i in rindices: if i < 0: continue self.updateFrame(*self.geomList[i]) for i in rindices: if i < 0: continue for j in rindices: if i < j: break if j not in self.mask[i]: continue if collide.collide(self.geomList[i][1],self.geomList[j][1]): yield (self.geomList[i][0],self.geomList[j][0])
def collisions(self,filter1=None,filter2=None): """Returns an iterator over the colliding pairs of objects, optionally that satisfies the filter(s)""" self.updateFrames() for (g0,g1) in self.collisionTests(filter1,filter2): if collide.collide(g0[1],g1[1]): yield (g0[0],g1[0])
def update(self, bulletsMgr, player): colider = collide.collide() self.timer() if self.canSpawn(): self.new(vec2.vec2(random.randint(20,780), -50)) for bullet in bulletsMgr.bullets: for asteroid in self.asteroids: if colider.collideRectRect(asteroid, bullet): bulletsMgr.bullets.remove(bullet) self.asteroids.remove(asteroid) player.score += 1 print(player.score) for asteroid in self.asteroids: if colider.collideRectRect(player.var, asteroid): player.exit = True self.clear() bulletsMgr.clear() asteroid.pos.y += 0.2 if asteroid.pos.y >= 600: self.asteroids.remove(asteroid)
def update(self, surface, otherCars): # surface: (us, uk, rr) self.mutex.acquire() call_time = time.time() delta = call_time - self.last_time self.last_time = time.time() t = self.throttle_curve() if math.hypot(*self.vel) != 0: b = self.brakes * BRAKE_FORCE else: b = 0 if self.wtheta != 0: ft = (-self.vel[1] * TURNCONST * (1 if self.wtheta > 0 else -1 if self.wtheta < 0 else 0), self.vel[0] * TURNCONST * (1 if self.wtheta > 0 else -1 if self.wtheta < 0 else 0)) else: ft = (0, 0) fv = ((t - b - surface[2]) * math.cos(self.theta) + ft[0], (t - b - surface[2]) * math.sin(self.theta) + ft[1]) self.pos = (self.pos[0] + delta * self.vel[0] + .5 * (fv[0] / MASS) * delta**2, self.pos[1] + delta * self.vel[1] + .5 * (fv[1] / MASS) * delta**2) self.vel = (self.vel[0] + (fv[0] / MASS) * delta, self.vel[1] + (fv[1] / MASS) * delta) # vel = math.sqrt(self.vel[0]**2 + self.vel[1]**2) # self.theta = self.theta + self.wtheta * vel * DUMB_CONST if self.vel[1] != 0 or self.vel[0] != 0: self.theta = math.atan2(self.vel[1], self.vel[0]) for car in otherCars: if collide.hit_cars(self, car): collide.collide(self, car) self.mutex.release()
def __init__(self, body_1: Body, body_2: Body) -> None: if id(body_1) < id(body_2): self.body_1 = body_1 self.body_2 = body_2 else: self.body_1 = body_2 self.body_2 = body_1 self.contacts = collide(self.body_1, self.body_2) self.friction = np.sqrt(self.body_1.friction * self.body_2.friction)
def Collide(self): ''' Collide stuff ''' # Collide bullets with asteroids if Asteroid in self._entities: roids = self._entities[Asteroid] if Player.Clonk in self._entities: for clonk in self._entities[Player.Clonk]: for roid in roids: if collide.collide(roid.Collision(), clonk.Collision()): if clonk.IsAlive() and roid.IsAlive(): roid.Clonk() self._maingame.Score().AddScore() roid.Kill() clonk.Kill() # Collide player with asteroids for roid in roids: if collide.collide(roid.Collision(), self._player.Collision()): roid.Kill() self._maingame.DieScreen() self._player.Kill()
def generate(self): """ Generate the hashquine """ graphic_control_extension = b'\x21\xf9\x04\x04\x02\x00\x00\x00' alternatives = {} # (char_pos, char): (coll_pos, coll) # header generated_gif = self.background_blocks['header'] generated_gif += self.background_blocks['lcd'] generated_gif += self.background_blocks['gct'] # place comment comment = b'Copyheart Rogdham, 2017\n' comment += b'<3 Copying is an act of love. Please copy and share.\n\n' comment += b'Released under the CC0 1.0 universel licence\nSee ' comment += b'https://creativecommons.org/publicdomain/zero/1.0/deed.fr' comment += b'\n' generated_gif += b'\x21\xfe%s%s\x00' % (bytes([len(comment)]), comment) # place background generated_gif += graphic_control_extension generated_gif += self.background_blocks['img_descriptor'] generated_gif += self.background_blocks['img_data'] # start comment generated_gif += b'\x21\xfe' # generate all possible md5 characters frames top, left = self.hash_img_coordinates for char_pos in range(32): left += self.char_width if self.md5_mask[char_pos] != ' ': continue for char in range(16): char_img = graphic_control_extension char_img += b'\x2c%s\x00' % struct.pack( # img descriptor '<HHHH', left, top, self.char_width, self.char_height) char_img += self.chars_img_data[char] # add comment to align to a md5 block coll_diff = collide.COLLISION_LAST_DIFF align = 64 - (len(generated_gif) % 64) generated_gif += bytes([align - 1 + coll_diff]) generated_gif += b'\x00' * (align - 1) # any char would do # generate collision while True: print('Generating collision', char_pos * 16 + char + 1) coll_img, coll_nop = collide.collide(generated_gif) assert coll_img[coll_diff] < coll_nop[coll_diff] offset = collide.COLLISION_LEN - coll_diff - 1 coll_p_img = coll_img[coll_diff] - offset coll_p_nop = coll_nop[coll_diff] - offset pad_len = coll_p_nop - coll_p_img - len(char_img) - 4 if coll_p_img >= 0 and pad_len >= 0: break print('Unsatisfying collision, trying again') # push collision alternatives[char_pos, char] = (len(generated_gif), coll_img) generated_gif += coll_nop # continue comment up to image generated_gif += b'\x00' * coll_p_img # any char would do generated_gif += b'\x00' # end comment # add image generated_gif += char_img # start comment and align with big comment (end of coll_nop) generated_gif += b'\x21\xfe' generated_gif += bytes([pad_len]) generated_gif += b'\x00' * pad_len # any char would do # add a comment and bruteforce it until GIF md5 match the md5 mask current_md5 = md5(generated_gif) print('Bruteforcing final md5...') for garbage in range(1 << 32): # 32 bits of bf should be enough end = struct.pack( '<BIBB', 4, garbage, # comment sub-block 0, # end comment 0x3b) # trailer new_md5 = current_md5.copy() new_md5.update(end) for mask_char, md5_char in zip(self.md5_mask, new_md5.hexdigest()): if mask_char != ' ' and mask_char != md5_char: break else: generated_gif += end break else: raise ValueError('Did not find a GIF matching the md5 mask') # replace colls to show md5 print('Target md5:', md5(generated_gif).hexdigest()) for char_pos, char in enumerate(md5(generated_gif).hexdigest()): if self.md5_mask[char_pos] != ' ': continue coll_pos, coll = alternatives[char_pos, int(char, 16)] generated_gif = (generated_gif[:coll_pos] + coll + generated_gif[coll_pos + len(coll):]) print('Final md5: ', md5(generated_gif).hexdigest()) return generated_gif