成人性生交大片免费看视频r_亚洲综合极品香蕉久久网_在线视频免费观看一区_亚洲精品亚洲人成人网在线播放_国产精品毛片av_久久久久国产精品www_亚洲国产一区二区三区在线播_日韩一区二区三区四区区区_亚洲精品国产无套在线观_国产免费www

主頁 > 知識庫 > Python實現我的世界小游戲源代碼

Python實現我的世界小游戲源代碼

熱門標簽:地圖地圖標注有嘆號 正安縣地圖標注app 電銷機器人系統(tǒng)廠家鄭州 舉辦過冬奧會的城市地圖標注 qt百度地圖標注 螳螂科技外呼系統(tǒng)怎么用 400電話申請資格 遼寧智能外呼系統(tǒng)需要多少錢 阿里電話機器人對話

我的世界小游戲使用方法:

移動

前進:W,后退:S,向左:A,向右:D,環(huán)顧四周:鼠標,跳起:空格鍵,切換飛行模式:Tab;

選擇建筑材料

磚:1,草:2,沙子:3,刪除建筑:鼠標左鍵單擊,創(chuàng)建建筑塊:鼠標右鍵單擊

ESC退出程序。

完整程序包請通過文末地址下載,程序運行截圖如下:

from __future__ import division

import sys
import math
import random
import time

from 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 = 60

# Size of sectors used to ease block loading.
SECTOR_SIZE = 16

WALKING_SPEED = 5
FLYING_SPEED = 15

GRAVITY = 20.0
MAX_JUMP_HEIGHT = 1.0 # 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 = 50

PLAYER_HEIGHT = 2

if sys.version_info[0] >= 3:
  xrange = range

def 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, # top
    x-n,y-n,z-n, x+n,y-n,z-n, x+n,y-n,z+n, x-n,y-n,z+n, # bottom
    x-n,y-n,z-n, x-n,y-n,z+n, x-n,y+n,z+n, x-n,y+n,z-n, # left
    x+n,y-n,z+n, x+n,y-n,z-n, x+n,y+n,z-n, x+n,y+n,z+n, # right
    x-n,y-n,z+n, x+n,y-n,z+n, x+n,y+n,z+n, x-n,y+n,z+n, # front
    x+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 / n
  dx = x * m
  dy = y * m
  return dx, dy, dx + m, dy, dx + m, dy + m, dx, dy + m


def 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 result


TEXTURE_PATH = 'texture.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))

FACES = [
  ( 0, 1, 0),
  ( 0,-1, 0),
  (-1, 0, 0),
  ( 1, 0, 0),
  ( 0, 0, 1),
  ( 0, 0,-1),
]


def normalize(position):
  """ Accepts `position` of arbitrary precision and returns the block
  containing that position.

  Parameters
  ----------
  position : tuple of len 3

  Returns
  -------
  block_position : tuple of ints of len 3

  """
  x, y, z = position
  x, 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 3

  Returns
  -------
  sector : tuple of len 3

  """
  x, y, z = normalize(position)
  x, y, z = x // SECTOR_SIZE, y // SECTOR_SIZE, z // SECTOR_SIZE
  return (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() calls
    self.queue = deque()

    self._initialize()

  def _initialize(self):
    """ Initialize the world by placing all the blocks.

    """
    n = 80 # 1/2 width and height of world
    s = 1 # step size
    y = 0 # initial y height
    for 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 randomly
    o = n - 10
    for _ in xrange(120):
      a = random.randint(-o, o) # x position of the hill
      b = random.randint(-o, o) # z position of the hill
      c = -1 # base of the hill
      h = random.randint(1, 6) # height of the hill
      s = random.randint(4, 8) # 2 * s is the side length of the hill
      d = 1 # how quickly to taper off the hills
      t = random.choice([GRASS, SAND, BRICK])
      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:
              continue
            if (x - 0) ** 2 + (z - 0) ** 2  5 ** 2:
              continue
            self.add_block((x, y, z), t, immediate=False)
        s -= d # decrement side lenth so hills taper off

  def hit_test(self, position, vector, max_distance=8):
    """ Line of sight search from current position. If a block is
    intersected it is returned, along with the block previously in the line
    of sight. If no block is found, return None, None.

    Parameters
    ----------
    position : tuple of len 3
      The (x, y, z) position to check visibility from.
    vector : tuple of len 3
      The line of sight vector.
    max_distance : int
      How many blocks away to search for a hit.

    """
    m = 8
    x, y, z = position
    dx, dy, dz = vector
    previous = None
    for _ in xrange(max_distance * m):
      key = normalize((x, y, z))
      if key != previous and key in self.world:
        return key, previous
      previous = key
      x, y, z = x + dx / m, y + dy / m, z + dz / m
    return None, None

  def exposed(self, position):
    """ Returns False is given `position` is surrounded on all 6 sides by
    blocks, True otherwise.

    """
    x, y, z = position
    for dx, dy, dz in FACES:
      if (x + dx, y + dy, z + dz) not in self.world:
        return True
    return False

  def add_block(self, position, texture, immediate=True):
    """ Add a block with the given `texture` and `position` to the world.

    Parameters
    ----------
    position : tuple of len 3
      The (x, y, z) position of the block to add.
    texture : list of len 3
      The coordinates of the texture squares. Use `tex_coords()` to
      generate.
    immediate : bool
      Whether or not to draw the block immediately.

    """
    if position in self.world:
      self.remove_block(position, immediate)
    self.world[position] = texture
    self.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 3
      The (x, y, z) position of the block to remove.
    immediate : bool
      Whether 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 visual
    state is current. This means hiding blocks that are not exposed and
    ensuring that all exposed blocks are shown. Usually used after a block
    is added or removed.

    """
    x, y, z = position
    for dx, dy, dz in FACES:
      key = (x + dx, y + dy, z + dz)
      if key not in self.world:
        continue
      if 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 the
    block has already been added with add_block()

    Parameters
    ----------
    position : tuple of len 3
      The (x, y, z) position of the block to show.
    immediate : bool
      Whether or not to show the block immediately.

    """
    texture = self.world[position]
    self.shown[position] = texture
    if 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 3
      The (x, y, z) position of the block to show.
    texture : list of len 3
      The coordinates of the texture squares. Use `tex_coords()` to
      generate.

    """
    x, y, z = position
    vertex_data = cube_vertices(x, y, z, 0.5)
    texture_data = list(texture)
    # create vertex list
    # FIXME Maybe `add_indexed()` should be used instead
    self._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 the
    block from the world.

    Parameters
    ----------
    position : tuple of len 3
      The (x, y, z) position of the block to hide.
    immediate : bool
      Whether 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 are
    drawn 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 are
    removed 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 a
    contiguous x, y sub-region of world. Sectors are used to speed up
    world rendering.

    """
    before_set = set()
    after_set = set()
    pad = 4
    for 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:
            continue
          if before:
            x, y, z = before
            before_set.add((x + dx, y + dy, z + dz))
          if after:
            x, y, z = after
            after_set.add((x + dx, y + dy, z + dz))
    show = after_set - before_set
    hide = before_set - after_set
    for 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 allows
    the game loop to run smoothly. The queue contains calls to
    _show_block() and _hide_block() so this method should be called if
    add_block() or remove_block() was called with immediate=False

    """
    start = time.perf_counter()
    while self.queue and time.time()- start  1.0 / 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]

    # 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]

    # 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 False
    the game will ignore the mouse.

    """
    super(Window, self).set_exclusive_mouse(exclusive)
    self.exclusive = exclusive

  def get_sight_vector(self):
    """ Returns the current line of sight vector indicating the direction
    the 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)) * m
    dz = math.sin(math.radians(x - 90)) * m
    return (dx, dy, dz)

  def get_motion_vector(self):
    """ Returns the current motion vector indicating the velocity of the
    player.

    Returns
    -------
    vector : tuple of len 3
      Tuple containing the velocity in x, y, and z respectively.

    """
    if any(self.strafe):
      x, y = self.rotation
      strafe = 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.0
          m = 1
        if 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) * m
        dz = math.sin(x_angle) * m
      else:
        dy = 0.0
        dx = math.cos(x_angle)
        dz = math.sin(x_angle)
    else:
      dy = 0.0
      dx = 0.0
      dz = 0.0
    return (dx, dy, dz)

  def update(self, dt):
    """ This method is scheduled to be called repeatedly by the pyglet
    clock.

    Parameters
    ----------
    dt : float
      The 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 = sector
    m = 8
    dt = 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 most
    of the motion logic lives, along with gravity and collision detection.

    Parameters
    ----------
    dt : float
      The change in time since the last call.

    """
    # walking
    speed = FLYING_SPEED if self.flying else WALKING_SPEED
    d = 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
    # gravity
    if 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 * GRAVITY
      self.dy = max(self.dy, -TERMINAL_VELOCITY)
      dy += self.dy * dt
    # collisions
    x, y, z = self.position
    x, 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 3
      The (x, y, z) position to check for collisions at.
    height : int or float
      The height of the player.

    Returns
    -------
    position : tuple of len 3
      The 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 = 0.25
    p = list(position)
    np = normalize(position)
    for face in FACES: # check all surrounding blocks
      for i in xrange(3): # check each dimension independently
        if not face[i]:
          continue
        # How much overlap you have with this dimension.
        d = (p[i] - np[i]) * face[i]
        if d  pad:
          continue
        for dy in xrange(height): # check each height
          op = list(np)
          op[1] -= dy
          op[i] += face[i]
          if tuple(op) not in self.model.world:
            continue
          p[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 = 0
          break
    return tuple(p)

  def on_mouse_press(self, x, y, button, modifiers):
    """ Called when a mouse button is pressed. See pyglet docs for button
    amd modifier mappings.

    Parameters
    ----------
    x, y : int
      The coordinates of the mouse click. Always center of the screen if
      the mouse is captured.
    button : int
      Number representing mouse button that was clicked. 1 = left button,
      4 = right button.
    modifiers : int
      Number representing any modifying keys that were pressed when the
      mouse 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]
        if texture != STONE:
          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 : int
      The coordinates of the mouse click. Always center of the screen if
      the mouse is captured.
    dx, dy : float
      The movement of the mouse.

    """
    if self.exclusive:
      m = 0.15
      x, y = self.rotation
      x, y = x + dx * m, y + dy * m
      y = 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 key
    mappings.

    Parameters
    ----------
    symbol : int
      Number representing the key that was pressed.
    modifiers : int
      Number representing any modifying keys that were pressed.

    """
    if symbol == key.W:
      self.strafe[0] -= 1
    elif symbol == key.S:
      self.strafe[0] += 1
    elif symbol == key.A:
      self.strafe[1] -= 1
    elif symbol == key.D:
      self.strafe[1] += 1
    elif symbol == key.SPACE:
      if self.dy == 0:
        self.dy = JUMP_SPEED
    elif symbol == key.ESCAPE:
      self.set_exclusive_mouse(False)
    elif symbol == key.TAB:
      self.flying = not self.flying
    elif 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 key
    mappings.

    Parameters
    ----------
    symbol : int
      Number representing the key that was pressed.
    modifiers : int
      Number representing any modifying keys that were pressed.

    """
    if symbol == key.W:
      self.strafe[0] += 1
    elif symbol == key.S:
      self.strafe[0] -= 1
    elif symbol == key.A:
      self.strafe[1] += 1
    elif symbol == key.D:
      self.strafe[1] -= 1

  def on_resize(self, width, height):
    """ Called when the window is resized to a new `width` and `height`.

    """
    # label
    self.label.y = height - 10
    # reticle
    if self.reticle:
      self.reticle.delete()
    x, y = self.width // 2, self.height // 2
    n = 10
    self.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.rotation
    glRotatef(x, 0, 1, 0)
    glRotatef(-y, math.cos(math.radians(x)), 0, math.sin(math.radians(x)))
    x, y, z = self.position
    glTranslatef(-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 the
    crosshairs.

    """
    vector = self.get_sight_vector()
    block = self.model.hit_test(self.position, vector)[0]
    if block:
      x, y, z = block
      vertex_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.position
    self.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)


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, 1))
  # 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 圖片
  # 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=1800, height=1600, caption='Pyglet', resizable=True)
  # Hide the mouse cursor and prevent the mouse from leaving the window.
  window.set_exclusive_mouse(True)
  setup()
  pyglet.app.run()


if __name__ == '__main__':
  main()

我的世界小游戲python源代碼包下載地址:

鏈接: https://pan.baidu.com/s/1gKAheRzAeNmRXgSU-A4PPg

提取碼: rya9

到此這篇關于Python實現我的世界小游戲源代碼的文章就介紹到這了,更多相關Python小游戲源代碼內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • 用Python實現童年貪吃蛇小游戲功能的實例代碼
  • 一行Python代碼玩遍童年的小游戲

標簽:阜新 濟源 信陽 淘寶好評回訪 隨州 昭通 合肥 興安盟

巨人網絡通訊聲明:本文標題《Python實現我的世界小游戲源代碼》,本文關鍵詞  Python,實現,我的,世界,小游戲,;如發(fā)現本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Python實現我的世界小游戲源代碼》相關的同類信息!
  • 本頁收集關于Python實現我的世界小游戲源代碼的相關信息資訊供網民參考!
  • 推薦文章
    欧美xxxxx在线视频| 国产精品久久久久久久久鸭| 成人av一区二区三区在线观看| 日韩中文在线电影| 精品一区二区三区视频在线播放| 黄色在线小视频| **孕交吃奶水一级毛片| 欲香欲色天天天综合和网| 国产又粗又猛又爽又黄91精品| 国产免费不卡| 在线免费观看视频网站| 久久九九99视频| 男人天堂资源网| 国内精品久久久久伊人av| 亚洲视频在线视频| 在线观看一区日韩| 女人黄色免费在线观看| 亚洲av人人澡人人爽人人夜夜| 亚洲乱码精品一二三四区日韩在线| 国产日韩精品视频一区| 日韩精品www| 不卡视频一区二区三区| 美国十次综合久久| 亚洲第一页在线播放| 亚欧精品一区二区三区| 影音先锋中文资源站| 成人在线观看免费播放| 欧美成人一区二区在线观看| 国产刺激高潮av| 国产精品原创巨作av| 久久精品中文字幕一区| 热久久这里只有精品| 欧美在线观看天堂一区二区三区| 免费成人深夜夜行视频| 欧美vide| 777午夜精品免费视频| 国产精品v日韩精品v在线观看| 97精品在线播放| 日韩电影二区| 在线精品一区二区| 亚洲综合123| 丁香花五月婷婷| 国产极品精品在线观看| 国产一区二区三区视频免费观看| 欧美极品另类videosde| 亚洲精品日韩专区silk| 色婷婷久久一区二区三区麻豆| 在线综合亚洲欧美在线视频| 日韩美女视频网站| 久久偷看各类wc女厕嘘嘘偷窃| 少妇人妻互换不带套| 最近中文字幕2019免费| 中文字幕成人一区| www.亚洲成人网| 日本久久免费| 国产无遮挡猛进猛出免费软件| 亚洲国产一区二区在线观看| 日韩国产精品久久久久久亚洲| 天堂аⅴ在线地址8| 亚洲精品电影网站| 特级毛片在线| 性生活视频软件| 亚洲AV无码国产成人久久| 国产奶水涨喷在线播放| 国产欧美午夜| 亚洲一区二区三区高清视频| 国产稀缺真实呦乱在线| www.av毛片| 日本少妇激三级做爰在线| 国产精品高清在线观看| 国产精品电影一区二区三区| 亚洲精品成人电影| 国产精品99久| 天天操天天操天天操| jizzjizz视频| 天天综合网久久综合网| 国产又粗又大又爽的视频| 天天操天天操天天干| 97精品国产aⅴ7777| 91欧美大片| 伊人精品视频| 中文字幕视频一区二区| 国产成人无遮挡在线视频| 爱情岛论坛亚洲入口| 欧美日本另类xxx乱大交| 美女精品在线观看| 91在线观看免费网站| 国产精品永久入口久久久| 粉嫩av免费一区二区三区| 欧美激情视频在线观看| 日韩精品美女| 国产精品区一区| 日韩av超清在线观看| 亚洲图片欧美激情| 亚洲直播在线一区| ijzzijzzij亚洲大全| 久久久久久少妇| 亚洲最新永久在线观看| 18video性欧美19sex高清| 亚洲你懂的在线视频| 在线观看亚洲精品| 色yeye免费人成网站在线观看| 高潮白浆视频| 国产亚洲欧美日韩日本| 精品久久久久久电影| 成人午夜网址| www成人免费观看网站| 亚洲香蕉成人av网站在线观看| 天堂√中文在线| 中文字幕无乱码| 综合操久久久| 国产精品色视频| 97干在线视频| 中文字幕1区2区| 国产美女一区二区| jizz国产在线| 黑人精品xxx一区一二区| 一级全黄裸体片| 日韩第一页在线观看| 亚洲视频中文字幕在线观看| 国产精品视频1区| 亚洲精品成人a在线观看| 污软件在线观看| 欧美女子与性| 国产欧美日韩小视频| 亚州av乱码久久精品蜜桃| 樱花草www在线| 亚洲欧美小说色综合小说一区| y111111国产精品久久久| 久久99青青精品免费观看| 日本性视频网站| 五十路亲子中出在线观看| 国产精品区一区二区三在线播放| 开心激情五月网| 欧美疯狂做受xxxx高潮| 国产九色91回来了| 久久精品一区二区免费播放| av中文字幕播放| 亚洲精品高潮| 欧美在线精品一区二区三区| 同性恋视频一区| 亚洲第一综合天堂另类专| 蜜臀久久99精品久久一区二区| 九九热精品视频在线观看| 亚洲第一综合天堂另类专| 天天av天天操| 日本男女交配视频| 国产欧美一区二区三区米奇| 中文一区二区| 456亚洲精品成人影院| 亚洲性在线观看| 精品日本一线二线三线不卡| 午夜精品久久久久久久蜜桃| 美女性感视频久久久| 九九精品视频在线看| 久久伊伊香蕉| 秋霞视频一区二区| 久久中文字幕二区| 三级4级全黄60分钟| 欧美啪啪小视频| 欧美激情一区二区三区全黄| 伊人婷婷欧美激情| 欧美视频在线观看| 国产成人精品三级高清久久91| www亚洲欧美| 日产精品久久久一区二区福利| 国产精品日韩欧美一区| 国内精品久久久久影院薰衣草| 欧美一区二区三区电影在线观看| av男人天堂网| 含羞草www国产在线视频| 国产91精品久久久久| 国产日韩av在线播放| 99久久久久国产精品免费| 欧美 日韩 国产一区| 久久久91精品国产一区不卡| 色啦啦av综合| 国产女主播喷水视频在线观看| 2欧美一区二区三区在线观看视频| 日韩精品自拍偷拍| 日韩在线观看你懂的| 欧美成人激情在线| 亚洲福利在线观看| 免费日韩av片| 在线观看国产精品日韩av| 久久久久久久久久av| 99久久久国产精品美女| 欧美乱妇高清无乱码| 国产欧美日本| 一二三在线视频社区| 国产精品黄网站| 亚洲风情在线资源站| 亚洲不卡的av| 懂色av粉嫩av蜜臀av一区二区三区| 国产精品女人毛片| 欧美激情视频三区| 欧美日韩高清一区二区三区| 91女神在线观看| 欧美日韩一二三| 高清欧美性猛交xxxx黑人猛交| 日韩美女免费观看| 亚洲一级少妇| 国产成人免费9x9x人网站视频| 91免费在线视频观看| 7777精品伊人久久久大香线蕉完整版| 欧美一区二区三区在| 黄网站在线观看高清免费| 曰本三级在线| 激情五月综合| 国产丝袜护土调教在线视频| 欧美日韩在线视频一区二区三区| 色老头一区二区三区| 尤物免费看在线视频| 亚洲三级电影| 亚洲国产日韩精品在线| 三级毛片在线| 中文字幕av高清| 亚洲AV无码一区二区三区性| 中文字幕乱码中文乱码51精品| 久久久久久久人妻无码中文字幕爆| 中文字幕在线成人| 欧美成人精品一区二区三区在线看| 91av免费看| 国产一区二区三区视频免费| 久久久久久久国产精品| 在线日韩一区| 久久99青青精品免费观看| 一区二区三区入口| 免费观看黄色的网站| 91社区视频在线观看| 欧美日韩中文字幕在线| 日韩激情啪啪| 69**夜色精品国产69乱| 日本大胆人体视频| 日韩免费av一区二区| 午夜一级久久| 人人妻人人爽人人澡人人精品| 亚洲美女15p| 国产成人精品www牛牛影视| 凹凸日日摸日日碰夜夜爽1| 午夜精品久久久久久久四虎美女版| 在线成人精品视频| 久久黄色级2电影| 亚洲va在线va天堂成人| 偷拍视频一区二区三区| 欧美亚洲三级| 亚洲不卡在线播放| 国产3p在线播放| 久久午夜精品一区二区| 成人在线国产精品| 中老年在线免费视频| 国产在线播放一区| 在线观看免费黄色网址| 亚洲免费av片| 能直接看的av| 午夜精品一区二区三区视频免费看| 九九热免费精品视频| 精品视频在线一区二区在线| 人妻av一区二区| 精品爽片免费看久久| 国产精品日韩电影| 亚洲精品日日夜夜| 亚洲欧美日韩精品久久| 国产精品久久久久7777婷婷| 精品国产aⅴ一区二区三区东京热| 久久久久久久久一区二区| 亚洲成人av免费观看| 先锋影视中文字幕| 色综合久久中文| 欧美成人免费在线视频| 91麻豆精品激情在线观看最新| 无码粉嫩虎白一线天在线观看| 97超碰蝌蚪网人人做人人爽| 91直播在线观看| 日韩精品免费一区二区在线观看| 国产精品中出一区二区三区| 欧美a在线观看| av永久不卡| av在线播放国产| 欧美老少做受xxxx高潮| 欧美综合在线视频| 日韩免费视频在线观看| 免费国产成人看片在线| 久久久www免费人成黑人精品| 国产视频福利在线| 成人av网站在线观看| 亚洲第一综合天堂另类专| 国产传媒在线视频| 国产又黄又嫩又滑又白| 精品免费视频123区| 成人av电影免费观看| 三级在线观看免费大全| 亚洲视频碰碰| 91精品欧美一区二区三区综合在| 1024精品视频| 大白屁股一区二区视频| 久久男女视频| 久草视频在线看| 国产性一乱一性一伧一色| 国产精品欧美激情在线播放| 精品少妇一区二区三区免费观看| 美国三级日本三级久久99| 欧美一级片免费观看| 欧美日本一区二区高清播放视频| 国产亚洲欧美精品久久久久久| xx欧美xxx| 国产成人aaa| 国产91高潮流白浆在线麻豆| 日韩欧美精品免费在线| www.xxxx国产| 116极品美女午夜一级| 精品国偷自产在线视频| 欧美精品在线一区二区| 日韩中文字幕亚洲一区二区va在线| 香港欧美日韩三级黄色一级电影网站| 夜夜嗨av一区二区三区中文字幕| 免费成人高清在线视频theav| 欧美日韩成人一区| 欧美娇小极度另类| 久久久久国产一区二区三区| 国产精品一区二区三区在线观| 激情视频在线播放| 久草福利视频在线| youjizz.com在线观看| av老司机在线观看| 456国产精品| 妞干网在线免费视频| 天天干,天天干|