def on_update(self, dt): self.oldx, self.oldy = self.x, self.y self.dmg = 10 * self.bonusdmg self.scale = 0.5 * self.game.kscale if self.game.keys[self.l]: self.nose -= (self.force) / 1.5 if self.game.keys[self.r]: self.nose += (self.force) / 1.5 if self.game.keys[self.d]: self.force -= 0.2 if self.force < -2: self.force = -2 pass if self.game.keys[self.u]: self.force += self.accel if self.force > 6: self.force = 6 else: self.force = decrease(self.force, self.accel) self.velocity[0] = decrease(self.velocity[0], self.accel) self.velocity[1] = decrease(self.velocity[1], self.accel) self.velocity[0] = +math.sin(math.radians(self.nose)) * self.force self.velocity[1] = +math.cos(math.radians(self.nose)) * self.force # Moving self.rotation = self.nose self.x += self.velocity[0] self.y += self.velocity[1] # Obstacle collision wallcollision = collision.Collision(self.game.points, self) if wallcollision.happened: responsevec = wallcollision.response() mtv = wallcollision.getMTV() self.x = self.x - mtv[0] + responsevec[0] self.y = self.y - mtv[1] + responsevec[1] self.force = decrease(self.force, self.accel * 2) # If response collides as well... wallcollision2 = collision.Collision(self.game.points, self) if wallcollision2.happened: self.x = self.oldx self.y = self.oldy # Bonus collision for bonus in Bonus._registry: if self.overlap(bonus): bonus.do(self)
def __init__(self, size=(700, 700)): super().__init__() self.geometrie = collision.Collision() self.x_mouse, self.y_mouse = 0, 0 self.size = size self.fps = 60 self.map = map.Map(self.size, 0) self.map.startPoint, self.map.finishPoint = QPoint(-100, -100), QPoint( -100, -100) self.poly = [] self.distance_min = 20 self.title = 'untitled' self.mode_edition = 0 self.distance_selection = 20 self.selectedPoint = (False, 0) self.style_base = QPen(Qt.white, 2, Qt.SolidLine) self.style_gris = QPen(Qt.gray, 2, Qt.SolidLine) self.style_fin = QPen(Qt.red, 2, Qt.SolidLine) self.style_rouge = QPen(Qt.red, 4, Qt.SolidLine) self.style_vert = QPen(Qt.green, 2, Qt.SolidLine) self.style_jaune = QPen(Qt.yellow, 2, Qt.SolidLine) title_font = QtGui.QFont() title_font.setFamily("Cooper Black") title_font.setPointSize(14) self.initWindow() self.timer = QTimer(self) self.timer.timeout.connect(self.update) self.timer.start(1000 / self.fps)
def move_y(self, room): self.y += self.base_dy + self.dy self.collider.y = self.y collisions = self.get_collisions(room) collisions = [c for c in collisions if self.collides_with(c)] bounce_scale = 0 for c in collisions: relative_vel = self.base_dy + self.dy if isinstance(c, PhysicsObject): relative_vel -= c.dy if relative_vel > 0: self.collider.bottom = c.collider.top self.y = self.collider.y self.ground_collision = True self.friction = c.friction self.collisions.append( collision.Collision(c, collision.Direction.down)) elif relative_vel < 0: self.collider.top = c.collider.bottom self.y = self.collider.y self.ceiling_collision = True self.collisions.append( collision.Collision(c, collision.Direction.up)) if c.group is CollisionGroup.springs: c.bounce() if self.dy != 0: bounce_scale = 3 * helpers.SCALE / self.dy else: bounce_scale = self.bounce_scale(c) if abs(relative_vel) >= helpers.SCALE: if c.group is not CollisionGroup.springs: self.sounds.add('bump') if collisions: self.dy *= -bounce_scale else: self.ground_collision = False self.ceiling_collision = False
def __init__(self, level=10): super().__init__() self.collision = collision.Collision() self.size = (700, 700) self.model = model.Model(self.size, level) self.r_player = 10 self.r_deplacement = 100 self.fps = 60 self.game_over = False self.tir = (0, 0, (False, (0, 0), 0) ) # angle, temps et impacte(bool, (i, j), r_min) self.v_tir = 500 self.lg_tir = 20 self.r_tir_max = 500 self.r_tache = 1000 self.v_tache = 600 self.t_tache = 0 # style self.style_base = QPen(Qt.white, 2, Qt.SolidLine) self.style_gris = QPen(Qt.gray, 2, Qt.SolidLine) self.style_fin = QPen(Qt.red, 2, Qt.SolidLine) self.style_rouge = QPen(Qt.red, 4, Qt.SolidLine) # chargement images self.drop = QPixmap('drop.png').scaled(100, 30, Qt.KeepAspectRatio, Qt.FastTransformation) self.splash = QPixmap('splash.png') #self.transform = QtGui.QTransform() self.deplacement = (0, (0, 0), 0 ) # angle, distance target, t0 initial time self.x_mouse, self.y_mouse = 0, 0 self.timer = QTimer(self) self.timer.timeout.connect(self.update) self.timer.start(1000 / self.fps) self.initWindow() # OPTION DE DEBBUG self.show_polygon = False self.show_impact = False self.show_numbers = False self.show_taches = True # attributs debbug self.pt_col = (0, 0)
def move_x(self, room): self.x += self.base_dx + self.dx self.collider.x = self.x collisions = self.get_collisions(room) collisions = [c for c in collisions if self.collides_with(c)] bounce_scale = 0 for c in collisions: relative_vel = self.base_dx + self.dx if isinstance(c, PhysicsObject): relative_vel -= c.dx if relative_vel > 0: self.collider.right = c.collider.left self.x = self.collider.x self.collisions.append( collision.Collision(c, collision.Direction.right)) elif relative_vel < 0: self.collider.left = c.collider.right self.x = self.collider.x self.collisions.append( collision.Collision(c, collision.Direction.left)) if c.group is not CollisionGroup.springs: bounce_scale = self.bounce_scale(c) if abs(relative_vel) > helpers.SCALE: self.sounds.add('bump') elif abs(relative_vel) >= 0.5 * helpers.SCALE: if self is not room.level.player: self.sounds.add('bump') if collisions: self.dx *= -bounce_scale self.wall_collision = True else: self.wall_collision = False
def __init__(self): super().__init__() self.collision = collision.Collision() self.size = (700, 700) self.model = model.Model(self.size, 3) self.model.map = self.load_map() self.r_player = 10 self.r_deplacement = 100 self.fps = 60 self.game_over = False self.tir = (0, 0, (False, (0, 0), 0) ) # angle, temps et impacte(bool, (i, j), r_min) self.v_tir = 500 self.lg_tir = 20 self.r_tir_max = 1000 self.r_tache = 30 self.v_tache = 40 self.t_tache = 0 # styles self.style_base = QPen(Qt.white, 2, Qt.SolidLine) self.style_gris = QPen(Qt.gray, 2, Qt.SolidLine) self.style_fin = QPen(Qt.red, 2, Qt.SolidLine) self.style_rouge = QPen(Qt.red, 4, Qt.SolidLine) self.style_vert = QPen(Qt.green, 2, Qt.SolidLine) self.style_jaune = QPen(Qt.yellow, 2, Qt.SolidLine) self.deplacement = (0, (0, 0), 0 ) # angle, distance target, t0 initial time self.x_mouse, self.y_mouse = 0, 0 self.timer = QTimer(self) self.timer.timeout.connect(self.update) self.timer.start(1000 / self.fps) self.initWindow() # OPTION DE DEBBUG self.show_polygon = True self.show_impact = True self.show_numbers = False self.show_taches = True # attributs debbug self.pt_col = (0, 0)
def predict_mean_movement(self, line_ped_x, line_ped_y, line_ped_x_mean, line_ped_y_mean, frame_id, ped_id, scene_id, collision_x, collision_y): """ Computes the average movement from the previous steps and predicts one more step based on that returns: newly computed lines (with appended step if no collision) """ mvmt_x = [] mvmt_y = [] # compute average movement for each step/frame for j in range(len(line_ped_x) - 1): mvmt_x.append(line_ped_x[j + 1] - line_ped_x[j]) mvmt_y.append(line_ped_y[j + 1] - line_ped_y[j]) # store last step for grid update last_step_x = line_ped_x[-1] last_step_y = line_ped_y[-1] # next step is the last step + mean of all movement-values next_step_x = last_step_x + mean(mvmt_x) next_step_y = last_step_y + mean(mvmt_y) # check for collisions when creating new path col_object = collision.Collision() line_collision = col_object.check_for_collisions(next_step_x, next_step_y, last_step_x, last_step_y, scene_id=scene_id, indexer=self) if not line_collision: # extend line to be plotted with this line_ped_x.append(next_step_x) line_ped_y.append(next_step_y) # additional line for plotting only the extension by mean line_ped_x_mean.append(next_step_x) line_ped_y_mean.append(next_step_y) # extend the grid with the newest step new_track = TrackRow(frame_id, ped_id, next_step_x, next_step_y, None, scene_id) self.extend_grid(track=new_track, pre_x=last_step_x, pre_y=last_step_y) else: collision_x.append(next_step_x) collision_y.append(next_step_y) return line_ped_x, line_ped_y, line_ped_x_mean, line_ped_y_mean, collision_x, collision_y
def collisionDetection(): for pInd, projectile in enumerate(cann.projectiles): for aInd, asteroid in enumerate(asteroids): if projectile.rect.colliderect(asteroid.rect): newCol = collision.Collision(gameSurf, asteroid.pos, frameTag) collisions.append(newCol) del asteroids[aInd] del cann.projectiles[pInd] gameData[1] += 100 for aInd, asteroid in enumerate(asteroids): if asteroid.pos[1] > size[1]: newGroundCol = collision.GroundImpact(gameSurf, asteroid.pos, frameTag) groundImpacts.append(newGroundCol) del asteroids[aInd] gameData[2] -= 1
def __init__(self, x, y, width, height, base_speed, img, char_type): self.x = x self.y = y self.start_x = x self.start_y = y self.width = width self.height = height self.img = img self.base_speed = base_speed self.char_type = char_type print("narejen karakter") if self.char_type != 1: data.list_of_chars.append(self) box = collision.Collision(x, y, width, height) data.list_of_boxes.append(box) print("Addan v char in box list") else: collision.goblin_coll(x, y)
def on_update(self, dt): self.oldx, self.oldy = self.x, self.y self.x += sin(radians(self.rotation)) * 10 self.y += cos(radians(self.rotation)) * 10 if not 0 < self.x < self.game.window.width or not 0 < self.y < self.game.window.height: self._registry.remove(self) else: # Obstacle collision if self.close(): wallcollision = collision.Collision(self.game.points, self) if wallcollision.happened: self.explode() self._registry.remove(self) # Car collision for car in Car._registry: if self.owner != car: if car.intersect(self.x, self.y): self.explode() car.update_hp(-self.owner.dmg) self._registry.remove(self)
def __init__(self, screen_s: pygame.Surface): self.screen = screen_s # asset load global FONT_12, FONT_SIZE_12, FONT_16, FONT_SIZE_16, FONT_20, FONT_SIZE_20, FONT_24, FONT_SIZE_24, FONT_BOLD_58 FONT_12 = pygame.font.Font("assets/font/Togalite-Regular.otf", 12) FONT_16 = pygame.font.Font("assets/font/Togalite-Medium.otf", 16) FONT_20 = pygame.font.Font("assets/font/Togalite-Medium.otf", 20) FONT_24 = pygame.font.Font("assets/font/Togalite-Medium.otf", 24) FONT_BOLD_58 = pygame.font.Font("assets/font/Togalite-bold.otf", 58) FONT_SIZE_12 = FONT_12.size('X') FONT_SIZE_16 = FONT_16.size('X') FONT_SIZE_20 = FONT_20.size('X') FONT_SIZE_24 = FONT_24.size('X') self.lang_ios = "en" self.lang = {} self.poke_lang = {} self.ability_lang = {} self.save_name = "" self._save = {} self.inv: Optional['inventory.Inventory'] = None self.load_save("save") # todo: lang selector self.load_lang(self.lang_ios) self.load_poke_lang(self.lang_ios) self.load_ability_lang(self.lang_ios) sounds.load_poke_sound() items.load() status_.load() abilitys_.load() pokemon.Pokemon.load_pokemons() hud.load_hud_item() pygame.joystick.init() self.joysticks = [ pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count()) ] pokemon.init_translate(self) # ============ self.__render_tick_counter = RenderTickCounter(20.00, 0) global game_instance game_instance = self self.display: 'pygame.Surface' = pygame.Surface( SURFACE_SIZE, pygame.HWSURFACE | pygame.SRCALPHA) self.player: 'player.Player' = player.Player(self) self.level = None load_coord = self.get_save_value("last_level_coord", [100, 100]) self.load_level(self.get_save_value("last_level", "level_1"), load_coord[0], load_coord[1]) self.clock = pygame.time.Clock() self.collision = collision.Collision() self.debug = False self.ignore_collision = False self.time_matrix = [1] * 10 running = True self.direct_battle: list[bool, bool] = ["--direct_battle" in sys.argv, True] self.last_input_type = INPUT_TYPE_KEYBOARD self.full_pokedex = "--full-pokedex" in sys.argv while self.tick(): self.clock.tick(60) print("end")