Example #1
0
 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__()
Example #2
0
    def init(self):
        ##	load some textures
        #	bakground texture
        stars_t = self.res.load_tex("stars.jpg")
        #	sun texture
        sun_t = self.res.load_tex("sun.png")

        ##	set up the background
        self.background = sf.Sprite(stars_t)
        scale = self.scn.get_window_size().x / stars_t.size.x
        self.background.scale((scale, scale))
        self.background.move((0, 0))
        #	make it a little fainter
        self.background.color = sf.Color(255, 255, 255, 150)

        ##	parse the solar system data
        self.system_data = resource.parse_json("system.json")

        ##	populate a dictionary of bodies
        for body_data in self.system_data["bodies"]:
            self.bodies[body_data["name"]] = body.Body()
            self.bodies[body_data["name"]].populate(body_data)

        self.sun = sf.Sprite(sun_t)
        self.sun.origin = (sun_t.size.x / 2., sun_t.size.y / 2.)
        self.sun.scale((0.001, 0.001))

        ##	initialize the views
        self.bgview = self.scn.default_view()
        self.bodyview = self.scn.default_view()

        #	TODO setup so that initial view shows orbit of earth
        self.bodyview.move(-self.scn.size().x / 2., -self.scn.size().y / 2.)
        self.bodyview.zoom(0.005)
Example #3
0
    def on_load(self):
        # create the off-screen surface
        self.surface = sf.RenderTexture(800, 600)
        self.surface.smooth = True

        # load the textures
        self.background_texture = sf.Texture.from_file("data/sfml.png")
        self.background_texture.smooth = True

        self.entity_texture = sf.Texture.from_file("data/devices.png")
        self.entity_texture.smooth = True

        # initialize the background sprite
        self.background_sprite = sf.Sprite(self.background_texture)
        self.background_sprite.position = (135, 100)

        # load the moving entities
        self.entities = []

        for i in range(6):
            sprite = sf.Sprite(self.entity_texture, (96 * i, 0, 96, 96))
            self.entities.append(sprite)

        # load the shader
        self.shader = sf.Shader.from_file(fragment="data/edge.frag")
        self.shader.set_parameter("texture")

        return True
Example #4
0
 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
Example #5
0
    def __init__(self):
        self.s = None
        self.width = SCREEN_W
        self.height = SCREEN_H
        self.hwnd_context = sf.ContextSettings()
        self.hwnd_context.antialiasing_level = 4
        self.hwnd = sf.RenderWindow(sf.VideoMode(self.width,
                                                 self.height), "Tankz2D",
                                    sf.Style.DEFAULT, self.hwnd_context)
        self.hwnd.framerate_limit = 60
        self.hwnd.vertical_synchronization = True
        self.state = STATE.IN_MENU
        self.turn = GameTurn()
        self.tank_sprites = [0] * 4
        self.winner = -1
        self.map_scroll = 0
        for x in range(4):
            self.tank_sprites[x] = sf.Sprite(texture_manager.textures[x + 1])
            self.tank_sprites[x].origin = (11, 6)
            self.tank_sprites[x].position = (SCREEN_W / 2, SCREEN_H / 2)
            self.tank_sprites[x].scale((16, 16))

        try:
            with open('./data/cfg.yaml', 'r') as stream:
                self.cfg = yaml.safe_load(stream)
        except Exception as e:
            print(f'reading config failed: [{e}]')
            os._exit(-1)

        self.ui = GUI(self.cfg['ui'])
        self.ui.set_scene('main_menu')

        self.map = None
        self.map = GameMap(MAP_W, MAP_H)
        self.tanks = []
        self.tank_id = 0
        self.timer = sf.Clock()
        self.timer.restart()

        self.finished = False

        self.bg = Background(texture_manager.textures[TEXTURE.BACKGROUND])
        self.landscape = sf.Sprite(texture_manager.textures[TEXTURE.LANDSCAPE])

        self.think_callbacks = {
            STATE.IN_MENU: self.menu_callback,
            STATE.WAIT_FOR_START: self.wait_for_start_callback,
            STATE.IN_GAME: self.ingame_callback,
            STATE.RESULT: self.results_callback,
        }
        self.render_callbacks = {
            STATE.IN_MENU: self.menu_render_callback,
            STATE.WAIT_FOR_START: self.wait_for_start_render_callback,
            STATE.IN_GAME: self.ingame_render_callback,
            STATE.RESULT: self.results_render_callback
        }

        self.projectiles = []

        self.cheat_active = False
Example #6
0
 def __init__(self):
     super(PlayerInterface, self).__init__()
     self.healthline = sf.Sprite(
         sf.Texture.from_file("data/images/healthline.png"))
     self.healthbar = sf.Sprite(
         sf.Texture.from_file("data/images/healthbar3.png"))
     self.inventory = sf.Sprite(
         sf.Texture.from_file("data/images/fast_inventory.png"))
Example #7
0
 def update(self):
     self.render_texture.clear(self.fill_color)
     temp_texture = sf.RenderTexture(self.render_texture.size.x,
                                     self.render_texture.size.y)
     temp_texture.clear(self.fill_color)
     for drawable in self._drawables:
         temp_texture.draw(drawable, sf.RenderStates(sf.BLEND_MULTIPLY))
     temp_texture.display()
     self.render_texture.draw(sf.Sprite(temp_texture.texture),
                              sf.RenderStates(sf.BLEND_MULTIPLY))
     self.render_texture.display()
     self.sprite = sf.Sprite(self.render_texture.texture)
Example #8
0
    def draw(self, window):
        """
        Draw this widget in window.
        
        Parameters:
            window (Window) : Window to draw.
        """
        self.__canvas.clear(sf.Color(155, 155, 155))

        self.__canvas.draw(self._text)

        #caret
        if self._focused:
            if self._elapsed_time < 0.5:
                self.__caret.position = (self._text.position.x +
                                         self._text.global_bounds.width,
                                         self._text.position.y)
                self.__canvas.draw(self.__caret)
            if self._elapsed_time > 1.0:
                self._elapsed_time = self._elapsed_time - 1.0

        self.__canvas.display()

        self.__sprite = sf.Sprite(self.__canvas.texture)
        self.__sprite.position = self._position
        window.draw(self.__sprite)
Example #9
0
    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
Example #10
0
    def __init__(self,
                 config_file="data/files/configs/test_game_object.json",
                 position=[0, 0],
                 state="deault_state"):
        super(GameObject, self).__init__()
        self.transparent = False
        self.solid = False
        self.usable = False
        self.is_solid = False
        self.is_transparent = False
        self.is_usable = False
        self.file = config_file
        self.state = state
        with open(config_file) as data_file:
            data = json.load(data_file)

        try:
            data = data[state]
        except Exception as e:
            print("Object ", self, " have no states")

        self.texture = sf.Texture.from_file(data['texture'])
        self.sprite = sf.Sprite(self.texture)

        if data['is_solid'] == "true":
            self.solid = True
            self.is_solid = False
            self.x_solid = data['x_solid']
            self.y_solid = data['y_solid']
        else:
            self.solid = False

        if data['is_transparent'] == "true":
            self.transparent = True
            self.is_transparent = False
            self.x_transparent = data["x_transparent"]
            self.y_transparent = data["y_transparent"]
            try:
                self.transparent_texture = sf.Texture.from_file(
                    data['transparent_texture'])
            except Exception as e:
                self.transparent_texture = self.texture
            self.is_transparent = False

        try:
            if data['is_usable'] == "true":
                self.usable = True
                self.is_usable = False
                self.x_usable = data['x_usable']
                self.y_usable = data['y_usable']
                self.usable_texture = sf.Texture.from_file(
                    data['usable_texture'])
                Usable.__init__(self, data['action'])
            else:
                self.usable = False
        except Exception as e:
            pass
            #print(config_file[19::] + " -> hasn't field 'is_usable'")

        self.setPosition(*position)
Example #11
0
    def __init__(self, tiledmap, xml: ElementTree.Element):
        super().__init__()
        self.xml = xml
        self.map = tiledmap

        self.id = int(self.xml.get('id'))
        self.name = self.xml.get('name')

        color = self.xml.get('color')
        if color:
            if len(color) == 9:
                self.color = sf.Color(int(color[3:5], 16), int(color[5:7], 16),
                                      int(color[7:9], 16), int(color[1:3], 16))
            else:
                self.color = sf.Color(int(color[1:3], 16), int(color[3:5], 16),
                                      int(color[5:7], 16), 255)
        else:
            self.color = sf.Color(100, 100, 100, 160)

        self.rectangles = []
        self.points = []
        self.ellipses = []
        self.polygons = []
        self.lines = []

        self._render_texture = sf.RenderTexture(
            tiledmap.width * tiledmap.tile_width,
            tiledmap.height * tiledmap.tile_height)
        self.sprite = sf.Sprite(self._render_texture.texture)
Example #12
0
 def load(self, config_file):
     sprite = sf.Sprite(sf.Texture.from_file("data/images/loading.png"))
     window.clear()
     window.draw(sprite)
     window.display()
     self.time_of_text_live = 250
     with open(config_file) as data_file:
         self.data = json.load(data_file)
     self.name = self.data['level_name']
     self.game_objects.clear()
     self.usable.clear()
     self.npcs.clear()
     self.loot.clear()
     for g_object in self.data['game_objects']:
         self.game_objects.append(
             GameObject(g_object['object'], position=g_object['position']))
     for f_npc in self.data['npc']:
         try:
             npc = f_npc['npc']
             pos = f_npc['position']
             self.npcs.append(NPC(npc, pos))
         except Exception as e:
             print(e)
             self.npcs.append(NPC(f_npc))
     self.floating_name = sf.Text(
         self.name, sf.Font.from_file("data/files/fonts/Bricks.otf"), 100)
     self.time_of_text_live = 250
Example #13
0
 def __init__(self, idle_texture, *args, **kwargs):
     self.idle_texture = idle_texture
     self.sprite = sf.Sprite(idle_texture)
     self.sprite.scale((self.scale_factor, self.scale_factor))
     size = idle_texture.size
     self.sprite.origin = (size.x / 2, size.y / 2)
     super(Player, self).__init__(*args, **kwargs)
Example #14
0
 def selfie():
     r = requests.get(bottle.request.POST['image_url'])
     gps = (48.1500, 11.5833)
     t = sf.Texture.from_memory(r.content)
     spr = sf.Sprite(t)
     spr.ratio = 0.1, 0.1
     spr.origin = (x / 2 for x in t.size)
     self.w.q.put(gps + (spr, ))
Example #15
0
 def new_game_setup(self, game):
     """ Must call this when running a new game!
     """
     self.level_tilemap = TileMap(game.level.tiles)
     self.tilegrid = sf.Sprite(self.textures[pz.SQUARE])
     self.tilegrid.texture_rectangle = sf.Rect(
         (0, 0), (game.level.size.x * pz.TILE_SIZE,
                  game.level.size.y * pz.TILE_SIZE))
     self.tilegrid.color = sf.Color(255, 255, 255, 50)
Example #16
0
 def reset(self):
     self.render_texture = sf.RenderTexture(self.game.window.ui_view.size.x, self.game.window.ui_view.size.y)
     self.r = self.g = self.b = 0
     self.a = 255
     self.blend_mode = sf.BLEND_NONE
     self.shapes = []
     self.sprite = sf.Sprite(self.render_texture.texture)
     self.ended = False
     self.started = False
Example #17
0
 def __init__(self, text: str, font: BitmapFont = None):
     super().__init__()
     self._font: Optional[BitmapFont] = None
     self._text = text
     self._render_texture = sf.RenderTexture(1, 1)
     self._sprite = sf.Sprite(self._render_texture.texture)
     self._glyphs_sprites = []
     if font is not None:
         self.font = font
     self.position = (0, 0)
Example #18
0
    def __init__(self, target):
        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.background = sf.Sprite(
            sf.Texture.from_file("data/images/inventory_background2.png"))
        codes = state_machine.states[len(state_machine.states) -
                                     1].player.inventory
        self.inventory = []
        for code in codes:
            self.inventory.append(InventoryObject(code))
        begin = {'x': 505, 'y': 165}
        #355,162
        self.offset = 57
        group_by = 10
        counter = -1
        row = 0
        for c, obj in enumerate(self.inventory, 0):
            counter += 1
            if counter >= group_by:
                counter = 0
                row += 1
            obj.sprite.position = [
                begin['x'] + counter * self.offset,
                begin['y'] + self.offset * row
            ]

        self.info_table = sf.Text("", sf.Font.from_file("data/font.ttf"), 20)
        self.cursor = sf.Sprite(
            sf.Texture.from_file("data/images/inventory_cursor.png"))
        self.cursor.position = [begin['x'] - 6, begin['y'] - 7]
        self.info_table.position = [
            begin['x'] + self.offset, begin['y'] + self.offset
        ]
        self.cursor_target = 0
        #self.cursor.position = [self.inventory[self.cursor_target].position.x-6,self.inventory[self.cursor_target].position.y-8]
        try:
            self.info_table.string = self.inventory[0].description
        except Exception as e:
            print(e)
Example #19
0
 def __init__(self, tank_type, map, start_x=100):
     self.type = tank_type
     self.crosshair_tex = texture_manager.textures[TEXTURE.CROSSHAIR]
     self.crosshair_sprite = sf.Sprite(self.crosshair_tex)
     self.crosshair_sprite.origin = (7, 7)
     self.barrel_tex = texture_manager.textures[TEXTURE.BARREL]
     self.barrel_sprite = sf.Sprite(self.barrel_tex)
     self.barrel_sprite.origin = (1, 6)
     self.texture = texture_manager.textures[tank_type]
     self.sprite = sf.Sprite(self.texture)
     self.sprite.origin = (11, 4)
     self.aim_angle = -90
     self.last_aim_angle = self.aim_angle
     self.map = map
     self.x = start_x
     self.last_x = 0
     self.y = map.get_height(self.x)
     self.final_x = -1
     self.health = 100
     self._redraw_healthbar()
Example #20
0
 def __init__(self, id, x, y, texture):
     super().__init__()
     self.id = id
     self.texture = sf.Texture.from_file(texture)
     self.sprite = sf.Sprite(self.texture)
     self.sprite.position = (x, y)
     self.x = x
     self.y = y
     self.w = self.sprite.local_bounds.width
     self.h = self.sprite.local_bounds.height
     self.clicked = False
     self.enabled = True
Example #21
0
    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)
Example #22
0
 def __init__(self):
     if self.__class__.__name__ == __class__.__name__:
         raise NotImplementedError("Transition class is not instantiable. Please use inheritance to create a Transition.")
     super().__init__()
     self.render_texture = sf.RenderTexture(self.game.window.ui_view.size.x, self.game.window.ui_view.size.y)
     self.r = self.g = self.b = 0
     self.a = 255
     self.blend_mode = sf.BLEND_NONE
     self.shapes = []
     self.sprite = sf.Sprite(self.render_texture.texture)
     self.ended = False
     self.started = False
Example #23
0
 def __init__(self,
              func=test_button_function,
              texture_path="data/texture.png",
              focused_texture_path="data/texture_focused.png",
              x=0,
              y=0):
     super(Button, self).__init__()
     self.focused = False
     self.texture = sf.Texture.from_file(texture_path)
     self.texture_focused = sf.Texture.from_file(focused_texture_path)
     self.sprite = sf.Sprite(self.texture)
     self.action = func
     self.setPosition(x, y)
Example #24
0
 def __init__(self, name: str, width: int, height: int,
              fill_color: sf.Color, *args: sf.Drawable):
     super().__init__()
     self.name = name
     self.fill_color = fill_color
     self.render_texture = sf.RenderTexture(width, height)
     self.sprite = sf.Sprite(self.render_texture.texture)
     self._drawables = []
     for arg in args:
         if isinstance(arg, sf.Drawable):
             self._drawables.append(arg)
         else:
             raise TypeError("Mask can only contain Drawables.")
Example #25
0
    def __init__(self, textures, target_width):
        self.textures = textures

        self.layers = []
        for texture in textures:
            texture.smooth = False
            texture.repeated = True
            size = texture.size
            scale_factor = target_width / size.x
            layer = sf.Sprite(texture)
            layer.scale((scale_factor, scale_factor))
            self.layers.append(layer)

        super(sf.TransformableDrawable, self).__init__()
Example #26
0
    def on_load(self):
        try:
            # load the texture and initialize the sprite
            self.texture = sf.Texture.from_file("data/background.jpg")
            self.sprite = sf.Sprite(self.texture)

            # load the shader
            self.shader = sf.Shader.from_file(fragment="data/pixelate.frag")
            self.shader.set_parameter("texture")

        except IOError as error:
            print("An error occured: {0}".format(error))
            exit(1)

        return True
Example #27
0
    def __init__(self, target, color):
        super().__init__(target)

        self.color = color

        self.time = sf.seconds(0)

        self.flipping = False

        self.black_tex = sf.Texture.from_file(
            assets.get_asset("/images/black.png"))
        self.black_tex.smooth = True
        self.white_tex = sf.Texture.from_file(
            assets.get_asset("/images/white.png"))
        self.white_tex.smooth = True

        self.texture_size = self.black_tex.size

        self.size = self.texture_size.x

        self.black = sf.Sprite(self.black_tex)
        self.black.origin = (self.texture_size.x / 2, self.texture_size.y / 2)
        self.white = sf.Sprite(self.white_tex)
        self.white.origin = (self.texture_size.x / 2, self.texture_size.y / 2)
Example #28
0
 def __init__(self, obj_code):
     #super(InventoryObject, self).__init__()
     sf.Drawable.__init__(self)
     with open("data/files/configs/inventory_objects.json") as data_file:
         data = json.load(data_file)
     for obj in data['inventory_objects']:
         if obj['obj_code'] == obj_code:
             data = obj
             break
     self.code = data['obj_code']
     Usable.__init__(self, data['action'])
     self.texture = sf.Texture.from_file("data/images/icons.png")
     self.sprite = sf.Sprite(self.texture)
     self.sprite.texture_rectangle = data['text_rect']
     self.description = data['description']
Example #29
0
    def load_assets(self):
        # Textures not in spritesheet
        for id_, path in asset_files.items():
            self.textures[id_] = sf.Texture.from_file(asset_files[id_])

        # Text/Font
        self.font = sf.Font.from_file("game/assets/SourceCodePro-Regular.otf")

        self.debug_hud_text = getTextObj(self.font)
        self.hud_stat_text = getTextObj(self.font)
        self.hud_help_text = getTextObj(self.font)

        self.textures[pz.SQUARE].repeated = True

        self.player = sf.Sprite(self.textures[pz.CAT])
        self.player.origin = self.textures[pz.CAT].size / 2.0
Example #30
0
 def __init__(self, map, x, y, angle, vel, final_pos=None):
     self.map = map
     self.texture = texture_manager.textures[TEXTURE.MISSLE]
     self.sprite = sf.Sprite(self.texture)
     self.sprite.origin = (2, 2)
     self.enemy_missle = True if final_pos is not None else False
     self.final_pos = final_pos
     self.start_x = normalize(x)
     self.start_y = y
     self.x = self.start_x
     self.y = y
     self.angle = radians(angle)
     self.vel = vel
     self.clock = None
     self.should_remove = False
     self.r = 24
     self.t = 0