| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 102 人关注过本帖
标题:今天分享一个小游戏!大家评估一下!
只看楼主 加入收藏
沉着的导弹鲨
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2024-11-28
结帖率:100%
收藏
 问题点数:0 回复次数:1 
今天分享一个小游戏!大家评估一下!
程序代码:
import pygame as pg
import sys
import random
import time

pg.init()

game_window = pg.display.set_mode((600, 500))
pg.display.set_caption('接球游戏')
score = 0
font = pg.font.Font(None, 60)
window_color = (0, 0, 0)
ball_color = (0, 255, 0)
rect_color = (255, 0, 0)
ball_x = random.randint(20, 580)
ball_y = random.randint(20, 480)
move_x = 1
move_y = 1
points = 1
count = 0

while True:
    game_window.fill(window_color)
    for event in pg.event.get():
        if event.type == pg.QUIT:
            print(score)
            sys.exit()
    mouse_x, mouse_y = pg.mouse.get_pos()
    pg.draw.circle(game_window, ball_color, (ball_x, ball_y), 20)
    pg.draw.rect(game_window, rect_color, (mouse_x, 490, 100, 10))
    ball_x += move_x
    ball_y += move_y
    my_score = font.render(str(score), False, (0, 238, 238))
    game_window.blit(my_score, (500, 30))
    if ball_x <= 20 or ball_x >= 580:
        move_x = -move_x
    if ball_y <= 20:
        move_y = -move_y
    elif (mouse_x - 20 < ball_x < mouse_x + 120) and ball_y >= 470:
        move_y = -move_y
        score += points
        count += 1
        if count == 5:
            count = 0
            points *= 2
            if move_x > 0:
                move_x += 1
            else:
                move_x -= 1
            move_y -= 1
    elif ball_y > 480 and (ball_x <= mouse_x - 20 or ball_x >= mouse_x + 120):
        ball_y = 490
        break
    pg.display.update()
    time.sleep(0.005)
print(score)

征求大家的意见!谢谢
搜索更多相关主题的帖子: 今天 if score count import 
2024-12-26 20:00
沉着的导弹鲨
Rank: 2
等 级:论坛游民
帖 子:24
专家分:10
注 册:2024-11-28
收藏
得分:0 
给个建议吧!

我是一个喜欢编程的菜鸟
2024-12-28 19:43
快速回复:今天分享一个小游戏!大家评估一下!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033069 second(s), 10 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved