示例#1
0
 def __init__(self):
     self.depth = 1
     self.weaponsprite = sfml.Sprite(
         function.load_texture(constants.SPRITE_FOLDER +
                               "weapons/miniguns/0.png"))
     self.firingsprite = sfml.Sprite(
         function.load_texture(constants.SPRITE_FOLDER +
                               "weapons/miniguns/2.png"))
示例#2
0
文件: main2.py 项目: Valian/IGK2015
    def spawn_rocks(self):
        if len(self.rocks) == 0:
            rock_down = sf.Sprite(self.rock_down)
            rock_down.position = sf.Vector2(float(WWIDTH), 0.0)
            self.rocks.append(rock_down)

            rock_up = sf.Sprite(self.rock_up)
            rock_up.position = sf.Vector2(rock_up.position.x + 300.0, float(WHEIGHT - rock_up.global_bounds.height))
            self.rocks.append(rock_up)
        else:
            print("Boş değil")
示例#3
0
 def init_tyles_types(self):
     print("init_tyles_types", self.data, self.available_letters)
     self.init_sprite_list()
     sprites = []
     lCounter = 0  # Line Counter
     cCounter = 0  # Character Coutner
     for line in self.data:
         cCounter = 0
         for char in line:
             if char in self.available_letters:
                 #print (lCounter, cCounter,(char))
                 sprite = sf.Sprite(self.textures[char])
                 position = sf.Vector2(TILE_SIZE * cCounter,
                                       TILE_SIZE * lCounter)
                 position.x = TILE_SIZE * cCounter
                 position.y = TILE_SIZE * lCounter
                 sprite.move(position)
                 #print(position)
                 self.sprite_list.append(sprite)
                 sprites.append(sprite)
                 self.sprite_count += 1
             cCounter += 1
         #print (lCounter, cCounter, self.sprite_list, self.sprite_count)
         lCounter += 1
         #print (self.sprite_list, self.sprite_count)
     self.set_available()
示例#4
0
def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480),
                             'SFML RenderTexture example')
    window.framerate_limit = 60
    running = True

    rect0 = sf.RectangleShape((5, 5))
    rect0.position = (90, 50)
    rect0.fill_color = sf.Color.GREEN
    rect0.outline_color = sf.Color.BLUE
    rect0.outline_thickness = 2.0

    rect1 = sf.RectangleShape((20, 30))
    rect1.position = (50, 50)
    rect1.fill_color = sf.Color.CYAN

    rt = sf.RenderTexture(110, 110)
    rt.clear(sf.Color(0, 0, 0, 0))
    rt.draw(rect0)
    rt.draw(rect1)
    rt.display()
    s = sf.Sprite(rt.texture)
    s.origin = (55, 55)
    s.position = (320, 240)

    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False

        window.clear(sf.Color.WHITE)
        s.rotate(5)
        window.draw(s)
        window.display()
    window.close()
示例#5
0
    def __init__(self, window, manager):
        super(MainMenuHandler, self).__init__(window, manager)

        self.menubg = sfml.Sprite(function.load_texture(constants.SPRITE_FOLDER + "gameelements/menubackgrounds/%s.png" % random.randint(0,2)))
        self.menubg.x = 200
        self.color = tuple(self.manager.config.setdefault('menu_color', [0.7, 0.25, 0]))
        self.color = sfml.Color(self.color[0] * 255, self.color[1] * 255, self.color[2] * 255)
示例#6
0
    def reset(self):
        self._meter_view = MeterView(self._window)
        self._points = 0
        self._acceleration = True

        self._powerbar_view = PowerbarView(self._window)
        self._energy = 100
        self._energy_cmp = self._energy
        self._dt = datetime.now()
        self._dt2 = datetime.now()
        self._dt3 = datetime.now()
        self._dt_cmp = self._dt
        self._dt_cmp2 = self._dt
        self._dt_cmp3 = self._dt

        self._frame_count = 0
        self._window_on_count = 50

        self._monster_texture = sf.Texture.from_file("assets/monster.png")
        self._monster_sprite = sf.Sprite(self._monster_texture)

        self._windows = {}  # contains all windows with their current status
        for x in range(0, self._columns):
            self._windows[x] = {}
            for y in range(0, self._rows):
                self._create_window(x, y)
示例#7
0
    def __init__(self, game, map_id, map_version):
        self.game = game
        self.texture = game.texturehandler.texture

        # load map properties and tank data
        self.map_properties = self.load_properties(map_id, map_version)
        self.tank_data = const.tank_data

        # set useful values for calculations
        self.centerview = (game.window.size.x * 0.5 *
                           game.window.view.viewport.width,
                           game.window.size.y * 0.5 *
                           game.window.view.viewport.height)
        self.tilewidth = game.texturehandler.tilewidth
        self.tileheight = game.texturehandler.tileheight
        self.max_x = game.battlefield.map_tiles_x - 1
        self.max_y = game.battlefield.map_tiles_y - 1

        # load hud sprites
        self.sprites = {}
        for key, val in const.hud_sprites.items():
            s = sf.Sprite(self.texture)
            s.texture_rectangle = game.get_texture_rect(val)
            s.origin = (s.texture_rectangle.width / 2,
                        s.texture_rectangle.height / 2)
            self.sprites[key] = s

        # initialize values
        self.update()
示例#8
0
    def init_hud_list(self):

        distance = 2
        margin_left = 35
        scale = 0.25
        counter = 0
        lCounter = 0
        cCounter = 0
        for char in self.available_letters:
            if cCounter == 2 and counter > 8:
                cCounter = 0
                lCounter += 1
            if cCounter == 3:
                cCounter = 0
                lCounter += 1

            sprite = sf.Sprite(self.textures[char])
            position = sf.Vector2(TILE_SIZE * scale * cCounter,
                                  TILE_SIZE * scale * lCounter)
            position.x = (TILE_SIZE * scale *
                          cCounter) + distance * (cCounter + 1) + margin_left
            position.y = (TILE_SIZE * scale *
                          lCounter) + distance * (lCounter + 1) + margin_left

            if counter > 8:
                position.x += (TILE_SIZE * scale / 2)

            print("POSA", counter, cCounter, lCounter, position)
            sprite.scale((scale, scale))
            sprite.move(position)
            self.hud_list.append(sprite)
            cCounter += 1
            counter += 1
示例#9
0
    def __init__(
        self, dData
    ):  #sComponentID, textureGrid, fDelay, iFrameWidth, iFrameHeight, iFramesWide, iFramesHigh):
        Component.__init__(self, "ANSPRITE:%s" % (dData['componentID']), True,
                           True)

        #This animation starts off as inactive and will await a trigger from a system function
        self._bActive = False

        #This will denote the time in-between each frame of the animation in the textureGrid.
        self._fDelay = dData['delay']

        #This will tell us when it is time to update the frame.
        self._fAnim_Time = 0.0

        #The current frame on the texture grid (top-left)
        self._iCurrent_Frame = [0, 0]

        #The texture grid details
        self._iFrame_Width = dData['frameWidth']
        self._iFrame_Height = dData['frameHeight']
        self._iFrames_Wide = dData['framesWide']
        self._iFrames_High = dData['framesHigh']

        #This holds the texture for the animation!
        self._Animation_Sprite = sf.Sprite(dData['Texture'][0])

        self._Animation_Sprite.set_texture_rect(
            sf.IntRect(0, 0, self._iFrame_Width, self._iFrame_Height))
示例#10
0
    def __init__(self):
        mode = sf.VideoMode.get_desktop_mode()
        style = sf.Style.FULLSCREEN

        self.window = sf.RenderWindow(mode, "BabyOS", style)
        Animation.setScreenSize(mode.size)

        self.bgImage = sf.Image.create(mode.size.x, mode.size.y,
                                       sf.Color.BLACK)
        bgTexture = sf.Texture.from_image(self.bgImage)
        self.bgSprite = sf.Sprite(bgTexture)

        self.scene = Scene()
        self.lettermap = {}
        self.codeword = "stop"
        self.typed = ""

        ic = ImageCache.ImageCache(maxDim=400)
        ic.scan("pictures")

        for i in ic.getCachedImages():
            try:
                texture = sf.Texture.from_file(i)
            except:
                print "Error loading texture %s" % (i)
                continue

            key = os.path.basename(i)[0]
            key = key.lower()
            if not key in self.lettermap:
                self.lettermap[key] = []
            self.lettermap[key].append(texture)
示例#11
0
    def __init__(self, window, manager):
        super(LobbyHandler, self).__init__(window, manager)

        self.menuitems = [
            ('Back to Main Menu', LobbyHandler.go_back),
            ('', None)
        ]

        self.menubg = sfml.Sprite(function.load_texture(constants.SPRITE_FOLDER + "gameelements/menubackgrounds/0.png"))
        self.menubg.x = 200
        self.menubg.x = 200
        self.color = tuple(self.manager.config.setdefault('menu_color', [0.7, 0.25, 0]))
        self.color = sfml.Color(self.color[0] * 255, self.color[1] * 255, self.color[2] * 255)

        self.sendbuf = b''

        self.lobbysocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        self.num_servers = -1
        self.servers_read = 0

        self.lobbysocket.connect((constants.LOBBY_HOST, constants.LOBBY_PORT))
        lobbyuuid = uuid.UUID(constants.LOBBY_MESSAGE_TYPE_LIST).get_bytes()
        self.protocoluuid = uuid.UUID(constants.GG2_LOBBY_UUID).get_bytes()
        self.send_all(lobbyuuid+self.protocoluuid)
        self.compatuuid = uuid.UUID(constants.PYGG2_COMPATIBILITY_PROTOCOL).get_bytes()
示例#12
0
def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480), 'Pixels test')
    window.framerate_limit = 60
    princess = sf.Image.load_from_file('princess.png')
    new_image = sf.Image(princess.width, princess.height)
    pixels = princess.get_pixels()
    unpacker = struct.Struct('BBBB')

    for i in xrange(princess.width):
        for j in xrange(princess.height):
            k = i * 4 + j * princess.width * 4
            s = pixels[k:k + 4]

            if s:
                color = sf.Color(*unpacker.unpack(s))
                mean = (color.r + color.g + color.b) / 3
                color.r = color.g = color.b = mean
                new_image[i, j] = color
            else:
                pass

    texture = sf.Texture.load_from_image(new_image)
    sprite = sf.Sprite(texture)
    running = True

    while running:
        for event in window.iter_events():
            if event.type == sf.Event.CLOSED:
                running = False

        window.clear(sf.Color.WHITE)
        window.draw(sprite)
        window.display()

    window.close()
示例#13
0
 def _display_main_monster(self):
     monster = sf.Sprite(self._monster_texture)
     monster.texture_rectangle = sf.Rectangle(
         (0, 0),
         (self._monster_texture.width, self._monster_texture.height))
     monster.position = (
         (settings.windowWidth - self._monster_texture.width) / 2,
         (settings.windowHeight - self._monster_texture.height) / 2)
示例#14
0
    def __init__(self):
        # Window
        self.window = sf.RenderWindow(sf.VideoMode(WWIDTH, WHEIGHT), WTITLE,
                                      sf.Style.CLOSE | sf.Style.TITLEBAR,
                                      SETTINGS)
        self.window.framerate_limit = 60

        # Clock
        self.clock = sf.Clock()

        # View
        self.view = sf.View(sf.Rectangle((0, 0), (WWIDTH, WHEIGHT)))
        self.window.view = self.view

        # Loading assets
        self.load_assets()

        self.backgrounds = [sf.Sprite(self.bg_texture) for i in xrange(2)]
        self.grounds = [sf.Sprite(self.ground_texture) for i in xrange(2)]

        self.grounds[0].position = 0, 409
        self.grounds[1].position = 0, 409

        # Plane
        fly_anim = Animation()
        fly_anim.texture = self.plane_sheet
        fly_anim.add_frame(sf.Rectangle((0, 0), (88, 73)))
        fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73)))
        fly_anim.add_frame(sf.Rectangle((176, 0), (88, 73)))
        fly_anim.add_frame(sf.Rectangle((88, 0), (88, 73)))

        self.plane = AnimatedSprite(sf.seconds(0.2), False, True)
        self.plane.play(fly_anim)
        self.plane.origin = self.plane.global_bounds.width / 2.0, self.plane.global_bounds.height / 2.0

        self.plane.position = sf.Vector2(150, 200)

        self.plane_speed = sf.Vector2(0.0, 0.0)

        self.jump_time = None

        self.plane_jumped = False

        # Rocks
        self.rocks = []
        self.spawn_rocks()
示例#15
0
    def __init__(self, layer=0, color=sf.Color.WHITE, texture=None):
        super(SpriteEntity, self).__init__(layer)
        (sf.Sprite, self).__init__(texture=texture)

        self.sprite = sf.Sprite(texture)
        self.sprite.color = color
        self.ratio = sf.Vector2(1.0, 1.0)
        self.origin = sf.Vector2(0.5, 0.5)
        self.__renderstate = sf.RenderStates()
示例#16
0
 def __init__(self):
     self.depth = 1
     self.currentindex = -1
     self.flamesprite = [
         sfml.Sprite(
             function.load_texture(constants.SPRITE_FOLDER +
                                   "projectiles/flames/{}.png".format(i)))
         for i in range(3)
     ]
示例#17
0
 def __init__(self):
     self.depth = -1
     self.sprites = [
         sfml.Sprite(
             function.load_texture(
                 constants.SPRITE_FOLDER +
                 "ingameelements/sentryred/{0}.png".format(i)))
         for i in range(10)
     ]
示例#18
0
 def __init__(self, texture, application):
     GameObject.__init__(self)
     self.sprite = sf.Sprite(texture)
     self.addChild(self.sprite)
     self.application = application
     x = texture.width / 2
     y = texture.height / 2
     self.origin = sf.Vector2(texture.width / 2, texture.height / 2)
     self.animations = Animation.createRandomGroup(self)
示例#19
0
    def __init__(self, actor, dark=False):
        self.actor = actor

        if dark:
            self.texture = sf.Texture.from_file("overlay-dark.png")
        else:
            self.texture = sf.Texture.from_file("overlay.png")

        self.sprite = sf.Sprite(self.texture)
示例#20
0
    def __init__(self, x, y):
        Monster.__init__(self)
        small_monster = sf.Texture.from_file("small_monster.png")
        self.sprite = sf.Sprite(small_monster)
        self.sprite.position = (x, y)

        self.speed = 1
        self.damage = 1
        self.sound_rarity = 4800
示例#21
0
    def __init__(self, x, y):
        Monster.__init__(self)
        big_monster = sf.Texture.from_file("big_monster.png")
        self.sprite = sf.Sprite(big_monster)
        self.sprite.position = (x, y)
        self.sound_rarity = 1200

        self.speed = 1.10
        self.damage = 5
示例#22
0
    def __init__(self, x, y):
        Actor.__init__(self)
        player = sf.Texture.from_file("player.png")
        self.sprite = sf.Sprite(player)
        self.position = (x, y)

        self.max_health = 5
        self.health = self.max_health
        self.max_stamina = 4
        self.stamina = self.max_stamina
示例#23
0
 def __init__(self):
     self.depth = -1
     self.base = sfml.Sprite(
         function.load_texture(constants.SPRITE_FOLDER +
                               "ingameelements/sentryred/11.png"))
     self.turrets = [
         sfml.Sprite(
             function.load_texture(
                 constants.SPRITE_FOLDER +
                 "ingameelements/sentryturrets/{0}.png".format(i)))
         for i in range(3)
     ]
     self.turning = [
         sfml.Sprite(
             function.load_texture(
                 constants.SPRITE_FOLDER +
                 "ingameelements/turretrotates/{0}.png".format(i)))
         for i in range(5)
     ]
示例#24
0
    def setUp(self):
        # Animation stuff
        dudeFrame = 6
        dudeFrameCounter = 0
        dudeFrameSpeed = 5

        # load the textures for possible heroes
        dudeTextures = []
        characters = []
        try:
            dudeTextures.append(
                sf.Texture.from_file("assets/sprites/dude0.png"))
            dudeTextures.append(
                sf.Texture.from_file("assets/sprites/dude1.png"))
            dudeTextures.append(
                sf.Texture.from_file("assets/sprites/dude2.png"))
        except IOError:
            print("ERROR")
            exit(1)

        for dudeTexture in dudeTextures:
            characters.append(sf.Sprite(dudeTexture))

        for i in range(len(characters)):
            characters[i].ratio = sf.Vector2(4, 4)
            characters[i].origin = texture_size / 2
            characters[i].position = (game_size.x / (len(characters) + 1) *
                                      (i + 1), game_size.y / 2)

        topLeft = sf.Vector2(114, 0)
        for character in characters:
            character.texture_rectangle = sf.Rectangle(topLeft, texture_size)

        level = 1
        space = pm.Space()
        sprite = characters[1]

        # create hero's physical body
        dude_body = pm.Body(50, pm.inf)  # Has a weight, but cannot rotate

        # create hero's boundaries
        dude_poly = pm.Poly.create_box(dude_body, person_size)
        dude_poly.friction = 1
        dude_poly.collision_type = 3

        jump_sensor = pm.Poly.create_box(dude_body,
                                         size=(50, 2),
                                         offset=(0, 65))
        jump_sensor.sensor = True
        jump_sensor.collision_type = 2

        space.add(dude_body, dude_poly, jump_sensor)

        self.base_entity = BaseEntity(dude_body, dude_poly, sprite,
                                      sf.Vector2(19, 44))
示例#25
0
文件: ship.py 项目: tedsta/spacegame
    def __init__(self, id=""):
        self.id = id

        # Drawing stuff
        self.sprite = sf.Sprite(res.ship)
        self.sprite_offset = sf.Vector2(-71, -40)
        self.room_offset = sf.Vector2(63, 32)  # Offset of room origin
        self.position = sf.Vector2(0, 0)

        # Shield renering
        self.shields_offset = sf.Vector2(-30, -50)
        self.shields_sprite = sf.Sprite(res.shields)
        #self.shields_sprite.origin - self.shields_sprite.local_bounds.size/2

        # Stats n stuff
        self.alive = True
        self.hull_points = 10

        # Explosion stuff
        self.exploding = False  # Playing the explosion animation
        self.explosion_timer = 0

        self.hull_pieces = [\
        HullPiece(res.ship_piece1, sf.Vector2(205, 60), 10, 20, 0, 360, -30, 30),\
        HullPiece(res.ship_piece2, sf.Vector2(70, 108), 20, 40, 160, 200, -40, 40),\
        HullPiece(res.ship_piece3, sf.Vector2(130, 127), 40, 60, 220, 260, -60, -20),\
        HullPiece(res.ship_piece4, sf.Vector2(17, 0), 30, 50, 20, 70, -30, 30),\
        HullPiece(res.ship_piece5, sf.Vector2(0, 61), 40, 80, 110, 160, -30, 30),\
        HullPiece(res.ship_piece6, sf.Vector2(72, 0), 20, 50, 330, 350, -30, 30),\
        ]

        # Path grid for pathfinding
        self.path_grid = Grid(10, 10)

        # Things on the ship
        self.rooms = []

        self.weapon_slots = []

        self.weapon_system = None
        self.engine_system = EngineSystem()
        self.shield_system = None
示例#26
0
    def __init__(self):
        self.depth = 0
        self.sprites = [
            sfml.Sprite(
                function.load_texture((constants.SPRITE_FOLDER +
                                       "characters/heavyreds/%s.png" % i)))
            for i in range(4)
        ]

        self.spriteoffset = (14, 30)
        self.spriteoffset_flipped = (26, 30)
示例#27
0
def run():
    SIZE = 0
    window = sf.RenderWindow(sf.VideoMode(WWIDTH, WHEIGHT), WTITLE)
    window.framerate_limit = 60

    # Background
    bg_texture = sf.Texture.from_file("assets/images/background.png")
    background = sf.Sprite(bg_texture)

    # Ball
    b_texture = []
    b_texture.append(sf.Texture.from_file("assets/bln/balon0.png"))
    b_texture.append(sf.Texture.from_file("assets/bln/balon1.png"))
    b_texture.append(sf.Texture.from_file("assets/bln/balon2.png"))
    b_texture.append(sf.Texture.from_file("assets/bln/balon3.png"))

    balls = []

    # Clock
    clock = sf.Clock()

    while window.is_open:
        for event in window.events:
            if type(event) is sf.CloseEvent:
                window.close()
        # Close
        if sf.Keyboard.is_key_pressed(sf.Keyboard.ESCAPE):
            window.close()

        elapsed = clock.elapsed_time.seconds
        clock.restart()
        for ball in balls:
            ball.position = ball.position.x, (ball.position.y + BALL_SPEED)
            if ball.position.y > WHEIGHT:
                balls.remove(ball)
                SIZE -= 1

        if SIZE < MAX_SIZE:
            ball = sf.CircleShape(rm.randint(20, 60))
            ball.texture = rm.choice(b_texture)
            ball.origin = 20, 20
            ball.position = rm.randint(40, WWIDTH - 80), rm.randint(
                -300, 0)  #WHEIGHT / 8.0
            balls.append(ball)
            SIZE += 1

        # Rendering
        window.clear(sf.Color.BLACK)

        window.draw(background)
        for ball in balls:
            window.draw(ball)

        window.display()
示例#28
0
 def initialize(self, renderer, game, state, character_id, spritepath):
     character = state.entities[character_id]
     if character.team == constants.TEAM_RED:
         team = "0"
     else:
         team = "1"
     self.hudsprite = sfml.Sprite(
         function.load_texture(constants.SPRITE_FOLDER + "huds/ammo/" +
                               spritepath + "/" + team + ".png"))
     self.background_bar.location = self.bar.location
     self.background_bar.color = sfml.Color(0, 0, 0, 255)
     self.bar.color = sfml.Color(217, 217, 183, 255)
示例#29
0
    def prerender(self, map_):
        # create textures for pre-rendering
        self.top_layers = sf.RenderTexture(self.mapwidth, self.mapheight)
        self.bottom_layers = sf.RenderTexture(self.mapwidth, self.mapheight)

        # render map tiles on the textures
        for z, layer in enumerate(map_):
            for col in layer:
                for tile in col:
                    if z > self.piece_layer:
                        self.top_layers.draw(tile)
                    else:
                        self.bottom_layers.draw(tile)

        # update textures
        self.top_layers.display()
        self.bottom_layers.display()

        # set sprites
        self.map_top = sf.Sprite(self.top_layers.texture)
        self.map_bottom = sf.Sprite(self.bottom_layers.texture)
示例#30
0
 def getHoverImage(self):
     succeeded = False
     try:
         imageRequest = urllib.request.urlopen(
             "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid="
             + str(self.multiverseID) + "&type=card")
         imageData = imageRequest.read()
         self.hoverTexture = sf.Texture.from_memory(imageData)
         self.hoverSprite = sf.Sprite(self.hoverTexture)
         self.hoverSprite.color = sf.Color(255, 255, 255, 225)
         succeeded = True
     except Exception as e:
         print(e)
     self.canDisplayImage = succeeded