我是一只可可爱爱的小粽子

import pygame

from pygame.locals import *

import pygame

import sys

import asyncio

import time

import random

class Player(pygame.sprite.Sprite):

    #粽子对象

    def __init__(self):

        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.image.load('min2.png')

        self.image = pygame.transform.scale(self.image, (130, 130))

        print(self.image)

        self.rect = self.image.get_rect()

        self.rect.midbottom = (20, screen_height )

    def update(self):

        screen.blit(self.image, (self.rect.x, self.rect.y))

        screen.blit(self.image, self.rect)

        x_move = 0

        y_move = 0

        # 获取按键,并进行相应的移动

        key = pygame.key.get_pressed()

        if key[pygame.K_LEFT]:

            x_move -= 4

        if key[pygame.K_RIGHT]:

            x_move += 4

        if key[pygame.K_UP]:

            y_move -= 4

        if key[pygame.K_DOWN]:

            y_move += 4

        self.rect.x += x_move

        self.rect.y += y_move

        # 控制人物的最低位置

        # 绘制人物

        screen.blit(self.image, self.rect)

        if  self.rect.right > 1400:

            self.rect.x -= 20

        elif  self.rect.left <=-10:

            self.rect.x += 20

        elif  self.rect.top < 0:

            self.rect.y += 50

        elif self.rect.bottom> 730:

            self.rect.y -= 60

    # def eat(self):

class Heart_game(pygame.sprite.Sprite):

    def __init__(self):

        pygame.sprite.Sprite.__init__(self)

        self.Heart_speed = [2,-3]

        # 加载小球图片

        self.image = pygame.image.load('min_love.png').convert_alpha()

        # 获取小球图片的区域开状

        self.rect = self.image.get_rect()

        x,y = random.randint(0,1300),random.randint(0,700)

        self.active = True

        self.rect.midbottom = (x, y )

    def Move_update(self):

        self.rect = self.rect.move(self.Heart_speed)

        screen.blit(self.image, self.rect)

        if  self.rect.right > 1400:

            x = random.randint(-5, 0)

            y = random.randint(-5, -2) or random.randint(1, 5)

            self.Heart_speed = [x, y]

        elif  self.rect.left <=-10:

            x = random.randint(0, 5)

            y = random.randint(-5, 5)

            self.Heart_speed = [x, y]

        elif  self.rect.top < -10:

            x = random.randint(-3,3)

            y = random.randint(0,3)

            self.Heart_speed = [x,y]

        elif self.rect.bottom> 695:

            x = random.randint(-3, 3)

            y = random.randint(-3,0)

            self.Heart_speed = [x, y]

# 加载基本的窗口和时钟

pygame.init()

screen_width = 1400

screen_height = 700

screen = pygame.display.set_mode((screen_width, screen_height))

pygame.display.set_caption('迟到的端午')

clock = pygame.time.Clock()  # 设置时钟

# 加载背景,粽子,爱心

bg =跟单网gendan5.com pygame.image.load("vack.jpeg").convert()

player = Player()

aixin = Heart_game()

group = pygame.sprite.Group(aixin)

count = 0

score = 0

score_font = pygame.font.Font("font.ttf",50)

BLACK= (0,0,0)

l = []

l.append(aixin)

#  游戏主循环

game_run = 1

while game_run:

    clock.tick(60)

    screen.blit(bg, (0, 0))

    # 持续更新

    count += 1

    for each in l:

        each.Move_update()

        screen.blit(each.image, each.rect)

        if pygame.sprite.spritecollide(player,group,True,pygame.sprite.collide_circle_ratio(0.5)) :

                l.pop()

                score += 1

                print(score)

                # del aixin

    if not l:

        l.append(Heart_game())

        group.add(l[0])

    player.update()

    score_text = score_font.render("Score: % s" % str(score), True, BLACK)

    screen.blit(score_text, (0, 0))

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            game_run = False

    # 窗口更新并绘制

    pygame.display.update()

pygame.quit()



https://www.dhzhongyi.cn/

 https://www.countdata.cn/

https://www.92blue.cn/

https://www.ffxwsc.cn/

https://www.hp27.cn/

https://www.repair.net.cn/

https://www.planetech.com.cn/

https://www.gzplq.cn/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值