Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

You can shoot now and collisions are almost ready.

  • Loading branch information...
commit 2edd2822d90d7b61eb9f7b2ec59e5a48efb5ff17 1 parent 5799c6c
@fabianhjr authored
Showing with 46 additions and 19 deletions.
  1. +32 −13 Engine/__main__.py
  2. +1 −0  Engine/loaders/obj.py
  3. +13 −6 Engine/object.py
View
45 Engine/__main__.py
@@ -29,7 +29,7 @@
##########
# Variables Globales
-global nRun, nTime, tick
+global nRun, nTime, tick, nWait
##########
# Funciones Globales
@@ -37,7 +37,7 @@ def typePrint(string):
for i in str(string):
stdout.write(i)
sys.stdout.flush()
- sleep(0.1)
+ sleep(0.05)
def login():
print """
@@ -102,19 +102,23 @@ def init():
# Add objects
object.create("resources/models/skybox.obj", {"id": "skybox", "pos": [0, 0, 0, 000], "scale": 30})
- object.create("resources/models/Pejuang_Final.obj", {"id": "player", "pos": [0, 0, 0, 100], "rot": [90,0,0]})
+ object.create("resources/models/Pejuang_Final.obj", {"id": "player", "pos": [0, 0, 0, 100], "rot": [90,0,0], "drag": 10.0})
+ object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
+ object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
+ object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
# Control de flujo
- global nRun, nTime, tick
- nRun = time()
+ global nRun, nTime, nWait, tick
+ nRun = time() + 3.0
nTime = 1.0 / config.fps
+ nWait = 0
tick = 0
# Info
print "OpenGL: ", glGetString(GL_VERSION), ", GLSL: ", glGetString(GL_SHADING_LANGUAGE_VERSION)
- login()
+ # login()
# Main Loop
glutFullScreen()
@@ -143,19 +147,29 @@ def display():
# Escena
glutSolidSphere(100,20, 20)
+ # GUI
+ glRasterPos(pos[0]*2 - 10, pos[1]*2 - 10, pos[2]*2)
+ glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_10, "FPS: " + str(config.fps))
+ glRasterPos(pos[0]*2, pos[1]*2, pos[2]*2)
+ glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_10, "Lives: 1")
+
# Pasar a pantalla
glutSwapBuffers()
# Looping and Scheduling
def idle():
- global nRun, nTime, tick
+ global nRun, nTime, nWait, tick
# Scheduling
if nRun - time() < 0:
# En caso de que no se pueda mantener el tiempo
if nRun - time() < -nTime and (tick + 1) % config.fps == 0:
config.fps /= 2
nTime = 1.0 / config.fps
- print config.fps
+
+ # En caso que se pueda duplicar el fps
+ if time() - nWait > nTime and (tick + 1) % config.fps == 0:
+ config.fps *= 2
+ nTime = 1.0 / config.fps
# Tick
nRun += nTime
@@ -164,18 +178,23 @@ def idle():
for i in object.objects: object.objects[i].update()
# Pantalla
glutPostRedisplay()
+ else:
+ if nWait == 0: nWait = time()
+
# Key bindings
def keys(key, x, y):
if key == "" : pass
- elif key == "w": object.objects["player"].force([10,0,0,0])
- elif key == "s": object.objects["player"].force([-10,0,0,0])
- elif key == "a": object.objects["player"].force([0,10,0,0])
- elif key == "d": object.objects["player"].force([0,-10,0,0])
- elif key == "q": object.objects["player"].force([0,0,-10,0])
+ elif key == "w": object.objects["player"].force([100,0,0,0])
+ elif key == "s": object.objects["player"].force([-100,0,0,0])
+ elif key == "a": object.objects["player"].force([0,100,0,0])
+ elif key == "d": object.objects["player"].force([0,-100,0,0])
+ elif key == "q": object.objects["player"].force([0,0,-100,0])
elif key == "e": object.objects["player"].force([0,0,10,0])
# ESC
elif key == chr(27): exit()
+ # Space
+ elif key == chr(32): object.objects["player"].fire()
else: print "No reconocido: ", ord(key)
View
1  Engine/loaders/obj.py
@@ -120,3 +120,4 @@ def draw(self = None):
def aabb():
try: self.aabb
except: self.aabb = [map(min, [i for i in self.vertices]), map(max, [i for i in self.vertices])]
+ return self.aabb
View
19 Engine/object.py
@@ -33,6 +33,7 @@ def __init__(self, resource):
self._prop["rot"] = [0.0,0.0,0.0]
self._prop["scale"] = 1.0
self._prop["mass"] = 1.0
+ self._prop["drag"] = 1.0
self._prop["health"] = float("inf")
self._prop["forces"] = []
self._prop["res"] = resource
@@ -42,7 +43,7 @@ def update(self):
if self._prop["health"] < 0: del self
# Friccion
- self._prop["vec"] = [i / 1.5 for i in self._prop["vec"]]
+ self._prop["vec"] = [(i / self._prop["drag"]) for i in self._prop["vec"]]
# Fuerzas
for force in self._prop["forces"]:
@@ -62,11 +63,9 @@ def update(self):
if objects[i] == self: continue
dist = 0
- # TODO
- #for j,l in objects[i]._prop["pos"], self._prop["pos"]:
- # dist += (j-l) if (j-l) > (l-j) else (l-j)
- #dist *= dist
- #if dist < 10**2: print "Collision"
+ # TODO AAB Physics
+ for i in objects:
+ pass
def force(self, force = [0,0,0,0]):
self._prop["forces"].append([float(i) / self._prop["mass"] for i in force])
@@ -107,3 +106,11 @@ def draw(self):
resourcemanager.get(self._prop["res"]).draw()
glPopMatrix()
+
+ def fire(self):
+ create("resources/models/skybox.obj",
+ {"pos": self._prop["pos"][:3] + [120],
+ "vec": [sin(radians(self._prop["pos"][2])) * 100,
+ cos(radians(self._prop["pos"][2])) * 100, 0, 0],
+ "scale": 0.5,
+ "class": "bullet"})
Please sign in to comment.
Something went wrong with that request. Please try again.