Skip to content

Commit

Permalink
merge with upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
jminardi committed Apr 3, 2013
2 parents 07d069e + 92723e7 commit a02cd4f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 5 deletions.
75 changes: 74 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,86 @@ Simple Minecraft-inspired demo written in Python and Pyglet.

http://www.youtube.com/watch?v=kC3lwK631X8

## Goals and Vision

I would like to see this project turn into an educational tool. Kids love Minecraft and Python is a great first language.
This is a good opportunity to get children excited about programming.

The code should become well commented and more easily configurable. It should be easy to make some simple changes
and see the results quickly.

I think it would be great to turn the project into more of a library / API... a Python package that you import and then
use / configure to setup a world and run it. Something along these lines...

import mc

world = mc.World(...)
world.set_block(x, y, z, mc.DIRT)
mc.run(world)

The API could contain functionality for the following:

- Easily configurable parameters like gravity, jump velocity, walking speed, etc.
- Hooks for terrain generation.

## How to Run

pip install pyglet
git clone https://github.com/fogleman/Minecraft.git
cd Minecraft
python main.py

On Mac OS X, you may have an issue with running Pyglet in 64-bit mode. Try this...
### Mac

On Mac OS X, you may have an issue with running Pyglet in 64-bit mode. Try running Python in 32-bit mode first:

arch -i386 python main.py

If that doesn't work, set Python to run in 32-bit mode by default:

defaults write com.apple.versioner.python Prefer-32-Bit -bool yes

This assumes you are using the OS X default Python. Works on Lion 10.7 with the default Python 2.7, and may work on other versions too. Please raise an issue if not.

Or try Pyglet 1.2 alpha, which supports 64-bit mode:

pip install https://pyglet.googlecode.com/files/pyglet-1.2alpha1.tar.gz

### If you don't have pip or git

For pip:

- Mac or Linux: install with `sudo easy_install pip` (Mac or Linux) - or (Linux) find a package called something like 'python-pip' in your package manager.
- Windows: [install Distribute then Pip](http://stackoverflow.com/a/12476379/992887) using the linked .MSI installers.

For git:

- Mac: install [Homebrew](http://mxcl.github.com/homebrew/) first, then `brew install git`.
- Windows or Linux: see [Installing Git](http://git-scm.com/book/en/Getting-Started-Installing-Git) from the _Pro Git_ book.

See the [wiki](https://github.com/fogleman/Minecraft/wiki) for this project to install Python, and other tips.

## How to Play

### Moving

- W: forward
- S: back
- A: strafe left
- D: strafe right
- Mouse: look around
- Space: jump
- Tab: toggle flying mode

### Building

- Selecting type of block to create:
- 1: brick
- 2: grass
- 3: sand
- Mouse left-click: remove block
- Mouse right-click: create block

### Quitting

- ESC: release mouse, then close window
15 changes: 11 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pyglet.gl import *
from pyglet.window import key
from ctypes import c_float
import math
import random
import time
Expand Down Expand Up @@ -347,6 +346,11 @@ def __init__(self, *args, **kwargs):
self.sector = None
self.reticle = None
self.dy = 0
self.inventory = [BRICK, GRASS, SAND]
self.block = self.inventory[0]
self.num_keys = [
key._1, key._2, key._3, key._4, key._5,
key._6, key._7, key._8, key._9, key._0]
self.model = Model()
self.label = pyglet.text.Label('', font_name='Arial', font_size=18,
x=10, y=self.height - 10, anchor_x='left', anchor_y='top',
Expand Down Expand Up @@ -462,7 +466,7 @@ def on_mouse_press(self, x, y, button, modifiers):
self.model.remove_block(block)
else:
if previous:
self.model.add_block(previous, BRICK)
self.model.add_block(previous, self.block)
else:
self.set_exclusive_mouse(True)

Expand Down Expand Up @@ -490,6 +494,9 @@ def on_key_press(self, symbol, modifiers):
self.set_exclusive_mouse(False)
elif symbol == key.TAB:
self.flying = not self.flying
elif symbol in self.num_keys:
index = (symbol - self.num_keys[0]) % len(self.inventory)
self.block = self.inventory[index]

def on_key_release(self, symbol, modifiers):
if symbol == key.W:
Expand Down Expand Up @@ -573,7 +580,7 @@ def draw_reticle(self):

def setup_fog():
glEnable(GL_FOG)
glFogfv(GL_FOG_COLOR, (c_float * 4)(0.53, 0.81, 0.98, 1))
glFogfv(GL_FOG_COLOR, (GLfloat * 4)(0.5, 0.69, 1.0, 1))
glHint(GL_FOG_HINT, GL_DONT_CARE)
glFogi(GL_FOG_MODE, GL_LINEAR)
glFogf(GL_FOG_DENSITY, 0.35)
Expand All @@ -582,7 +589,7 @@ def setup_fog():


def setup():
glClearColor(0.53, 0.81, 0.98, 1)
glClearColor(0.5, 0.69, 1.0, 1)
glEnable(GL_CULL_FACE)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
Expand Down
Binary file modified texture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a02cd4f

Please sign in to comment.