python遊戲pygame模組畫圓及移動方法介紹

來源:互聯網
上載者:User

標籤:init   lse   初始   isp   填充   span   spl   usr   bsp   

 1 #!/usr/bin/env python 2 # -*- coding:utf-8 -*-  3 #Author: ss 4  5 import pygame 6 import sys 7  8 # 初始化 9 pygame.init()10 11 size = width,height = 1000,600 # 設定螢幕尺寸12 BLUE = 0,0,25513 WHITE = 255,255,25514 BLACK = 0,0,015 RED = 255,0,016 GREEN = 0,255,017 18 screen = pygame.display.set_mode(size) # 建立surface對象19 pygame.display.set_caption(‘畫圓及拖拽‘) # 建立標題20 21 # 圓心位置定義22 position = size[0] // 2 , size[1] // 2  23 24 moving = False25 26 while True:27     for event in pygame.event.get():28         if event.type == pygame.QUIT:29             sys.exit()30         if event.type == pygame.MOUSEBUTTONDOWN: # 擷取點擊滑鼠事件31             if event.button == 1: # 點擊滑鼠左鍵32                 moving = True33         if event.type == pygame.MOUSEBUTTONUP: # 擷取鬆開滑鼠事件34             if event.button == 1: # 鬆開滑鼠左鍵35                 moving = False36     if moving:37         position = pygame.mouse.get_pos() # 更新圓心位置為滑鼠當前位置38 39 40 41     screen.fill(WHITE) # 填充螢幕42     # 畫各種尺寸顏色的圓43     pygame.draw.circle(screen,BLUE,position,30,1) 44     pygame.draw.circle(screen, BLACK, position, 50, 1)45     pygame.draw.circle(screen, RED, position, 80, 1)46     pygame.draw.circle(screen, GREEN, position, 120, 1)47     # 重新整理螢幕48     pygame.display.flip()

 

python遊戲pygame模組畫圓及移動方法介紹

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.