Boren-接小球游戏

1.0

import random
import pygame
pygame.init()  # 1.游戏初始化
screen = pygame.display.set_mode((700,600)) # 2.创建一个窗口,设置大小
pygame.display.set_caption("接小球游戏")
ball_x,ball_y = 400,400
ban_x, ban_y ,ban_width, ban_height = 400,550,220,100
font = pygame.font.Font('ziti.ttf',24)
ball_true = pygame.image.load("qiu.gif")
score=0
hp = 3

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEMOTION:
            ban_x,_ = event.pos
    ball_y = ball_y+1
    screen.fill((255,255,255))
    # 没接到小球的判定
    if ball_y>600:
        ball_x = random.randint(0,600)
        ball_y = 0
        hp=hp-1
    # 接到小球的判定结果
    if ban_x <=ball_x<=ban_x+220 and ban_y <=ball_y<=ban_y+100:
        score = score+1
        ball_x = random.randint(0, 600)
        ball_y = 0
    imgtext = font.render('分数:%d'%score,True,(0,0,0)) # 设置文字参数,内容,锯齿话,颜色
    screen.blit(imgtext,(0,0)) # 将文字放在屏幕上

    imgtext2 = font.render("生命值:%d"%hp,True,(150,162,22))
    screen.blit(imgtext2,(580,0))
    # pygame.draw.circle(screen,(100,255,0),(ball_x,ball_y),30,0)
    screen.blit(ball_true,(ball_x,ball_y))
    pygame.draw.rect(screen,(100,255,0),(ban_x, ban_y ,ban_width, ban_height),0)
    pygame.display.update() #3.不断循环



2.0

import random
import pygame
pygame.init()  # 1.游戏初始化
pygame.mixer.init() # 2.音乐初始化
screen = pygame.display.set_mode((700,600)) # 2.创建一个窗口,设置大小
pygame.display.set_caption("接小球游戏")
ball_x,ball_y = 400,0
ban_x, ban_y ,ban_width, ban_height = 400,550,220,100
font = pygame.font.Font('ziti.ttf',24)
ball_true = pygame.image.load("ball2.png")
hit = pygame.mixer.Sound("hit_wall.wav") # 加载音乐
hit.set_volume(0.4) # 设置音量


#pygame.mixer.music.load("bg.mp3")
#pygame.mixer.music.set_volume(0.3)
#pygame.mixer.music.plat(-1)
score=0
hp = 3
game_over = True

while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        elif event.type == pygame.MOUSEBUTTONUP:
            if game_over:
                game_over = False
                score = 0
                hp = 4
        elif event.type == pygame.MOUSEMOTION:
            ban_x,_ = event.pos
    screen.fill((255,255,255))
    if game_over:
        imgtext = font.render('请点击屏幕开始游戏' , True, (0, 0, 0))  # 设置文字参数,内容,锯齿话,颜色
        screen.blit(imgtext, (350, 300))  # 将文字放在屏幕上
    else:
        ball_y = ball_y + 1
        # 没接到小球的判定
        if ball_y>600:
            ball_x = random.randint(0,600)
            ball_y = 0
            hp = hp-1
            if hp ==0:
                game_over=True

        # 接到小球的判定结果
        if ban_x <=ball_x<=ban_x+220 and ban_y <=ball_y<=ban_y+100:
            score = score+1
            hit.play()
            ball_x = random.randint(0, 600)
            ball_y = 0
        imgtext = font.render('分数:%d'%score,True,(0,0,0)) # 设置文字参数,内容,锯齿话,颜色
        screen.blit(imgtext,(0,0)) # 将文字放在屏幕上

        imgtext2 = font.render("生命值:%d"%hp,True,(150,162,22))
        screen.blit(imgtext2,(580,0))
        # pygame.draw.circle(screen,(100,255,0),(ball_x,ball_y),30,0)
        screen.blit(ball_true,(ball_x,ball_y))
        pygame.draw.rect(screen,(100,255,0),(ban_x, ban_y ,ban_width, ban_height),0)
    pygame.display.update() #3.不断循环







  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
/* * File: ADC.c * Author: tlfte *AD转换,结果在C口和D口的LED上显示,能进行各种通道选择和参考电压,结果对齐方式选择 * Created on 2018年8月6日, 上午10:07 练习AD结果的计算验证,AD_RESULT=VIN×1023÷VREF,讲解887头文件的作用 */ // PIC16F887 Configuration Bit Settings // 'C' source line config statements // CONFIG1 #pragma config FOSC = XT // Oscillator Selection bits (XT oscillator: Crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN) #pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT disabled and can be enabled by SWDTEN bit of the WDTCON register) #pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled) #pragma config MCLRE = ON // RE3/MCLR pin function select bit (RE3/MCLR pin function is digital input, MCLR internally tied to VDD) #pragma config CP = OFF // Code Protection bit (Program memory code protection is disabled) #pragma config CPD = OFF // Data Code Protection bit (Data memory code protection is disabled) #pragma config BOREN = OFF // Brown Out Reset Selection bits (BOR disabled) #pragma config IESO = OFF // Internal External Switchover bit (Internal/External Switchover mode is disabled) #pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enabled bit (Fail-Safe Clock Monitor is disabled) #pragma config LVP = OFF // Low Voltage Programming Enable bit (RB3 pin has digital I/O, HV on MCLR must be used for programming) // CONFIG2 #pragma config BOR4V = BOR40V // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V) #pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off) // #pragma config statements should precede project file includes. // Use project enums instead of #define for ON and OFF. #include <xc.h> #define _XTAL_FREQ 4000000 //指明时钟晶振为4MHz,使delay宏定义可以正常使用 void CSH(void); unsigned int AD_SUB(char k); void main( ) { unsigned int y; CSH(); while(1) { __delay_ms(100); //每隔100毫秒循环一次 y=AD_
最新发布
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值