Bob 雙人接小球遊戲

2021-10-06 09:59:06 字數 3659 閱讀 3676

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 - speed

if right:

x += speed

else

: x -= speed

if y > screen_width:

down =

false

if x > screen_long:

right =

falseif0

> y:

down =

true

if x <0:

right =

true

# pygame.draw.circle(screen, (green, 255, 20), (x, y), 50)

return x, y, down, right, speed

pygame.init(

)screen_long, screen_width =

1200

,800

screen = pygame.display.set_mode(

(screen_long, screen_width )

)x, y, down, right, speed = random.randint(

0, screen_long)

, random.randint(

0, screen_width)

,true

,true,1

ban_x, ban_y, ban_k, ban_g = screen_long-

100,

250,

100,

100ban_x2, ban_y2, ban_k2, ban_g2 =0,

250,

100,

100# 電腦每隔多少毫秒時間響應一次

# 文字1:設定文字的字型和大小 font 字型

)# 1秒=1000毫秒

pygame.key.set_repeat(1,

1)while

true

:for event in pygame.event.get():

if event.

type

== pygame.quit:

pygame.quit(

)# elif event.type == pygame.mousemotion:

# ban_x, ban_y = event.pos # pos---> position

elif event.

type

== pygame.keydown:

if event.key == pygame.k_up:

ban_y -=

5if ban_y <0:

ban_y =

0if event.key == pygame.k_down:

ban_y +=

5if ban_y > screen_width -

100:

ban_y = screen_width -

100if event.key == pygame.k_w:

ban_y2 -=

5if ban_y2 <0:

ban_y2 =

0if event.key == pygame.k_s:

ban_y2 +=

5if ban_y2 > screen_width -

100:

ban_y2 = screen_width-

100 screen.fill((65

,105

,225))

screen.blit(dunhuang,(0

,0))

screen.blit(dunhuang,

(500,0

))screen.blit(dunhuang,(0

,400))

screen.blit(dunhuang,

(500

,400))

x, y, down, right, speed = ball(screen, x, y, down, right,

0, speed)

if x > screen_long-

100and ban_y < y < ban_y +

100:

yihaowanjiadefen +=

1 x = screen_long-

100 right =

false

speed +=

1if x <

100and ban_y2 < y < ban_y2 +

100:

erhaowanjiadefen +=

1 x =

100 right =

true

speed +=

1# px,py,pdown,pright = ball(screen, px,py,pdown,pright,255)

pygame.draw.rect(screen,

(220,0

,0),

(ban_x, ban_y, ban_k, ban_g)

) pygame.draw.rect(screen,

(220

,100,0

),(ban_x2, ban_y2, ban_k2, ban_g2)

)# 文字2:設定文字內容和顏色

wen_zi_nei_rong = wen_zi_da_xiao.render(

"雙人對戰遊戲"

,true,(

0,0,

0)) wenzi_neirong = wen_zi_da_xiao.render(

"%s : %s"

%(erhaowanjiadefen,yihaowanjiadefen)

,true,(

205,38,

38))# 文字3:把文字放在視窗上 blit 傳送

screen.blit(wen_zi_nei_rong,

(screen_long/2-

70,0)

) screen.blit(wenzi_neirong,

(screen_long /2-

70,30)

) screen.blit(toukui,

(x,y)

) pygame.display.update(

)pygame.quit(

)

junjie 接小球遊戲

import pygame import random import time python game loading.初始化.載入中.pygame.init 介面遊戲 dis 分開 play玩 diaplay 展覽展示的意思 set設定 mode模式 chuang kou pygame.displ...

雙人彈小球

include include include define high 480 遊戲畫面尺寸 define width 640 全域性變數 int ball x,ball y 小球的座標 int ball vx,ball vy 小球的速度 int radius 小球的半徑 int bar1 left...

junjie 接小球遊戲3 0

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 s...