Python制作经典游戏案例-水果忍者(附源码等文件)

这篇具有很好参考价值的文章主要介绍了Python制作经典游戏案例-水果忍者(附源码等文件)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

前言

大家好,我是辣条哥,今天给大家分享一款我以前特爱玩的游戏,水果大战,今天我就教大家使用python把这款游戏制作出来。我们先来看效果
点击跳转文末
相关的一些音乐文件,还有代码文件都在文末直接找辣条拿就行~ 记得给辣条顶一顶支持一下啊~
Python制作经典游戏案例-水果忍者(附源码等文件)

当我运行代码这个就是第一效果图,还会有熟悉的音乐的声音。然后拖动鼠标就会有水果跳上来。

Python制作经典游戏案例-水果忍者(附源码等文件)
接下来我们就可以通过鼠标随便切,可以横着切,也可以竖着切,是不是很解压呢?好了,我们直接进入主题,接下来辣条哥把这个水果大战游戏效果跟大家详细介绍。

代码展示

import time
import math
import random
import pygame
from pygame.constants import *

pygame.init()
class OptionMode(pygame.sprite.Sprite):
    """ 模式选项类 """

    def __init__(self, window, x, y, image_path, turn_angel, flag):
        pygame.sprite.Sprite.__init__(self)
        self.window = window
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y
        self.turn_angel = turn_angel
        self.v_angel = 0
        self.flag = flag

    def update(self):
        new_image = pygame.transform.rotate(self.image, -self.v_angel)
        self.window.blit(new_image, (self.rect.x + self.rect.width / 2 - new_image.get_width() / 2,
                                     self.rect.y + self.rect.height / 2 - new_image.get_height() / 2))
        self.v_angel += self.turn_angel


class Background(pygame.sprite.Sprite):
    """ 背景图片 """

    def __init__(self, window, x, y, image_path):
        pygame.sprite.Sprite.__init__(self)
        self.window = window
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()
        self.rect.x = x
        self.rect.y = y

    def update(self):
        self.window.blit(self.image, self.rect)


class ThrowFruit(pygame.sprite.Sprite):
    """ 被抛出的水果类 """

    def __init__(self, window, image_path, speed, turn_angel, flag):
        pygame.sprite.Sprite.__init__(self)

        # 游戏窗口
        self.window = window

        # 导入水果图像并获取其矩形区域
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()

        # 水果抛出时x坐标取随机数
        self.rect.x = random.randint(0, Manager.WIDTH)

        # 水果初始y坐标
        self.rect.y = Manager.HEIGHT

        # 抛出时速度
        self.speed = speed

        # 旋转速度
        self.turn_angel = turn_angel

        # 水果抛出时与窗口下水平线的夹角弧度,因为要用到随机函数, 所以取整数, 使用时除以100
        self.throw_angel = 157

        # 水果抛出后所经历的时间, 初始化为0
        self.fruit_t = 0

        # 旋转的总角度
        self.v_angel = 0

        # 水果抛出时的初速度
        self.v0 = 6

        # 水果标记
        self.flag = flag

    def update(self):
        """ 水果运动状态更新 """

        # 如果水果的初始X坐标位于窗口左边区域, 取抛出时弧度在1.4  ~ 1.57 之间(70度至90度之间)
        if self.rect.x <= Manager.WIDTH / 2:
            self.throw_angel = random.randint(140, 157)

        # 如果水果的初始X坐标位于窗口右侧区域, 取抛出时弧度在1.57 * 100 ~ 1.75 * 100之间(90度至110度之间)
        elif self.rect.x >= Manager.WIDTH / 2:
            self.throw_angel = random.randint(157, 175)

        # 水果旋转后的新图像
        new_fruit = pygame.transform.rotate(self.image, self.v_angel)

        # 将旋转后的新图像贴入游戏窗口, 注意, 旋转后的图像尺寸以及像素都不一样了(尺寸变大了), 所以坐标需要进行适当处理
        self.window.blit(new_fruit, (self.rect.x + self.rect.width / 2 - new_fruit.get_width() / 2,
                                     self.rect.y + self.rect.height / 2 - new_fruit.get_height() / 2))

        # 水果抛出后的运动时水平匀速运动以及竖直向上的变速运动到达最高点时下落, 所以可以判断水果做的是斜上抛运动
        # 可以利用重力加速度来求出每隔一段时间水果运动后的y坐标
        # 公式: v0 * t * sin(α) - g * t^2 / 2
        if self.rect.y >= Manager.HEIGHT + self.rect.height:
            if self.flag != 5:
                Manager.classic_miss += 1
            self.kill()
        self.rect.y -= self.v0 * self.fruit_t * math.sin(self.throw_angel / 100) - (Manager.G *
                                                                                    self.fruit_t ** 2 / 10) / 2

        # 计算水果在水平方向的位移之后的X坐标, 匀速运动,没啥好说的
        # 公式: v0 * t * cos(α)
        self.rect.x += self.v0 * self.fruit_t * math.cos(self.throw_angel / 100)

        # 累加经过的时间
        self.fruit_t += 0.1

        # 累加旋转总角度
        self.v_angel += self.turn_angel


class HalfFruit(pygame.sprite.Sprite):
    """ 水果切片类 """

    def __init__(self, window, image_path, x, y, turn_angel, v_angel, v0):
        pygame.sprite.Sprite.__init__(self)
        # 游戏窗口
        self.window = window

        # 导入水果图像并获取其矩形区域
        self.image = pygame.image.load(image_path)
        self.rect = self.image.get_rect()

        # 水果被切开后的
        self.rect.x = x

        # 水果初始y坐标
        self.rect.y = y

        # 旋转速度
        self.turn_angel = turn_angel

        # 水果被切开时开始计时
        self.fruit_t = 0

        # 旋转的总角度
        self.v_angel = v_angel

        # 水果抛出时的水平初速度
        self.v0 = v0

    def update(self):
        """ 水果运动状态更新 """

        # 如果水果的初始X坐标位于窗口左边区域, 取抛出时弧度在1.4  ~ 1.57 之间(70度至90度之间)
        # if self.rect.x <= v1版本.Manager.WIDTH / 2 - self.rect.width:
        # 	self.throw_angel = random.randint(140, 157)
        #
        # 如果水果的初始X坐标位于窗口右侧区域, 取抛出时弧度在1.57 * 100 ~ 1.75 * 100之间(90度至110度之间)
        # elif self.rect.x >= v1版本.Manager.WIDTH / 2 + self.rect.width:
        # 	self.throw_angel = random.randint(157, 175)

        # 水果旋转后的新图像
        new_fruit = pygame.transform.rotate(self.image, self.v_angel)

        # 将旋转后的新图像贴入游戏窗口, 注意, 旋转后的图像尺寸以及像素都不一样了(尺寸变大了), 所以坐标需要进行适当处理
        self.window.blit(new_fruit, (self.rect.x + self.rect.width / 2 - new_fruit.get_width() / 2,
                                     self.rect.y + self.rect.height / 2 - new_fruit.get_height() / 2))

        # 水果被切开之后的切片做的是平抛运动
        # 可以利用重力加速度来求出每隔一段时间水果运动后的y坐标
        # 公式: h += v0 * t * sin(α) - g * t^2 / 2
        if self.rect.y >= Manager.HEIGHT:
            self.kill()
        self.rect.y += Manager.G * self.fruit_t ** 2 / 2

        # 计算水果在水平方向的位移之后的X坐标, 匀速运动,没啥好说的
        # 公式: v0 * t * cos(α)
        self.rect.x += self.v0 * self.fruit_t

        # 累加经过的时间
        self.fruit_t += 0.01

        # 累加旋转总角度
        self.v_angel += self.turn_angel


class Bgm(object):
    """ 游戏音乐类 """

    def __init__(self):
        pygame.mixer.init()

    def play_menu(self):
        pygame.mixer.music.load("./sound/menu.ogg")
        pygame.mixer.music.play(-1, 0)

    def play_classic(self):
        pygame.mixer.music.load("./sound/start.mp3")
        pygame.mixer.music.play(1, 0)

    def play_throw(self):
        pygame.mixer.music.load("./sound/throw.mp3")
        pygame.mixer.music.play(1, 0)

    def play_splatter(self):
        pygame.mixer.music.load("./sound/splatter.mp3")
        pygame.mixer.music.play(1, 0)

    def play_over(self):
        pygame.mixer.music.load("./sound/over.mp3")
        pygame.mixer.music.play(1, 0)


class Knife(object):
    def __init__(self, window):
        self.window = window
        self.apple_flash = pygame.image.load("./images/apple_flash.png")
        self.banana_flash = pygame.image.load("./images/banana_flash.png")
        self.peach_flash = pygame.image.load("./images/peach_flash.png")
        self.sandia_flash = pygame.image.load("./images/sandia_flash.png")

    def show_apple_flash(self, x, y):
        self.window.blit(self.apple_flash, (x, y))

    def show_banana_flash(self, x, y):
        self.window.blit(self.banana_flash, (x, y))

    def show_peach_flash(self, x, y):
        self.window.blit(self.peach_flash, (x, y))

    def show_sandia_flash(self, x, y):
        self.window.blit(self.sandia_flash, (x, y))


class Manager(object):
    # 窗口尺寸
    WIDTH = 640
    HEIGHT = 480

    # 游戏中的定时器常量
    THROWFRUITTIME = pygame.USEREVENT
    pygame.time.set_timer(THROWFRUITTIME, 3000)

    # 重力加速度, 取整数,使用时除以10
    G = random.randint(21, 23)

    # 经典模式miss掉的水果数
    classic_miss = 0

    def __init__(self):
        # 生成游戏窗口
        self.window = pygame.display.set_mode((Manager.WIDTH, Manager.HEIGHT))
        self.window_icon = pygame.image.load("./images/score.png")
        pygame.display.set_icon(self.window_icon)
        pygame.display.set_caption("FruitNinja")

        # 游戏分数
        self.classic_score = 0
        self.zen_score = 0

        # 创建游戏中用到的的精灵组
        self.background_list = pygame.sprite.Group()
        self.circle_option = pygame.sprite.Group()
        self.option_fruit_list = pygame.sprite.Group()
        self.fruit_half_list = pygame.sprite.Group()
        self.throw_fruit_list = pygame.sprite.Group()

        # 导入背景图像并添加入背景精灵组
        self.background = Background(self.window, 0, 0, "./images/background.jpg")
        self.home_mask = Background(self.window, 0, 0, "./images/home-mask.png")
        self.logo = Background(self.window, 20, 10, "./images/logo.png")
        self.ninja = Background(self.window, Manager.WIDTH - 320, 45, "./images/ninja.png")
        self.home_desc = Background(self.window, 20, 135, "./images/home-desc.png")

        self.background_list.add(self.background)
        self.background_list.add(self.home_mask)
        self.background_list.add(self.logo)
        self.background_list.add(self.ninja)
        self.background_list.add(self.home_desc)

        # 创建旋转的圈并添加进精灵组
        self.dojo = OptionMode(self.window, Manager.WIDTH - 600, Manager.HEIGHT - 250, "./images/dojo.png", 3, None)
        self.new_game = OptionMode(self.window, Manager.WIDTH - 405, Manager.HEIGHT - 250, "./images/new-game.png", 3,
                                   None)
        self.game_quit = OptionMode(self.window, Manager.WIDTH - 160, Manager.HEIGHT - 150, "./images/quit.png", -3,
                                    None)

        self.circle_option.add(self.dojo)
        self.circle_option.add(self.new_game)
        self.circle_option.add(self.game_quit)

        # 创建主菜单界面旋转的水果并添加进精灵组
        self.home_sandia = OptionMode(self.window, Manager.WIDTH - 405 + self.new_game.rect.width / 2 - 49,
                                      Manager.HEIGHT - 250 + self.new_game.rect.height / 2 - 85 / 2,
                                      "./images/sandia.png", -3, "option_sandia")
        self.home_peach = OptionMode(self.window, Manager.WIDTH - 600 + self.dojo.rect.width / 2 - 31,
                                     Manager.HEIGHT - 250 + self.dojo.rect.height / 2 - 59 / 2,
                                     "./images/peach.png", -3, "option_peach")
        self.home_boom = OptionMode(self.window, Manager.WIDTH - 160 + self.game_quit.rect.width / 2 - 66 / 2,
                                    Manager.HEIGHT - 150 + self.game_quit.rect.height / 2 - 68 / 2,
                                    "./images/boom.png", 3, "option_boom")
        self.option_fruit_list.add(self.home_sandia)
        self.option_fruit_list.add(self.home_peach)
        self.option_fruit_list.add(self.home_boom)

        # 设置定时器
        self.clock = pygame.time.Clock()

        # 模式标记
        self.mode_flag = 0

        # 音效
        self.bgm = Bgm()

        # 刀光
        self.knife = Knife(self.window)

    def create_fruit(self):
        """ 创建水果 """
        if self.mode_flag == 1:
            boom_prob = random.randint(0, 10)
            if boom_prob == 8:
                self.bgm.play_throw()
                boom = ThrowFruit(self.window, "./images/boom.png", None, 5, 5)
                self.throw_fruit_list.add(boom)

        fruit_image_path = ["./images/sandia.png", "./images/peach.png",
                            "./images/banana.png", "./images/apple.png",
                            "./images/basaha.png"]
        fruit_number = random.randint(1, 4)
        for n in range(fruit_number):
            rand_fruit_index = random.randint(0, len(fruit_image_path) - 1)
            self.bgm.play_throw()
            fruit = ThrowFruit(self.window, fruit_image_path[rand_fruit_index], None, 5, rand_fruit_index)
            self.throw_fruit_list.add(fruit)

    def create_fruit_half(self, fruit_flag, fruit_x, fruit_y, turn_angel, v_angel):
        if fruit_flag == "option_sandia":
            """ 经典模式西瓜被切开 """
            fruit_left = HalfFruit(self.window, "./images/sandia-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel,
                                   -5)
            fruit_right = HalfFruit(self.window, "./images/sandia-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)
        if fruit_flag == "option_peach":
            """ 禅宗模式的梨被切开 """
            fruit_left = HalfFruit(self.window, "./images/peach-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel, -5)
            fruit_right = HalfFruit(self.window, "./images/peach-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)

        if fruit_flag == 0:
            """ 西瓜被切开 """
            fruit_left = HalfFruit(self.window, "./images/sandia-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel, -5)
            fruit_right = HalfFruit(self.window, "./images/sandia-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)
        if fruit_flag == 1:
            """ 梨被切开 """
            fruit_left = HalfFruit(self.window, "./images/peach-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel, -5)
            fruit_right = HalfFruit(self.window, "./images/peach-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)
        if fruit_flag == 2:
            """ 香蕉被切开 """
            fruit_left = HalfFruit(self.window, "./images/banana-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel, -5)
            fruit_right = HalfFruit(self.window, "./images/banana-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)
        if fruit_flag == 3:
            """ 苹果被切开 """
            fruit_left = HalfFruit(self.window, "./images/apple-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel, -5)
            fruit_right = HalfFruit(self.window, "./images/apple-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)
        if fruit_flag == 4:
            """ 草莓被切开 """
            fruit_left = HalfFruit(self.window, "./images/basaha-1.png", fruit_x - 50, fruit_y, turn_angel, v_angel, -5)
            fruit_right = HalfFruit(self.window, "./images/basaha-2.png", fruit_x + 50, fruit_y, -turn_angel, v_angel,
                                    5)
            self.fruit_half_list.add(fruit_left)
            self.fruit_half_list.add(fruit_right)

    def impact_check(self):
        """ 碰撞检测 """
        for item in self.option_fruit_list:
            """ 主页的模式选择 """
            mouse_pos = pygame.mouse.get_pos()
            if mouse_pos[0] > item.rect.left and mouse_pos[0] < item.rect.right \
                    and mouse_pos[1] > item.rect.top and mouse_pos[1] < item.rect.bottom:
                self.bgm.play_splatter()
                self.create_fruit_half(item.flag, item.rect.x, item.rect.y, item.turn_angel, item.v_angel)
                self.option_fruit_list.remove_internal(item)
                if item.flag == "option_sandia":
                    self.mode_flag = 1
                    return 1
                elif item.flag == "option_peach":
                    self.mode_flag = 2
                    return 2
                elif item.flag == "option_boom":
                    return 0

        for item in self.throw_fruit_list:
            """ 游戏开始后判断水果是否被切到 """
            mouse_pos = pygame.mouse.get_pos()
            if mouse_pos[0] > item.rect.left and mouse_pos[0] < item.rect.right \
                    and mouse_pos[1] > item.rect.top and mouse_pos[1] < item.rect.bottom:
                if item.flag == 0:
                    self.knife.show_sandia_flash(item.rect.x, item.rect.y)
                if item.flag == 1:
                    self.knife.show_peach_flash(item.rect.x, item.rect.y)
                if item.flag == 2:
                    self.knife.show_banana_flash(item.rect.x, item.rect.y)
                if item.flag == 3:
                    self.knife.show_apple_flash(item.rect.x, item.rect.y)
                if item.flag == 4:
                    self.knife.show_apple_flash(item.rect.x, item.rect.y)

                if self.mode_flag == 1:
                    self.classic_score += 2
                if self.mode_flag == 2:
                    self.zen_score += 2
                    print(self.zen_score)
                self.bgm.play_splatter()
                self.create_fruit_half(item.flag, item.rect.x, item.rect.y, item.turn_angel, item.v_angel)
                self.throw_fruit_list.remove_internal(item)
                if item.flag == 5:
                    return 3

    def check_key(self):
        """ 监听事件 """
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                exit()
            elif event.type == Manager.THROWFRUITTIME and self.mode_flag == 1:
                self.create_fruit()
            elif event.type == Manager.THROWFRUITTIME and self.mode_flag == 2:
                self.create_fruit()

    def classic_mode(self):
        """ 经典模式 """
        pygame.font.init()
        self.bgm.play_classic()
        score_image = Background(self.window, 10, 5, "./images/score.png")
        text = pygame.font.Font("./images/simhei.ttf", 20)  # 设置分数显示的字体
        x_times = pygame.sprite.Group()
        miss_times = pygame.sprite.Group()
        xxx = Background(self.window, Manager.WIDTH - 30, 5, "./images/xxx.png")
        xx = Background(self.window, Manager.WIDTH - 60, 5, "./images/xx.png")
        x = Background(self.window, Manager.WIDTH - 90, 5, "./images/x.png")
        x_times.add(xxx)
        x_times.add(xx)
        x_times.add(x)

        while True:
            # 设置游戏帧率
            self.clock.tick(60)
            pygame.display.update()
            self.check_key()
            self.background_list.sprites()[0].update()
            score_image.update()
            text_score = text.render("%d" % self.classic_score, 1, (0, 255, 0))
            self.window.blit(text_score, (50, 10))
            x_times.update()
            miss_times.update()
            temp_flag = self.impact_check()
            if temp_flag == 3:
                return
            self.throw_fruit_list.update()
            self.fruit_half_list.update()
            if Manager.classic_miss == 1:
                xf = Background(self.window, Manager.WIDTH - 90, 5, "./images/xf.png")
                miss_times.add(xf)
            elif Manager.classic_miss == 2:
                xf = Background(self.window, Manager.WIDTH - 90, 5, "./images/xf.png")
                miss_times.add(xf)
                xxf = Background(self.window, Manager.WIDTH - 60, 5, "./images/xxf.png")
                miss_times.add(xxf)
            elif Manager.classic_miss >= 3:
                self.bgm.play_over()
                Manager.classic_miss = 0
                return

    def zen_mode(self):
        """ 禅宗模式 """
        self.bgm.play_classic()

        # 记录分数
        record_time = 0
        while True:
            # 设置游戏帧率
            self.clock.tick(60)
            self.check_key()
            self.background_list.sprites()[0].update()
            self.impact_check()
            self.throw_fruit_list.update()
            self.fruit_half_list.update()
            pygame.display.update()

            if record_time == 3000:
                return
            record_time += 1

    def main(self):
        """ 主页 """
        self.bgm.play_menu()
        while True:
            # 设置游戏帧率
            self.clock.tick(60)
            self.background_list.update()
            self.circle_option.update()
            self.option_fruit_list.update()
            self.fruit_half_list.update()

            temp_flag = self.impact_check()
            pygame.display.update()
            if temp_flag == 1:
                self.classic_mode()
                self.__init__()
                self.bgm.play_over()
                self.bgm.play_menu()

            if temp_flag == 2:
                self.zen_mode()
                self.__init__()
                self.bgm.play_over()
                self.bgm.play_menu()

            elif temp_flag == 0:
                pygame.quit()
                exit()
            elif temp_flag == 3:
                self.__init__()
                self.bgm.play_over()
                self.bgm.play_menu()
            self.check_key()


if __name__ == '__main__':
    manager = Manager()
    manager.main()

总结

这个是全部的python代码,里面使用了python的math库,random库,还有pygame,就只用了这三个库,我们就能制作一个水果大战游戏是不是python还是很牛逼的。里面还有多代码,那么在这个里面的我也每一行代码都帮大家写好注释了,大家可以看注释也是能看明白的。

除了代码之外,当然还有我们很多的图片文件,还有配置资源。

Python制作经典游戏案例-水果忍者(附源码等文件)

Python制作经典游戏案例-水果忍者(附源码等文件)

Python制作经典游戏案例-水果忍者(附源码等文件)

Python制作经典游戏案例-水果忍者(附源码等文件)

里面包括有图片文件,有音乐文件,还有代码文件。有了这些文件,在加上我们前面的代码,水果大战游戏就制作完成啦。
想要资料文件的文末有我名片,直接找我拿即可。文章来源地址https://www.toymoban.com/news/detail-505684.html

↓ ↓ ↓ 加下方名片找我,直接拿源码还有案例 ↓ ↓ ↓

到了这里,关于Python制作经典游戏案例-水果忍者(附源码等文件)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • python游戏开发入门经典教程,python游戏开发引擎

    大家好,给大家分享一下python游戏开发入门经典教程,很多人还不知道这一点。下面详细解释一下。现在让我们来看看! 消消乐小游戏相信大家都玩过,大人小孩都喜欢玩的一款小游戏,那么基于程序是如何实现的呢?今天带大家,用python+pygame来实现一下这个花里胡哨的消

    2024年02月02日
    浏览(36)
  • 【计算机毕设经典案例】基于SpringBoot的使命召唤游戏助手小程序

    前言:我是IT源码社,从事计算机开发行业数年,专注Java领域,专业提供程序设计开发、源码分享、技术指导讲解、定制和毕业设计服务 👉IT源码社-SpringBoot优质案例推荐👈 👉IT源码社-小程序优质案例推荐👈 👉IT源码社-Python优质案例推荐👈 👇👇文末获取源码👇👇 项目

    2024年02月06日
    浏览(36)
  • Python经典游戏:贪吃蛇

    Python108款,小游戏集合,总有一个是你想要的 中国象棋 像素鸟 五子棋 24点小游戏 贪吃蛇 扫雷 俄罗斯方块 魂斗罗 消消乐 坦克大战 外星人入侵 汤姆猫 斗地主 乒乓球 推箱子 植物大战僵尸 围棋 超级玛丽 飞机大战 迷宫 滑雪 吃豆人…等等 (需要的回复666或点击最下方的历史

    2024年04月22日
    浏览(34)
  • Python经典游戏 唤醒你童年记忆

    👉游戏规则:使用方向键控制蛇去吃球。每吃一次球,蛇身就长出一格。吃到自己或者出界游戏结束。 游戏演示: 👉游戏规则:用箭头导航控制黄色吃豆人吃掉所有白色食物,若被红色的鬼魂抓住,游戏结束。 游戏演示: 👉游戏规则:点击屏幕发射炮弹。炮弹在它的路径

    2024年02月03日
    浏览(51)
  • 【pygame游戏开发】这几个经典游戏,小红书Python面试题目

    pygame.time.set_timer(change_hole_event, 800) mole = Mole(cfg.MOLE_IMAGEPATHS, hole_pos) hammer = Hammer(cfg.HAMMER_IMAGEPATHS, (500, 250)) clock = pygame.time.Clock() your_score = 0 flag = False init_time = pygame.time.get_ticks() while True: time_remain = round((61000 - (pygame.time.get_ticks() - init_time)) / 1000.) if time_remain == 40 and not flag: hole

    2024年04月25日
    浏览(31)
  • python游戏库pygame经典教程

    目录 一.Pygame程序基本搭建过程         1.初始化化程序         2.创建Surface对象         3.事件监听         4.游戏循环  二.Pygame Display显示模块详解         1.将Surface对象粘贴至主窗口上         2.设置窗口主窗口         3.填充主窗口背景,参数

    2024年02月03日
    浏览(38)
  • Python 实现经典游戏“贪吃蛇”:从零开始的趣味编程之旅

    在计算机科学和编程教育中,通过实现小游戏是学习和掌握一门编程语言的重要实践方式。今天,我们将一起探索如何使用Python来打造一款经典的、风靡全球的游戏——贪吃蛇。这个项目不仅涵盖了Python的基础语法、面向对象编程思想,还会涉及pygame库的使用以及游戏循环、

    2024年02月21日
    浏览(34)
  • python毕设分享 经典魔塔游戏设计与实现 (源码)

    🔥 Hi,各位同学好呀,这里是L学长! 🥇今天向大家分享一个今年(2022)最新完成的毕业设计项目作品 python小游戏毕设 经典魔塔游戏设计与实现 (源码) 🥇 学长根据实现的难度和等级对项目进行评分(最低0分,满分5分) 难度系数:3分 工作量:3分 创新点:4分 项目获取: htt

    2024年02月04日
    浏览(32)
  • Python经典游戏04:用tkinter给老板写一封拒绝不了的辞职信

    ★★★★★博文原创不易,我的博文不需要打赏,也不需要知识付费,可以白嫖学习编程小技巧。**如果使用代码的过程,有疑问的地方,欢迎大家指正留言交流。**喜欢的老铁可以多多帮忙点赞,小红牛在此表示感谢。★★★★★ 1.使用以下代码需要准备一个素材图片资源,

    2024年02月09日
    浏览(35)
  • Python版经典小游戏愤怒的小鸟源代码,基于pygame+pymunk

    Python版经典小游戏愤怒的小鸟源代码,基于pygame+pymunk 程序依赖:pygame 2.0.1, pymunk 5.5.0 直接运行main.py 完整代码下载地址:Python版经典小游戏愤怒的小鸟源代码 tool.py 完整代码下载地址:Python版经典小游戏愤怒的小鸟源代码

    2024年02月16日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包