SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Minecraft in 500 lines of Python
Richard Donkin
@rdonkin
cloudfindhq.com
http://xkcd.com/353/
Why Python?
Easy to write
Great community
Fast enough
Compilers (Cython)
JIT (PyPy)
3D and Game
Libraries
http://xkcd.com/353/
Demo
github.com/fogleman/Minecraft
- Michael Fogleman
Early version:
Minecraft Essentials
Objects are blocks, in 3D grid
Operations
Move: W, S, A, D
Look around: move mouse
Add or remove blocks: click mouse
Textures
How Pyglet Helps
3D gaming library - pyglet.org
Simple wrapper for OpenGL
Pure Python
Library not a framework
This is a quick Minecraft code walkthrough,
not a Pyglet tutorial
Tutorial based on Asteroids: steveasleep.com
Overview of Structure
Window class
Subclass of Pyglet window class
User interaction, movement, rendering
Model class
Models the world as blocks in 3D grid
“The Whole World is an (x, y, z) Dictionary”
Dictionary world[position]
Where position is tuple (x, y, z)
Each entry contains texture such as
Window & Startup Code
Building stuff
Mouse locking, sight vector, hit testing
Remove Block – STONE is special
Look around
Motion matters (dx, dy), not absolute position
Get ‘look vector’ rotation (as x, y degrees) &
add proportion of motion
Mouse left/right is x (look left/right)
And forward/back is y (look up/down) – max ±90°
Highlighting ‘target block’
Hit-test from player position to target block
Draw line around visible edges of block, using
Pyglet
Model
Adding a Block
Remove any existing block at (x, y, z) position from the
‘world dictionary’
Set texture for this block at position
Update sectors (16x16 2D grid) to record this block
Enables speedup by only rendering some sectors
Show the block, and check if any neighbours now visible
1100 commits later…
github.com/boskee/Minecraft
Major fork
8,000 lines
19 contributors
Multi-player
Cython
Pyglet and More
2D game toolkits:
Cocos2D: http://cocos2d.org/ - uses Pyglet
Fife: http://www.fifengine.net/ - esp. RTSs and RPGs
Add-on libraries that can work with Pyglet:
Rabbyt – sprites:
http://arcticpaint.com/projects/rabbyt/
Pymunk – physics: http://pymunk.org
Alternative frameworks:
Pygame – larger community, more game-specific, open
source book at http://inventwithpython.com/
Wrap Up
Concise, elegant code
You can do a lot in 500 lines!
Thank You
Download slides:
https://www.slideshare.net/rdonkin/minecraft-in-500-lines-with-pyglet-pycon-uk
Richard Donkin
@rdonkin
cloudfindhq.com
Sect0rization
Technique used to speed up rendering of
world – only render nearby sectors
Sector = 16x16 2D region of world
In Model, dictionary sectors[sector]
maps from sector to list of positions in that
sector
Track player position in sector
If player moves between sectors, determine
which adjacent sectors to show – see
change_sectors()

Weitere ähnliche Inhalte

Was ist angesagt?

聚焦 AIoT 打造智慧機械新服務
聚焦 AIoT 打造智慧機械新服務聚焦 AIoT 打造智慧機械新服務
聚焦 AIoT 打造智慧機械新服務
Amazon Web Services
 
Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...
Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...
Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...
Dijana Pekić
 
Splunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdfSplunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdf
nitinscribd
 
Strategia
StrategiaStrategia
Strategia
ptwp
 
Shortlisted_Applicants_PI_MBAFT2022 (1) (1).pdf
Shortlisted_Applicants_PI_MBAFT2022 (1) (1).pdfShortlisted_Applicants_PI_MBAFT2022 (1) (1).pdf
Shortlisted_Applicants_PI_MBAFT2022 (1) (1).pdf
AnoopPatel42
 

Was ist angesagt? (20)

Virtual Reality
Virtual RealityVirtual Reality
Virtual Reality
 
Best Practice on using Azure OpenAI Service
Best Practice on using Azure OpenAI ServiceBest Practice on using Azure OpenAI Service
Best Practice on using Azure OpenAI Service
 
Nezavisno složena rečenica vježba
Nezavisno složena rečenica vježbaNezavisno složena rečenica vježba
Nezavisno složena rečenica vježba
 
聚焦 AIoT 打造智慧機械新服務
聚焦 AIoT 打造智慧機械新服務聚焦 AIoT 打造智慧機械新服務
聚焦 AIoT 打造智慧機械新服務
 
The Art of the Possible: Machine Learning and WordPress
The Art of the Possible: Machine Learning and WordPressThe Art of the Possible: Machine Learning and WordPress
The Art of the Possible: Machine Learning and WordPress
 
Amazon CodeWhisperer
Amazon CodeWhispererAmazon CodeWhisperer
Amazon CodeWhisperer
 
Apple Prezentacija
Apple PrezentacijaApple Prezentacija
Apple Prezentacija
 
AzureOpenAI.pptx
AzureOpenAI.pptxAzureOpenAI.pptx
AzureOpenAI.pptx
 
Virtual reality
Virtual realityVirtual reality
Virtual reality
 
Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...
Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...
Avangarda i smjerovi: futurizam, ekspresionizam, dadaizam, nadrealizam, vizua...
 
Apache NiFi Record Processing
Apache NiFi Record ProcessingApache NiFi Record Processing
Apache NiFi Record Processing
 
Drama iva 1
Drama iva 1Drama iva 1
Drama iva 1
 
Splunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdfSplunk 6.4 Administration.pdf
Splunk 6.4 Administration.pdf
 
Strategia
StrategiaStrategia
Strategia
 
Splunk Artificial Intelligence & Machine Learning Webinar
Splunk Artificial Intelligence & Machine Learning WebinarSplunk Artificial Intelligence & Machine Learning Webinar
Splunk Artificial Intelligence & Machine Learning Webinar
 
Shortlisted_Applicants_PI_MBAFT2022 (1) (1).pdf
Shortlisted_Applicants_PI_MBAFT2022 (1) (1).pdfShortlisted_Applicants_PI_MBAFT2022 (1) (1).pdf
Shortlisted_Applicants_PI_MBAFT2022 (1) (1).pdf
 
Konfucije
KonfucijeKonfucije
Konfucije
 
Splunk Enterprise for IT Troubleshooting
Splunk Enterprise for IT TroubleshootingSplunk Enterprise for IT Troubleshooting
Splunk Enterprise for IT Troubleshooting
 
Pi day
Pi dayPi day
Pi day
 
Comp4010 lecture3-AR Technology
Comp4010 lecture3-AR TechnologyComp4010 lecture3-AR Technology
Comp4010 lecture3-AR Technology
 

Andere mochten auch

Разработка GUI игрового проекта на Scaleform
Разработка GUI игрового проекта на ScaleformРазработка GUI игрового проекта на Scaleform
Разработка GUI игрового проекта на Scaleform
Dmitry Dichkovsky
 

Andere mochten auch (10)

Minecraft in 500 lines of Python with Pyglet
Minecraft in 500 lines of Python with PygletMinecraft in 500 lines of Python with Pyglet
Minecraft in 500 lines of Python with Pyglet
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
 
Introduction to Game programming with PyGame Part 1
Introduction to Game programming with PyGame Part 1Introduction to Game programming with PyGame Part 1
Introduction to Game programming with PyGame Part 1
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Денис Ковалев «Python в игровой индустрии»
Денис Ковалев «Python в игровой индустрии»Денис Ковалев «Python в игровой индустрии»
Денис Ковалев «Python в игровой индустрии»
 
Introducción a las librerías PyGame y PyOpenGL
Introducción a las librerías PyGame y PyOpenGLIntroducción a las librerías PyGame y PyOpenGL
Introducción a las librerías PyGame y PyOpenGL
 
Real-time Online Multiplayer with Godot Engine
Real-time Online Multiplayer with Godot EngineReal-time Online Multiplayer with Godot Engine
Real-time Online Multiplayer with Godot Engine
 
Python games
Python gamesPython games
Python games
 
S378 introduction to robocup & soccer simulation
S378 introduction to robocup & soccer simulationS378 introduction to robocup & soccer simulation
S378 introduction to robocup & soccer simulation
 
Разработка GUI игрового проекта на Scaleform
Разработка GUI игрового проекта на ScaleformРазработка GUI игрового проекта на Scaleform
Разработка GUI игрового проекта на Scaleform
 

Ähnlich wie Minecraft in 500 lines with Pyglet - PyCon UK

A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010
Rex Tsai
 
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
Krzysztof Opałka
 

Ähnlich wie Minecraft in 500 lines with Pyglet - PyCon UK (20)

Creating 3D games and applications using Castle Game Engine
Creating 3D games and applications using Castle Game EngineCreating 3D games and applications using Castle Game Engine
Creating 3D games and applications using Castle Game Engine
 
Developing games and graphic visualizations in Pascal
Developing games and graphic visualizations in PascalDeveloping games and graphic visualizations in Pascal
Developing games and graphic visualizations in Pascal
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
At the end of the rainbow
At the end of the rainbowAt the end of the rainbow
At the end of the rainbow
 
Squeak
SqueakSqueak
Squeak
 
Ics2311 l02 Graphics fundamentals
Ics2311 l02 Graphics fundamentalsIcs2311 l02 Graphics fundamentals
Ics2311 l02 Graphics fundamentals
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
 
Ansiblefest 2018 Network automation journey at roblox
Ansiblefest 2018 Network automation journey at robloxAnsiblefest 2018 Network automation journey at roblox
Ansiblefest 2018 Network automation journey at roblox
 
Android game development
Android game developmentAndroid game development
Android game development
 
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolutio...
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolutio...WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolutio...
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolutio...
 
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 RevolutionWebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution
WebKit and Blink: Bridging the Gap Between the Kernel and the HTML5 Revolution
 
A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010A Study of SVG-based Application Development @ OSDC 2010
A Study of SVG-based Application Development @ OSDC 2010
 
Game development with_lib_gdx
Game development with_lib_gdxGame development with_lib_gdx
Game development with_lib_gdx
 
Castle Game Engine and the joy of making and using a custom game engine
Castle Game Engine and the joy  of making and using a custom game engineCastle Game Engine and the joy  of making and using a custom game engine
Castle Game Engine and the joy of making and using a custom game engine
 
The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189The Ring programming language version 1.6 book - Part 50 of 189
The Ring programming language version 1.6 book - Part 50 of 189
 
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
 
Casual Engines 2009
Casual Engines 2009Casual Engines 2009
Casual Engines 2009
 
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with XgxperfDeveloping and Benchmarking Qt applications on Hawkboard with Xgxperf
Developing and Benchmarking Qt applications on Hawkboard with Xgxperf
 
Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3Cape Cod Web Technology Meetup - 3
Cape Cod Web Technology Meetup - 3
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 

Minecraft in 500 lines with Pyglet - PyCon UK

Hinweis der Redaktion

  1. Pyglet is actually 60,000 lines of code, and requires some understanding of OpenGL, but is still quite easy to usePanda3D is an alternative higher-end 3D library, more complex to use than Pyglet. Other 3D and gaming libraries are discussed later.
  2. STONE is specially treated because the base of the world is stone (grey colour) – this stops you drilling through the bottom of the world, which would look bad. To see this, remove the layer of earth blocks on the ground until you get to stone.
  3. Now 8000 lines of code, including full inventory, multi-player client/server, etc. Supports compiling to C using Cython for speed, but not as easy to get started with as the original fogleman version.
  4. Panda3D and PyOpenGL are two other 3D frameworks.