Esempio n. 1
0
def main():
    """ main routine """
    cubedata = [
        {"xpos": 25, "ypos": 600, "width": 25, "height": 600},
        {"xpos": 575, "ypos": 600, "width": 25, "height": 600},
    ]

    for cube in cubedata:
        xpos, ypos, width, height = cube["xpos"], cube["ypos"],\
            cube["width"], cube["height"]
        CUBES.append(Cube(xpos, ypos, 0, width, height, 25, "cube"))
        cube_obj = RectangleEntity(xpos - width, ypos - height,
                                   width * 2, height * 2)
        ENGINE.entities.append(cube_obj)

    ENGINE.entities.append(BALL)
    IMAGES.append(Cube(0, 0, 0, 15, 15, 15, "ball"))

    for yindex in range(5):
        for xindex in range(7 + yindex%2):
            xpos = xindex * 60 + (95 if yindex % 2 == 1 else 120)
            ypos = yindex * 150 + 100
            pin = Cube(xpos, ypos, 0, 10, 10, 10, "pin0")
            IMAGES.append(pin)
            pin_obj = CircleEntity(xpos, ypos, 10, True, 0.8)
            pin_obj.pin = pin
            pin_obj.onhit = types.MethodType(onhit, pin_obj)
            ENGINE.entities.append(pin_obj)

    while True:
        tick()
        paint()
        FPSCLOCK.tick(30)
Esempio n. 2
0
def main():
    """ main routine """
    colors = [(255, 0, 0), (255, 165, 0), (242, 242, 0), (0, 128, 0),
              (128, 0, 128), (0, 0, 250)]
    engine = Engine(0, 0, 600, 800, 0, 9.8)

    rect = RectangleEntity(500, 50, 50, 400)
    rect.color = (0, 255, 0)
    engine.entities.append(rect)

    rect = RectangleEntity(0, 50, 50, 400)
    rect.color = (255, 255, 0)
    engine.entities.append(rect)

    line = LineEntity(50, 300, 400, 350)
    line.color = (255, 128, 0)
    engine.entities.append(line)

    line = LineEntity(500, 400, 100, 450)
    line.color = (255, 128, 0)
    engine.entities.append(line)

    for xpos in range(7):
        for ypos in range(3):
            circle = CircleEntity(xpos * 60 + 100, ypos * 60 + 100, 5, True)
            circle.color = colors[ypos]
            engine.entities.append(circle)

    for _ in range(20):
        circle = CircleEntity(randint(0, 400) + 50, randint(0, 200), 10, False)
        circle.color = colors[randint(0, 5)]
        circle.velocity.xpos = randint(0, 10) - 5
        circle.velocity.ypos = randint(0, 10) - 5
        engine.entities.append(circle)

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()

        engine.step(0.01)

        SURFACE.fill((0, 0, 0))
        for entity in engine.entities:
            if entity.shape == SHAPE_RECTANGLE:
                rect = Rect(entity.xpos, entity.ypos, entity.width,
                            entity.height)
                pygame.draw.rect(SURFACE, entity.color, rect)
            elif entity.shape == SHAPE_CIRCLE:
                pos = (int(entity.xpos), int(entity.ypos))
                pygame.draw.circle(SURFACE, entity.color, pos, entity.radius)
            elif entity.shape == SHAPE_LINE:
                pos0 = (int(entity.pos0[0]), int(entity.pos0[1]))
                pos1 = (int(entity.pos1[0]), int(entity.pos1[1]))
                pygame.draw.line(SURFACE, entity.color, pos0, pos1)

        pygame.display.update()
        FPSCLOCK.tick(15)
            xpos = xindex * 60 + (95 if yindex % 2 == 1 else 120)
            ypos = yindex * 150 + 100
            pin = Cube(xpos, ypos, 0, 10, 10, 10, "pin0")
            IMAGES.append(pin)
            pin_obj = CircleEntity(xpos, ypos, 10, True, 0.8)
            pin_obj.pin = pin
            pin_obj.onhit = types.MethodType(onhit, pin_obj)
            ENGINE.entities.append(pin_obj)

    while True:
        tick()
        paint()
        FPSCLOCK.tick(30)


pygame.init()
pygame.key.set_repeat(5, 5)
SURFACE = pygame.display.set_mode([600, 600])
FPSCLOCK = pygame.time.Clock()
ENGINE = Engine(-100, -100, 800, 1400, 0, 0)
BALL = CircleEntity(randint(0, 300) + 100, 1000, 15, False, 0.9)
CUBES = []
IMAGES = []
CAMERA_THETA = [1.2, 0]
LIGHT = normalize([0.5, -0.8, -0.2])
PNGS = (pygame.image.load("pin0.png"), pygame.image.load("pin1.png"),
        pygame.image.load("ball.png"))

if __name__ == '__main__':
    main()
Esempio n. 4
0
def main():
    """ メインルーチン """
    colors = [(255, 0, 0), (255, 64, 0), (255, 201, 38),
              (35, 140, 0), (0, 128, 255), (163, 0, 217),
              (255, 77, 255), (255, 255, 255)]
    color = colors[0]
    background_image \
        = pygame.image.load("images/background/wall0.png")
    ball_image = pygame.image.load("ball.png")
    ball_image = pygame.transform.scale(ball_image, (30, 30))
    palette_image = pygame.image.load("images/bg_palette.png")
    palette_image = pygame.transform.scale(palette_image,
                                           (800, 54))
    palette_rect = Rect(0, 0, 800, 54)

    button_images = []
    for index in range(8):
        path = "images/button/color" + str(index) + ".png"
        button_images.append(pygame.image.load(path))

    current_line = None
    mouse_pos = (0, 0)
    mousedown = False
    count = 0

    engine = Engine(0, 0, 800, 500, 0, 9.8)

    while True:
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            elif event.type == MOUSEBUTTONDOWN:
                if palette_rect.collidepoint(event.pos):
                    pindex = floor(event.pos[0] / 72)
                    if 0 <= pindex < 8:
                        color = colors[pindex]
                else:
                    mousedown = True
                    mouse_pos = event.pos
            elif event.type == MOUSEMOTION:
                if mousedown:
                    current_line = (mouse_pos, event.pos, color)
                else:
                    current_line = None
            elif event.type == MOUSEBUTTONUP:
                if mousedown and not \
                   (mouse_pos[0] == event.pos[0] and \
                    mouse_pos[1] == event.pos[1]):
                    line_entity = LineEntity(mouse_pos[0],
                                             mouse_pos[1],
                                             event.pos[0],
                                             event.pos[1])
                    line_entity.color = color
                    engine.entities.append(line_entity)
                mousedown = False
                current_line = None

        # 100カウント毎にボールを落とす
        if count % 100 == 0:
            circle = CircleEntity(randint(0, 600)+100, 0, 10)
            circle.color = color
            engine.entities.append(circle)
        count += 1
        engine.step(0.01)

        # パレットと未確定の線の描画
        for ypos in range(0, 500, 150):
            for xpos in range(0, 800, 150):
                SURFACE.blit(background_image, (xpos, ypos))
        SURFACE.blit(palette_image, (0, 0))
        for index in range(8):
            SURFACE.blit(button_images[index], (index*72, 0))

        if current_line:
            pygame.draw.line(SURFACE, current_line[2], 
                             current_line[0], current_line[1], 3)

        # ボールと線の描画
        for entity in engine.entities:
            if entity.shape == SHAPE_CIRCLE:
                pos = (int(entity.xpos), int(entity.ypos))
                rect = ball_image.get_rect()
                rect.center = pos
                SURFACE.blit(ball_image, rect.topleft)
            elif entity.shape == SHAPE_LINE:
                pos0 = (int(entity.pos0[0]), int(entity.pos0[1]))
                pos1 = (int(entity.pos1[0]), int(entity.pos1[1]))
                pygame.draw.line(SURFACE, entity.color,
                                 pos0, pos1, 3)

        pygame.display.update()
        FPSCLOCK.tick(20)
Esempio n. 5
0
    for cube in cubedata:
        xpos, ypos, width, height = \
            cube["x"], cube["y"], cube["w"], cube["h"]
        CUBES.append(Cube(xpos, ypos, 0, width, height, 25, cube["near"]))
        cube_object = RectangleEntity(xpos - width, ypos - height, width * 2,
                                      height * 2)
        ENGINE.entities.append(cube_object)

    ENGINE.entities.append(BALL)

    while True:
        tick()
        paint()
        FPSCLOCK.tick(30)


pygame.init()
pygame.key.set_repeat(5, 5)
SURFACE = pygame.display.set_mode([600, 600])
FPSCLOCK = pygame.time.Clock()
ENGINE = Engine(0, 0, 600, 600, 0, 0)
BALL = CircleEntity(100, 100, 30, False, 0.2)
CUBES = []
CAMERA_THETA = [0, 0]
LIGHT = normalize([0.5, -0.8, -0.2])
BALL_IMAGE = pygame.image.load("ball.png")
BALL_IMAGE = pygame.transform.scale(BALL_IMAGE, (60, 60))

if __name__ == '__main__':
    main()