def __init__(self): self.loading_text = sf.Text('Initializing...') self.loading_text.character_size = 64 self.loading_text.font = sf.Font.from_file('loading.ttf') self.texture = sf.Texture.from_file("data/world16384.png") self.world = sf.Sprite(self.texture) self.video_mode = sf.VideoMode.get_fullscreen_modes()[0] vm_size = self.video_mode.width, self.video_mode.height self.world.origin = (c / 2 for c in self.texture.size) self.world.position = (c / 2 for c in vm_size) self.world.ratio = (min( v / t for t, v in zip(self.texture.size, vm_size)), ) * 2 self.original_ratio = self.world.ratio.x self.fc_logo = sf.Sprite(sf.Texture.from_file("fcbayern.png")) self.fc_logo.origin = 200, 400 self.fc_logo.position = vm_size[0] / 2, vm_size[1] / 2 - 30 self.dhl = sf.Sprite(sf.Texture.from_file("globalfamily.png")) self.dhl.origin = self.dhl.texture.size self.dhl.position = (x - 60 for x in vm_size) self.loading_text.position = vm_size[0] / 2, vm_size[1] / 2 + 30 self.loading_text.color = sf.Color(255, 255, 255, 255) self.fade = sf.RectangleShape(vm_size) self.fade.fill_color = sf.Color(0, 0, 0, 200) self.fade.position = (0, 0) self.window = sf.RenderWindow(self.video_mode, "FanMap") self.window.framerate_limit = 60 self.q = Queue() self.objects = [] self.zoomt = -1 self.zoomdirec = 0 self.target_origin = self.world.origin super().__init__()
def __init__(self, target): self.target = target self.background_image = sf.Sprite( sf.Texture.from_file(target.dialog_background)) self.dialog_icon = sf.Sprite(sf.Texture.from_file(target.dialog_icon)) self.label = target.label self.next_label = self.label ### ATTENTION ^ BUG IF STRING IS EMPTY` self.name = sf.Text(target.name, sf.Font.from_file("data/font.ttf"), 40) self.name.position = 300, 475 #self.name.string = target.name self.name.color = sf.Color(241, 213, 169) #self.dialog_file = target.dialog_file with open(target.dialog_file) as data_file: self.data = json.load(data_file) #print(self.data[self.label]) #self.font = sf.Font.from_file() self.text = sf.Text(self.data[self.label]['text'], sf.Font.from_file("data/font.ttf"), 40) #self.text.string = self.data[self.label]['text'] self.text.position = 500, 610 self.text.color = sf.Color(45, 35, 18) self.answers = [] self.cursor = sf.RectangleShape() self.cursor.fill_color = sf.Color(30, 40, 50, 60) self.cursor.size = 300, 30 self.cursor.position = 50, 565 self.loadAnswers() self.texture = sf.Texture.create(window.size.x, window.size.y) self.texture.update(window) self.sprite = sf.Sprite(self.texture) self.camera = sf.View() self.camera.reset([0, 0, 1280, 800]) window.view = self.camera
def nuklearSfmlDrawRectFilled(self,cmd,window): p=pynk.ffi.cast("struct nk_command_rect_filled*",cmd) rectangle=sf.RectangleShape() rectangle.fill_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) rectangle.size=sf.Vector2(p.w, p.h) rectangle.position=sf.Vector2(p.x, p.y) window.draw(rectangle)
def create_grid(self, step): self.grid_step = step self.grid_box = sf.RectangleShape((1000, 700)) self.grid_box.position = self.GRID_POS self.grid_box.outline_color = sf.Color(150, 150, 150) self.grid_box.outline_thickness = 2 self.horizontal_lines_nb = int(self.grid_box.size.y // step) self.horizontal_lines = sf.VertexArray(sf.PrimitiveType.LINES, 2 * self.horizontal_lines_nb) for y, i in zip(range(self.horizontal_lines_nb), range(0, 2 * self.horizontal_lines_nb, 2)): self.horizontal_lines[i].position = self.GRID_POS + (0, step * y) self.horizontal_lines[i + 1].position = self.GRID_POS + (self.grid_box.size.x, step * y) self.horizontal_lines[i].color = sf.Color(180, 180, 180) self.horizontal_lines[i + 1].color = sf.Color(180, 180, 180) self.vertical_lines_nb = int(self.grid_box.size.x // step) self.vertical_lines = sf.VertexArray(sf.PrimitiveType.LINES, 2 * self.vertical_lines_nb) for x, i in zip(range(self.vertical_lines_nb), range(0, 2 * self.vertical_lines_nb, 2)): self.vertical_lines[i].position = self.GRID_POS + (step * x, 0) self.vertical_lines[i + 1].position = self.GRID_POS + (step * x, self.grid_box.size.y) self.vertical_lines[i].color = sf.Color(180, 180, 180) self.vertical_lines[i + 1].color = sf.Color(180, 180, 180) self.grid = [] for j in range(self.horizontal_lines_nb + 1): self.grid.append([]) for i in range(self.vertical_lines_nb + 1): self.grid[j].append(0)
def draw(self, window): for snakeSquare in self.snakeLocations: square = sf.RectangleShape((self.size - 1, self.size - 1)) square.fill_color = sf.Color.WHITE square.position = (snakeSquare[0] * self.size, snakeSquare[1] * self.size) window.draw(square)
def __init__(self, name: str, data, gridsize: int = 16): super().__init__() self.data = data self.name = name self._anim_state = "idle" self.anims: Dict[str, Anim] = self.data.anims self.anim_player: AnimPlayer = AnimPlayer(self.anims[self._anim_state]) self.animate = False if self.anims is None else True self.sprite = sf.Sprite(self.data.texture) self.sprite.texture_rectangle = self.anims[ self.anim_state].frames[0].rectangle self.sprite.origin = self.anims[self.anim_state].frames[0].origin self.direction = sf.Vector2(1, 1) self.gx = self.sprite.position.x self.gy = self.sprite.position.y self.rx = 0 self.ry = 0 self.collision_box = self.global_bounds self.collision_box_shape = sf.RectangleShape( (self.collision_box.width, self.collision_box.height)) self.collision_box_shape.position = (self.collision_box.left, self.collision_box.top) self.collision_box_shape.fill_color = sf.Color(200, 0, 0, 150) self.gridsize = gridsize
def __init__(self, position=(0, 0), size=(10, 3), health=1): self.shape = sf.RectangleShape() self.shape.position = position self.shape.size = size self.shape.outline_thickness = 1 self.shape.outline_color = sf.Color.BLACK self.health = health
def __init__(self): self.global_bbox_rect = sf.RectangleShape() self.global_bbox_rect.outline_color = sf.Color.GREEN self.global_bbox_rect.outline_thickness = -1 self.global_bbox_rect.fill_color = sf.Color.TRANSPARENT self.local_bbox_rect = sf.RectangleShape() self.local_bbox_rect.outline_color = sf.Color.RED self.local_bbox_rect.outline_thickness = -1 self.local_bbox_rect.fill_color = sf.Color.TRANSPARENT self.scale_factor = 1 self.pool = [] self.is_dead = False self.draw_bbox = draw_bbox super(sf.TransformableDrawable, self).__init__()
def get_rectangle(): start_point_x, start_point_y = self._draw_scope['start-point'] current_x, current_y = event.position rect = sf.RectangleShape((abs(start_point_x - current_x), abs(start_point_y - current_y))) rect.outline_color = self._draw_color rect.fill_color = sf.Color.TRANSPARENT rect.outline_thickness = 1 rect.position = (min(current_x, start_point_x), min(current_y, start_point_y)) return rect
def reset(self): super().reset() shape = sf.RectangleShape() shape.position = (self.width / 2, self.height / 2) shape.size = (self.width, self.width) shape.origin = (self.width / 2, self.width / 2) shape.fill_color = sf.Color.TRANSPARENT self.shapes.append(shape) self.update()
def nuklearSfmlDrawRectOutline(self,cmd,window): p=pynk.ffi.cast("struct nk_command_rect*",cmd) rect=sf.RectangleShape() rect.size=sf.Vector2(p.w, p.h) rect.position=sf.Vector2(p.x, p.y) rect.outline_thickness=p.line_thickness rect.fill_color=sf.Color(0,0,0,0) rect.outline_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) window.draw(rect)
def nuklearSfmlDrawLine(self,cmd,window): p=pynk.ffi.cast("struct nk_command_line*",cmd) rect=sf.RectangleShape() rect.size=sf.Vector2(p.line_thickness, abs(p.begin.y-p.end.y)) rect.position=sf.Vector2(p.begin.x, p.begin.y) rect.outline_thickness=p.line_thickness rect.fill_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) rect.outline_color=sf.Color(p.color.r, p.color.g, p.color.b, p.color.a) window.draw(rect)
def update_tile(self, i, j): tile = self.tiles[j][i] if tile is not None and tile.animated: tile.update() clear = sf.RectangleShape() clear.position = tile.position clear.size = tile.size clear.fill_color = sf.Color.TRANSPARENT self.render_texture.draw(clear, sf.RenderStates(sf.BLEND_NONE)) self.render_texture.draw(tile)
def __init__(self, speed=5): super().__init__() self.speed = speed self.limit = math.sqrt((self.width/2)**2 + (self.height/2)**2) self.shape = sf.RectangleShape() self.shape.position = (self.width/2, self.height/2) self.shape.size = (0.1, 0.1) self.shape.origin = (0.05, 0.05) self.shape.fill_color = sf.Color.TRANSPARENT self.shapes.append(self.shape) self.update()
def __init__(self, position=(0,0), boundary=(1000,500), width=20, height=5): self.width = width self.height = height self.boundary = boundary self.shape = sf.RectangleShape() self.shape.size = (width, height) self.shape.fill_color = sf.Color.WHITE self.position = (boundary[0]/2 - width/2, boundary[1]-height) self.shape.position = self.position self.moveSpeed = 1
def new_button(self, name, position, color, size="standard"): btn_shape = sf.RectangleShape() if size == "standard": btn_shape.size = (200, 75) elif size == "small": btn_shape.size = (100, 75) btn_shape.position = position btn_shape.fill_color = color btn_text = sf.Text(name) btn_text.font = self.FONT btn_text.color = sf.Color.BLACK btn_text.position = btn_shape.position + sf.Vector2(25, 75 / 2) return {'shape': btn_shape, 'text': btn_text}
def reset(self): super().reset() self.remaining = [] col_nb = math.ceil(self.render_texture.size.x / self.pixel_size) row_nb = math.ceil(self.render_texture.size.y / self.pixel_size) for x in range(col_nb): for y in range(row_nb): s = sf.RectangleShape() s.position = (x * self.pixel_size, y * self.pixel_size) s.size = (self.pixel_size, self.pixel_size) s.fill_color = sf.Color.TRANSPARENT self.shapes.append(s) self.remaining.append(s) self.update()
def __init__(self, position=(0, 0), speed=3, direction=325, color=sf.Color.WHITE): self.shape = sf.RectangleShape() self.shape.size = (3, 3) self.shape.fill_color = color self.position = position self.speed = speed self.direction = direction # Measured in degrees from horizontal self.velocity = self.getVelocity() self.lastFramePosition = None
def rect(window, colors, pos, outline_thickness=0): o = sf.RectangleShape() o.position = pos[0:2] o.size = pos[2:4] o.outline_thickness = outline_thickness try: o.outline_color = sf.Color(colors[1][0], colors[1][1], colors[1][2]) except: o.outline_color = sf.Color(0, 0, 0) o.fill_color = sf.Color(colors[0][0], colors[0][1], colors[0][2]) o.origin = (0, 0) window.draw(o) return o
def draw_cube(win, r): # win: la window / r: votre rectangle x = r.position.x y = r.position.y w = r.size.x h = r.size.y #print(x,y,w,h,WIDTH,x+w) if x < WIDTH and x + w > WIDTH: # il faut connaitre la largeur de votre fenêtre newR = sf.RectangleShape() newR.size = (w - (WIDTH - x), h) newR.position = (0, y) newR.fill_color = r.fill_color win.draw(newR) win.draw(r)
def __init__(self, pos, size, acc, ang_speed, color=sf.Color.BLACK): self.params = [pos, size, acc, ang_speed, 0] self.acceleration = acc self.angular_speed = ang_speed self.speed = 0 self.velocity = sf.Vector2(0, 0) self.rect = sf.RectangleShape(size) self.rect.fill_color = color self.rect.outline_color = sf.Color.BLACK self.rect.outline_thickness = 0 self.rect.position = pos self.rect.origin = (size[0] / 2.0, size[1] / 2.0) self.calculateCorners() self.calculateAxis() self.ID = -1
def __init__(self, name: str, style: MenuStyle, *args: Button): super().__init__() self.name = name self._style = style self._buttons: List[Button] = [] self.cursor_index = 0 self.opened = False if isinstance(self._style.background, sf.Color): self._bg = sf.RectangleShape( (self._style.width, self._style.height)) self._bg.fill_color = self._style.background elif isinstance(self._style.background, sf.Texture): self._bg = sf.Sprite(self._style.background) elif isinstance(self._style.background, BoxBorder): texture = self._style.background.generate_texture( self._style.size.x, self._style.size.y) self._bg = sf.Sprite(texture) self._bg.position = (0, 0) for btn in args: self.add_button(btn)
def __init__(self): self.camera = sf.View() self.camera.reset([0, 0, 1280, 800]) window.view = self.camera self.texture = sf.Texture.create(window.size.x, window.size.y) self.texture.update(window) self.sprite = sf.Sprite(self.texture) self.rect = sf.RectangleShape() self.rect.position = 0, 0 self.rect.size = window.size.x, window.size.y / 2 self.rect.fill_color = sf.Color(30, 30, 30, 200) self.text = sf.Text("", sf.Font.from_file("data/files/fonts/Bricks.otf"), 20) self.ps1 = sf.Text("->: ", sf.Font.from_file("data/font.ttf"), 20) self.ps1.position = 0, window.size.y / 2 - 30 self.text.position = 25, window.size.y / 2 - 30 self.shader = sf.Shader.from_file(fragment="data/blur.frag") self.shader.set_parameter("source") self.shader.set_parameter("offsetFactor", 0.00075, 0.00075) self.states = sf.RenderStates() self.states.shader = self.shader
def _create(self): self.anim_player.play(self._style.anim) if isinstance(self._style.background, sf.Color): self._bg = sf.RectangleShape( (self._style.width, self._style.height)) self._bg.fill_color = self._style.background else: self._bg = sf.Sprite(self._style.background) if self._style.anim is not None: self._bg.texture_rectangle = self._style.anim.frames[ 0].rectangle self._bg.position = self._position if isinstance(self._style.font, sf.Font): self._front = sf.Text(self._text) self._front.font = self._style.font self._front.character_size = self._style.font_size else: self._front = BitmapText(self._text, self._style.font) self._front.font = self._style.font self._front.position = self._position + sf.Vector2(self.style.width, self.style.height) / 2\ - sf.Vector2(self._front.global_bounds.width / 2, self._front.global_bounds.height / 2) \ - sf.Vector2(self._front.global_bounds.left, self._front.global_bounds.top)
def drawFood(self): food = sf.RectangleShape((self.squareSize, self.squareSize)) food.fill_color = sf.Color.WHITE food.position = (self.food[0] * self.squareSize, self.food[1] * self.squareSize) self.window.draw(food)
xin = vin.x yin = vin.y newX = abs((xin + x) % mod) return sf.Vector2(newX, yin) vit = sf.Vector2(0, 0) window = sf.RenderWindow(sf.VideoMode(WIDTH, HEIGHT), 'Basic Window Tutorial', sf.Style.DEFAULT) window.framerate_limit = 60 window.key_repeat_enabled = False rect = sf.RectangleShape() rect.size = (50, 50) rect.position = (475, 25) rect.fill_color = sf.Color.GREEN while window.is_open: # fetch events (explained in next tutorial function) for event in window.events: if event == sf.Event.CLOSED: window.close() if event == sf.Event.KEY_PRESSED: # if event["code"] == sf.Keyboard.UP: # rect.move((0,-5)) # if event["code"] == sf.Keyboard.DOWN: # rect.move((0,5)) # if event["code"] == sf.Keyboard.LEFT:
def create_rect(x, y, w, h, color): rect = sf.RectangleShape() rect.position = (x, y) rect.size = (w, h) rect.fill_color = color return rect
def new_wall(self): new_wall_shape = sf.RectangleShape((self.grid_step, self.grid_step)) new_wall_shape.fill_color = sf.Color(120, 120, 120) new_wall_shape.origin = (self.grid_step / 2, self.grid_step / 2) new_wall_shape.position = (-self.grid_step / 2, -self.grid_step / 2) return new_wall_shape
def scaled_pixel(self, pos): pixel = sf.RectangleShape((self._scale, self._scale)) pixel.position = (pos[0]*self._scale, pos[1]*self._scale) return pixel
# define some constants game_size = sf.Vector2(800, 600) paddle_size = sf.Vector2(25, 100) ball_radius = 10. # create the window of the application w, h = game_size window = sf.RenderWindow(sf.VideoMode(w, h), "pySFML - Pong") window.vertical_synchronization = True # load the sounds used in the game ball_sound_buffer = sf.SoundBuffer.from_file("data/ball.wav") ball_sound = sf.Sound(ball_sound_buffer) # create the left paddle left_paddle = sf.RectangleShape() left_paddle.size = paddle_size - (3, 3) left_paddle.outline_thickness = 3 left_paddle.outline_color = sf.Color.BLACK left_paddle.fill_color = sf.Color(100, 100, 200) left_paddle.origin = paddle_size / 2 # create the right paddle right_paddle = sf.RectangleShape() right_paddle.size = paddle_size - (3, 3) right_paddle.outline_thickness = 3 right_paddle.outline_color = sf.Color.BLACK right_paddle.fill_color = sf.Color(200, 100, 100) right_paddle.origin = paddle_size / 2 # create the ball