from components.core import GameConfig
from components.core import GameLoop
from components.core import GameLoopEvents
from components.core import GameScreen

from components.shapes import Point

class DisplayRectangle(GameScreen): 
    
    def __init__(self, screen_size):
        super(DisplayRectangle, self).__init__(screen_size)
        self.__rectangle = Rectangle(Point(10, 10), Point(40, 40), Colors.BLACK)
    
    @property
    def rectangle(self):
        return self.__rectangle
    
    def draw_screen(self, window):
        super(DisplayRectangle, self).draw_screen(window)
        self.rectangle.draw(window)

if __name__ == "__main__":
    config = GameConfig()
    config.clock_rate = 12
    config.window_size = [500, 500]
    config.window_title = "Rectangle Test"
    rscreen = DisplayRectangle(config.window_size)
    rloop_events = GameLoopEvents(config, rscreen)
    loop = GameLoop(rloop_events)
    loop.go()
Ejemplo n.º 2
0
    def loop_setup(self):
        super(ImageLoader, self).loop_setup()
        init_x = super(ImageLoader, self).config.window_size[GameConfig.WIDTH_INDEX] - \
            self.game_screen.meteormon.width
        
        self.game_screen.meteormon.position = Point(init_x, 0)

class ImageScreen(GameScreen):
    
    @property
    def meteormon(self):
        return self.__meteormon
    
    def setup(self):
        super(ImageScreen, self).setup()
        self.__meteormon = Image(os.path.join("sample_sprites","meteormon_clueless.png"))
    
    def draw_screen(self, window):
        super(ImageScreen, self).draw_screen(window)
        window.fill(Colors.WHITE)
        self.meteormon.draw(window)

config = GameConfig()
config.window_size = [500, 500]
config.clock_rate = 12
config.window_title = "Image Class Test"
screen = ImageScreen(config.window_size)
image_gle = ImageLoader(config, screen)
gl = GameLoop(image_gle)
gl.go()
Ejemplo n.º 3
0
        for i in range(self.grid_width):
            for j in range(self.grid_height):
                upper_left_x = j * self.block_width
                upper_left_y = i * self.block_height
                rect = (upper_left_x, upper_left_y, self.block_width, self.block_height)
                rect_list.append(rect)

        return rect_list

    def draw_screen(self, window):
        rects = self.get_rects()

        for r in rects:
            pygame.draw.rect(window, Colors.BLACK, r, 1)

        self.dragon_group.draw(window)
        self.gun_group.draw(window)
        self.hat_group.draw(window)

if __name__ == "__main__":
    config = GameConfig()
    config.clock_rate = 12
    config.window_size = (1357, 708)
    config.window_title = "Hat vs Dragons"

    screen = MainScreen(config.window_size, (10, 10))
    loop_events = GameLoopEvents(config, screen)
    loop = GameLoop(loop_events)
    loop.go()
Ejemplo n.º 4
0
    
    def loop_invariant(self):
        parent_invariant = super(AmoebaLoopEvents, self).loop_invariant()
        return self.__i < self.__limit and parent_invariant
    
    def loop_event(self):
        self.window.fill(Colors.WHITE)
        
        upper_bound = len(super(AmoebaLoopEvents, self).game_screen.mutating_shape.point_list) - 1
        insertion_point = random.randint(0, upper_bound)
        
        rand_x = random.randint(0, self.config.window_size[GameConfig.WIDTH_INDEX])
        rand_y = random.randint(0, self.config.window_size[GameConfig.HEIGHT_INDEX])
        
        super(AmoebaLoopEvents, self).game_screen.mutating_shape.add_point(Point(rand_x, rand_y), insertion_point)
        
        super(AmoebaLoopEvents, self).loop_event()
        
        self.__i += 1

gameconfig = GameConfig()
gameconfig.window_size = [500, 500]
gameconfig.clock_rate = 12
gameconfig.window_title = "Mutating Amoeba"

game_screen = AmoebaScreen(gameconfig.window_size)

loop_events = AmoebaLoopEvents(gameconfig, game_screen)
gameloop = GameLoop(loop_events)
gameloop.go()
Ejemplo n.º 5
0
A simple demo of using the framework that randomly draws
gray circles on a white canvas.

@author Chad Estioco
"""

class GrayCircle(GameLoopEvents):
    
    def __init__(self, config):
        super(GrayCircle, self).__init__(config, GameScreen([500,500]))
        self.__limit = 100
        self.__count = 0
    
    def loop_invariant(self):
        parent_invariant = super(GrayCircle, self).loop_invariant()
        return self.__count < self.__limit and parent_invariant
    
    def loop_event(self):
        x = random.randint(0, 500)
        y = random.randint(0, 500)
        pygame.draw.circle(self.window, [218, 218, 218], [x, y], 50, 2)
        self.__count += 1

gconfig = GameConfig()
gconfig.clock_rate = 10
gconfig.window_size = [500, 500]
gconfig.window_title = "Framework test"
gc_object = GrayCircle(gconfig)
game_loop = GameLoop(gc_object)
game_loop.go()
Ejemplo n.º 6
0
    I want a 500x500 window!
    """
    
    def __init__(self, config, game_screen):
        super(LineMesh, self).__init__(config, game_screen)
        self.__limit = 200
        self.__count = 0
        
    
    def loop_invariant(self):
        parent_invariant = super(LineMesh, self).loop_invariant()
        return self.__count < self.__limit and parent_invariant
    
    def loop_event(self):
        self.window.fill(Colors.WHITE)
        self.game_screen.triangle.draw(self.window)
        self.game_screen.triangle.add_point(Point(random.randint(0, 500), random.randint(0, 500)))
        
        self.__count += 1

config = GameConfig()
config.window_size = [500, 500]
config.clock_rate = 10
config.window_title = "Line Mesh"

game_screen = LineMeshScreen(config.window_size)

ms = LineMesh(config, game_screen)
game_loop = GameLoop(ms)
game_loop.go()