ziheng -無限接球3.0

import pygame as p
import time

p.init()
screen = p.display.set_mode((682, 500))
# 設置標題 captiion 船長 首都 ----標題
p.display.set_caption("無限接球")
# 具體指應用函數的時候寫括號
ballx = 100
bally = 150
ban_x, ban_y, ban_k, ban_g = 300, 460, 120, 40
# 讓電腦沒過多少毫秒監控一次
p.key.set_repeat(100, 1)
# 1.設置字體 font 字體
ziti = p.font.Font(None, 30)
score = 0
while 1 > 0:
    for sj in p.event.get():
        # print(sj)
        if sj.type == p.QUIT:
            p.quit()
        # 判斷事件類型是不是按鍵 鍵 key
        elif sj.type == p.KEYDOWN:
            # 判斷按了哪一個鍵
            if sj.key == p.K_RIGHT:
                ban_x = ban_x + 10
            elif sj.key == p.K_LEFT:
                ban_x = ban_x - 10
        # 判斷事件類型是不是鼠標動作 motion動作
        elif sj.type == p.MOUSEMOTION:
            ban_x, _ = sj.pos
    screen.fill((120, 255, 30))
    bally = bally + 1
    if bally > 500:
        bally = 0
        ballx = ballx + 100
    if ballx > 682:
        ballx = 0
    # 左邊空氣牆
    if ban_x < -50:
        ban_x = 5
    elif 682 < ban_x:
        ban_x = 580

    # 畫一個小球
    p.draw.circle(screen, (172, 85, 255), (ballx, bally), 10, 0)
    # 畫一個長方形  rect 屏幕 顏色
    p.draw.rect(screen, (172, 85, 255), (ban_x, ban_y, ban_k, ban_g), 0)

    score = score+1
    # 設置文字
    text = ziti.render("score:%d"%score, True, (0, 0, 0))
    screen.blit(text,(132,436))


    p.display.update()
    # time.sleep(0.00001)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章