import pygame
import random
defqiu
(bally,speedy,ballx,speedx,r,g,b )
: bally = bally + speedy
ballx = ballx + speedx
if bally <0:
speedy =
1if ballx >= chuang_kou_kuan:
speedx =-1
if ballx <=0:
speedx =
1if bally >= chuang_kou_gao:
ballx = random.randint(10,
590)
bally =
0 r = random.randint(0,
255)
g = random.randint(0,
255)
b = random.randint(0,
255)
pygame.draw.circle(chuang_kou,
(r, g, b)
,(ballx, bally)
, bai_jing)
return bally,speedy,ballx,speedx,r,g,b
r=random.randint(0,
255)
g=random.randint(0,
255)
b=random.randint(0,
255)
ballx=
200bally=
0pygame.init(
)chuang_kou_kuan =
600chuang_kou_gao =
700chuang_kou=pygame.display.set_mode(
(chuang_kou_kuan,chuang_kou_gao)
)bai_jing=random.randint(20,
50)speedy =
1speedx =
1rect_gao=
10rect_kuan=
150banx=
300bany=
650# 設定每多少毫秒電腦響應識別多少次
pygame.key.set_repeat(
100,1)
# 文字1.0 設定文字的字型和大小 font
wz1 = pygame.font.sysfont(
"simhei",40
)fen_shu=
0while
1>0:
for event in pygame.event.get():
if event.
type
==pygame.quit:
pygame.quit(
)elif event.
type
== pygame.keydown:
if event.key == pygame.k_a:
banx = banx-
20elif event.key == pygame.k_d:
banx = banx+
20elif event.
type
== pygame.mousemotion:
banx,bany=event.pos
chuang_kou.fill((1
,1,1
))bally,speedy,ballx,speedx,r,g,b = qiu(bally,speedy,ballx,speedx ,r,g,b)
# 板的空氣牆
if banx<-40
: banx=
5elif banx>
460:
banx=
450# 判斷接到小球?
if banxbally = bany-
1 speedy=-1
fen_shu = fen_shu +
1# 畫乙個長方形:rect
pygame.draw.rect(chuang_kou,
(255
,255
,255),
(banx,bany,rect_kuan,rect_gao)
)# 文字2.0 設定字型內容和顏色
wz2 = wz1.render(
"分數%d"
%fen_shu,
true,(
255,
255,
255)
)# 文字3.0 設定文字位置
chuang_kou.blit(wz2,
(400,50
))pygame.display.update(
)
junjie 接小球遊戲
import pygame import random import time python game loading.初始化.載入中.pygame.init 介面遊戲 dis 分開 play玩 diaplay 展覽展示的意思 set設定 mode模式 chuang kou pygame.displ...
Bob 雙人接小球遊戲
import pygame import random yihaowanjiadefen 0erhaowanjiadefen 0import time as t defball screen,x,y,down,right,green,speed if down y y speed else y y ...
binrui 接藥水遊戲3 0 原接炸藥遊戲
import random import pygame import sys import time 1。載入中 loading 初始化 pygame.init 2.設定視窗大小 dis分開 展覽館 展示 寬,高 screen pygame.display.set mode 890 550 4.設定...