SlideShare a Scribd company logo
4
Most read
6
Most read
14
Most read
Minecraft in 500 lines of Python
Richard Donkin
@rdonkin
cloudfindhq.com
github.com/fogleman/Minecraft
Early version:
http://xkcd.com/353/
Why Python?
Easy to write
Great community
Fast enough
Can use compilers
(Cython etc) or JIT (PyPy)
Or use a spare GPU …
Libraries, broad usage
Raspberry Pi to scientific
computing to cloud apps
http://xkcd.com/353/
Pyglet
3D gaming library - pyglet.org
Simple to learn
Doesn’t mandate program structure
Wraps OpenGL
Can use py2exe / py2app
This is a quick Minecraft code walkthrough,
not a tutorial
Tutorial based on Asteroids: steveasleep.com
Minecraft Essentials
Objects are blocks, in 3D grid
Operations
Move: W, S, A, D – and Tab to fly
Mouse to look (or fly)
Mouse to add or remove blocks
Textures
Overview
Window class
Subclass of Pyglet window class
User interaction, movement, rendering
Model class
Models the world as blocks in 3D grid
Dictionary world[position]
where position is tuple (x, y, z)
Contains texture such as
Window & Startup Code
Model
Look around
X axis is horizontal (look left/right)
Y axis is vertical (look up/down) – max ±90°
Only motion matters, not absolute position
Python tuple assignment
Building stuff
Mouse locking, sight vector
Hit testing, block add/remove
Adding a Block
Remove any existing block at (x, y, z) position from the
‘world dictionary’
Set texture for this block at position
Create or update sector (16x16 2D grid) in which this block
resides – enables speedup by only rendering some sectors
Show the block, and check if any neighbours now visible
Highlighting ‘target block’
Hit-test from player position to target block
Draw line around visible edges of block, using
Pyglet
1100 commits later…
github.com/boskee/Minecraft
Major fork
8,000 lines
19 contributors
Multi-player
Optionally,
compile to C via
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/
Summary
Concise, elegant code
Choose the right framework
Small games to get started
Write your own!
Try pyweek.org challenges
Thank You
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()

More Related Content

PDF
12 分くらいで知るLuaVM
Yuki Tamura
 
PPTX
【出張ヒストリア2017】 想像と違ってた! VRUI作りのコツ
historia_Inc
 
DOCX
Industrial training report
Anurag Gautam
 
PDF
Google flutter and why does it matter
Ahmed Abu Eldahab
 
PDF
RENDERING 最適化「禍つヴァールハイト」
KLab Inc. / Tech
 
PDF
WebRTC と Native とそれから、それから。
tnoho
 
PDF
【Unite 2018 Tokyo】『CARAVAN STORIES』のアセットバンドル事例
UnityTechnologiesJapan002
 
PDF
DNNのモデル特化ハードウェアを生成するオープンソースコンパイラNNgenのデモ
Shinya Takamaeda-Y
 
12 分くらいで知るLuaVM
Yuki Tamura
 
【出張ヒストリア2017】 想像と違ってた! VRUI作りのコツ
historia_Inc
 
Industrial training report
Anurag Gautam
 
Google flutter and why does it matter
Ahmed Abu Eldahab
 
RENDERING 最適化「禍つヴァールハイト」
KLab Inc. / Tech
 
WebRTC と Native とそれから、それから。
tnoho
 
【Unite 2018 Tokyo】『CARAVAN STORIES』のアセットバンドル事例
UnityTechnologiesJapan002
 
DNNのモデル特化ハードウェアを生成するオープンソースコンパイラNNgenのデモ
Shinya Takamaeda-Y
 

What's hot (20)

PDF
Boost Fusion Library
Akira Takahashi
 
PDF
テクニカルアーティストの仕事とスキル ~パイプライン系TAの事例~
Manabu Murakami
 
PPTX
Flutter
Shyju Madathil
 
PPTX
Procedural PLATEAU: プロシージャル技術と3D都市モデル「Project PLATEAU」を組み合わせたファサード自動生成と テクスチャ...
Silicon Studio Corporation
 
PDF
Precomputed atmospheric scattering(사전 계산 대기 산란)
Bongseok Cho
 
PDF
PyQtではじめるGUIプログラミング
Ransui Iso
 
PDF
Technical Deep Dive into the New Prefab System
Unity Technologies
 
PDF
Unity道場aseスペシャル補足資料
小林 信行
 
PDF
UE4を用いた人間から狼男への変身表現法の解説
エピック・ゲームズ・ジャパン Epic Games Japan
 
PDF
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
Shinya Takamaeda-Y
 
PDF
Building beautiful apps with Google flutter
Ahmed Abu Eldahab
 
PDF
Introduction to Labview
mayank agarwal
 
PDF
Cv luca terlizzi_maggio2013
Luca Terlizzi
 
PPSX
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
AMD Developer Central
 
PDF
Intro to Flutter
Eason Pai
 
PDF
シリコンスタジオによる HDR出力対応の理論と実践
Silicon Studio Corporation
 
PDF
Checkerboard Rendering in Dark Souls: Remastered by QLOC
QLOC
 
PDF
ソフトシンセを作りながら学ぶPythonプログラミング
Ransui Iso
 
PDF
Mobile development with Flutter
Awok
 
PDF
ソフトウェア技術者から見たFPGAの魅力と可能性
Kenichiro MITSUDA
 
Boost Fusion Library
Akira Takahashi
 
テクニカルアーティストの仕事とスキル ~パイプライン系TAの事例~
Manabu Murakami
 
Procedural PLATEAU: プロシージャル技術と3D都市モデル「Project PLATEAU」を組み合わせたファサード自動生成と テクスチャ...
Silicon Studio Corporation
 
Precomputed atmospheric scattering(사전 계산 대기 산란)
Bongseok Cho
 
PyQtではじめるGUIプログラミング
Ransui Iso
 
Technical Deep Dive into the New Prefab System
Unity Technologies
 
Unity道場aseスペシャル補足資料
小林 信行
 
UE4を用いた人間から狼男への変身表現法の解説
エピック・ゲームズ・ジャパン Epic Games Japan
 
オープンソースコンパイラNNgenでつくるエッジ・ディープラーニングシステム
Shinya Takamaeda-Y
 
Building beautiful apps with Google flutter
Ahmed Abu Eldahab
 
Introduction to Labview
mayank agarwal
 
Cv luca terlizzi_maggio2013
Luca Terlizzi
 
Vertex Shader Tricks by Bill Bilodeau - AMD at GDC14
AMD Developer Central
 
Intro to Flutter
Eason Pai
 
シリコンスタジオによる HDR出力対応の理論と実践
Silicon Studio Corporation
 
Checkerboard Rendering in Dark Souls: Remastered by QLOC
QLOC
 
ソフトシンセを作りながら学ぶPythonプログラミング
Ransui Iso
 
Mobile development with Flutter
Awok
 
ソフトウェア技術者から見たFPGAの魅力と可能性
Kenichiro MITSUDA
 
Ad

Viewers also liked (20)

PPTX
Minecraft in 500 lines with Pyglet - PyCon UK
Richard Donkin
 
PDF
3D Computer Graphics with Python
Martin Christen
 
PDF
Introduction to Game programming with PyGame Part 1
Abhishek Mishra
 
PDF
Денис Ковалев «Python в игровой индустрии»
DataArt
 
PPTX
Python games
molw
 
PPT
Sneaking Scala through the Back Door
Dianne Marsh
 
PDF
Pygame presentation
Felix Z. Hoffmann
 
PDF
An Introduction to CQRS
Dennis Traub
 
PDF
Python Beginner Class day-10-class
Khánh Nguyễn
 
PDF
Presentation Iberomoldes Group Automotive
rodolfomouta
 
PPTX
Yesica Guacaneme 99
yesicavivis
 
PPT
Data Marketing Fmcg 26 Oct 09
3d interactive
 
PPT
3D Blocks Organizational Charts
PoweredTemplate.com
 
PPS
YouCube
Bernard Richeux
 
PDF
iTest
Tronic Siregar
 
PPT
Niflar3 d finalsymposium
Ton Koenraad
 
PPTX
Sysinfo3D
Tronic Siregar
 
PPTX
Analyze database system using a 3 d method
Ajith Narayanan
 
PDF
Using postgre sql for 3d cms
Tim Child
 
PPT
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
Simone Brogi
 
Minecraft in 500 lines with Pyglet - PyCon UK
Richard Donkin
 
3D Computer Graphics with Python
Martin Christen
 
Introduction to Game programming with PyGame Part 1
Abhishek Mishra
 
Денис Ковалев «Python в игровой индустрии»
DataArt
 
Python games
molw
 
Sneaking Scala through the Back Door
Dianne Marsh
 
Pygame presentation
Felix Z. Hoffmann
 
An Introduction to CQRS
Dennis Traub
 
Python Beginner Class day-10-class
Khánh Nguyễn
 
Presentation Iberomoldes Group Automotive
rodolfomouta
 
Yesica Guacaneme 99
yesicavivis
 
Data Marketing Fmcg 26 Oct 09
3d interactive
 
3D Blocks Organizational Charts
PoweredTemplate.com
 
Niflar3 d finalsymposium
Ton Koenraad
 
Sysinfo3D
Tronic Siregar
 
Analyze database system using a 3 d method
Ajith Narayanan
 
Using postgre sql for 3d cms
Tim Child
 
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
Simone Brogi
 
Ad

Similar to Minecraft in 500 lines of Python with Pyglet (20)

KEY
Introduction to Game Programming Tutorial
Richard Jones
 
PDF
Learning Python with Minecraft and my Dad - PyOhio 2018
Hank Preston
 
PPTX
R in Minecraft
Revolution Analytics
 
PPTX
Decima Engine: Visibility in Horizon Zero Dawn
Guerrilla
 
PPTX
GRAPHICS AND OPENGL.pptx
OMNATHSINGH1
 
PPT
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
Mark Kilgard
 
ODP
Minecraft and Scala: Creating a DSL to enable kids to create Minecraft Mods
Paulo Siqueira
 
PPTX
Game Development with Pygame
Framgia Vietnam
 
PDF
Hackersuli Minecraft hackeles kezdoknek
hackersuli
 
PPT
Pygame : créer des jeux interactifs en Python.
fakhroushka
 
PPT
"Pemrograman Python untuk Pemula dan Ahli"
Muhammadlenterabawon
 
PDF
AN INTERNSHIP REPORT ON AIRPLANE GAME MANAGEMENT SYSTEM PROJECT REPORT.
Kamal Acharya
 
PDF
Airplane game management system project report .pdf
Kamal Acharya
 
PDF
iOS intro to 3D graphics with Metal
Sigmapoint
 
PPT
Felwyrld Tech
Alex Nankervis
 
PDF
Computer Graphics Project Report on Sinking Ship using OpenGL
Sharath Raj
 
PDF
Modern OpenGL scientific visualization
Nicolas Rougier
 
PDF
3D Modeling and Printing by Python
Takuro Wada
 
PPT
SIGGRAPH 2012: NVIDIA OpenGL for 2012
Mark Kilgard
 
PPTX
XIX PUG-PE - Pygame game development
matheuscmpm
 
Introduction to Game Programming Tutorial
Richard Jones
 
Learning Python with Minecraft and my Dad - PyOhio 2018
Hank Preston
 
R in Minecraft
Revolution Analytics
 
Decima Engine: Visibility in Horizon Zero Dawn
Guerrilla
 
GRAPHICS AND OPENGL.pptx
OMNATHSINGH1
 
SIGGRAPH Asia 2012 Exhibitor Talk: OpenGL 4.3 and Beyond
Mark Kilgard
 
Minecraft and Scala: Creating a DSL to enable kids to create Minecraft Mods
Paulo Siqueira
 
Game Development with Pygame
Framgia Vietnam
 
Hackersuli Minecraft hackeles kezdoknek
hackersuli
 
Pygame : créer des jeux interactifs en Python.
fakhroushka
 
"Pemrograman Python untuk Pemula dan Ahli"
Muhammadlenterabawon
 
AN INTERNSHIP REPORT ON AIRPLANE GAME MANAGEMENT SYSTEM PROJECT REPORT.
Kamal Acharya
 
Airplane game management system project report .pdf
Kamal Acharya
 
iOS intro to 3D graphics with Metal
Sigmapoint
 
Felwyrld Tech
Alex Nankervis
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Sharath Raj
 
Modern OpenGL scientific visualization
Nicolas Rougier
 
3D Modeling and Printing by Python
Takuro Wada
 
SIGGRAPH 2012: NVIDIA OpenGL for 2012
Mark Kilgard
 
XIX PUG-PE - Pygame game development
matheuscmpm
 

Recently uploaded (20)

PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PPTX
Simple and concise overview about Quantum computing..pptx
mughal641
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Get More from Fiori Automation - What’s New, What Works, and What’s Next.pdf
Precisely
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Software Development Methodologies in 2025
KodekX
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Simple and concise overview about Quantum computing..pptx
mughal641
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 

Minecraft in 500 lines of Python with Pyglet

  • 1. Minecraft in 500 lines of Python Richard Donkin @rdonkin cloudfindhq.com
  • 4. Why Python? Easy to write Great community Fast enough Can use compilers (Cython etc) or JIT (PyPy) Or use a spare GPU … Libraries, broad usage Raspberry Pi to scientific computing to cloud apps http://xkcd.com/353/
  • 5. Pyglet 3D gaming library - pyglet.org Simple to learn Doesn’t mandate program structure Wraps OpenGL Can use py2exe / py2app This is a quick Minecraft code walkthrough, not a tutorial Tutorial based on Asteroids: steveasleep.com
  • 6. Minecraft Essentials Objects are blocks, in 3D grid Operations Move: W, S, A, D – and Tab to fly Mouse to look (or fly) Mouse to add or remove blocks Textures
  • 7. Overview Window class Subclass of Pyglet window class User interaction, movement, rendering Model class Models the world as blocks in 3D grid Dictionary world[position] where position is tuple (x, y, z) Contains texture such as
  • 10. Look around X axis is horizontal (look left/right) Y axis is vertical (look up/down) – max ±90° Only motion matters, not absolute position Python tuple assignment
  • 11. Building stuff Mouse locking, sight vector Hit testing, block add/remove
  • 12. Adding a Block Remove any existing block at (x, y, z) position from the ‘world dictionary’ Set texture for this block at position Create or update sector (16x16 2D grid) in which this block resides – enables speedup by only rendering some sectors Show the block, and check if any neighbours now visible
  • 13. Highlighting ‘target block’ Hit-test from player position to target block Draw line around visible edges of block, using Pyglet
  • 14. 1100 commits later… github.com/boskee/Minecraft Major fork 8,000 lines 19 contributors Multi-player Optionally, compile to C via Cython
  • 15. 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/
  • 16. Summary Concise, elegant code Choose the right framework Small games to get started Write your own! Try pyweek.org challenges
  • 18. 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()

Editor's Notes

  • #6: Panda3D is a higher-end 3D library, more eomplex to use than Pyglet.
  • #12: STONE is specially treated because the base of the world is stone (grey colour) – this stops you removing the base which would look bad. To see this, remove the layer of earth blocks on the ground until you get to stone.
  • #15: 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.
  • #16: Panda3D and PyOpenGL are two other 3D frameworks.