本文整理汇总了Python中pygame.quit函数的典型用法代码示例。如果您正苦于以下问题:Python quit函数的具体用法?Python quit怎么用?Python quit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: terminate
def terminate():
"""Function to handle the termination of the game.
This function will make sure the relevant exit calls have been made.
"""
pygame.quit()
sys.exit()
开发者ID:inJeans,项目名称:pygame,代码行数:7,代码来源:04-bouncing_clown_soln.py
示例2: main
def main():
""" Main program function. """
# Initialize Pygame and set up the window
pygame.init()
size = [SCREEN_WIDTH, SCREEN_HEIGHT]
screen = pygame.display.set_mode(size)
pygame.display.set_caption("My Game")
pygame.mouse.set_visible(False)
# Create our objects and set the data
done = False
clock = pygame.time.Clock()
# Create an instance of the Game class
game = Game()
# Main game loop
while not done:
# Process events (keystrokes, mouse clicks, etc)
done = game.process_events()
# Update object positions, check for collisions
game.run_logic()
# Draw the current frame
game.display_frame(screen)
# Pause for the next frame
clock.tick(60)
# Close window and exit
pygame.quit()
开发者ID:Waveharp,项目名称:Arcade_games,代码行数:35,代码来源:game_class_example.py
示例3: loop
def loop():
global CAT_POSITION, MICE
MICE = [Mouse() for i in range(4)]
while True:
for e in pg.event.get():
if e.type == pg.QUIT:
pg.quit()
sys.exit()
# keyboard logic
key_pressed = pg.key.get_pressed()
if key_pressed[pg.K_q] == 1 or key_pressed[pg.K_ESCAPE] == 1:
pg.event.post(pg.event.Event(pg.QUIT))
if pg.mouse.get_focused():
CAT_POSITION = set_cat_after_mouse()
for mouse in MICE:
if random.randint(0, 30) == 0:
mouse.direction = random.randint(0, 3)
mouse.run_away()
if len(MICE) > 0 and len(MICE) <= 23 and random.randint(0, 50) == 0:
new_mouse = Mouse()
new_mouse.position = MICE[-1].position
MICE.append(new_mouse)
draw()
clock.tick(24)
开发者ID:moggers87,项目名称:lazycat,代码行数:30,代码来源:__init__.py
示例4: run
def run(self):
"""The mainloop
"""
running = True
while running:
# handle any events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
running = False
# Clean the background
self.background.fill((255, 255, 255)) # fill background white
if SHOW_TIME:
self.playtime += self.clock.tick(self.fps) / 1000.0
self.draw_text(self.time_font, "FPS: {:6.3} {:6.3} sec.".format(self.clock.get_fps(), self.playtime), (15, self.h - 15))
# get all game-state from cpp-engine
# update all objects' position, color, etc.
self.stash_balls()
# finally, update screen
pygame.display.flip()
self.screen.blit(self.background, (0, 0))
pygame.quit()
开发者ID:mukeshmk,项目名称:explore-git,代码行数:26,代码来源:sim.py
示例5: game_intro
def game_intro():
intro = True
while intro :
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_c:
intro = False
if event.key == pygame.K_q:
pygame.quit()
quit()
gameDisplay.fill(white)
message_to_screen("Welcome to Sliter",
green,
-100,
size="large")
message_to_screen("The objective of the game is to eat red apples",
black,
-30)
message_to_screen("The more apples you eat, the longer you get",
black,
10)
message_to_screen("if you run into yourself, or the edges, you die!",
black,
50)
message_to_screen("Press C to play or Q to quit.",
black,
180)
pygame.display.update()
clock.tick(15)
开发者ID:shsong97,项目名称:python,代码行数:34,代码来源:snake_game.py
示例6: main
def main():
"draw loop"
# Initial robot state
origin_x, origin_y = 0.0, 0.0
arm = DebraArm.DebraArm(l1=L1, l2=L2, flip_x=1)
arm.inverse_kinematics(RobotSpacePoint(0.99*(L1+L2), 0, 0, 0))
tool = arm.get_tool()
joints = arm.get_joints()
# Draw robot
origin, p1, p2, p3, z = arm.get_detailed_pos(L3)
draw_arm(origin, p1, p2, p3, RANGE_MIN, RANGE_MAX)
pygame.display.update()
paused = False
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_p:
paused = not paused
if event.type == pygame.MOUSEBUTTONUP:
x, y = get_cursor_pos()
tool_prev = tool
tool = RobotSpacePoint(x, y, z, GRIPPER_HEADING)
if MODE == PLAN_JOINT_SPACE:
start_time = time.time()
pth1, pth2, pz, pth3 = arm.get_path(tool_prev,
RobotSpacePoint(0,0,0,0),
tool,
RobotSpacePoint(0,0,0,0),
DELTA_T)
elapsed_time = time.time() - start_time
print('elapsed time: ', elapsed_time)
else:
start_time = time.time()
pth1, pth2, pz, pth3, px, py, pz, pgrp = \
arm.get_path_xyz(tool_prev, RobotSpacePoint(0,0,0,0),
tool, RobotSpacePoint(0,0,0,0),
DELTA_T, 'all')
elapsed_time = time.time() - start_time
print('elapsed time: ', elapsed_time)
graph_trajectory_xyz(px, py, pz, pgrp)
graph_trajectory_joint(pth1, pth2, pth3)
draw_trajectory(arm, pth1, pth2, pz, pth3, DELTA_T)
if not paused:
SCREEN.fill(BLACK)
origin, p1, p2, p3, z = arm.get_detailed_pos(L3)
draw_arm(origin, p1, p2, p3, RANGE_MIN, RANGE_MAX)
pygame.display.update()
开发者ID:SyrianSpock,项目名称:inverse-kinematics,代码行数:60,代码来源:debra_arm_planner_visualiser.py
示例7: main
def main():
# change the current directory to the one of the game
# this is to allow executions like ``python src/tct.py''
try:
os.chdir(os.path.abspath(os.path.dirname(sys.argv[0])))
except IOError as e:
print(e)
exit(constants.FILE_ERR)
# get the command line options; return the option flags
game_opts = get_parsed_opts()
# MVC stuff
event_manager = EventManager()
gui_view = MainGUIView(event_manager, game_opts)
# the game manager
game_manager = GameManager(game_opts)
# controller which handles the main game loop
main_controller = MainController(event_manager, gui_view, game_manager)
# keep running the game until a quit event occurs
main_controller.run()
# if control somehow reaches this point close all the pygame subsystems
pygame.quit()
safe_exit()
开发者ID:faif,项目名称:The-Crime-Tracer,代码行数:28,代码来源:tct.py
示例8: event_handler
def event_handler():
for event in pygame.event.get():
# if [esc] or [x] pressed...
if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE):
# ... then quit!
pygame.quit()
sys.exit()
开发者ID:code-pylet,项目名称:Tutorials,代码行数:7,代码来源:Tutorial_2.py
示例9: main_menu
def main_menu():
meh = True
def broken():
global meh
print("this is broken")
new_game_btn = Button(325, 250, 150, 75, None, green, greenHightlight, black, "Play")
load_save_game = Button(150, 482, 500, 75, None, green, greenHightlight, black, "Load Save Game")
mapBtn = Button(175, 366, 450, 75, None, blue, blueHightlight, black, "Map Creator")
settingsBtn = Button(0, 525, 250, 75, None, black, grey, white, "Settings")
while meh:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
gameDisplay.fill(white)
new_game_btn.run(mediumFont, create_character)
# 2 is not broken. Just have to do editor
mapBtn.run(mediumFont, map_editor)
settingsBtn.run(mediumFont, none)
load_save_game.run(mediumFont, none)
if new_game_btn.is_clicked():
meh = False
pygame.display.update()
clock.tick(30)
开发者ID:vinenoob,项目名称:Python-2D-Game-Engine,代码行数:27,代码来源:GameEngine.py
示例10: deadText
def deadText():
x=300
y=350
length=200
height=50
font = pygame.font.SysFont("monospace", 120)
font_small=pygame.font.SysFont("monospace",30)
label=font.render("You Died!", 1,black)
label_small=font_small.render("Press enter to continue", 1, red)
setDisplay.blit(label, (100,200))
setDisplay.blit(label_small, (200,350))
#pygame.draw.rect(setDisplay, black, (x,y,length,height))
pygame.display.update()
pygame.time.wait(1000)
while True:
for event in pygame.event.get():
#print event
if event.type == MOUSEBUTTONDOWN:
print "click"
mouseClickRepeat(pygame.mouse.get_pos(),x, y, length, height)
if event.type == KEYDOWN:
runGame()
if event.type == QUIT:
pygame.quit()
sys.exit()
开发者ID:edy02,项目名称:test,代码行数:30,代码来源:snake_test.py
示例11: GetInput
def GetInput(self):
keystate = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == QUIT or keystate[K_q]:
pygame.quit(); sys.exit()
self.player.speed[0] *= 0.995
self.player.speed[1] *= 0.995
if self.player.accel > 0.007:
self.player.accel *= 0.99
if keystate[K_LEFT]:
self.player.rot += 1.0
if self.player.rot > 360:
self.player.rot = 0
if keystate[K_RIGHT]:
self.player.rot -= 1.0
if self.player.rot < 0:
self.player.rot = 359
if keystate[K_UP]:
self.player.accel += self.player.accel_append;
self.player.speed[0] += self.player.accel*sin(radians(self.player.rot))
self.player.speed[1] += self.player.accel*cos(radians(self.player.rot))
if keystate[K_DOWN]:
self.player.accel = 0.007
self.player.speed[0] *= 0.993
self.player.speed[1] *= 0.993
if keystate[K_SPACE]:
if not self.player.fired and not self.player.dead:
self.player.shoot()
if keystate[K_ESCAPE]:
if not self.player.dead:
self.teleportPlayer()
if keystate[K_r]:
self=aGame()
self.eventLoop()
开发者ID:Jornason,项目名称:UpennCoursework,代码行数:34,代码来源:asteroid.py
示例12: main
def main(version):
pygame.init()
with DataFile('settings.json', get_settings, json, False) as settings:
page = mainmenu.MainMenu()
text._set_lang(settings['lang'])
loop(settings, version, page)
pygame.quit()
开发者ID:geeklint,项目名称:vyolet,代码行数:7,代码来源:clientmain.py
示例13: main
def main():
SCALE = 10 # pixels per meter
pygame.init()
screen = pygame.display.set_mode((800,600))
screenWidth,screenHeight = screen.get_size()
worldSize = np.array(screen.get_size())/SCALE
pygame.display.set_caption("Newton World")
screen.fill((255,255,255))
pygame.display.flip()
world = NewtonWorld("NewtonWorld",screen,framesPerSecond=40,scale=SCALE)
#square = MouseTracker(world,position=worldSize/2,mass=1)
#world.add(square)
paddleImage = pygame.Surface((30,120))
paddleImage.fill(pygame.Color('red'))
paddle1 = MouseTracker1DOF(world,position=worldSize/2-(38,0),mass=1,image=paddleImage)
paddle1.set_dof('y')
world.add(paddle1)
#paddle2 = MouseTracker1DOF(world,position=worldSize/2+(38,0),mass=1,image=paddleImage)
#paddle2.set_dof('x')
#paddle2.set_k(10,100)
#world.add(paddle2)
world.unpause()
world.run_main_loop()
pygame.quit()
开发者ID:kjchavez,项目名称:pygame-engine,代码行数:29,代码来源:MouseTracker.py
示例14: handleEvents
def handleEvents(self):
# Handle events, starting with the quit event
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
# Find which key was pressed and start moving appropriate bat
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
#elif event.key == K_w:
elif event.key == K_DOWN:
self.shape.lessSides()
elif event.key == K_UP:
self.shape.moreSides()
elif event.key == K_LEFT:
self.shape.rotateLeft()
elif event.key == K_RIGHT:
self.shape.rotateRight()
elif event.key == K_SPACE:
self.surface.fill(colors.BLACK)
elif event.key == K_a:
self.shape.colorUp()
elif event.key == K_z:
self.shape.colorDn()
开发者ID:benjaminbradley,项目名称:pacworld,代码行数:28,代码来源:shape.py
示例15: main
def main():
width = 800;
height = 600;
title = "Swept AABB";
fps = 60;
fpsClock = pygame.time.Clock();
pygame.init();
displaySurface = pygame.display.set_mode((width, height));
pygame.display.set_caption(title);
player = Box(10, 300, 50, 50, 0, 0);
moveSpeed = 10;
wall = Box(300, 200, 100, 200, 0, 0);
gameRunning = True;
while (gameRunning):
for event in pygame.event.get():
if (event.type == QUIT):
gameRunning = False;
getInput(player, moveSpeed);
doCollision(player, wall);
render(displaySurface, player, wall);
pygame.display.update();
fpsClock.tick(fps);
pygame.quit();
sys.exit();
开发者ID:dr01d3k4,项目名称:teal-duck,代码行数:31,代码来源:main.py
示例16: main
def main():
must_quit = False
cursor = 0
screen = pygame.display.set_mode((640, 480))
cursor_visible = True
init_mice(screen.get_width(), screen.get_height())
while not must_quit:
for e in pygame.event.get():
if e.type == pygame.locals.QUIT:
must_quit = True
elif e.type == pygame.locals.KEYDOWN:
if e.key == pygame.locals.K_ESCAPE:
must_quit = True
elif e.key == pygame.locals.K_g:
pygame.event.set_grab(not pygame.event.get_grab())
elif e.key == pygame.locals.K_s:
cursor_visible = not cursor_visible
pygame.mouse.set_visible(0)
elif e.key == pygame.locals.K_r:
manymouse.quit()
init_mice(screen.get_width(), screen.get_height())
update_mice(screen.get_width(), screen.get_height())
draw_mice(screen)
manymouse.quit()
pygame.quit()
开发者ID:nfirvine,项目名称:pymanymouse,代码行数:28,代码来源:test_manymouse_sdl.py
示例17: mainloop
def mainloop(display, framerate):
"""Runs a pygame / planes main loop.
framerate is the framerate.
This must be run in the main thread, otherwise pygame.event will not
receive any events under MS Windows.
"""
print("about to start main loop")
clock = pygame.time.Clock()
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT:
print("got pygame.QUIT, terminating in mainloop()")
pygame.quit()
raise SystemExit
display.process(events)
display.update()
display.render()
pygame.display.flip()
# Slow down to framerate given
#
clock.tick(framerate)
return
开发者ID:flberger,项目名称:planes,代码行数:32,代码来源:gui_widgets.py
示例18: joystick
def joystick(timeout=-1):
running = True
if timeout != -1:
timeout = timeout * 1000000
startTime = datetime.datetime.now()
while running:
for event in pygame.event.get():
if event.type == KEYUP:
jPressed = handle_event(event)
running = False
if event.type == QUIT:
pygame.quit()
quit()
if timeout != -1:
endTime = datetime.datetime.now()
totalTime = endTime - startTime
if totalTime.microseconds >= timeout:
return "NONE"
return jPressed
开发者ID:swooningfish,项目名称:reaction-games,代码行数:26,代码来源:Main.py
示例19: run
def run(self):
# Main Game Loop
while self.done == False:
# Limit FPS of Game Loop
self.clock.tick(30)
# Check for Events
for event in pygame.event.get():
# Quit Game
if event.type == pygame.QUIT:
printDebug("PyGame.Quit Called.")
self.done = True
# Clear the Screen
self.screen.fill(white)
# Try to Draw Background at (0,0)
if self.background_image != None:
self.screen.blit( self.background_image, [0,0])
# Draw all Sprites
for sprite in self.sprites:
sprite.render(self.screen)
# Update Display
pygame.display.flip()
# End Main Game Loop
# Exit Program
printDebug("PyGame Exit.")
pygame.quit()
开发者ID:slapin,项目名称:Zombie-Factory,代码行数:31,代码来源:world.py
示例20: __del__
def __del__(self):
""" Stuff to do when we are totally done. """
self.sounds.stop_music()
# finished with pygame, make sure the window gets closed
pygame.quit()
开发者ID:kjwilcox,项目名称:hex,代码行数:7,代码来源:menu.py
注:本文中的pygame.quit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论