Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic API addition #61

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5043e87
Create mc.py
drohrbaugh9 Apr 2, 2015
96d8a53
Update mc.py
drohrbaugh9 Apr 2, 2015
6f75b23
Update mc.py
drohrbaugh9 Apr 2, 2015
c1659fe
Update mc.py
drohrbaugh9 Apr 3, 2015
f1203ea
Update mc.py
drohrbaugh9 Apr 3, 2015
f84b944
Update mc.py
drohrbaugh9 Apr 3, 2015
de1af30
Update mc.py
drohrbaugh9 Apr 3, 2015
820fd41
Update mc.py
drohrbaugh9 Apr 4, 2015
4ca740e
Remove Model.remove_block as Model.add_block does this already
drohrbaugh9 Apr 17, 2015
586d733
Update mc.py
drohrbaugh9 Apr 17, 2015
fedfc70
Update mc.py, create .gitignore, test.py
Apr 19, 2015
cc31d88
Update .gitignore, main.py, mc.py
Apr 19, 2015
2bc315c
Update mc.py, test.py
Apr 19, 2015
c186ea9
Update mc.py
Apr 19, 2015
810e944
Update mc.py
Apr 19, 2015
873bb02
Update main.py, mc. py
Apr 20, 2015
a2ae2f2
Update mc.py
drohrbaugh9 Apr 20, 2015
f7f3119
Update main.py
drohrbaugh9 Apr 20, 2015
0801254
Update main.py
drohrbaugh9 Apr 20, 2015
a31cd67
Update mc.py
drohrbaugh9 Apr 20, 2015
0a81857
Update mc.py
drohrbaugh9 Apr 20, 2015
288bcf2
New methods in main.Window, add mc.py, test.py
Apr 24, 2015
d620df9
Add .gitignore
Apr 24, 2015
314702b
Remove public initialize function in Model that I had added
Apr 24, 2015
533895b
Update test.py
drohrbaugh9 Apr 24, 2015
4deac37
Return world in main_window method
Apr 24, 2015
8750d35
Update main.py, mc.py, test.py
Apr 26, 2015
41602f0
Update mc.py, test.py
Apr 26, 2015
6162b58
Merge pull request #1 from drohrbaugh9/testing
drohrbaugh9 Apr 28, 2015
cc643a8
Update test.py
Apr 28, 2015
37db5a1
Merge branch 'master' of https://www.github.com/drohrbaugh8/Minecraft
Apr 30, 2015
5a424ee
Merge pull request #2 from drohrbaugh9/testing
drohrbaugh9 Apr 30, 2015
668106e
Merge branch 'master' of https://www.github.com/drohrbaugh9/Minecraft
Apr 30, 2015
bc2d188
Merge branch 'master' of https://www.github.com/drohrbaugh9/Minecraft…
May 24, 2015
f30cb7c
Merge branch 'testing' of https://www.github.com/drohrbaugh9/Minecraf…
May 24, 2015
2049af0
Merge pull request #3 from drohrbaugh9/testing
drohrbaugh9 May 24, 2015
7e4f106
Update README.md
drohrbaugh9 May 24, 2015
82ea746
Add texture_original
Oct 13, 2015
57daba5
Add main_original.py
Oct 13, 2015
e982ce1
Add terrain image from Pi Edition
Oct 14, 2015
5b39ee5
Modify and add to texture.png
Oct 14, 2015
e89e00d
Add mc_original.py
Oct 14, 2015
251bb56
Update README.md
Oct 14, 2015
ddc4737
Remove extra files
Oct 15, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*#
*.pyc
54 changes: 48 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,20 @@ class Window(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)

self.walking_speed = WALKING_SPEED

self.flying_speed = FLYING_SPEED

self.gravity = GRAVITY

self.max_jump_height = MAX_JUMP_HEIGHT

self.jump_speed = JUMP_SPEED

self.terminal_velocity = TERMINAL_VELOCITY

self.player_height = PLAYER_HEIGHT

# Whether or not the window exclusively captures the mouse.
self.exclusive = False

Expand Down Expand Up @@ -495,6 +509,29 @@ def set_exclusive_mouse(self, exclusive):
"""
super(Window, self).set_exclusive_mouse(exclusive)
self.exclusive = exclusive

def set_walking_speed(self, speed):
self.walking_speed = speed

def set_flying_speed(self, speed):
self.flying_speed = speed

def set_gravity(self, g):
self.gravity = g
self.jump_speed = math.sqrt(2 * self.gravity * self.max_jump_height)

def set_max_jump_height(self, height):
self.max_jump_height = height
self.jump_speed = math.sqrt(2 * self.gravity * self.max_jump_height)

def set_jump_speed(self, speed):
self.jump_speed = speed

def set_terminal_velocity(self, velocity):
self.terminal_velocity = velocity

def set_player_height(self, height):
self.player_height = height

def get_sight_vector(self):
""" Returns the current line of sight vector indicating the direction
Expand Down Expand Up @@ -585,7 +622,7 @@ def _update(self, dt):

"""
# walking
speed = FLYING_SPEED if self.flying else WALKING_SPEED
speed = self.flying_speed if self.flying else self.walking_speed
d = dt * speed # distance covered this tick.
dx, dy, dz = self.get_motion_vector()
# New position in space, before accounting for gravity.
Expand All @@ -595,12 +632,12 @@ def _update(self, dt):
# Update your vertical speed: if you are falling, speed up until you
# hit terminal velocity; if you are jumping, slow down until you
# start falling.
self.dy -= dt * GRAVITY
self.dy = max(self.dy, -TERMINAL_VELOCITY)
self.dy -= dt * self.gravity
self.dy = max(self.dy, -(self.terminal_velocity))
dy += self.dy * dt
# collisions
x, y, z = self.position
x, y, z = self.collide((x + dx, y + dy, z + dz), PLAYER_HEIGHT)
x, y, z = self.collide((x + dx, y + dy, z + dz), self.player_height)
self.position = (x, y, z)

def collide(self, position, height):
Expand Down Expand Up @@ -722,7 +759,7 @@ def on_key_press(self, symbol, modifiers):
self.strafe[1] += 1
elif symbol == key.SPACE:
if self.dy == 0:
self.dy = JUMP_SPEED
self.dy = self.jump_speed
elif symbol == key.ESCAPE:
self.set_exclusive_mouse(False)
elif symbol == key.TAB:
Expand Down Expand Up @@ -843,7 +880,6 @@ def draw_reticle(self):
glColor3d(0, 0, 0)
self.reticle.draw(GL_LINES)


def setup_fog():
""" Configure the OpenGL fog properties.

Expand Down Expand Up @@ -889,6 +925,12 @@ def main():
setup()
pyglet.app.run()

def main_window(window):
if isinstance (window, Window):
window.set_exclusive_mouse(True)
setup()
pyglet.app.run()


if __name__ == '__main__':
main()
35 changes: 35 additions & 0 deletions mc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import main

class World (main.Window):

def __init__(self):
main.Window.__init__(self, width=800, height=600, caption='Pyglet', resizable=True)

def add_block(self, x, y, z, texture):
position = (x, y - 1, z)
if isinstance(texture, (str, int, float, long)):
if isinstance(texture, str):
texture = texture.upper()
if texture == "SAND" or texture == 1:
texture = SAND
elif texture == "BRICK" or texture == 2:
texture = BRICK
elif texture == "STONE" or texture == 3:
texture = STONE
else:
texture = GRASS
self.model.add_block(position, texture)

def remove_block(self, x, y, z):
position = (x, y - 1, z)
self.model.remove_block(position)

def set_block(self, x, y, z, texture):
self.add_block(x, y, z, texture)

def run(world):
if isinstance(world, main.Window):
main.main_window(world)

def normal_world():
main.main()
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import mc

world = mc.World()
mc.run(world)