示例#1
0
from window import Window
from shapes import Cube, Star, Curve
from interface import Interface

width = 1080
height = 720

def toggle_turning(window):
	for shape in window.shapes:
		if not isinstance(shape, Curve):
			shape.turning = not shape.turning

l = Window(width, height)
cube1 = Cube(0, 0, 0, 200, (1, 0, 0), True)
l.add_shape(cube1)
cube2 = Cube(0, -150, 0, 100, (0, 1, 0), True)
l.add_shape(cube2)
star = Star(350, 0, 0, 100, (1, 0, 1), True)
l.add_shape(star)
interface = Interface(50, 25, 100, 50, (0, 1, 1), toggle_turning)
l.add_interface(interface)
curve1 = Curve((100, 100), (100, 200), (200, 200), (0.5, 0, 0.5))
curve2 = Curve((100, 100), (100, 200), (0, 200), (0.5, 0, 0.5))
curve3 = Curve((100, 300), (100, 200), (0, 200), (0.5, 0, 0.5))
curve4 = Curve((100, 300), (100, 200), (200, 200), (0.5, 0, 0.5))
l.add_shape(curve1)
l.add_shape(curve2)
l.add_shape(curve3)
l.add_shape(curve4)
l.draw()
示例#2
0
文件: Main.py 项目: miko083/PongGame
# Setting paddles sizes.
paddle_width_half = 90 / 2
paddle_height_half = 10 / 2
if window_size[0] < 200:
    print("Error - windows size too small. Windows size set to 500 x 500.")
    window_size[0] = 500
    window_size[1] = 500
if window_size[0] != 500:
    paddle_width_half = paddle_width_half + (window_size[0] - 500) / 10
    radius = radius + (window_size[0] - 500) / 1000

pause = False  # Pause boolean to manage pause.
game_window = Window(window_size)  # Initialization of window game.
# We need paddle shape in our window -
# we are doing it by using static method from paddle class and adding shape to our game window.
game_window.add_shape(
    Paddle.make_paddle_shape(paddle_width_half, paddle_height_half), "paddle")

score = [0, 0]  # Score tuple stores our score.
game_window.write_scores(score)  # Write score on the screen.

# Initialization of paddles, getting area size from window and setting them on the proper place.
paddle_down = Paddle(paddle_width_half, paddle_height_half)
paddle_down.set_area(game_window.get_area())
paddle_down.set_down()

paddle_up = Paddle(paddle_width_half, paddle_height_half)
paddle_up.set_area(game_window.get_area())
paddle_up.set_up()

# Initialization of ball, getting some game elements to ball to optimize code.
# (I don't want to give every element to update methods, so i will give them once in constructor).