Simple Minecraft Clone in 580 lines of Python
If someone were to make something like this a step-by-step tutorial/template appropriate for a classroom setting it would be huge. Imagine a class at High School where you start off learning the basics of Python for the first few weeks and the rest of the semester is spent writing the chunks of code into a template that has lots of notes for guidance.
I'd image something like :
def setDefaultBlockColor(color): # recall that this is a function that takes in a variable called 'color' as its argument, write the code that will set the current game files configuration file to either 'red', 'blue' or 'green' (p.s. DONT FORGET TO INDENT YOUR CODE!)
Just writing this function and seeing it work once you load up the game is enough to hook almost anyone that has the potential to enjoy programming but just doesn't know it yet.
I wrote down the basic steps to get this running on windows at https://github.com/fogleman/Minecraft/wiki
I used a variant of this code for a project for my students. Just had to clean it up a bit and organize the code into parts they should be reading (game logic) and parts they should ignore unless they're really curious (mostly the OpenGL stuff).
Pyglet is vastly more pythonic than pygame for writing games. I have found it much easier to teach pyglet for newcomers and the code is easier to read too. Since it uses ctypes, it is very easy to port pyglet to a platform that supports OpenGL.
Unfortunately there is very little momentum in the project. Last year an alpha version was released after a gap of two years. I truly hope that pyglet gets the popularity it deserves.
These seemingly "big" games written in a handful of lines of code always make me feel very, very stupid. I know if I made this, I could easily imagine writing 50,000 lines.
How do people do this? How do their minds work?
This is incredibly inspiring for young kids. I am going to study this so I can teach it to my younger brother who loves Minecraft and is trying to learn Python.
I think everyone forgets that Minecraft's big feature is not its graphics or its gameplay, it's the procedural content generation. Almost anyone could learn to do Minecraft-level graphics in a few weeks, and the level of interactions (combat, crafting, moving things) could be reasonably approximated, too. But its procedural content generation algorithm is quite complex. You're not going to make an algorithm quite as nice as Minecraft's without a lot of research, a lot of hard work, and a lot of tweaking time.
More than 100 lines of this are textures!
Got this error though. Any ideas?
OSError: dlopen(/System/Library/Frameworks/QuickTime.framework/QuickTime, 6): no suitable image found. Did find: /System/Library/Frameworks/QuickTime.framework/QuickTime: mach-o, but wrong architecture /System/Library/Frameworks/QuickTime.framework/QuickTime: mach-o, but wrong architecture
[rant mode on]
1. 80% of the bang takes 20% of the time
2. Writing games is 99% fine tuning and game play
3. It's just a rendering exercise, certainly not a "clone"
FYI: The above is "the internet" in three lines! :-)
[rant mode off]
Software has a habit of becoming exponentially complex as the featureset increases, so I am not that impressed by small code if you cut features aggressively.
To prove a point, I wrote a minecraft clone in about 60 lines of code (10x less than the Python version). It cuts a few more corners (no textures, no gravity), but has the basics of world generation, rendering, and most importantly, adding and removing blocks in front of the crosshairs to build (see the little arch I made in the middle):
http://i.imgur.com/ZZWFkXn.jpg
It's written in Lobster in about 1.5hrs, which is quite similar in features to Python + pyglet. Yes it uses a few high level calls like simplex() and camera_FPS_view(), but these have been part of the Lobster standard library for a while, so I believe that's fair. All code I created for this demo are in that screenshot.
Please...someone put a Udacity course together which backs into the underlying math used to create this (for those of us who didn't have it or don't remember it)...
Nice. Next stop: Dwarf Fortress.
See I look at this and absolutely amazed. I wish I could make something like this but I have no idea of how to event start.
I tried making a Settlers game in Python/PyGame and so far all I have been able to do is generate the board: https://gist.github.com/sareon/5268205 - I've been told I am not properly discretizing the difference between the drawing of the game and the logic of the game which is going to hinder the development of the game.
I have a BSc and an MSc in CS - focusing on NLP and Machine Learning, so I have an idea how to program, just not how to program games like the Minecraft clone or my own Settlers game. I've tried looking for tutorials and resources online and I've followed the InventWithPython which showed me how to make a simple game similar to how I started making my own. Clearly it was inefficient for a larger game.
What are some good resources out there that can help me learn how to make games such as the Minecraft clone or even how to make my own settlers game actually be a useable game?
This is really freaking cool. I can't believe how short the code is.
Just curious, what is it that makes the performance not so great?
Could performance be significantly improved by doing a re-write in Lua, for example? (Probably not... it's probably something in Pyglet itself...)
(FWIW, it's choppy compared to Minecraft, which is obviously much more complex and has a greater rendering distance.)
Jump speed is too fast... if you slow it it works better and is more like minecraft IMHO
elif symbol == key.SPACE: if self.dy == 0: self.dy = 0.500 # jump speedA fork for those having trouble getting this to run on Mountain Lion.
Hook this code up to redstone (the nodejs server also on the front page) and you'll really have something :) Not to detract from the demo, it's really cool!
Could someone annotate this and re-release it. This seems like an awesome learning tool. A little more info about what everything does would go a long way.
I have been teaching my 10 year old Python as an exercise. Recently I've noticed he's getting a little bored and I'm being very careful not to 'sicken' him, as this needs to be fun. I've just shown him the video for this and downloaded the code to show him that its possible in Python. He loves Minecraft (we watched the documentary movie about Mojang) and seeing this has given him a bit more of an interest again
Can we get a JS answer to this in the browser? I'm curious if Three.js can match this level of terseness.
I find this comment a bit distracting, and in poor taste. Everybody knows real minecraft users build castles.building penises out of dirt right now.building castles in the sky.I was thinking of writing something like this to help my girls code. Modding minecraft with Java is fun, but the language gets in the way of beginners. This python version is great for that.
undefined
This works on PyPy (Pyglet, and therefore this) by the way.
Just grab Pyglet trunk and install it, and run main.py with pypy instead of with CPython.
This is amazing. I've been playing with it all night. From a high level, what would be a strategy for making this multiplayer?
I remember being as excited about Liero as kids are about Minecraft today. Minecraft is great, but so was Liero.
If anyone are having problems starting this:
* You need Python2 virtualenv,
* You need to install `pyglet` in it,
* Start it with `bin/python main.py`;
I remember the times when I had time and readed this things until I digested them...
How are the graphics being drawn? Is Pyglet being used to so this?
Wow! This is so cool!
This proves Python's ability to be RAD.
This is really amazing, nice job.
This is, in a word, dope.