Exemplo n.º 1
0
def main():
    time = None

    #Input loop (never trust a user!)
    gewd = False
    while not gewd:
        #Ask for the time
        time = raw_input(
            "Enter the hour of day you wish to view (within interval [0,24)): "
        )

        #Error checking
        if time.isdigit() != True or int(time) >= 24 or int(time) < 0:
            print "Incorrect input"
        else:
            gewd = True

    wind = sf.RenderWindow(sf.VideoMode(1024, 768), "Test")

    squares = Create_Background(wind.width, wind.height, time)

    finished = False
    while not finished:
        for event in wind.iter_events():
            if event.type == sf.Event.CLOSED:
                finished = True

        wind.clear(sf.Color.BLUE)
        wind.draw(squares, sf.QUADS)
        wind.display()
Exemplo n.º 2
0
def main():
    random.seed(datetime.datetime.now())

    window = sf.RenderWindow(sf.VideoMode(WIDTH, HEIGHT), "A Walk In The Dark")
    sound.ambient.loop = True
    sound.ambient.volume = 10
    sound.ambient.play()

    state_counter = 0
    current_state = IntroState(window)
    last_state = None

    step_timer = sf.Clock()

    while window.is_open:
        dt = step_timer.elapsed_time.milliseconds / 16.0
        step_timer.restart()
        
        current_state.step(dt)

        window.clear()
        current_state.draw()
        window.display()

        if current_state.has_ended:
            old_current_state = current_state
            if current_state.next_state is None:
                window.close()
            elif current_state.next_state == State.PREVIOUS_STATE:
                print("restoring previous state")
                current_state = last_state
            else:
                current_state = current_state.next_state(window)
            last_state = old_current_state
            last_state.has_ended = False
Exemplo n.º 3
0
 def __init__(self):
     self.__window = sf.RenderWindow(
         sf.VideoMode(sheet.WINDOW_SIZE.x, sheet.WINDOW_SIZE.y),
         sheet.WINDOW_TITLE)
     self.__window.framerate_limit = sheet.WINDOW_FRAME_LIMIT
     self.__window.vertical_synchronization = True
     self.__hero = doodle.Doodle()
Exemplo n.º 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()
Exemplo n.º 5
0
    def __init__(self):
        self.window = sf.RenderWindow(sf.VideoMode(WIDHT, HEIGHT), TITLE,
                                      sf.Style.DEFAULT, settings)
        self.window.framerate_limit = FPS

        self.clock = sf.Clock()

        self.ball = sf.CircleShape(30)
        self.ball.origin = self.ball.radius, self.ball.radius
        self.ball.position = self.window.size / 2
        x = randint(1, 5)
        y = randint(1, 5)
        if randint(0, 1) % 2 == 0:
            x *= -1.0
        if randint(0, 1) % 2 == 0:
            y *= -1.0

        self.ball_vel = sf.Vector2(x, y)
        self.ball_sound = None

        #sol çubuk
        self.p_left = sf.RectangleShape((30, 200))
        x = self.p_left.size.x / 2
        y = (HEIGHT - self.p_left.size.y) / 2
        self.p_left.position = sf.Vector2(x, y)
        self.left_score = 0

        #sağ çubuk
        self.p_right = sf.RectangleShape((30, 200))
        x = WIDHT - (self.p_right.size.x * 1.5)
        y = (HEIGHT - self.p_left.size.y) / 2
        self.p_right.position = sf.Vector2(x, y)
        self.right_score = 0

        self.font = None
Exemplo n.º 6
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()
Exemplo n.º 7
0
def display_error():
    # Create the main window
    window = sf.RenderWindow(sf.VideoMode(800, 600), 'SFML Shader example')

    # Define a string for displaying the error message
    error = sf.Text("Sorry, your system doesn't support shaders")
    error.position = (100.0, 250.0)
    error.color = sf.Color(200, 100, 150)

    # Start the game loop
    while window.opened:
        # Process events
        for event in window.iter_events():
            # Close window: exit
            if event.type == sf.Event.CLOSED:
                window.close()

            # Escape key: exit
            if (event.type == sf.Event.KEY_PRESSED
                    and event.code == sf.Keyboard.ESCAPE):
                window.close()

        # Clear the window
        window.clear()

        # Draw the error message
        window.draw(error)

        # Finally, display the rendered frame on screen
        window.display()
    def __init__(self, world):
        self.window = sf.RenderWindow(sf.VideoMode(1024, 600),
                                      "Emergency Facility Location Problem")
        self.facilities = []
        self.world = []

        font = sf.Font.from_file("font.ttf")
        for x in xrange(world.shape[0]):
            for y in xrange(world.shape[1]):
                demand = sf.Text(str(world[x, y]), font)
                demand.character_size = 10
                demand.color = sf.Color.BLUE
                demand.position = (x * 20, y * 20)
                area = sf.RectangleShape()
                area.size = (20, 20)
                area.fill_color = sf.Color(0, 0, 0, world[x, y] / 10 * 255)
                area.position = (x * 20, y * 20)
                self.world.append((area, demand))

        self.stats = sf.Text(
            "Iterations :  0000000000000000000 \nFitness    : 0000000000000000000",
            font)
        self.stats.character_size = 14
        self.stats.color = sf.Color.MAGENTA
        self.stats.position = (self.window.size.x -
                               self.stats.local_bounds.width, 0)
Exemplo n.º 9
0
def main(args):
    window = sf.RenderWindow(sf.VideoMode(640, 480),
                             'SFML sound streaming example')
    window.framerate_limit = 60
    running = True

    stream = None
    error_message = None

    if len(args) > 1:
        stream = CustomStream(args[1])
        stream.play()
    else:
        error_message = sf.Text(
            "Error: please provide an audio file as a command-line argument\n"
            "Example: ./soundstream.py sound.wav")
        error_message.color = sf.Color.BLACK
        error_message.character_size = 17

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

        window.clear(sf.Color.WHITE)

        if error_message is not None:
            window.draw(error_message)

        window.display()
 def __init__(self):
     sf.RenderWindow.__init__(self, sf.VideoMode(*SCREEN_SIZE), CAPTION)
     ##        self.vertical_synchronization = True
     self.framerate_limit = 60
     self.active = True
     self.clock = sf.Clock()
     self.player = Player(SCREEN_SIZE / 2, 100, 300)
     self.done = False
Exemplo n.º 11
0
def Window(wd=800, ht=600):  # on_resize	class Window(sf.Window):
    vm = sf.VideoMode(wd, ht)
    window = sf.RenderWindow(vm, "Press Esc to close")
    window.position = 400, 50
    window.vertical_synchronization = True
    window.view.center = (0, 0)
    #window.view.size = window.size/8
    return window
Exemplo n.º 12
0
    def __init__(self):
        # Constants
        window_size = sf.Vector2(640, 400)  # TODO: Make these variable
        self.game_size = sf.Vector2(320, 200)

        # Init window
        w, h = window_size
        self.window = sf.RenderWindow(sf.VideoMode(w, h), "PyDreams 0.1")
        self.window.vertical_synchronization = True
Exemplo n.º 13
0
 def __init__(self):
     self.window = sf.RenderWindow(sf.VideoMode(WIDHT, HEIGHT), TITLE,
                                   sf.Style.DEFAULT, settings)
     self.window.framerate_limit = 20
     self.circle = sf.CircleShape(50)
     self.circle.origin = self.circle.radius, self.circle.radius
     self.circle.position = self.window.size / 2
     self.c_vel = sf.Vector2(5, 5)
     self.clock = sf.Clock()
Exemplo n.º 14
0
 def __init__(self):
     self._window = sf.RenderWindow(
         sf.VideoMode(settings.windowWidth, settings.windowHeight),
         "BaconBulb")
     self._window.vertical_synchronization = True
     self._window.framerate_limit = 60
     self._window.mouse_cursor_visible = False
     self._cursor = Cursor(self._window)
     self._game_menu = GameMenu(self._window)
Exemplo n.º 15
0
    def __init__(self):
        self.window = sf.RenderWindow(sf.VideoMode(WIDHT, HEIGHT), TITLE,
                                      sf.Style.DEFAULT, settings)
        self.circle = sf.CircleShape(50)
        self.rectangle = sf.RectangleShape((150, 200))
        self.rectangle.position = 200, 100

        self.view = sf.View()
        self.view.reset(sf.Rectangle((0, 0), self.window.size))
        self.window.view = self.view
Exemplo n.º 16
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()
Exemplo n.º 17
0
    def __init__(self):
        self.window = sf.RenderWindow(sf.VideoMode(WIDTH, HEIGHT), TITLE)
        self.window.framerate_limit = FPS

        self.backgrounds = [None, None]
        self.grounds = [None, None]

        self.bird_texture = None
        self.bird_animation = None
        self.bird_sprite = None

        self.clock = sf.Clock()
Exemplo n.º 18
0
 def _reload(self, other, proxy):
     self.__init__()
     self.set_fullscreen(other.is_fullscreen())
     # preserve window size
     self.wnd_size = other.wnd_size
     if not self._fullscreen:
         new_mode = sfml.VideoMode(*self.wnd_size)
         self.wnd_handle.recreate(new_mode, self.wnd_title,
                                  window.Style.RESIZE | window.Style.CLOSE,
                                  self.settings)
         self.wnd_handle.position = other.wnd_position
     self.wnd_handle.vertical_synchronization = Window.vsync
Exemplo n.º 19
0
def Init():
    """This will setup the window and whatever needs setup (just once) at the start of the program."""
    wind = sf.RenderWindow(
        sf.VideoMode(config.WINDOW_WIDTH, config.WINDOW_HEIGHT),
        "CS CLUB PROJECT!")

    #This makes the background of the screen Black.
    wind.clear(sf.Color.BLACK)

    wind.framerate_limit = 50

    windView = sf.View()

    return wind, windView
Exemplo n.º 20
0
 def __init__(self,
              proxy,
              name=wnd_name,
              size=wnd_size,
              clr=background_color):
     self.settings = window.ContextSettings(0, 0, 4, 2, 0)
     self.wnd_handle = sfml.RenderWindow(
         sfml.VideoMode(*size), name,
         window.Style.RESIZE | window.Style.CLOSE, self.settings)
     self._fullscreen = False
     self.wnd_handle.vertical_synchronization = Window.vsync
     self.background_color = clr
     self.wnd_handle.clear(sfml.Color(*self.background_color))
     self.wnd_title = name
     self.wnd_size = size
Exemplo n.º 21
0
    def __init__(self, handler):
        # set display mode
        self.window = sfml.RenderWindow(sfml.VideoMode(800, 600),
                                        title="PyGG2 - Not Connected")

        self.load_config()
        self.window.framerate_limit = self.config.setdefault(
            'framerate_limit', 80)  #prevent 100% cpu usage
        self.window.vertical_synchronization = constants.VSYNC_ENABLED
        self.quitting = False
        self.newhandler = None
        self.newhandler_args = []
        self.newhandler_kwargs = {}

        self.handler = handler(self.window, self)
Exemplo n.º 22
0
 def set_fullscreen(self, val):
     if val != self._fullscreen:
         if val:
             self.wnd_size = self.wnd_handle.size
             flscr_mode = sfml.VideoMode.get_fullscreen_modes()[0]
             self.wnd_handle.recreate(flscr_mode, self.wnd_title,
                                      window.Style.FULLSCREEN,
                                      self.settings)
         else:
             mode = sfml.VideoMode(*self.wnd_size)
             self.wnd_handle.recreate(
                 mode, self.wnd_title,
                 window.Style.RESIZE | window.Style.CLOSE, self.settings)
         self._fullscreen = val
         self.wnd_handle.vertical_synchronization = Window.vsync
Exemplo n.º 23
0
def scanner_test():
    w = sf.RenderWindow(sf.VideoMode(400, 400), "Scanner Test")
    clock = sf.Clock()

    em = MyEntityManager()
    sm = SystemManager(em)

    car1 = em.create_entity()
    em.add_component(car1, PositionComponent(0, 0, 0))
    em.add_component(car1, VelocityComponent(0, 0, 0))
    car1_circle = sf.CircleShape()
    car1_circle.radius = 10
    car1_circle.fill_color = sf.Color.RED
    em.add_component(car1, DrawableComponent(car1_circle))
    em.add_component(car1, MovementControlComponent())
    em.add_component(car1,
                     ScanSoundComponent("engine_idle_freesound_loop.wav"))
    car1_engine_sound = PositionSoundComponent(
        "engine_idle_freesound_loop.wav")
    car1_engine_sound.sound.loop = True
    em.add_component(car1, car1_engine_sound)

    player = em.create_entity()
    em.add_component(player, PositionComponent(100, 100, 0))
    em.add_component(player, VelocityComponent(0, 0, 0))
    em.add_component(player, DirectionComponent(radians(180)))
    player_circle = sf.CircleShape()
    player_circle.radius = 10
    player_circle.fill_color = sf.Color.WHITE
    em.add_component(player, DrawableComponent(player_circle))
    #em.add_component(player, MovementControlComponent())
    em.add_component(player, AudioListenerComponent())
    em.add_component(player, HydrophoneComponent(radians(0)))

    sm.add_system(InputSystem(w))
    sm.add_system(PhysicsSystem())
    sm.add_system(AudioSystem())
    sm.add_system(RenderSystem(w))

    while w.is_open:
        sm.update(clock.restart())

        for event in w.events:
            if type(event) is sf.CloseEvent:
                w.close()

        #
        w.display()
Exemplo n.º 24
0
    def create_window(self):
        # create a new window
        size, bpp = sf.VideoMode.get_desktop_mode()  # get bits per pixel
        w = sf.RenderWindow(sf.VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, bpp),
                            "Tank Commander Panic")

        # set the window view
        v = sf.View(sf.Rect((0, 0), (VIEW_WIDTH, VIEW_HEIGHT)))
        v.viewport = (0.0, 0.0, 1.0,
                      (WINDOW_HEIGHT - HUD_HEIGHT) / WINDOW_HEIGHT)
        w.view = v

        # limit the framerate to 60 fps
        w.framerate_limit = 60

        return w
	def __init__(self):

		font = sf.Font.from_file("media/fonts/UbuntuMono-R.ttf")
		self.statistics = Statistics(font)

		window_settings = sf.window.ContextSettings()
		window_settings.antialiasing_level = 8
		self.window = sf.RenderWindow(
			sf.VideoMode(width, height),
			"Steering Behaviors For Autonomous Characters",
			sf.Style.DEFAULT, window_settings)
		self.window.vertical_synchronization = False

		self.entities = []
		self.grid = CollisionGrid(width, height, cell_size)
		self.collision = 0
Exemplo n.º 26
0
    def __init__(self):
        self.window = sf.RenderWindow(sf.VideoMode(WIDTH, HEIGHT), TITLE)

        self.circle = sf.CircleShape(50)
        self.circle.origin = self.circle.radius, self.circle.radius

        try:
            bg_texture = sf.Texture.from_file('assets/images/background.png')

            plane_texture = sf.Texture.from_file('assets/images/planeRed1.png')
            s_buffer = sf.SoundBuffer.from_file('assets/sounds/tone1.ogg')
            music = sf.Music.from_file('assets/sounds/spaceTrash3.ogg')
            font = sf.Font.from_file('assets/fonts/kenvector_future_thin.ttf')
        except IOError:
            print("HATA VERDİ!!")
            sys.exit(-1)
Exemplo n.º 27
0
def main():
    desktop_mode = sf.VideoMode.get_desktop_mode()
    print('The current desktop mode is:', desktop_mode)
    fullscreen_modes = sf.VideoMode.get_fullscreen_modes()
    print('The available fullscreen modes are:')

    for mode in fullscreen_modes:
        print(' {0}'.format(mode))

    format = raw_input('Please enter a video mode format (e.g. 1024x768x32): ')
    values = [int(item) for item in format.split('x')]
    mode = sf.VideoMode(*values)

    if mode.is_valid():
        print('The mode {0} is valid!'.format(mode))
    else:
        print('The mode {0} is not valid!'.format(mode))
Exemplo n.º 28
0
 def __init__(self, swarm, size=(800, 600)):
     self.swarm = swarm
     self.window = sf.RenderWindow(sf.VideoMode(*size), argv[0])
     w = self.window
     self.view = w.view
     self.is_open = w.is_open
     self.close = w.close
     self.paused = False
     self.clock = sf.Clock()
     self.sfVert = SFVert(self.window, Red)
     self.sfNVert = SFVert(self.window, Blue)
     self.view.size = 2, 2
     self.view.center = 0, 0
     self.drawNeighbors = False
     self.drawCentroids = False
     self.drawPolies = True
     self.wClicked = None
Exemplo n.º 29
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()
Exemplo n.º 30
0
def main():
    window = sf.RenderWindow(sf.VideoMode(640, 480), 'Sprite example')
    window.framerate_limit = 60
    running = True
    texture = sf.Texture.load_from_file('python-logo.png')
    sprite = sf.Sprite(texture)

    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()