本文整理汇总了Python中stage.Stage.spawn_swing方法的典型用法代码示例。如果您正苦于以下问题:Python Stage.spawn_swing方法的具体用法?Python Stage.spawn_swing怎么用?Python Stage.spawn_swing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stage.Stage
的用法示例。
在下文中一共展示了Stage.spawn_swing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from stage import Stage [as 别名]
# 或者: from stage.Stage import spawn_swing [as 别名]
def main():
global stage_width, stage_height, sidebar_width, wall_gap, gap_size, padding, colors, screen, stage, stage2, barrel_cannon1, child_bonus, grandchild_bonus
stage_width, stage_height = 550, 720
sidebar_width = 150 # sidebar displays statistics
wall_gap = 20.0 # space between the walls and the edge of the window
gap_size = 350.0 # how big the gap in the middle is
padding = 5.0 # segment padding
gravity = (0.0, -100.0)
bound_color = "lightgray" # boundary walls color
bg_color = "black" # window background color
ball_spacing = 10 # used to space initially fixed balls
ball_radius = 20
bullet_color = "green"
child_bonus = 1.5
grandchild_bonus = 2.0
# used in collisions to change ball color
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
pygame.init()
screen = pygame.display.set_mode((stage_width + sidebar_width, stage_height))
clock = pygame.time.Clock()
running = True
pm.init_pymunk()
matt = Player("Matt", 1)
stage = Stage(
matt,
screen,
K_LEFT,
K_RIGHT,
K_UP,
stage_width,
stage_height,
wall_gap,
gap_size,
padding,
bound_color,
gravity,
0,
100,
bullet_color,
)
stage.space.add_collisionpair_func(1, 3, barrelcannon_load)
spinner1 = Spinner(stage, 150, 100, 25, 25, 1, 1, math.pi / 120, 1, 0.2 * stage_width, 0.5 * stage_width)
spinner2 = Spinner(stage, 275, 200, 25, 25, 1, 1, -math.pi / 60, 2, 0.5 * stage_width, 0.8 * stage_width)
poly_swing1 = Polyswing(stage, 100, 600, 1, 10, 10, 500, 1, 10, 20, 1, 3, None, 3, 1, "orange")
poly_swing2 = Polyswing(stage, 275, 650, 1, 10, 10, 500, 1, 10, 20, 1, 3, None, 3, 1, "red")
poly_swing3 = Polyswing(stage, 450, 600, 1, 10, 10, 500, 1, 10, 20, 1, 3, None, 3, 1, "orange")
stage.swing_limit = len(stage.swings) * 10
barrel_cannon1 = Barrelcannon(stage, 275, 300, 20, 30, 1, 1, -math.pi / 60, 1, 0.2 * stage_width, 0.8 * stage_width)
ticks_to_next_reload = 0
ticks_to_next_respawn = 120
swing_index = 0
last_swing_spawn = 0
start_time = time.time()
while running: # main game loop
pg_time = pygame.time.get_ticks() / 1000.0
# ===============================================================================
# ball_spawn_interval should decrease with time
# ===============================================================================
if pg_time < 30:
ball_spawn_interval = 3
elif pg_time < 60:
ball_spawn_interval = 2.75
elif pg_time < 90:
ball_spawn_interval = 2.5
elif pg_time < 120:
ball_spawn_interval = 2.25
elif pg_time < 150:
ball_spawn_interval = 2
elif pg_time < 180:
ball_spawn_interval = 1.75
elif pg_time < 210:
ball_spawn_interval = 1.5
elif pg_time < 240:
ball_spawn_interval = 1.25
elif pg_time < 270:
ball_spawn_interval = 1
elif pg_time < 300:
ball_spawn_interval = 0.75
elif pg_time < 330:
ball_spawn_interval = 0.5
if pg_time - last_swing_spawn >= ball_spawn_interval:
last_swing_spawn = pg_time
stage.spawn_swing()
for event in pygame.event.get():
try:
if event.type == QUIT:
running = False
#.........这里部分代码省略.........