如果说,你们现在玩的minecraft已经1.19了(今年6月8日公布)。更新的有很多,有循声守卫、有青蛙、有红树林等等......

可是远古版的你们玩过吗?你们可能会说,远古版的有啥好玩的?比现在的差了100000倍还不止!

哎?话题偏了!咳咳!我们今天还是要带来远古版的minecraft!

之前不是有过一次了吗?

这次我们要做一个远古版的!

你们肯定会说:这次的讲解一定很无聊,都已经写过一次了,再写一次有什么用?

这次,我要讲解了!

如果你们只想要代码,可以到最后去复制粘贴。


目录

一、程序准备

二、编写内容

2.1.方块导入

2.2.中间部分

2.3.最后编写

三、图片

四、提示讲解

五、总结


一、程序准备

和之前一样,导入模块

from __future__ import divisionimport sys
import math
import random
import timefrom collections import deque
from pyglet import image
from pyglet.gl import *
from pyglet.graphics import TextureGroup
from pyglet.window import key, mouse# 每秒帧数
TICKS_PER_SEC = 120# 你可以走的大小
SECTOR_SIZE =20000# 行走速度与飞行速度
WALKING_SPEED = 5.5
FLYING_SPEED = 15# 重力与跳跃高度
GRAVITY = 20
MAX_JUMP_HEIGHT =1# About the height of a block.
# To derive the formula for calculating jump speed, first solve
#    v_t = v_0 + a * t
# for the time at which you achieve maximum height, where a is the acceleration
# due to gravity and v_t = 0. This gives:
#    t = - v_0 / a
# Use t and the desired MAX_JUMP_HEIGHT to solve for v_0 (jump speed) in
#    s = s_0 + v_0 * t + (a * t^2) / 2
JUMP_SPEED = math.sqrt(2 * GRAVITY * MAX_JUMP_HEIGHT)
TERMINAL_VELOCITY = 50PLAYER_HEIGHT = 2

都和之前差不多,是吗?

二、编写内容

2.1.方块导入

文件我会放在最后。

想要导入图片,先要找到顶部,底部,左边,右边......

总之,想要得到方块还是有点难度的。首先要有图片,还要有算法......

if sys.version_info[0] >= 3:xrange = rangedef cube_vertices(x, y, z, n):""" Return the vertices of the cube at position x, y, z with size 2*n."""return [x-n,y+n,z-n, x-n,y+n,z+n, x+n,y+n,z+n, x+n,y+n,z-n,  # topx-n,y-n,z-n, x+n,y-n,z-n, x+n,y-n,z+n, x-n,y-n,z+n,  # bottomx-n,y-n,z-n, x-n,y-n,z+n, x-n,y+n,z+n, x-n,y+n,z-n,  # leftx+n,y-n,z+n, x+n,y-n,z-n, x+n,y+n,z-n, x+n,y+n,z+n,  # rightx-n,y-n,z+n, x+n,y-n,z+n, x+n,y+n,z+n, x-n,y+n,z+n,  # frontx+n,y-n,z-n, x-n,y-n,z-n, x-n,y+n,z-n, x+n,y+n,z-n,  # back]def tex_coord(x, y, n=4):""" Return the bounding vertices of the texture square."""m = 1.0 / ndx = x * mdy = y * mreturn dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + mdef tex_coords(top, bottom, side):""" Return a list of the texture squares for the top, bottom and side."""top = tex_coord(*top)bottom = tex_coord(*bottom)side = tex_coord(*side)result = []result.extend(top)result.extend(bottom)result.extend(side * 4)return resultTEXTURE_PATH = 'texture1_1.png'GRASS = tex_coords((1, 0), (0, 1), (0, 0))
SAND = tex_coords((1, 1), (1, 1), (1, 1))
BRICK = tex_coords((2, 0), (2, 0), (2, 0))
STONE = tex_coords((2, 1), (2, 1), (2, 1))
PURPLE = tex_coords((3, 1), (3, 1), (3, 1))
RED = tex_coords((3, 0), (3, 0), (3, 0))
GREEN = tex_coords((3, 2), (3, 2), (3, 2))
BLUE = tex_coords((1, 2), (1, 2), (1, 2))
BLACK = tex_coords((2, 2), (2, 2), (2, 2))
ORANGE = tex_coords((3, 2), (3, 2), (3, 2))FACES = [( 0, 1, 0),( 0,-1, 0),(-1, 0, 0),( 1, 0, 0),( 0, 0, 1),( 0, 0,-1),
]

2.2.中间部分

这次里面就不一样了。首先是地形问题:

地形的原因导致了代码的变化。

我们要更改一下生成系统,我们为了更加接近远古版,所以就做小山。

还有边界,边界可就有问题了。远古版的边界是一堵墙,而不是空的。

这就是远古版要改的地方。

改动列表:

代码改动
地形变化 改动方式 
山地 函数生成
边界 函数生成
def normalize(position):""" Accepts `position` of arbitrary precision and returns the blockcontaining that position.Parameters----------position : tuple of len 3Returns-------block_position : tuple of ints of len 3"""x, y, z = positionx, y, z = (int(round(x)), int(round(y)), int(round(z)))return (x, y, z)def sectorize(position):""" Returns a tuple representing the sector for the given `position`.Parameters----------position : tuple of len 3Returns-------sector : tuple of len 3"""x, y, z = normalize(position)x, y, z = x // SECTOR_SIZE, y // SECTOR_SIZE, z // SECTOR_SIZEreturn (x, 0, z)class Model(object):def __init__(self):# A Batch is a collection of vertex lists for batched rendering.self.batch = pyglet.graphics.Batch()# A TextureGroup manages an OpenGL texture.self.group = TextureGroup(image.load(TEXTURE_PATH).get_texture())# A mapping from position to the texture of the block at that position.# This defines all the blocks that are currently in the world.self.world = {}# Same mapping as `world` but only contains blocks that are shown.self.shown = {}# Mapping from position to a pyglet `VertextList` for all shown blocks.self._shown = {}# Mapping from sector to a list of positions inside that sector.self.sectors = {}# Simple function queue implementation. The queue is populated with# _show_block() and _hide_block() callsself.queue = deque()self._initialize()def _initialize(self):""" Initialize the world by placing all the blocks."""n = 200 # 1/2 width and height of worlds = 1  # step sizey =0   # initial y heightfor x in xrange(-n, n + 1, s):for z in xrange(-n, n + 1, s):# create a layer stone an grass everywhere.self.add_block((x, y - 2, z), GRASS, immediate=False)self.add_block((x, y - 3, z), STONE, immediate=False)if x in (-n, n) or z in (-n, n):# create outer walls.for dy in xrange(-2, 3):self.add_block((x, y + dy, z), STONE, immediate=False)# generate the hills randomlyo = n -15for _ in xrange(120):a = random.randint(-o, o)  # x position of the hillb = random.randint(-o, o)  # z position of the hillc = -1  # base of the hillh = random.randint(2,6) # height of the hills = random.randint(4,12)  # 2 * s is the side length of the hilld = 1  # how quickly to taper off the hillst = random.choice([GRASS, SAND,STONE])for y in xrange(c, c + h):for x in xrange(a - s, a + s + 1):for z in xrange(b - s, b + s + 1):if (x - a) ** 2 + (z - b) ** 2 > (s + 1) ** 2:continueif (x - 0) ** 2 + (z - 0) ** 2 < 5 ** 2:continueself.add_block((x, y, z), t, immediate=False)s -= d  # decrement side lenth so hills taper offdef hit_test(self, position, vector, max_distance=8):""" Line of sight search from current position. If a block isintersected it is returned, along with the block previously in the lineof sight. If no block is found, return None, None.Parameters----------position : tuple of len 3The (x, y, z) position to check visibility from.vector : tuple of len 3The line of sight vector.max_distance : intHow many blocks away to search for a hit."""m = 8x, y, z = positiondx, dy, dz = vectorprevious = Nonefor _ in xrange(max_distance * m):key = normalize((x, y, z))if key != previous and key in self.world:return key, previousprevious = keyx, y, z = x + dx / m, y + dy / m, z + dz / mreturn None, Nonedef exposed(self, position):""" Returns False is given `position` is surrounded on all 6 sides byblocks, True otherwise."""x, y, z = positionfor dx, dy, dz in FACES:if (x + dx, y + dy, z + dz) not in self.world:return Truereturn Falsedef add_block(self, position, texture, immediate=True):""" Add a block with the given `texture` and `position` to the world.Parameters----------position : tuple of len 3The (x, y, z) position of the block to add.texture : list of len 3The coordinates of the texture squares. Use `tex_coords()` togenerate.immediate : boolWhether or not to draw the block immediately."""if position in self.world:self.remove_block(position, immediate)self.world[position] = textureself.sectors.setdefault(sectorize(position), []).append(position)if immediate:if self.exposed(position):self.show_block(position)self.check_neighbors(position)def remove_block(self, position, immediate=True):""" Remove the block at the given `position`.Parameters----------position : tuple of len 3The (x, y, z) position of the block to remove.immediate : boolWhether or not to immediately remove block from canvas."""del self.world[position]self.sectors[sectorize(position)].remove(position)if immediate:if position in self.shown:self.hide_block(position)self.check_neighbors(position)def check_neighbors(self, position):""" Check all blocks surrounding `position` and ensure their visualstate is current. This means hiding blocks that are not exposed andensuring that all exposed blocks are shown. Usually used after a blockis added or removed."""x, y, z = positionfor dx, dy, dz in FACES:key = (x + dx, y + dy, z + dz)if key not in self.world:continueif self.exposed(key):if key not in self.shown:self.show_block(key)else:if key in self.shown:self.hide_block(key)def show_block(self, position, immediate=True):""" Show the block at the given `position`. This method assumes theblock has already been added with add_block()Parameters----------position : tuple of len 3The (x, y, z) position of the block to show.immediate : boolWhether or not to show the block immediately."""texture = self.world[position]self.shown[position] = textureif immediate:self._show_block(position, texture)else:self._enqueue(self._show_block, position, texture)def _show_block(self, position, texture):""" Private implementation of the `show_block()` method.Parameters----------position : tuple of len 3The (x, y, z) position of the block to show.texture : list of len 3The coordinates of the texture squares. Use `tex_coords()` togenerate."""x, y, z = positionvertex_data = cube_vertices(x, y, z, 0.5)texture_data = list(texture)# create vertex list# FIXME Maybe `add_indexed()` should be used insteadself._shown[position] = self.batch.add(24, GL_QUADS, self.group,('v3f/static', vertex_data),('t2f/static', texture_data))def hide_block(self, position, immediate=True):""" Hide the block at the given `position`. Hiding does not remove theblock from the world.Parameters----------position : tuple of len 3The (x, y, z) position of the block to hide.immediate : boolWhether or not to immediately remove the block from the canvas."""self.shown.pop(position)if immediate:self._hide_block(position)else:self._enqueue(self._hide_block, position)def _hide_block(self, position):""" Private implementation of the 'hide_block()` method."""self._shown.pop(position).delete()def show_sector(self, sector):""" Ensure all blocks in the given sector that should be shown aredrawn to the canvas."""for position in self.sectors.get(sector, []):if position not in self.shown and self.exposed(position):self.show_block(position, False)def hide_sector(self, sector):""" Ensure all blocks in the given sector that should be hidden areremoved from the canvas."""for position in self.sectors.get(sector, []):if position in self.shown:self.hide_block(position, False)def change_sectors(self, before, after):""" Move from sector `before` to sector `after`. A sector is acontiguous x, y sub-region of world. Sectors are used to speed upworld rendering."""before_set = set()after_set = set()pad = 4for dx in xrange(-pad, pad + 1):for dy in [0]:  # xrange(-pad, pad + 1):for dz in xrange(-pad, pad + 1):if dx ** 2 + dy ** 2 + dz ** 2 > (pad + 1) ** 2:continueif before:x, y, z = beforebefore_set.add((x + dx, y + dy, z + dz))if after:x, y, z = afterafter_set.add((x + dx, y + dy, z + dz))show = after_set - before_sethide = before_set - after_setfor sector in show:self.show_sector(sector)for sector in hide:self.hide_sector(sector)def _enqueue(self, func, *args):""" Add `func` to the internal queue."""self.queue.append((func, args))def _dequeue(self):""" Pop the top function from the internal queue and call it."""func, args = self.queue.popleft()func(*args)def process_queue(self):""" Process the entire queue while taking periodic breaks. This allowsthe game loop to run smoothly. The queue contains calls to_show_block() and _hide_block() so this method should be called ifadd_block() or remove_block() was called with immediate=False"""start = time.timewhile self.queue and time.time < 1 / TICKS_PER_SEC:self._dequeue()def process_entire_queue(self):""" Process the entire queue with no breaks."""while self.queue:self._dequeue()class Window(pyglet.window.Window):def __init__(self, *args, **kwargs):super(Window, self).__init__(*args, **kwargs)# Whether or not the window exclusively captures the mouse.self.exclusive = False# When flying gravity has no effect and speed is increased.self.flying = False# Strafing is moving lateral to the direction you are facing,# e.g. moving to the left or right while continuing to face forward.## First element is -1 when moving forward, 1 when moving back, and 0# otherwise. The second element is -1 when moving left, 1 when moving# right, and 0 otherwise.self.strafe = [0, 0]# Current (x, y, z) position in the world, specified with floats. Note# that, perhaps unlike in math class, the y-axis is the vertical axis.self.position = (0, 0, 0)# First element is rotation of the player in the x-z plane (ground# plane) measured from the z-axis down. The second is the rotation# angle from the ground plane up. Rotation is in degrees.## The vertical plane rotation ranges from -90 (looking straight down) to# 90 (looking straight up). The horizontal rotation range is unbounded.self.rotation = (0, 0)# Which sector the player is currently in.self.sector = None# The crosshairs at the center of the screen.self.reticle = None# Velocity in the y (upward) direction.self.dy = 0# A list of blocks the player can place. Hit num keys to cycle.self.inventory = [BRICK, GRASS, SAND,STONE,RED,PURPLE,GREEN,BLUE,BLACK,ORANGE]# The current block the user can place. Hit num keys to cycle.self.block = self.inventory[0]# Convenience list of num keys.self.num_keys = [key._1, key._2, key._3, key._4, key._5,key._6, key._7, key._8, key._9, key._0,key.E,key.R]# Instance of the model that handles the world.self.model = Model()# The label that is displayed in the top left of the canvas.self.label = pyglet.text.Label('', font_name='Arial', font_size=18,x=10, y=self.height - 10, anchor_x='left', anchor_y='top',color=(0, 0, 0, 255))# This call schedules the `update()` method to be called# TICKS_PER_SEC. This is the main game event loop.pyglet.clock.schedule_interval(self.update, 1.0 / TICKS_PER_SEC)def set_exclusive_mouse(self, exclusive):""" If `exclusive` is True, the game will capture the mouse, if Falsethe game will ignore the mouse."""super(Window, self).set_exclusive_mouse(exclusive)self.exclusive = exclusivedef get_sight_vector(self):""" Returns the current line of sight vector indicating the directionthe player is looking."""x, y = self.rotation# y ranges from -90 to 90, or -pi/2 to pi/2, so m ranges from 0 to 1 and# is 1 when looking ahead parallel to the ground and 0 when looking# straight up or down.m = math.cos(math.radians(y))# dy ranges from -1 to 1 and is -1 when looking straight down and 1 when# looking straight up.dy = math.sin(math.radians(y))dx = math.cos(math.radians(x - 90)) * mdz = math.sin(math.radians(x - 90)) * mreturn (dx, dy, dz)def get_motion_vector(self):""" Returns the current motion vector indicating the velocity of theplayer.Returns-------vector : tuple of len 3Tuple containing the velocity in x, y, and z respectively."""if any(self.strafe):x, y = self.rotationstrafe = math.degrees(math.atan2(*self.strafe))y_angle = math.radians(y)x_angle = math.radians(x + strafe)if self.flying:m = math.cos(y_angle)dy = math.sin(y_angle)if self.strafe[1]:# Moving left or right.dy = 0.0m = 1if self.strafe[0] > 0:# Moving backwards.dy *= -1# When you are flying up or down, you have less left and right# motion.dx = math.cos(x_angle) * mdz = math.sin(x_angle) * melse:dy = 0.0dx = math.cos(x_angle)dz = math.sin(x_angle)else:dy = 0.0dx = 0.0dz = 0.0return (dx, dy, dz)def update(self, dt):""" This method is scheduled to be called repeatedly by the pygletclock.Parameters----------dt : floatThe change in time since the last call."""self.model.process_queue()sector = sectorize(self.position)if sector != self.sector:self.model.change_sectors(self.sector, sector)if self.sector is None:self.model.process_entire_queue()self.sector = sectorm = 8dt = min(dt, 0.2)for _ in xrange(m):self._update(dt / m)def _update(self, dt):""" Private implementation of the `update()` method. This is where mostof the motion logic lives, along with gravity and collision detection.Parameters----------dt : floatThe change in time since the last call."""# walkingspeed = FLYING_SPEED if self.flying else WALKING_SPEEDd = dt * speed # distance covered this tick.dx, dy, dz = self.get_motion_vector()# New position in space, before accounting for gravity.dx, dy, dz = dx * d, dy * d, dz * d# gravityif not self.flying:# Update your vertical speed: if you are falling, speed up until you# hit terminal velocity; if you are jumping, slow down until you# start falling.self.dy -= dt * GRAVITYself.dy = max(self.dy, -TERMINAL_VELOCITY)dy += self.dy * dt# collisionsx, y, z = self.positionx, y, z = self.collide((x + dx, y + dy, z + dz), PLAYER_HEIGHT)self.position = (x, y, z)def collide(self, position, height):""" Checks to see if the player at the given `position` and `height`is colliding with any blocks in the world.Parameters----------position : tuple of len 3The (x, y, z) position to check for collisions at.height : int or floatThe height of the player.Returns-------position : tuple of len 3The new position of the player taking into account collisions."""# How much overlap with a dimension of a surrounding block you need to# have to count as a collision. If 0, touching terrain at all counts as# a collision. If .49, you sink into the ground, as if walking through# tall grass. If >= .5, you'll fall through the ground.pad = 0p = list(position)np = normalize(position)for face in FACES:  # check all surrounding blocksfor i in xrange(3):  # check each dimension independentlyif not face[i]:continue# How much overlap you have with this dimension.d = (p[i] - np[i]) * face[i]if d < pad:continuefor dy in xrange(height):  # check each heightop = list(np)op[1] -= dyop[i] += face[i]if tuple(op) not in self.model.world:continuep[i] -= (d - pad) * face[i]if face == (0, -1, 0) or face == (0, 1, 0):# You are colliding with the ground or ceiling, so stop# falling / rising.self.dy = 0breakreturn tuple(p)def on_mouse_press(self, x, y, button, modifiers):""" Called when a mouse button is pressed. See pyglet docs for buttonamd modifier mappings.Parameters----------x, y : intThe coordinates of the mouse click. Always center of the screen ifthe mouse is captured.button : intNumber representing mouse button that was clicked. 1 = left button,4 = right button.modifiers : intNumber representing any modifying keys that were pressed when themouse button was clicked."""if self.exclusive:vector = self.get_sight_vector()block, previous = self.model.hit_test(self.position, vector)if (button == mouse.RIGHT) or \((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):# ON OSX, control + left click = right click.if previous:self.model.add_block(previous, self.block)elif button == pyglet.window.mouse.LEFT and block:texture = self.model.world[block]self.model.remove_block(block)else:self.set_exclusive_mouse(True)def on_mouse_motion(self, x, y, dx, dy):""" Called when the player moves the mouse.Parameters----------x, y : intThe coordinates of the mouse click. Always center of the screen ifthe mouse is captured.dx, dy : floatThe movement of the mouse."""if self.exclusive:m = 0.15x, y = self.rotationx, y = x + dx * m, y + dy * my = max(-90, min(90, y))self.rotation = (x, y)def on_key_press(self, symbol, modifiers):""" Called when the player presses a key. See pyglet docs for keymappings.Parameters----------symbol : intNumber representing the key that was pressed.modifiers : intNumber representing any modifying keys that were pressed."""if symbol == key.W:self.strafe[0] -= 1elif symbol == key.S:self.strafe[0] += 1elif symbol == key.A:self.strafe[1] -= 1elif symbol == key.D:self.strafe[1] += 1elif symbol == key.SPACE:if self.dy == 0:self.dy = JUMP_SPEEDelif symbol == key.ESCAPE:self.set_exclusive_mouse(False)elif symbol == key.TAB:self.flying = not self.flyingelif symbol in self.num_keys:index = (symbol - self.num_keys[0]) % len(self.inventory)self.block = self.inventory[index]def on_key_release(self, symbol, modifiers):""" Called when the player releases a key. See pyglet docs for keymappings.Parameters----------symbol : intNumber representing the key that was pressed.modifiers : intNumber representing any modifying keys that were pressed."""if symbol == key.W:self.strafe[0] += 1elif symbol == key.S:self.strafe[0] -= 1elif symbol == key.A:self.strafe[1] += 1elif symbol == key.D:self.strafe[1] -= 1def on_resize(self, width, height):""" Called when the window is resized to a new `width` and `height`."""# labelself.label.y = height - 10# reticleif self.reticle:self.reticle.delete()x, y = self.width // 2, self.height // 2n = 10self.reticle = pyglet.graphics.vertex_list(4,('v2i', (x - n, y, x + n, y, x, y - n, x, y + n)))def set_2d(self):""" Configure OpenGL to draw in 2d."""width, height = self.get_size()glDisable(GL_DEPTH_TEST)viewport = self.get_viewport_size()glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1]))glMatrixMode(GL_PROJECTION)glLoadIdentity()glOrtho(0, max(1, width), 0, max(1, height), -1, 1)glMatrixMode(GL_MODELVIEW)glLoadIdentity()def set_3d(self):""" Configure OpenGL to draw in 3d."""width, height = self.get_size()glEnable(GL_DEPTH_TEST)viewport = self.get_viewport_size()glViewport(0, 0, max(1, viewport[0]), max(1, viewport[1]))glMatrixMode(GL_PROJECTION)glLoadIdentity()gluPerspective(65.0, width / float(height), 0.1, 60.0)glMatrixMode(GL_MODELVIEW)glLoadIdentity()x, y = self.rotationglRotatef(x, 0, 1, 0)glRotatef(-y, math.cos(math.radians(x)), 0, math.sin(math.radians(x)))x, y, z = self.positionglTranslatef(-x, -y, -z)def on_draw(self):""" Called by pyglet to draw the canvas."""self.clear()self.set_3d()glColor3d(1, 1, 1)self.model.batch.draw()self.draw_focused_block()self.set_2d()self.draw_label()self.draw_reticle()def draw_focused_block(self):""" Draw black edges around the block that is currently under thecrosshairs."""vector = self.get_sight_vector()block = self.model.hit_test(self.position, vector)[0]if block:x, y, z = blockvertex_data = cube_vertices(x, y, z, 0.51)glColor3d(0, 0, 0)glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)pyglet.graphics.draw(24, GL_QUADS, ('v3f/static', vertex_data))glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)def draw_label(self):""" Draw the label in the top left of the screen."""x, y, z = self.positionself.label.text = '%02d (%.2f, %.2f, %.2f) %d / %d' % (pyglet.clock.get_fps(), x, y, z,len(self.model._shown), len(self.model.world))self.label.draw()def draw_reticle(self):""" Draw the crosshairs in the center of the screen."""glColor3d(0, 0, 0)self.reticle.draw(GL_LINES)

2.3.最后编写

为了更加像原版,我这里加了一个工作台的ico文件做图标。

还有雾气,视角关系。这些涉及到一些很难的知识,所以我不讲解。

def setup_fog():""" Configure the OpenGL fog properties."""# Enable fog. Fog "blends a fog color with each rasterized pixel fragment's# post-texturing color."glEnable(GL_FOG)# Set the fog color.glFogfv(GL_FOG_COLOR, (GLfloat * 4)(0.5, 0.69, 1.0, 0))# Say we have no preference between rendering speed and quality.glHint(GL_FOG_HINT, GL_DONT_CARE)# Specify the equation used to compute the blending factor.glFogi(GL_FOG_MODE, GL_LINEAR)# How close and far away fog starts and ends. The closer the start and end,# the denser the fog in the fog range.glFogf(GL_FOG_START, 20.0)glFogf(GL_FOG_END, 60.0)def setup():""" Basic OpenGL configuration."""# Set the color of "clear", i.e. the sky, in rgba.glClearColor(0.5, 0.69, 1.0, 1)# Enable culling (not rendering) of back-facing facets -- facets that aren't# visible to you.glEnable(GL_CULL_FACE)# Set the texture minification/magnification function to GL_NEAREST (nearest# in Manhattan distance) to the specified texture coordinates. GL_NEAREST# "is generally faster than GL_LINEAR, but it can produce textured images# with sharper edges because the transition between texture elements is not# as smooth."glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)setup_fog()def main():window = Window(width=800, height=450, caption='Minecraft 1.1', resizable=True)# Hide the mouse cursor and prevent the mouse from leaving the window.window.set_exclusive_mouse(True)# image for iconimg = image = pyglet.resource.image("Minecraft.ico")# setting image as iconwindow.set_icon(img)setup()pyglet.app.run()if __name__ == '__main__':print("Welcome play python Minecraft 1.1")main()

还好,不比之前的难。难的是2.1版本!所以我再发一次文章,仔细讲解远古版。

三、图片

texture1_1

Minecraft.ico

对不起,这里暂时无法放入ico文件。

如果有机会的话,我可以上传一般文件。

希望大家可以谅解

四、提示讲解

w,a,s,d进行移动

左键破坏方块

右键建造方块

tab起飞,降落

启动要花一点时间,不要急。

输入法换成英文,中文的话会一直往后走(doge~)

五、总结

python做出来的东西真的好!大家可以学习学习。

我本来想做一个超级玛丽,可是我只做了一点。

如果谁有超级玛丽的,可以私信给我代码。希望大家真的可以帮帮我,我会多发文章,多多给大家展示代码。如果你不喜欢我的话,也可以给我差评。但是你不可以骂我,说我。你可以私信我,给我建议,毕竟,我只是一个四年级的小学生,并不是写论文,有工作的大人。

大家一起加油吧!

python-pyglet游戏之minecraft远古版相关推荐

  1. python编程小游戏代码-Python小游戏之300行代码实现俄罗斯方块

    前言 本文代码基于 python3.6 和 pygame1.9.4. 俄罗斯方块是儿时最经典的游戏之一,刚开始接触 pygame 的时候就想写一个俄罗斯方块.但是想到旋转,停靠,消除等操作,感觉好像很 ...

  2. python小游戏源码-Python小游戏之300行代码实现俄罗斯方块

    Python小游戏之300行代码实现俄罗斯方块 来源:中文源码网 浏览: 次 日期:2019年11月5日 [下载文档: Python小游戏之300行代码实现俄罗斯方块.txt ] (友情提示:右键点上 ...

  3. python小游戏之二

    20行python代码的入门级小游戏 20行python代码的入门级小游戏_linmo8256的博客-CSDN博客_py游戏代码 猜数字小游戏python实现(可用来撩妹撩汉) 猜数字小游戏pytho ...

  4. 我的世界python写游戏_用python写游戏之 Give it up

    <永不言弃 Give It Up>,这是一款极具虐心色彩的音乐题材闯关游戏. 这篇文章就来分析这款游戏原理,并用python写出来一个简易版.废话不多说,直接开始分析. 游戏元素,暂且把主 ...

  5. pygame做的著名游戏_用python写游戏之2D跑酷游戏(一)

    2D的跑酷游戏有很多,著名的例如Chrome的彩蛋小游戏,手机上的天天酷跑等. 打开Chrome浏览器输入 chrome://dino/,按空格激活彩蛋 这篇文章来分析一下这类横版跑酷游戏的主角奔跑, ...

  6. python小游戏代码大全-Python小游戏之300行代码实现俄罗斯方块

    前言 本文代码基于 python3.6 和 pygame1.9.4. 俄罗斯方块是儿时最经典的游戏之一,刚开始接触 pygame 的时候就想写一个俄罗斯方块.但是想到旋转,停靠,消除等操作,感觉好像很 ...

  7. python游戏彩蛋_用python写游戏之2D跑酷游戏(一)

    2D的跑酷游戏有很多,著名的例如Chrome的彩蛋小游戏,手机上的天天酷跑等.打开Chrome浏览器输入 chrome://dino/,按空格激活彩蛋 这篇文章来分析一下这类横版跑酷游戏的主角奔跑,跳 ...

  8. 用python写跑酷游戏脚本_用python写游戏之2D跑酷游戏(二)

    这篇文章介绍2D跑酷游戏中,添加地板资源, 给主角附加重力作用,以及添加游戏控制器和游戏场景的切换. 废话不多说,直接开始. 添加地板资源 定义地板类,继承自pygame.sprite.Sprite ...

  9. Python小游戏之“读心术”

    读心术:猜数字游戏 〉 一款经典的猜数字AI:用户先随机在 0-1000之间随意写一个数字,AI开 始猜,如果猜的数大了,用户就说大 了,反之,则说小了. 算法:二分查找 〉 从中间的数开始,如果猜中 ...

最新文章

  1. 跨年之际,中文版畅销书《TensorFlow深度学习实战大全》分享,直接送!
  2. 充分利用移动支付系统的10种方法
  3. Sqlmap爆库命令的简单使用
  4. 库卡机器人CELL程序解析
  5. orm和mysql_orm与mysql
  6. 相邻省份最多的省区_拉萨万达广场开业 实现中国大陆省份全覆盖
  7. kafka中处理超大消息的一些考虑
  8. Android 退出app,后台推送的服务也停止了,怎么可以做到不停止后台服务呢?
  9. 一键破解宝塔面板的专业版本权限
  10. win7如何设置通电自动开机_WIN7自动开机怎么设置?
  11. C语言自学之路二(C语言数据类型)
  12. 强制删除“无法删除文件/文件夹”方法全集合
  13. Poi Excel 设置列宽计算公式
  14. 成都理工大学计算机组成原理考试,计算机组成原理试题.doc
  15. 在Linux中传输文件/目录的scp命令
  16. Charles 2 - breakpoint断点、compose编辑、rewrite重写、map映射重定向、repeat重发、throttling弱网测试
  17. 使用Keras构建深度图像搜索引擎
  18. 【博客566】Linux内核系统日志查看方式汇总
  19. 用C语言代码实现布雷森汉姆直线插补
  20. 使用sil9233a芯片控制海思hi3531d的hdmi输入

热门文章

  1. 包装实训总结报告_包装设计专业实习报告总结和格式范文
  2. 菜鸟程序员与资深程序员的区别
  3. linux命令stat和top,用top,du,df,ls,free,tree,stat命令更人性化显示数据
  4. Python设置画布大小_Python绘图库Turtle详细分析
  5. 音频驱动篇之pop音攻略
  6. 【openjudge】魔兽世界(终极版)
  7. 干货丨好用到哭的网站
  8. NFV、DPDK以及部分用户态协议研究
  9. java封装264成flv,FLV视频封装格式详细解析
  10. 搭建velocity开发环境