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
SECTOR_SIZE = 16
WALKING_SPEED = 5 FLYING_SPEED = 15
GRAVITY = 20.0 MAX_JUMP_HEIGHT = 1.0 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): """ 在 x,y,z 的位置返回立方体的顶点,大小为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): """ 返回方块的边界顶点。 """ 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): """ 返回顶部、底部和侧面的方块列表. """ 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): x, y, z = position x, y, z = (int(round(x)), int(round(y)), int(round(z))) return (x, y, z)
def sectorize(position): x, y, z = normalize(position) x, y, z = x // SECTOR_SIZE, y // SECTOR_SIZE, z // SECTOR_SIZE return (x, 0, z)
class Model(object):
<span class="hl-entity hl-other hl-inherited-class hl-c++">def</span> <span class="hl-entity hl-other hl-inherited-class hl-c++">__init__</span>(<span class="hl-entity hl-other hl-inherited-class hl-c++">self</span>): # <span class="hl-entity hl-other hl-inherited-class hl-c++">批处理是用于批处理渲染的顶点列表的集合</span>. <span class="hl-entity hl-other hl-inherited-class hl-c++">self</span>.<span class="hl-entity hl-other hl-inherited-class hl-c++">batch</span> = <span class="hl-entity hl-other hl-inherited-class hl-c++">pyglet</span>.<span class="hl-entity hl-other hl-inherited-class hl-c++">graphics</span>.<span class="hl-entity hl-other hl-inherited-class hl-c++">Batch</span>() # <span class="hl-entity hl-other hl-inherited-class hl-c++">TextureGroup</span> <span class="hl-entity hl-other hl-inherited-class hl-c++">管理opengl</span>. <span class="hl-entity hl-other hl-inherited-class hl-c++">self</span>.<span class="hl-entity hl-other hl-inherited-class hl-c++">group</span> = <span class="hl-entity hl-other hl-inherited-class hl-c++">TextureGroup</span>(<span class="hl-entity hl-other hl-inherited-class hl-c++">image</span>.<span class="hl-entity hl-other hl-inherited-class hl-c++">load</span>(<span class="hl-entity hl-other hl-inherited-class hl-c++">TEXTURE_PATH</span>).<span class="hl-entity hl-other hl-inherited-class hl-c++">get_texture</span>()) # <span class="hl-entity hl-other hl-inherited-class hl-c++">从位置到该位置块的映射</span>. # <span class="hl-entity hl-other hl-inherited-class hl-c++">这定义了当前所有的方块</span>. <span class="hl-entity hl-other hl-inherited-class hl-c++">self</span>.<span class="hl-entity hl-other hl-inherited-class hl-c++">world</span> = <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span></span></span><span class="hl-meta hl-class hl-c++"></span><span class="hl-meta hl-class hl-c++"><span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span></span> # 与world相同的映射,但只包含显示的方块 self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span><span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span> # 从位置映射到所有显示块的vertextlist<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_shown</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span><span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span> # 从分区映射到该分区内的坐标列表<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sectors</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-block hl-c++"><span class="hl-punctuation hl-section hl-block hl-begin hl-c++">{</span><span class="hl-punctuation hl-section hl-block hl-end hl-c++">}</span></span> # 用简单的函数队列实现 # <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">_show_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> 和 <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">_hide_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">queue</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">deque</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_initialize</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">_initialize</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 通过放置所有的方块来初始化世界. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> n <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">80</span> # 二分之一的世界的宽度和高度 s <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">1</span> # 尺寸 y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0</span> # 初始y的高度 <span class="hl-keyword hl-control hl-c++">for</span> x in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>n<span class="hl-punctuation hl-separator hl-c++">,</span> n <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> s</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">for</span> z in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>n<span class="hl-punctuation hl-separator hl-c++">,</span> n <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> s</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 创建一个石头,和到处都有的草方块<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> GRASS<span class="hl-punctuation hl-separator hl-c++">,</span> immediate<span class="hl-keyword hl-operator hl-assignment hl-c">=</span>False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">3</span><span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> STONE<span class="hl-punctuation hl-separator hl-c++">,</span> immediate<span class="hl-keyword hl-operator hl-assignment hl-c">=</span>False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> x <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">in</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>n<span class="hl-punctuation hl-separator hl-c++">,</span> n</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-operator hl-word hl-c++">or</span> z <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">in</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>n<span class="hl-punctuation hl-separator hl-c++">,</span> n</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 建造围墙<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">for</span> dy in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">3</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> STONE<span class="hl-punctuation hl-separator hl-c++">,</span> immediate<span class="hl-keyword hl-operator hl-assignment hl-c">=</span>False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 随机生成小山丘 o <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> n <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">10</span> <span class="hl-keyword hl-control hl-c++">for</span> _ in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">120</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> a <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> random<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">randint</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>o<span class="hl-punctuation hl-separator hl-c++">,</span> o</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 山丘的x坐标 b <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> random<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">randint</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>o<span class="hl-punctuation hl-separator hl-c++">,</span> o</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 山丘的z坐标 c <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span> # 山脚 h <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> random<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">randint</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">6</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 山丘的高度 s <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> random<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">randint</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">4</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">8</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # <span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-keyword hl-operator hl-c">*</span>s是山的一边长度 d <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">1</span> # 要多久才能逐渐消失 t <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> random<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">choice</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>GRASS<span class="hl-punctuation hl-separator hl-c++">,</span> SAND<span class="hl-punctuation hl-separator hl-c++">,</span> BRICK<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">for</span> y in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">c<span class="hl-punctuation hl-separator hl-c++">,</span> c <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> h</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">for</span> x in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">a <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> s<span class="hl-punctuation hl-separator hl-c++">,</span> a <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> s <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">for</span> z in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">b <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> s<span class="hl-punctuation hl-separator hl-c++">,</span> b <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> s <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> a<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>z <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> b<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-comparison hl-c">></span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>s <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>z <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-comparison hl-c"><</span> <span class="hl-constant hl-numeric hl-c++">5</span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> t<span class="hl-punctuation hl-separator hl-c++">,</span> immediate<span class="hl-keyword hl-operator hl-assignment hl-c">=</span>False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> s <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> d # 减少侧面的长度,使山坡逐渐变细 def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">hit_test</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">vector</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">max_distance</span><span class="hl-keyword hl-operator hl-assignment hl-c++">=</span><span class="hl-constant hl-numeric hl-c++">8</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> m <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">8</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> position dx<span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> vector previous <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> None <span class="hl-keyword hl-control hl-c++">for</span> _ in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">max_distance <span class="hl-keyword hl-operator hl-c">*</span> m</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> key <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">normalize</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> key <span class="hl-keyword hl-operator hl-comparison hl-c">!=</span> previous <span class="hl-keyword hl-operator hl-word hl-c++">and</span> key in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">return</span> key<span class="hl-punctuation hl-separator hl-c++">,</span> previous previous <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> key x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> m<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> m<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> m <span class="hl-keyword hl-control hl-c++">return</span> None<span class="hl-punctuation hl-separator hl-c++">,</span> None def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">exposed</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> position <span class="hl-keyword hl-control hl-c++">for</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz in FACES<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-word hl-c++">not</span> in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">return</span> True <span class="hl-keyword hl-control hl-c++">return</span> False def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">add_block</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">texture</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">immediate</span><span class="hl-keyword hl-operator hl-assignment hl-c++">=</span>True<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> position in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">remove_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position<span class="hl-punctuation hl-separator hl-c++">,</span> immediate</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>position<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> texture self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sectors</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">setdefault</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">sectorize</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">append</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> immediate<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">exposed</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">show_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">check_neighbors</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">remove_block</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">immediate</span><span class="hl-keyword hl-operator hl-assignment hl-c++">=</span>True<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> del self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>position<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sectors</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">sectorize</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">remove</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> immediate<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> position in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">hide_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">check_neighbors</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">check_neighbors</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 检查周围所有区,确保他们的视线 状态是当前的.这意味着隐藏方块没有暴露和 确保所有暴露的块都显示出来.通常在方块之后使用 被添加或删除 <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> position <span class="hl-keyword hl-control hl-c++">for</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz in FACES<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> key <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-control hl-c++">if</span> key <span class="hl-keyword hl-operator hl-word hl-c++">not</span> in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">exposed</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">key</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> key <span class="hl-keyword hl-operator hl-word hl-c++">not</span> in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">show_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">key</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">else</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> key in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">hide_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">key</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">show_block</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">immediate</span><span class="hl-keyword hl-operator hl-assignment hl-c++">=</span>True<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> texture <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>position<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>position<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> texture <span class="hl-keyword hl-control hl-c++">if</span> immediate<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_show_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position<span class="hl-punctuation hl-separator hl-c++">,</span> texture</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">else</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_enqueue</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_show_block</span><span class="hl-punctuation hl-separator hl-c++">,</span> position<span class="hl-punctuation hl-separator hl-c++">,</span> texture</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">_show_block</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">texture</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> position vertex_data <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">cube_vertices</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0.5</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> texture_data <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">list</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">texture</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 创建顶点列表 # 也许应该用add _ <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">indexed</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span>来代替 self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_shown</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>position<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">batch</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">24</span><span class="hl-punctuation hl-separator hl-c++">,</span> GL_QUADS<span class="hl-punctuation hl-separator hl-c++">,</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">group</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>v3f/static<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> vertex_data<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>t2f/static<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> texture_data<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">hide_block</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">immediate</span><span class="hl-keyword hl-operator hl-assignment hl-c++">=</span>True<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">pop</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> immediate<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_hide_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">else</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_enqueue</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_hide_block</span><span class="hl-punctuation hl-separator hl-c++">,</span> position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">_hide_block</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> _hide_block()方法的私有实现 <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_shown</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">pop</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">delete</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">show_sector</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">sector</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 确保给定分区中应该显示的所有方块都绘制到画布上 <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">for</span> position in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sectors</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">sector<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> position <span class="hl-keyword hl-operator hl-word hl-c++">not</span> in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span> <span class="hl-keyword hl-operator hl-word hl-c++">and</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">exposed</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">show_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position<span class="hl-punctuation hl-separator hl-c++">,</span> False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">hide_sector</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">sector</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 确保从画布中删除给定分区中应该隐藏的所有方块 <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">for</span> position in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sectors</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">sector<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> position in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">shown</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">hide_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">position<span class="hl-punctuation hl-separator hl-c++">,</span> False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">change_sectors</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">before</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">after</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 从前面的区域转移到后面的区域. 分区是world上一个连续的x,y次区域. 分区是用来加速世界渲染. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> before_set <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">set</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> after_set <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">set</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> pad <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">4</span> <span class="hl-keyword hl-control hl-c++">for</span> dx in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>pad<span class="hl-punctuation hl-separator hl-c++">,</span> pad <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">for</span> dy in <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>pad<span class="hl-punctuation hl-separator hl-c++">,</span> pad <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">for</span> dz in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>pad<span class="hl-punctuation hl-separator hl-c++">,</span> pad <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> dx <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span> <span class="hl-keyword hl-operator hl-comparison hl-c">></span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>pad <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> <span class="hl-keyword hl-control hl-c++">if</span> before<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> before before_set<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> after<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> after after_set<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> show <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> after_set <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> before_set hide <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> before_set <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> after_set <span class="hl-keyword hl-control hl-c++">for</span> sector in show<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">show_sector</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">sector</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">for</span> sector in hide<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">hide_sector</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">sector</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">_enqueue</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">func</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-variable hl-parameter hl-c++">args</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 把func加到内部队列中. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">queue</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">append</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>func<span class="hl-punctuation hl-separator hl-c++">,</span> args<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">_dequeue</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 从内部队列中取出top函数并调用它. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> func<span class="hl-punctuation hl-separator hl-c++">,</span> args <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">queue</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">popleft</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">func</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-c">*</span>args</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">process_queue</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 处理整个队列,同时采取周期性休息. 这样游戏循环才能顺利进行。 队列包含对_show_block()和_hide_block()的调用, 因此,如果调用add_block()或remove_block()的方法 为immediate=false,则应调用此方法 <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> start <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> time<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">clock</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">while</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">queue</span> <span class="hl-keyword hl-operator hl-word hl-c++">and</span> time<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">clock</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> start <span class="hl-punctuation hl-section hl-generic hl-begin hl-c++"><</span> <span class="hl-constant hl-numeric hl-c++">1.0</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> TICKS_PER_SEC<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_dequeue</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def process_entire_queue<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 不间断地处理整个队列. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">while</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">queue</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_dequeue</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span>
class Window(pyglet.window.Window):
def __init__<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-c">*</span>args<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span>kwargs<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> super<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>Window<span class="hl-punctuation hl-separator hl-c++">,</span> self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">__init__</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-c">*</span>args<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-c">*</span><span class="hl-keyword hl-operator hl-c">*</span>kwargs</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 不管窗口是否专门捕获鼠标<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">exclusive</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> False # 当飞行重力没有作用<span class="hl-punctuation hl-separator hl-c++">,</span>速度增加时<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">flying</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> False # 扫射是朝你所面对的方向移动<span class="hl-punctuation hl-separator hl-c++">,</span> # 例如向左或向右移动<span class="hl-punctuation hl-separator hl-c++">,</span>同时继续面向前方 # # 第一个元素是向前移动时为<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> # 向后移动时为<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span>否则是0<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">第二个元素向左移动时为</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span>向右移动时为1否则为0<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> # 当前x<span class="hl-punctuation hl-separator hl-c++">,</span>y<span class="hl-punctuation hl-separator hl-c++">,</span>z坐标<span class="hl-punctuation hl-separator hl-c++">,</span>使用浮点数指定<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">注意</span><span class="hl-punctuation hl-separator hl-c++">,</span>也许不像数学课y轴是垂直轴<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> # 第一个元素是玩家在从z轴向下测量的x<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>z平面<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>地平面<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>上 # 的旋转<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">第二个是从地面向上的旋转角度</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">旋转角度是</span>°<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">垂直平面的旋转范围从</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">90</span>°<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>垂直向下看<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>到90°<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>垂直向上看<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">水平旋转的范围是无限的</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">rotation</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> # 玩家现在在哪个区域 self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sector</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> None # 屏幕中央的准星<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">reticle</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> None # y<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>向上<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>方向的速度<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0</span> # 玩家可以放置的方块列表,按下数字键来循环<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # ------- # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">番外话</span>(注释时加的一句话) # 这里的话如果添加方块可以从这里添加哦 # <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">inventory</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>BRICK<span class="hl-punctuation hl-separator hl-c++">,</span> GRASS<span class="hl-punctuation hl-separator hl-c++">,</span> SAND<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> # 用户可以放置的当前方块<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">按下数字键循环</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # ------- # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">番外话</span>(注释时加的一句话) # 这里可不能添加方块哦<span class="hl-keyword hl-operator hl-arithmetic hl-c">~</span> # <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">block</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">inventory</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> # 按键列表<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # ------- # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">番外话</span>(注释时加的一句话) # 无<span class="hl-keyword hl-operator hl-arithmetic hl-c">~</span> # <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">num_keys</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_1</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_2</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_3</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_4</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_5</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_6</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_7</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_8</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_9</span><span class="hl-punctuation hl-separator hl-c++">,</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> # 处理世界的模型的实例<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> Model<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> # 显示在画布左上角的标签<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">label</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> pyglet<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">text</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">Label</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> font_name<span class="hl-keyword hl-operator hl-assignment hl-c">=</span><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>Arial<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> font_size<span class="hl-keyword hl-operator hl-assignment hl-c">=</span><span class="hl-constant hl-numeric hl-c++">18</span><span class="hl-punctuation hl-separator hl-c++">,</span> x<span class="hl-keyword hl-operator hl-assignment hl-c">=</span><span class="hl-constant hl-numeric hl-c++">10</span><span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-keyword hl-operator hl-assignment hl-c">=</span>self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">height</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">10</span><span class="hl-punctuation hl-separator hl-c++">,</span> anchor_x<span class="hl-keyword hl-operator hl-assignment hl-c">=</span><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>left<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> anchor_y<span class="hl-keyword hl-operator hl-assignment hl-c">=</span><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>top<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> color<span class="hl-keyword hl-operator hl-assignment hl-c">=</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">255</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 这个调用将update<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>方法调度为 # ticks_per_sec<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">这是主要的游戏事件循环</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">pyglet</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">clock</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">schedule_interval</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">update</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1.0</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> TICKS_PER_SEC</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def set_exclusive_mouse<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> exclusive<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 如果exclusive为真,则游戏将捕获鼠标,如果为假 游戏会忽略鼠标. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> super<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>Window<span class="hl-punctuation hl-separator hl-c++">,</span> self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">set_exclusive_mouse</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">exclusive</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">exclusive</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> exclusive def get_sight_vector<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> Returns the current line of sight vector indicating the direction the player is looking. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">rotation</span> # Y的范围是<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>90到90<span class="hl-punctuation hl-separator hl-c++">,</span>或者<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>π<span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span>2到π<span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span><span class="hl-constant hl-numeric hl-c++">2</span><span class="hl-punctuation hl-separator hl-c++">,</span> # 所以m的范围是0到1<span class="hl-punctuation hl-separator hl-c++">,</span>当平行于地面时为1<span class="hl-punctuation hl-separator hl-c++">,</span> # 当向上或向下看时为0<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">m</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">cos</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">y</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # Dy在<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>1到1之间<span class="hl-punctuation hl-separator hl-c++">,</span>垂直向下时为<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span>垂直向上时为<span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span> dy <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">sin</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">y</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> dx <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">cos</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">90</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-operator hl-c">*</span> m dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">sin</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">90</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-operator hl-c">*</span> m <span class="hl-keyword hl-control hl-c++">return</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>dx<span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def get_motion_vector<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 返回表示玩家速度的当前运动矢量. 返回值 ------- 矢量 : tuple of len 3 包含速度分别为x,y和z的组. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">if</span> any<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">rotation</span> strafe <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">degrees</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">atan2</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-keyword hl-operator hl-c">*</span>self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> y_angle <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">y</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> x_angle <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> strafe</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">flying</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> m <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">cos</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">y_angle</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> dy <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">sin</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">y_angle</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 向左或向右移动<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.0</span> m <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">1</span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-punctuation hl-section hl-generic hl-end hl-c++">></span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 倒退<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">*=</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span> # 当你向上或向下飞行时<span class="hl-punctuation hl-separator hl-c++">,</span> #你的左右运动就会减少<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dx</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">cos</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x_angle</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-operator hl-c">*</span> m dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">sin</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x_angle</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-operator hl-c">*</span> m <span class="hl-keyword hl-control hl-c++">else</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> dy <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.0</span> dx <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">cos</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x_angle</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">sin</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x_angle</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">else</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> dy <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.0</span> dx <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.0</span> dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.0</span> <span class="hl-keyword hl-control hl-c++">return</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>dx<span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">update</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">dt</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">process_queue</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> sector <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">sectorize</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> sector <span class="hl-keyword hl-operator hl-comparison hl-c">!=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sector</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">change_sectors</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sector</span><span class="hl-punctuation hl-separator hl-c++">,</span> sector</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sector</span> is None<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">process_entire_queue</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">sector</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> sector m <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">8</span> dt <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">min</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">dt<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0.2</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">for</span> _ in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">m</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">_update</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">dt <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> m</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">_update</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">dt</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> update()方法的私有实现. 这是大部分运动逻辑存在的地方,还有重力和碰撞侦测 参数列表 ---------- dt : 浮点数 上次的时间变化. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> # 走路 speed <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> FLYING_SPEED <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">flying</span> <span class="hl-keyword hl-control hl-c++">else</span> WALKING_SPEED d <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> dt <span class="hl-keyword hl-operator hl-c">*</span> speed # 距离覆盖<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dx</span><span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_motion_vector</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 空间中的新坐标,在解释重力之前<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dx</span><span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> dz <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> dx <span class="hl-keyword hl-operator hl-c">*</span> d<span class="hl-punctuation hl-separator hl-c++">,</span> dy <span class="hl-keyword hl-operator hl-c">*</span> d<span class="hl-punctuation hl-separator hl-c++">,</span> dz <span class="hl-keyword hl-operator hl-c">*</span> d # 重力 <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-keyword hl-operator hl-word hl-c++">not</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">flying</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 更新垂直速度<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 如果你正在下降<span class="hl-punctuation hl-separator hl-c++">,</span>加速直到你达到终端速度<span class="hl-punctuation hl-terminator hl-c++">;</span> # 如果你正在跳跃,减速直到你开始下降 self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> dt <span class="hl-keyword hl-operator hl-c">*</span> GRAVITY self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>TERMINAL_VELOCITY</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> dy <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">+=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-c">*</span> dt # 碰撞 x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">collide</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dz<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> PLAYER_HEIGHT</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def <span class="hl-meta hl-function hl-c++"><span class="hl-entity hl-name hl-function hl-c++">collide</span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function hl-parameters hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-variable hl-parameter hl-c++">self</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-variable hl-parameter hl-c++">height</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 检查球员在给定的’位置’和’高度’ 是否与世界上任何块碰撞. 参数列表 ---------- 坐标 : tuple of len 3 x,y,z坐标检查碰撞. 高度: 整数类型或浮点数 玩家的身高. 返回值 ------- 坐标 : tuple of len 3 考虑到碰撞,玩家的新位置. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> # 多少重叠的一个周围的块的维度<span class="hl-punctuation hl-separator hl-c++">,</span>你需要计算为一个碰撞<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">如果0</span><span class="hl-punctuation hl-separator hl-c++">,</span>触及地形就算碰撞<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">如果是</span><span class="hl-constant hl-numeric hl-c">.49</span><span class="hl-punctuation hl-separator hl-c++">,</span> # 你就会沉入地下<span class="hl-punctuation hl-separator hl-c++">,</span>就像穿过高高的草丛<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> # <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">如果</span><span class="hl-keyword hl-operator hl-comparison hl-c">>=</span><span class="hl-constant hl-numeric hl-c++">0.5</span><span class="hl-punctuation hl-separator hl-c++">,</span>你就会从地上掉下来 pad <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.25</span> p <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">list</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> np <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">normalize</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">position</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">for</span> face in FACES<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 检查周围所有分区 <span class="hl-keyword hl-control hl-c++">for</span> i in <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">xrange</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">3</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 独立检查每个尺寸 <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-keyword hl-operator hl-word hl-c++">not</span> face<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> # 你和这个空间有多少交集<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">d</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>p<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> np<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span> face<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-control hl-c++">if</span> d <span class="hl-punctuation hl-section hl-generic hl-begin hl-c++"><</span> pad<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> <span class="hl-keyword hl-control hl-c++">for</span> dy in xrange<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>height<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> op <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> list<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>np<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> op<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> dy op<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">+=</span> face<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-control hl-c++">if</span> tuple<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>op<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-word hl-c++">not</span> in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">continue</span> p<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>d <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> pad<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-c">*</span> face<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>i<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-control hl-c++">if</span> face <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-word hl-c++">or</span> face <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 你会碰到地面或天空<span class="hl-punctuation hl-separator hl-c++">,</span>所以停下来 # 下降<span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span>上升<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">self</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0</span> <span class="hl-keyword hl-control hl-c++">break</span> <span class="hl-keyword hl-control hl-c++">return</span> tuple<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>p<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def on_mouse_press<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> button<span class="hl-punctuation hl-separator hl-c++">,</span> modifiers<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 当鼠标按钮被按下时调用. 参见 pyglet 文档中的按钮和修饰符映射. 参数列表 ---------- x, y : 整数类型 鼠标点击的坐标.如果鼠标被捕获,总是在屏幕的中心. button : 整数类型 表示单击鼠标按钮的数字. 1 = 左键, 4 = 右键. modifiers : 整数类型 数字表示单击鼠标按钮时所按的任何修改键. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">exclusive</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> vector <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_sight_vector</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> block<span class="hl-punctuation hl-separator hl-c++">,</span> previous <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">hit_test</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> vector</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">if</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>button <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> mouse<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">RIGHT</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-word hl-c++">or</span> \ <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>button <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> mouse<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">LEFT</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-word hl-c++">and</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>modifiers <span class="hl-keyword hl-operator hl-c">&</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">MOD_CTRL</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> # 在osx上<span class="hl-punctuation hl-separator hl-c++">,</span>控制<span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span>左键点击<span class="hl-keyword hl-operator hl-assignment hl-c">=</span>右键点击<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">if</span> previous<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">add_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">previous<span class="hl-punctuation hl-separator hl-c++">,</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">block</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> elif button <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> pyglet<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">window</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">mouse</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">LEFT</span> <span class="hl-keyword hl-operator hl-word hl-c++">and</span> block<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> texture <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>block<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-control hl-c++">if</span> texture <span class="hl-keyword hl-operator hl-comparison hl-c">!=</span> STONE<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">remove_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">block</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> <span class="hl-keyword hl-control hl-c++">else</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">set_exclusive_mouse</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">True</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def on_mouse_motion<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> dx<span class="hl-punctuation hl-separator hl-c++">,</span> dy<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 当玩家移动鼠标时调用. 参数列表 ---------- x, y : 整数类型 鼠标点击的坐标.如果 鼠标被捕获,总是在屏幕的中心. dx, dy : 浮点数 鼠标の运动. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">exclusive</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> m <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-constant hl-numeric hl-c++">0.15</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">rotation</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> x <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dx <span class="hl-keyword hl-operator hl-c">*</span> m<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-arithmetic hl-c">+</span> dy <span class="hl-keyword hl-operator hl-c">*</span> m y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> max<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">90</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">min</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">90</span><span class="hl-punctuation hl-separator hl-c++">,</span> y</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">rotation</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def on_key_press<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> symbol<span class="hl-punctuation hl-separator hl-c++">,</span> modifiers<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 当玩家按下一个键的时候调用, 请查看pyglet文档中的按键映射. 参数列表 ---------- symbol : 整数类型 表示被按下的键的数字. modifiers : 整数类型 表示任何被按下的修改键的数字. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">if</span> symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">W</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">S</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">+=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">A</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">D</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">+=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">SPACE</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">dy</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> JUMP_SPEED elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">ESCAPE</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">set_exclusive_mouse</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">False</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">TAB</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">flying</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-keyword hl-operator hl-word hl-c++">not</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">flying</span> elif symbol in self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">num_keys</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> index <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>symbol <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">num_keys</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">%</span> len<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">inventory</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">block</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">inventory</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span>index<span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> def on_key_release<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> symbol<span class="hl-punctuation hl-separator hl-c++">,</span> modifiers<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 当玩家释放时调用,请参阅pyglet文档中的密钥映射. 参数列表 ---------- symbol : 整数类型 表示被按下的键的数字. modifiers : 整数类型 表示任何被按下的修改键的数字. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> <span class="hl-keyword hl-control hl-c++">if</span> symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">W</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">+=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">S</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">A</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">+=</span> <span class="hl-constant hl-numeric hl-c++">1</span> elif symbol <span class="hl-keyword hl-operator hl-comparison hl-c">==</span> key<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">D</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">strafe</span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-operator hl-assignment hl-augmented hl-c">-=</span> <span class="hl-constant hl-numeric hl-c++">1</span> def on_resize<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-separator hl-c++">,</span> width<span class="hl-punctuation hl-separator hl-c++">,</span> height<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 当窗口大小调整为新的width和height时调用. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> # 标签<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>好吧我本来不想翻译Label的<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">label</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">y</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> height <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span> <span class="hl-constant hl-numeric hl-c++">10</span> # 十字线 <span class="hl-keyword hl-control hl-c++">if</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">reticle</span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">reticle</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">delete</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">width</span> <span class="hl-comment hl-line hl-double-slash hl-c"><span class="hl-punctuation hl-definition hl-comment hl-c">//</span> 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<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 配置opengl绘制二维图形. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> width<span class="hl-punctuation hl-separator hl-c++">,</span> height <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_size</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glDisable<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_DEPTH_TEST<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> viewport <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_viewport_size</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glViewport<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> viewport<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> viewport<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glMatrixMode<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_PROJECTION<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glLoadIdentity<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glOrtho<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> width</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> height</span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glMatrixMode<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_MODELVIEW<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glLoadIdentity<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def set_3d<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 配置opengl绘制三维图形. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> width<span class="hl-punctuation hl-separator hl-c++">,</span> height <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_size</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glEnable<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_DEPTH_TEST<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> viewport <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_viewport_size</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glViewport<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> viewport<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">max</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> viewport<span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glMatrixMode<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_PROJECTION<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glLoadIdentity<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> gluPerspective<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">65.0</span><span class="hl-punctuation hl-separator hl-c++">,</span> width <span class="hl-keyword hl-operator hl-arithmetic hl-c">/</span> <span class="hl-storage hl-type hl-c">float</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>height<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0.1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">60.0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glMatrixMode<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_MODELVIEW<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glLoadIdentity<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">rotation</span> glRotatef<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glRotatef<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>y<span class="hl-punctuation hl-separator hl-c++">,</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">cos</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">sin</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">math<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">radians</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">x</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span> glTranslatef<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>y<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">-</span>z<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def on_draw<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 来画画. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">clear</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">set_3d</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glColor3d<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">batch</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw_focused_block</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">set_2d</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw_label</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw_reticle</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def draw_focused_block<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 画出黑色边缘的方块,目前是在十字线下. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> vector <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_sight_vector</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> block <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">hit_test</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span><span class="hl-punctuation hl-separator hl-c++">,</span> vector</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-meta hl-brackets hl-c++"><span class="hl-punctuation hl-section hl-brackets hl-begin hl-c++">[</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-brackets hl-end hl-c++">]</span></span> <span class="hl-keyword hl-control hl-c++">if</span> block<span class="hl-keyword hl-operator hl-ternary hl-c">:</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> block vertex_data <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> cube_vertices<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0.51</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glColor3d<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glPolygonMode<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_FRONT_AND_BACK<span class="hl-punctuation hl-separator hl-c++">,</span> GL_LINE<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> pyglet<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">graphics</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-constant hl-numeric hl-c++">24</span><span class="hl-punctuation hl-separator hl-c++">,</span> GL_QUADS<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>v3f/static<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span><span class="hl-punctuation hl-separator hl-c++">,</span> vertex_data<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glPolygonMode<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_FRONT_AND_BACK<span class="hl-punctuation hl-separator hl-c++">,</span> GL_FILL<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> def draw_label<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 在屏幕左上角绘制标签. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">position</span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">label</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">text</span> <span class="hl-keyword hl-operator hl-assignment hl-c">=</span> <span class="hl-string hl-quoted hl-single hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">'</span>%02d (%.2f, %.2f, %.2f) %d / %d<span class="hl-punctuation hl-definition hl-string hl-end hl-c">'</span></span> <span class="hl-keyword hl-operator hl-arithmetic hl-c">%</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span> pyglet<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">clock</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">get_fps</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> x<span class="hl-punctuation hl-separator hl-c++">,</span> y<span class="hl-punctuation hl-separator hl-c++">,</span> z<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">len</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">_shown</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-function-call hl-c++"><span class="hl-variable hl-function hl-c++">len</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++">self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">model</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">world</span></span></span><span class="hl-meta hl-function-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">label</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> def draw_reticle<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>self<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-keyword hl-operator hl-ternary hl-c">:</span> <span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span> 在屏幕中央画准星. <span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> glColor3d<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> self<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-variable hl-other hl-readwrite hl-member hl-c++">reticle</span><span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span><span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">draw</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">GL_LINES</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span>
def setup_fog(): """ 配置opengl雾属性.
<span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> # enable fog<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-variable hl-other hl-readwrite hl-member hl-c++">雾将雾的颜色与每个栅格化像素片段的后纹理颜色混合</span> glEnable<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_FOG<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> # 设置雾的颜色 glFogfv<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_FOG_COLOR<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GLfloat <span class="hl-keyword hl-operator hl-c">*</span> <span class="hl-constant hl-numeric hl-c++">4</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0.5</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0.69</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1.0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> # 我们对渲染速度和质量没有偏好<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">glHint</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">GL_FOG_HINT<span class="hl-punctuation hl-separator hl-c++">,</span> GL_DONT_CARE</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 指定用来计算混合因子的公式<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">glFogi</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">GL_FOG_MODE<span class="hl-punctuation hl-separator hl-c++">,</span> GL_LINEAR</span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> # 雾起始和结束的距离有多远,起始和结束的距离越近<span class="hl-punctuation hl-separator hl-c++">,</span> # 浓度越大,雾区的雾越浓<span class="hl-punctuation hl-accessor hl-dot hl-c++">.</span> <span class="hl-meta hl-method-call hl-c++"><span class="hl-variable hl-function hl-member hl-c++">glFogf</span><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++">GL_FOG_START<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">20.0</span></span></span><span class="hl-meta hl-method-call hl-c++"><span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span></span> glFogf<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_FOG_END<span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">60.0</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>
def setup(): """ Basic OpenGL configuration.
<span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span><span class="hl-string hl-quoted hl-double hl-c"><span class="hl-punctuation hl-definition hl-string hl-begin hl-c">"</span><span class="hl-punctuation hl-definition hl-string hl-end hl-c">"</span></span> glClearColor<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-constant hl-numeric hl-c++">0.5</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">0.69</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1.0</span><span class="hl-punctuation hl-separator hl-c++">,</span> <span class="hl-constant hl-numeric hl-c++">1</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glEnable<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_CULL_FACE<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glTexParameteri<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_TEXTURE_2D<span class="hl-punctuation hl-separator hl-c++">,</span> GL_TEXTURE_MIN_FILTER<span class="hl-punctuation hl-separator hl-c++">,</span> GL_NEAREST<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> glTexParameteri<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span>GL_TEXTURE_2D<span class="hl-punctuation hl-separator hl-c++">,</span> GL_TEXTURE_MAG_FILTER<span class="hl-punctuation hl-separator hl-c++">,</span> GL_NEAREST<span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span> setup_fog<span class="hl-meta hl-group hl-c++"><span class="hl-punctuation hl-section hl-group hl-begin hl-c++">(</span><span class="hl-punctuation hl-section hl-group hl-end hl-c++">)</span></span>
def main(): window = Window(width=800, height=600, caption='Pyglet', resizable=True) # 隐藏鼠标光标并防止鼠标离开窗口. window.set_exclusive_mouse(True) setup() pyglet.app.run()
if name == 'main': main()
共 1 条回复
6