Simple pie game, mastering the Pygame of lines and arcs, as well as the response to input.
1 ImportMath2 Importpygame, sys3 fromPygame.localsImport*4 Pygame.init ()5Screen = Pygame.display.set_mode ((600, 500))6Pygame.display.set_caption ("The Pie Game--Press 1 2 3 4")7MyFont = Pygame.font.Font (None, 60)8 9color = 200, 80, 60Tenwidth = 5 Onex = 300 Ay = 250 -RADIUS = 200 -Position = X-radius, Y-radius, radius*2, radius*2 the -Piece1 =False -Piece2 =False -Piece3 =False +Piece4 =False - + #main game Loop A whileTrue: at forEventinchpygame.event.get (): - ifEvent.type = =Pygame. QUIT: - pygame.quit () - sys.exit () - elifEvent.type = =KEYUP: - ifEvent.key = =Pygame. K_escape: in pygame.quit () - sys.exit () to elifEvent.key = =Pygame. K_1: +Piece1 =True - elifEvent.key = =Pygame. K_2: thePiece2 =True * elifEvent.key = =Pygame. K_3: $Piece3 =TruePanax Notoginseng elifEvent.key = =Pygame. K_4: -Piece4 =True the #Clear the screen +Screen.fill ((0,0,200)) A theTEXTIMG1 = Myfont.render ("1", True, color) +Screen.blit (TEXTIMG1, X+RADIUS/2, Y-RADIUS/2)) - $TextImg2 = Myfont.render ("2", True, color) $Screen.blit (TextImg2, X-RADIUS/2, Y-RADIUS/2)) - -TEXTIMG3 = Myfont.render ("3", True, color) theScreen.blit (TEXTIMG3, X-RADIUS/2, Y+RADIUS/2)) - WuyiTEXTIMG4 = Myfont.render ("4", True, color) theScreen.blit (TextImg4, X+RADIUS/2, Y+RADIUS/2)) - Wu #should the pieces be drawn? - ifPiece1: AboutStart_angle =Math.radians (0) $End_angle = Math.radians (90) - pygame.draw.arc (screen, color, position, Start_angle, end_angle, width) -Pygame.draw.line (screen, color, (x, y),radius), width) -Pygame.draw.line (screen, color, (x, y), (x+radius, y), width) A + ifPiece2: theStart_angle = Math.radians (90) -End_angle = Math.radians (180) $ pygame.draw.arc (screen, color, position, Start_angle, end_angle, width) thePygame.draw.line (screen, color, (x, y),radius), width) thePygame.draw.line (screen, color, (x, y),radius, y), width) the the ifPiece3: -Start_angle = Math.radians (180) inEnd_angle = Math.radians (270) the pygame.draw.arc (screen, color, position, Start_angle, end_angle, width) thePygame.draw.line (screen, color, (x, y),radius, y), width) AboutPygame.draw.line (screen, color, (x, y), (x, y+radius), width) the the ifPiece4: theStart_angle = Math.radians (270) +End_angle = Math.radians (360) - pygame.draw.arc (screen, color, position, Start_angle, end_angle, width) thePygame.draw.line (screen, color, (x, y), (x, y+radius), width)BayiPygame.draw.line (screen, color, (x, y), (x+radius, y), width) the the #finished? - ifPiece1 andPiece2 andPiece3 andPiece4: -color = 0, 255, 0 the thePygame.display.update ()
View Code
:
To draw an ellipse:
Pygame Practice PIE Game (and simple graphics training)