SlideShare une entreprise Scribd logo
1  sur  18
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()

Contenu connexe

Tendances

ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
ドキュメントを作りたくなってしまう魔法のツール「Sphinx」ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
ドキュメントを作りたくなってしまう魔法のツール「Sphinx」Yoshiki Shibukawa
 
2 D게임 프로그래밍 발표 자료
2 D게임 프로그래밍 발표 자료2 D게임 프로그래밍 발표 자료
2 D게임 프로그래밍 발표 자료Lee Jungmin
 
Redmineって何ができるの?
Redmineって何ができるの?Redmineって何ができるの?
Redmineって何ができるの?Tomohisa Kusukawa
 
経営のアジリティを支えるDevOpsと組織
経営のアジリティを支えるDevOpsと組織経営のアジリティを支えるDevOpsと組織
経営のアジリティを支えるDevOpsと組織Recruit Technologies
 
Redmine にいろいろ埋め込んでみた
Redmine にいろいろ埋め込んでみたRedmine にいろいろ埋め込んでみた
Redmine にいろいろ埋め込んでみたKohei Nakamura
 
データベース08 - 関係データモデルと関係代数
データベース08 - 関係データモデルと関係代数データベース08 - 関係データモデルと関係代数
データベース08 - 関係データモデルと関係代数Kenta Oku
 
JPAの基礎と現場で役立つ開発Tips
JPAの基礎と現場で役立つ開発TipsJPAの基礎と現場で役立つ開発Tips
JPAの基礎と現場で役立つ開発Tipsyuichi_kuwahara
 
Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020
Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020
Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020onozaty
 
超簡単! インストールなしでRedmineを試す
超簡単! インストールなしでRedmineを試す超簡単! インストールなしでRedmineを試す
超簡単! インストールなしでRedmineを試すShin Tanigawa
 
はじめる! Redmine (2021年版)
はじめる! Redmine (2021年版) はじめる! Redmine (2021年版)
はじめる! Redmine (2021年版) Go Maeda
 
システムダウンのひみつ
システムダウンのひみつシステムダウンのひみつ
システムダウンのひみつYoshitaka Kawashima
 
ちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てるちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てる増田 亨
 
3週連続DDDその1 ドメイン駆動設計の基本を理解する
3週連続DDDその1  ドメイン駆動設計の基本を理解する3週連続DDDその1  ドメイン駆動設計の基本を理解する
3週連続DDDその1 ドメイン駆動設計の基本を理解する増田 亨
 
ある工場のRedmine画面カスタム【View customize plugin 活用例】
ある工場のRedmine画面カスタム【View customize plugin 活用例】ある工場のRedmine画面カスタム【View customize plugin 活用例】
ある工場のRedmine画面カスタム【View customize plugin 活用例】Kohei Nakamura
 
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解するそうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解するshigeki_ohtsu
 
IdrisでWebアプリを書く
IdrisでWebアプリを書くIdrisでWebアプリを書く
IdrisでWebアプリを書くHideyuki Tanaka
 
Lychee Redmine最新機能紹介とLycheeの未来について
Lychee Redmine最新機能紹介とLycheeの未来についてLychee Redmine最新機能紹介とLycheeの未来について
Lychee Redmine最新機能紹介とLycheeの未来についてagileware_jp
 
Redmineを使ってみよう
Redmineを使ってみようRedmineを使ってみよう
Redmineを使ってみようmrgoofy33 .
 
うちのRedmineの使い方(2)
うちのRedmineの使い方(2)うちのRedmineの使い方(2)
うちのRedmineの使い方(2)Tomohisa Kusukawa
 

Tendances (20)

ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
ドキュメントを作りたくなってしまう魔法のツール「Sphinx」ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
ドキュメントを作りたくなってしまう魔法のツール「Sphinx」
 
2 D게임 프로그래밍 발표 자료
2 D게임 프로그래밍 발표 자료2 D게임 프로그래밍 발표 자료
2 D게임 프로그래밍 발표 자료
 
Redmineって何ができるの?
Redmineって何ができるの?Redmineって何ができるの?
Redmineって何ができるの?
 
経営のアジリティを支えるDevOpsと組織
経営のアジリティを支えるDevOpsと組織経営のアジリティを支えるDevOpsと組織
経営のアジリティを支えるDevOpsと組織
 
Redmine にいろいろ埋め込んでみた
Redmine にいろいろ埋め込んでみたRedmine にいろいろ埋め込んでみた
Redmine にいろいろ埋め込んでみた
 
データベース08 - 関係データモデルと関係代数
データベース08 - 関係データモデルと関係代数データベース08 - 関係データモデルと関係代数
データベース08 - 関係データモデルと関係代数
 
JPAの基礎と現場で役立つ開発Tips
JPAの基礎と現場で役立つ開発TipsJPAの基礎と現場で役立つ開発Tips
JPAの基礎と現場で役立つ開発Tips
 
Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020
Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020
Redmineの画面をあなた好みにカスタマイズ - View customize pluginの紹介 - Redmine Japan 2020
 
超簡単! インストールなしでRedmineを試す
超簡単! インストールなしでRedmineを試す超簡単! インストールなしでRedmineを試す
超簡単! インストールなしでRedmineを試す
 
はじめる! Redmine (2021年版)
はじめる! Redmine (2021年版) はじめる! Redmine (2021年版)
はじめる! Redmine (2021年版)
 
システムダウンのひみつ
システムダウンのひみつシステムダウンのひみつ
システムダウンのひみつ
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
 
ちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てるちいさなオブジェクトでドメインモデルを組み立てる
ちいさなオブジェクトでドメインモデルを組み立てる
 
3週連続DDDその1 ドメイン駆動設計の基本を理解する
3週連続DDDその1  ドメイン駆動設計の基本を理解する3週連続DDDその1  ドメイン駆動設計の基本を理解する
3週連続DDDその1 ドメイン駆動設計の基本を理解する
 
ある工場のRedmine画面カスタム【View customize plugin 活用例】
ある工場のRedmine画面カスタム【View customize plugin 活用例】ある工場のRedmine画面カスタム【View customize plugin 活用例】
ある工場のRedmine画面カスタム【View customize plugin 活用例】
 
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解するそうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
そうだったのか! よくわかる process.nextTick() node.jsのイベントループを理解する
 
IdrisでWebアプリを書く
IdrisでWebアプリを書くIdrisでWebアプリを書く
IdrisでWebアプリを書く
 
Lychee Redmine最新機能紹介とLycheeの未来について
Lychee Redmine最新機能紹介とLycheeの未来についてLychee Redmine最新機能紹介とLycheeの未来について
Lychee Redmine最新機能紹介とLycheeの未来について
 
Redmineを使ってみよう
Redmineを使ってみようRedmineを使ってみよう
Redmineを使ってみよう
 
うちのRedmineの使い方(2)
うちのRedmineの使い方(2)うちのRedmineの使い方(2)
うちのRedmineの使い方(2)
 

En vedette

Minecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UKMinecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UKRichard Donkin
 
3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with PythonMartin Christen
 
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 1Abhishek Mishra
 
Денис Ковалев «Python в игровой индустрии»
Денис Ковалев «Python в игровой индустрии»Денис Ковалев «Python в игровой индустрии»
Денис Ковалев «Python в игровой индустрии»DataArt
 
Python games
Python gamesPython games
Python gamesmolw
 
Sneaking Scala through the Back Door
Sneaking Scala through the Back DoorSneaking Scala through the Back Door
Sneaking Scala through the Back DoorDianne Marsh
 
An Introduction to CQRS
An Introduction to CQRSAn Introduction to CQRS
An Introduction to CQRSDennis Traub
 
Python Beginner Class day-10-class
Python Beginner Class day-10-classPython Beginner Class day-10-class
Python Beginner Class day-10-classKhánh Nguyễn
 
Presentation Iberomoldes Group Automotive
Presentation Iberomoldes Group AutomotivePresentation Iberomoldes Group Automotive
Presentation Iberomoldes Group Automotiverodolfomouta
 
Yesica Guacaneme 99
Yesica Guacaneme 99Yesica Guacaneme 99
Yesica Guacaneme 99yesicavivis
 
Data Marketing Fmcg 26 Oct 09
Data Marketing Fmcg 26 Oct 09Data Marketing Fmcg 26 Oct 09
Data Marketing Fmcg 26 Oct 093d interactive
 
Niflar3 d finalsymposium
Niflar3 d finalsymposiumNiflar3 d finalsymposium
Niflar3 d finalsymposiumTon Koenraad
 
Analyze database system using a 3 d method
Analyze database system using a 3 d methodAnalyze database system using a 3 d method
Analyze database system using a 3 d methodAjith Narayanan
 
Using postgre sql for 3d cms
Using postgre sql for 3d cmsUsing postgre sql for 3d cms
Using postgre sql for 3d cmsTim Child
 
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...Simone Brogi
 
Application of 3D printing in analytical chemistry (by Fariborz Amoozgar)
Application  of 3D printing in analytical chemistry (by Fariborz Amoozgar)Application  of 3D printing in analytical chemistry (by Fariborz Amoozgar)
Application of 3D printing in analytical chemistry (by Fariborz Amoozgar)Iranian Spase Research Center (ISRC)
 

En vedette (20)

Minecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UKMinecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UK
 
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
 
Денис Ковалев «Python в игровой индустрии»
Денис Ковалев «Python в игровой индустрии»Денис Ковалев «Python в игровой индустрии»
Денис Ковалев «Python в игровой индустрии»
 
Python games
Python gamesPython games
Python games
 
Sneaking Scala through the Back Door
Sneaking Scala through the Back DoorSneaking Scala through the Back Door
Sneaking Scala through the Back Door
 
An Introduction to CQRS
An Introduction to CQRSAn Introduction to CQRS
An Introduction to CQRS
 
Python Beginner Class day-10-class
Python Beginner Class day-10-classPython Beginner Class day-10-class
Python Beginner Class day-10-class
 
Presentation Iberomoldes Group Automotive
Presentation Iberomoldes Group AutomotivePresentation Iberomoldes Group Automotive
Presentation Iberomoldes Group Automotive
 
Yesica Guacaneme 99
Yesica Guacaneme 99Yesica Guacaneme 99
Yesica Guacaneme 99
 
Data Marketing Fmcg 26 Oct 09
Data Marketing Fmcg 26 Oct 09Data Marketing Fmcg 26 Oct 09
Data Marketing Fmcg 26 Oct 09
 
3D Blocks Organizational Charts
3D Blocks Organizational Charts3D Blocks Organizational Charts
3D Blocks Organizational Charts
 
YouCube
YouCubeYouCube
YouCube
 
iTest
iTestiTest
iTest
 
Niflar3 d finalsymposium
Niflar3 d finalsymposiumNiflar3 d finalsymposium
Niflar3 d finalsymposium
 
Sysinfo3D
Sysinfo3DSysinfo3D
Sysinfo3D
 
Analyze database system using a 3 d method
Analyze database system using a 3 d methodAnalyze database system using a 3 d method
Analyze database system using a 3 d method
 
Using postgre sql for 3d cms
Using postgre sql for 3d cmsUsing postgre sql for 3d cms
Using postgre sql for 3d cms
 
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
PROGRAM PHASE IN LIGAND-BASED PHARMACOPHORE MODEL GENERATION AND 3D DATABASE ...
 
Application of 3D printing in analytical chemistry (by Fariborz Amoozgar)
Application  of 3D printing in analytical chemistry (by Fariborz Amoozgar)Application  of 3D printing in analytical chemistry (by Fariborz Amoozgar)
Application of 3D printing in analytical chemistry (by Fariborz Amoozgar)
 

Similaire à Minecraft in 500 lines of Python with Pyglet

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 PascalMichalis Kamburelis
 
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 EngineMichalis Kamburelis
 
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 1benDesigning
 
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 XgxperfPrabindh Sundareson
 
Developing new zynq based instruments
Developing new zynq based instrumentsDeveloping new zynq based instruments
Developing new zynq based instrumentsGraham NAYLOR
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Jian-Hong Pan
 
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 robloxDamien Garros
 
2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkitCocoaHeads Tricity
 
Berlin Embedded Linux meetup: How to Linux on RISC-V
Berlin Embedded Linux meetup: How to Linux on RISC-VBerlin Embedded Linux meetup: How to Linux on RISC-V
Berlin Embedded Linux meetup: How to Linux on RISC-VDrew Fustini
 
Devoxx 2015 - Building the Internet of Things with Eclipse IoT
Devoxx 2015 - Building the Internet of Things with Eclipse IoTDevoxx 2015 - Building the Internet of Things with Eclipse IoT
Devoxx 2015 - Building the Internet of Things with Eclipse IoTBenjamin Cabé
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemoachipa
 
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 engineMichalis Kamburelis
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIYoni Davidson
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Codemotion
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingHenry Schreiner
 
[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep DiveAkihiro Suda
 
Ics2311 l02 Graphics fundamentals
Ics2311 l02 Graphics fundamentalsIcs2311 l02 Graphics fundamentals
Ics2311 l02 Graphics fundamentalsbridgekloud
 

Similaire à Minecraft in 500 lines of Python with Pyglet (20)

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
 
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
 
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
 
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
 
Linux on RISC-V
Linux on RISC-VLinux on RISC-V
Linux on RISC-V
 
Developing new zynq based instruments
Developing new zynq based instrumentsDeveloping new zynq based instruments
Developing new zynq based instruments
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
Package a PyApp as a Flatpak Package: An HTTP Server for Example @ PyCon APAC...
 
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
 
2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit2013-03-07 indie developer toolkit
2013-03-07 indie developer toolkit
 
Berlin Embedded Linux meetup: How to Linux on RISC-V
Berlin Embedded Linux meetup: How to Linux on RISC-VBerlin Embedded Linux meetup: How to Linux on RISC-V
Berlin Embedded Linux meetup: How to Linux on RISC-V
 
Devoxx 2015 - Building the Internet of Things with Eclipse IoT
Devoxx 2015 - Building the Internet of Things with Eclipse IoTDevoxx 2015 - Building the Internet of Things with Eclipse IoT
Devoxx 2015 - Building the Internet of Things with Eclipse IoT
 
PyQt Application Development On Maemo
PyQt Application Development On MaemoPyQt Application Development On Maemo
PyQt Application Development On Maemo
 
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
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
At the end of the rainbow
At the end of the rainbowAt the end of the rainbow
At the end of the rainbow
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
 
Digital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meetingDigital RSE: automated code quality checks - RSE group meeting
Digital RSE: automated code quality checks - RSE group meeting
 
[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive[KubeCon EU 2020] containerd Deep Dive
[KubeCon EU 2020] containerd Deep Dive
 
Ics2311 l02 Graphics fundamentals
Ics2311 l02 Graphics fundamentalsIcs2311 l02 Graphics fundamentals
Ics2311 l02 Graphics fundamentals
 

Dernier

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
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 WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
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...Martijn de Jong
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
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 productivityPrincipled Technologies
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
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)wesley chun
 
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 WorkerThousandEyes
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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...Neo4j
 
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...Miguel Araújo
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 

Dernier (20)

AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
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...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
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
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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)
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
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...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

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()

Notes de l'éditeur

  1. Panda3D is a higher-end 3D library, more eomplex to use than Pyglet.
  2. 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.
  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.