Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
45f6f43
Fix window close
Jukitsu Jun 27, 2022
8ee716a
Merge pull request #71 from Jukitsu/master
obiwac Jun 27, 2022
e4af927
Added odin implementation
talonateox Oct 24, 2022
96672f5
Merge pull request #75 from anthony-63/master
obiwac Oct 25, 2022
c201590
Remove the link to the lighting test from README.md
Chubercik Nov 15, 2022
2efc2d4
Merge pull request #78 from Chubercik/master
obiwac Nov 16, 2022
b3af5c2
Update main.py
Jukitsu Dec 30, 2022
134de35
Merge pull request #79 from Jukitsu/pyglet-2
obiwac Dec 31, 2022
a4c7c4e
community: Make sprinting behaviour more similar to Minecraft - fixes…
Arta48 Feb 7, 2023
ec24af2
Add lua implementation to README
brennop Apr 16, 2023
df68a5c
Merge pull request #90 from brennop/master
obiwac Apr 16, 2023
0d3389a
Update controller.py to use pyglet 2
drakeerv Apr 23, 2023
94bb39b
make js demo more obvious
drakeerv Apr 23, 2023
2017e70
Revert "Update controller.py to use pyglet 2"
drakeerv Apr 24, 2023
3463830
made requested changes
drakeerv Apr 24, 2023
9398e29
Merge pull request #91 from drakeerv/master
obiwac Apr 24, 2023
7a3c7f8
add newline
drakeerv Apr 25, 2023
ca2d95c
merge: Resolve conflicts
obiwac Apr 25, 2023
c340059
~: Set `double_buffer` to true in GL config
obiwac May 15, 2023
f76033b
merge: Resolve conflicts
obiwac May 15, 2023
eec9efa
13: Set `double_buffer` to true in GL config
obiwac May 15, 2023
7c56b97
gitignore: Ignore VIM swap files
obiwac May 15, 2023
a09bf7c
Merge branch 'master' of ssh://github.com/obiwac/python-minecraft-clo…
obiwac May 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.core
*.log
.vscode
*.ogg
*.ogg
*.sw[nop]
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ The community has several features and options that can be toggled in `options.p
- **Nim implementation:** https://github.com/phargobikcin/nim-minecraft-clone
- **Java implementation:** https://github.com/StartForKillerMC/JavaMinecraft
- **C++ implementation:** https://github.com/Jukitsu/CppMinecraft-clone
- **Lighting test:** https://github.com/Jukitsu/python-minecraft-clone-ep10-lighting
- **Odin implementation:** https://github.com/anthony-63/lvo
- **Lua implementation:** https://github.com/brennop/lunarcraft
- **Javascript implementation:** https://github.com/drakeerv/js-minecraft-clone ([Demo](https://drakeerv.github.io/js-minecraft-clone/))
1 change: 1 addition & 0 deletions community/audio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
For music download `.ogg` (or other) from [archive.org](https://archive.org/details/C418-MinecraftSoundtrackVolumeAlpha/) and put them into the music `dir`.
1 change: 0 additions & 1 deletion community/audio/readme.txt

This file was deleted.

5 changes: 5 additions & 0 deletions community/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,8 @@ def start_modifier(self, mode):
def end_modifier(self, mode):
if mode == self.ModifierMode.SPRINT:
self.game.player.target_speed = player.WALKING_SPEED

def apply_deadzone(self, value):
if abs(value[0]) < self.joystick_deadzone: value[0] = 0
if abs(value[1]) < self.joystick_deadzone: value[1] = 0
return value
24 changes: 20 additions & 4 deletions community/keyboard_mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def __init__(self, game):
self.game.on_key_press = self.on_key_press
self.game.on_key_release = self.on_key_release

self.w_pressed = False
self.ctrl_pressed = False

def on_mouse_press(self, x, y, button, modifiers):
if not self.game.mouse_captured:
self.game.mouse_captured = True
Expand Down Expand Up @@ -43,12 +46,19 @@ def on_key_press(self, key, modifiers):

if key == pyglet.window.key.D: self.start_move(self.MoveMode.RIGHT)
elif key == pyglet.window.key.A: self.start_move(self.MoveMode.LEFT)
elif key == pyglet.window.key.W: self.start_move(self.MoveMode.FORWARD)
elif key == pyglet.window.key.W:
self.w_pressed = True
self.start_move(self.MoveMode.FORWARD)
if self.ctrl_pressed:
self.start_modifier(self.ModifierMode.SPRINT)
elif key == pyglet.window.key.S: self.start_move(self.MoveMode.BACKWARD)
elif key == pyglet.window.key.SPACE : self.start_move(self.MoveMode.UP)
elif key == pyglet.window.key.LSHIFT: self.start_move(self.MoveMode.DOWN)

elif key == pyglet.window.key.LCTRL : self.start_modifier(self.ModifierMode.SPRINT)
elif key == pyglet.window.key.LCTRL:
self.ctrl_pressed = True
if self.w_pressed:
self.start_modifier(self.ModifierMode.SPRINT)

elif key == pyglet.window.key.E: self.misc(self.MiscMode.SPAWN)
elif key == pyglet.window.key.F: self.misc(self.MiscMode.FLY)
Expand All @@ -67,9 +77,15 @@ def on_key_release(self, key, modifiers):

if key == pyglet.window.key.D: self.end_move(self.MoveMode.RIGHT)
elif key == pyglet.window.key.A: self.end_move(self.MoveMode.LEFT)
elif key == pyglet.window.key.W: self.end_move(self.MoveMode.FORWARD)
elif key == pyglet.window.key.W:
self.w_pressed = False
self.end_move(self.MoveMode.FORWARD)
self.end_modifier(self.ModifierMode.SPRINT)
elif key == pyglet.window.key.S: self.end_move(self.MoveMode.BACKWARD)
elif key == pyglet.window.key.SPACE : self.end_move(self.MoveMode.UP)
elif key == pyglet.window.key.LSHIFT: self.end_move(self.MoveMode.DOWN)

elif key == pyglet.window.key.LCTRL : self.end_modifier(self.ModifierMode.SPRINT)
elif key == pyglet.window.key.LCTRL:
self.ctrl_pressed = False
if not self.w_pressed:
self.end_modifier(self.ModifierMode.SPRINT)
40 changes: 8 additions & 32 deletions community/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def on_close(self):
for fence in self.fences:
gl.glDeleteSync(fence)

self.close()
super().on_close()

def update_f3(self, delta_time):
"""Update the F3 debug screen content"""
Expand All @@ -157,7 +157,7 @@ def update_f3(self, delta_time):
visible_quad_count = sum(chunk.mesh_quad_count for chunk in self.world.visible_chunks)
self.f3.text = \
f"""
{round(pyglet.clock.get_fps())} FPS ({self.world.chunk_update_counter} Chunk Updates) {"inf" if not self.options.VSYNC else "vsync"}{"ao" if self.options.SMOOTH_LIGHTING else ""}
{round(1 / delta_time)} FPS ({self.world.chunk_update_counter} Chunk Updates) {"inf" if not self.options.VSYNC else "vsync"}{"ao" if self.options.SMOOTH_LIGHTING else ""}
C: {visible_chunk_count} / {chunk_count} pC: {self.world.pending_chunk_update_count} pU: {len(self.world.chunk_building_queue)} aB: {chunk_count}
E: {self.world.visible_entities} / {len(self.world.entities)}
Client Singleplayer @{round(delta_time * 1000)} ms tick {round(1 / delta_time)} TPS
Expand Down Expand Up @@ -218,35 +218,16 @@ def on_draw(self):

# Draw the F3 Debug screen
if self.show_f3:
self.draw_f3()
self.f3.draw()

# CPU - GPU Sync
if not self.options.SMOOTH_FPS:
self.fences.append(gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
# self.fences.append(gl.glFenceSync(gl.GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
# Broken in pyglet 2; glFenceSync is missing
pass
else:
gl.glFinish()

def draw_f3(self):
"""Draws the f3 debug screen. Current uses the fixed-function pipeline since pyglet labels uses it"""
gl.glDisable(gl.GL_DEPTH_TEST)
gl.glUseProgram(0)
gl.glBindVertexArray(0)
gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glPushMatrix()
gl.glLoadIdentity()

gl.glMatrixMode(gl.GL_PROJECTION)
gl.glPushMatrix()
gl.glLoadIdentity()
gl.glOrtho(0, self.width, 0, self.height, -1, 1)

self.f3.draw()

gl.glPopMatrix()

gl.glMatrixMode(gl.GL_MODELVIEW)
gl.glPopMatrix()

# input functions

def on_resize(self, width, height):
Expand All @@ -265,10 +246,8 @@ def __init__(self):
depth_size = 16, sample_buffers=bool(options.ANTIALIASING), samples=options.ANTIALIASING)
self.window = Window(config = self.config, width = 852, height = 480, caption = "Minecraft clone", resizable = True, vsync = options.VSYNC)

def run(self):
pyglet.app.run()


def run(self):
pyglet.app.run(interval = 0)

def init_logger():
log_folder = "logs/"
Expand All @@ -284,9 +263,6 @@ def init_logger():
logging.basicConfig(level=logging.INFO, filename=log_path,
format="[%(asctime)s] [%(processName)s/%(threadName)s/%(levelname)s] (%(module)s.py/%(funcName)s) %(message)s")




def main():
init_logger()
game = Game()
Expand Down
4 changes: 2 additions & 2 deletions episode-10/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def on_key_release(self, key, modifiers):

class Game:
def __init__(self):
self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16)
self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16)
self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False)

def run(self):
pyglet.app.run()

Expand Down
3 changes: 1 addition & 2 deletions episode-11/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import math
import ctypes
import random
Expand Down Expand Up @@ -154,7 +153,7 @@ def on_key_release(self, key, modifiers):

class Game:
def __init__(self):
self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16)
self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16)
self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False)

def run(self):
Expand Down
3 changes: 1 addition & 2 deletions episode-12/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import math
import ctypes
import random
Expand Down Expand Up @@ -194,7 +193,7 @@ def on_key_release(self, key, modifiers):

class Game:
def __init__(self):
self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16)
self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16)
self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False)

def run(self):
Expand Down
3 changes: 1 addition & 2 deletions episode-13/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import math
import random
import pyglet
Expand Down Expand Up @@ -162,7 +161,7 @@ def on_key_release(self, key, modifiers):

class Game:
def __init__(self):
self.config = gl.Config(major_version = 3, minor_version = 3, depth_size = 16)
self.config = gl.Config(double_buffer = True, major_version = 3, minor_version = 3, depth_size = 16)
self.window = Window(config = self.config, width = 800, height = 600, caption = "Minecraft clone", resizable = True, vsync = False)

def run(self):
Expand Down