猫史档案馆


耗时一天,做了个背景...

用户:PlumStevenPlumSteven查看:15 回复:4 评论:15 创建时间:2022-05-22T22:29:53


最近看到有人用Python做MC啊!

我也来试试

3D。。。不会,那就2D吧

(arcade好像更简单)

别人写的3D我放评论区里吧,720行呢!

给你们看下我实现的效果

找不到史蒂夫素材...

还实现了鼠标点击隐藏,按esc显示的功能呢!center_image

就是不给你们看代码:-)


回复

上一页1 页 / 共 1下一页
PlumStevenPlumSteven

我的代码:

from arcade import *
import random

SW = 1200
SH = 900
TT = "Minecraft 2D version 0.0.1"

class Voxels(arcade.Sprite):
    def __init__(self, image):
        super().__init__(image)

    def update(self):
        pass

class window(arcade.Window):
    def __init__(self, width, height, title):
        super().__init__(width, height, title)
        self.setup()
    
    def setup(self):
        set_background_color(color.SKY_BLUE)
        self.GRASS = Voxels(".\\resources\\Voxels\\simple_voxels\\grass.png")
        self.STONE = Voxels(".\\resources\\Voxels\\simple_voxels\\stone.png")
        self.DIRT = Voxels(".\\resources\\Voxels\\simple_voxels\\dirt.png")
        self.world = []
        self.mouseVisible = True

    def on_draw(self):
        start_render()
        self.setupWorld()
    
    def on_update(self, delte_time):
        self.set_mouse_visible(self.mouseVisible)

    def setupGrass(self, x, y):
        self.GRASS.center_x = x
        self.GRASS.center_y = y

    def setupStone(self, x, y):
        self.STONE.center_x = x
        self.STONE.center_y = y

    def setupDirt(self, x, y):
        self.DIRT.center_x = x
        self.DIRT.center_y = y

    # def setupWorldList(self):
    #     tmpLs = []
    #     for i in range(0, 30):
    #         for j in range(0, 10):
    #             if j <= 3:
    #                 tmpLs.append(0)
    #             elif j < 10:
    #                 if(random.randint(0, 1) == 0):
    #                     tmpLs.append(2)
    #                     break
    #                 else:
    #                     tmpLs.append(1)            
    #             else:
    #                 tmpLs.append(2)
    #         self.world.append(tmpLs)

    def setupWorld(self):
        # self.setupWorldList()
        for i in range(0, 35):
            for j in range(0, 10):
                if(j < 5):
                    self.setupStone(19 + i * 38, 19 + j * 38)
                    self.STONE.draw()
                elif(j < 9):
                    self.setupDirt(19 + i * 38, 19 + j * 38)
                    self.DIRT.draw()
                else:
                    self.setupGrass(19 + i * 38, 19 + j * 38)
                    self.GRASS.draw()

    def on_mouse_press(self, x, y, button, modifier):
        if(button == arcade.MOUSE_BUTTON_LEFT):
            self.mouseVisible = False

    def on_key_press(self, symbol, modifier):
        if(symbol == key.ESCAPE):
            self.mouseVisible = True


if __name__ == "__main__":
    win = window(SW, SH, TT)
    run()

 

点赞0


评论


PlumStevenPlumSteven

3D下载链接:https:/喵fogleman/Minecraft

点赞0


评论


༺追梦の人༻༺追梦の人༻

mc3d我有,你要吗

点赞0


评论


༺追梦の人༻༺追梦の人༻

center_image

点赞0


评论