Exemplo n.º 1
0
class GameWindow(pyglet.window.Window):
    
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.set_location(100, 100)
        self.frame_rate = 1/60.0
        self.fps_display = FPSDisplay(self)
        self.fps_display.label.font_size = 24
        
        # Hier wird der Pfad zum Verzeichnis des ».py«-Files gesetzt
        # Erspart einem das Herumgehample in TextMate mit dem os.getcwd()
        # und os.path.join()
        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)
        
        self.space_list = []
        self.space_img = preload_image("farback.gif")
        for i in range(2):
            self.space_list.append(GameObject(i*1782, 0, Sprite(self.space_img)))
        
        for space in self.space_list:
            space.velx = SPACESPEED
        
        player_spr = Sprite(preload_image_animation("Spritesheet_64x29.png", 4, 1, 64, 29))
        self.player = GameObject(50, 300, player_spr)
    
    def on_key_press(self, symbol, modifiers):
        if symbol == key.UP:
            self.player.vely = PLAYERSPEED
        if symbol == key.DOWN:
            self.player.vely = -PLAYERSPEED
    
    def on_key_release(self, symbol, modifiers):
        if symbol in (key.UP, key.DOWN):
            self.player.vely = 0
    
    def on_draw(self):
        self.clear()
        for space in self.space_list:
            space.draw()
        self.player.draw()
        
        self.fps_display.draw()
    
    def update_space(self, dt):
        for space in self.space_list:
            space.update(dt)
            if space.posx <= -1882:
                self.space_list.remove(space)
                self.space_list.append(GameObject(1682, 0, Sprite(self.space_img)))
            space.velx = SPACESPEED
    
    def update(self, dt):
        self.player.update(dt)
        self.update_space(dt)
Exemplo n.º 2
0
 def pursue_behaviour(self):
     self._background.fill(WHITE)
     self.rect1 = GameObject((10, 10), 40, (SCREEN_HEIGHT) / 2, 0, RED)
     self.rect1.is_chaser = True
     self.rect2 = GameObject((10, 10), SCREEN_WIDTH / 2, SCREEN_HEIGHT - 20,
                             0, BLUE)
     self.gameObjects.clear()
     self.gameObjects.append(self.rect1)
     self.gameObjects.append(self.rect2)
     self.doing_seek = False
     self.doing_astar = False
     self.doing_pursue = True
Exemplo n.º 3
0
 def update_space(self, dt):
     for space in self.space_list:
         space.update(dt)
         if space.posx <= -1882:
             self.space_list.remove(space)
             self.space_list.append(GameObject(1682, 0, Sprite(self.space_img)))
         space.velx = SPACESPEED
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.set_location(100, 100)
     self.frame_rate = 1/60.0
     self.fps_display = FPSDisplay(self)
     self.fps_display.label.font_size = 24
     
     # Hier wird der Pfad zum Verzeichnis des ».py«-Files gesetzt
     # Erspart einem das Herumgehample in TextMate mit dem os.getcwd()
     # und os.path.join()
     file_path = os.path.dirname(os.path.abspath(__file__))
     os.chdir(file_path)
     
     self.space_list = []
     self.space_img = preload_image("farback.gif")
     for i in range(2):
         self.space_list.append(GameObject(i*1782, 0, Sprite(self.space_img)))
     
     for space in self.space_list:
         space.velx = SPACESPEED
     
     player_spr = Sprite(preload_image_animation("Spritesheet_64x29.png", 4, 1, 64, 29))
     self.player = GameObject(50, 300, player_spr)
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.set_location(100, 100)
        self.frame_rate = 1 / 60.0
        self.fps_display = FPSDisplay(self)
        self.fps_display.label.font_size = 24

        # Hier wird der Pfad zum Verzeichnis des ».py«-Files gesetzt
        # Erspart einem das Herumgehample in TextMate mit dem os.getcwd()
        # und os.path.join()
        file_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(file_path)

        self.player = GameObject(50, 300, "Spritesheet_64x29.png")
Exemplo n.º 6
0
# init pygame
pygame.init()
clock = pygame.time.Clock()

# init screen and window
SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("ping-pong")

PAD_ALIGN = SCREEN_WIDTH // 5
PAD_WIDTH = 25
PAD_HEIGHT = 150

ball = GameObject(body=Circle(init_pos=Point(SCREEN_WIDTH // 2,
                                             SCREEN_HEIGHT // 2),
                              r=25),
                  init_v=Vector(8, 0))

left_pad = GameObject(body=Rect(init_pos=Point(PAD_ALIGN, 0),
                                width=PAD_WIDTH,
                                height=PAD_HEIGHT),
                      init_v=Vector(0, 0))

right_pad = GameObject(body=Rect(Point(SCREEN_WIDTH - PAD_ALIGN,
                                       SCREEN_HEIGHT),
                                 width=PAD_WIDTH,
                                 height=PAD_HEIGHT),
                       init_v=Vector(0, 0))

game_ended = False
last_hit = pygame.time.get_ticks()