Skip to content

Commit

Permalink
commint final
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenver committed Feb 22, 2014
1 parent 6325032 commit 9664bdb
Show file tree
Hide file tree
Showing 9 changed files with 102 additions and 63 deletions.
42 changes: 39 additions & 3 deletions Duelo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def comenzar(self,jugador):
self.show()

def terminar(self):
sleep(0.3)
if(self.jugador.getNivel()==1):
self.observer.update(EscenarioDos(self.jugador,self.observer))
elif(self.jugador.getNivel()==2):
Expand Down Expand Up @@ -87,7 +88,7 @@ def infoJugador(self,painter):
painter.drawText (area, Qt.AlignCenter, text)

def keyPressEvent(self,e):
if e.key()==QtCore.Qt.Key_Right and self.aleatorio==1:
if self.mover and e.key()==QtCore.Qt.Key_Right and self.aleatorio==1:
self.anchopintado=498
if (self.dificultad>1):
self.aleatorio=random.choice(range(3))
Expand All @@ -97,7 +98,7 @@ def keyPressEvent(self,e):
self.pintar.stop=True
print "gano"
self.terminar()
if e.key()==QtCore.Qt.Key_Left and self.aleatorio==2:
if self.mover and e.key()==QtCore.Qt.Key_Left and self.aleatorio==2:
self.anchopintado=498
if (self.dificultad>1):
self.aleatorio=random.choice(range(3))
Expand All @@ -107,7 +108,42 @@ def keyPressEvent(self,e):
self.pintar.stop=True
print "gano"
self.terminar()
if e.key()==QtCore.Qt.Key_X and self.aleatorio==0:
if self.mover and e.key()==QtCore.Qt.Key_X and self.aleatorio==0:
self.anchopintado=498
if (self.dificultad>1):
self.aleatorio=random.choice(range(3))
self.dificultad-=1
else:
self.hilo.stop=True
self.pintar.stop=True
print "gano"
self.terminar()

def derecha(self):
if self.mover and self.aleatorio==1:
self.anchopintado=498
if (self.dificultad>1):
self.aleatorio=random.choice(range(3))
self.dificultad-=1
else:
self.hilo.stop=True
self.pintar.stop=True
print "gano"
self.terminar()
def izquierda(self):
if self.mover and self.aleatorio==2:
self.anchopintado=498
if (self.dificultad>1):
self.aleatorio=random.choice(range(3))
self.dificultad-=1
else:
self.hilo.stop=True
self.pintar.stop=True
print "gano"
self.terminar()

def accion(self):
if self.mover and self.aleatorio==0:
self.anchopintado=498
if (self.dificultad>1):
self.aleatorio=random.choice(range(3))
Expand Down
9 changes: 1 addition & 8 deletions Escenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ def setObserver(self,observer):

def informa(self):
self._observer.update()

def dibujarVidas(self,painter):
vidas=QImage("vida","png")
desplazamiento=0
for i in range (self.jugador.getVidas()):
painter.drawImage(QPoint(10+desplazamiento,10),vidas)
desplazamiento+=55


def deterHilos(self):
pass

8 changes: 4 additions & 4 deletions EscenarioDos.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def paintEvent(self, event):
paint.setBrush(self.jugador.getColor())
paint.drawEllipse(self.jugador.getPosX(),self.jugador.getPosY(),self.jugador.getRadio(),self.jugador.getRadio())
paint.setBrush(Qt.gray)
self.dibujarVidas(paint)
if self.thread_pintarPasadizo!=None:
paint.drawRect(self.tam,Escenario.dimension_y-self.nivel_piso_y,self.thread_pintarPasadizo.valor_X,5)#rectangulo que se mueve
paint.end()
Expand All @@ -80,6 +79,7 @@ def dibujarPisos(self,painter):
painter.drawRect(self.tam,Escenario.dimension_y-20-20,30,20)
painter.drawRect(self.tam+self.nivel_piso_x+2*self.tam-30,Escenario.dimension_y-self.nivel_piso_y-20,30,20)


def derecha(self):
if self.mover==True:
if self.estadoEscenario==EstadoEscenario.pasadizoOff or self.estadoEscenario==EstadoEscenario.pisoTres:
Expand All @@ -98,7 +98,7 @@ def derecha(self):
self.jugador.avanzar()

def izquierda(self):
if self.mover==True and self.jugador.getPosX()>0:
if self.jugador.getPosX()>20 and self.mover==True:
if self.estadoEscenario==EstadoEscenario.pasadizoOff or self.estadoEscenario==EstadoEscenario.pisoTres:
self.jugador.retroceder()
else:
Expand All @@ -122,7 +122,7 @@ def keyPressEvent(self,e):
if e.key()==QtCore.Qt.Key_Right:
self.derecha()

if e.key()==QtCore.Qt.Key_Left:
if self.jugador.getPosX()>20 and e.key()==QtCore.Qt.Key_Left:
self.izquierda()

if e.key()==QtCore.Qt.Key_X:
Expand All @@ -133,7 +133,7 @@ def keyPressEvent(self,e):
self.hilo=Hilo(self,Accion.caidaLibre)
self.hilo.start()

if self.mover==True and self.jugador.getPosX()>3*self.tam+self.nivel_piso_x+self.nivel_piso_x+70:
if self.mover==True and self.jugador.getPosX()>3*self.tam+self.nivel_piso_x+self.nivel_piso_x+75:
self.observer.update2()
self.mover=False
self.detenerHilos()
Expand Down
14 changes: 8 additions & 6 deletions EscenarioTres.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def paintEvent(self, event):
paint.setBrush(self.jugador.getColor())
center = QPoint(self.jugador.getPosX(), self.jugador.getPosY())
paint.drawEllipse(center,self.jugador.getRadio(),self.jugador.getRadio())
self.dibujarVidas(paint)
paint.end()




#se define el movimiento de el jugador
def keyPressEvent(self,e):
if self.mover and e.key()==QtCore.Qt.Key_Right:
Expand All @@ -72,7 +74,7 @@ def keyPressEvent(self,e):
self.hiloCaida.start()
else:
self.repaint()
if self.mover and e.key()==QtCore.Qt.Key_Left:
if self.jugador.getPosX()>20 and self.mover and e.key()==QtCore.Qt.Key_Left:
x=self.jugador.getPosX()
if(x>self._iniPendiente and x<self._finPendiente):
self.jugador.retroceder()
Expand Down Expand Up @@ -113,7 +115,7 @@ def derecha(self):
self.repaint()

def izquierda(self):
if self.mover:
if self.jugador.getPosX()>20 and self.mover:
x=self.jugador.getPosX()
if(x>self._iniPendiente and x<self._finPendiente):
self.jugador.retroceder()
Expand Down Expand Up @@ -199,10 +201,10 @@ def run(self):
self.escenario.repaint()
sleep(0.25)


'''
if __name__=="__main__":
app=QApplication(sys.argv)
jugador=Jugador(0,0,Qt.white,5)
escenario_Tres=EscenarioTres(jugador,None)
escenario_Tres=EscenarioTres()
escenario_Tres.show()
sys.exit(app.exec_())
'''
2 changes: 1 addition & 1 deletion Jugador.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def __init__(self,x,y,c,v):
self._posX=x
self._posY=y
self._color=c
self.vidas=1
self.vidas=3
self._velocidad=v
self._radio=20
self.nivel_actual=1
Expand Down
30 changes: 26 additions & 4 deletions Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import math
from neuroListener import *
from nivel1 import *
from pantallaPerdio import *

class Menu(Escenario,NeuroListener):

Expand All @@ -21,11 +22,17 @@ def __init__(self,*args):
Bt_nuevoJ.setGeometry(360,320,200,65)
Bt_AcercaDe=QPushButton("Acerca De",self)
Bt_AcercaDe.setGeometry(360,450,200,65)
Bt_Instrucciones=QPushButton("Instrucciones",self)
Bt_Instrucciones.setGeometry(360,580,200,65)
self.connect(Bt_nuevoJ, SIGNAL("clicked()"), self.nuevoJuego)
self.connect(Bt_AcercaDe, SIGNAL("clicked()"), self.acercaDe)
self.connect(Bt_Instrucciones, SIGNAL("clicked()"), self.instrucciones)
self.EscenarioActual=None
self.Duelo=Duelo(self)
self.state=0 #si esta en un escenario es 0 , si esta en un duelo es 1
self.inst=None
#self.setDaemon(True)


def nuevoJuego(self):
print "Nuevo Juego"
Expand All @@ -37,19 +44,34 @@ def nuevoJuego(self):
def acercaDe(self):
print "Acerca De"

def instrucciones(self):
print "instrucciones"
self.inst=pantallaPerdio()
self.inst.show()

def update(self, Escenario):
self.State=0
self.state=0
if Escenario!=None:
self.EscenarioActual=Escenario
self.EscenarioActual.mover=True
else:
self.stop=True


self.Pperdio=pantallaPerdio()
sleep(0.1)
self.Pperdio.show()

def perder(self):
self.state=0
self.stop=True
self.close()

def update2(self):
self.State=1
self.state=1
self.Duelo.setJugador(self.Jugador)
self.EscenarioActual.mover=False
self.Duelo.mover=False
self.Duelo.comenzar(self.Jugador)
self.Duelo.mover=True

def paintEvent(self, event):
paint = QPainter()
Expand Down
19 changes: 6 additions & 13 deletions neuroListener.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@

userID = c_uint(0)
user = pointer(userID)
composerPort = c_uint(1726)
timestamp = c_float(0.0)
option = c_int(0)
#composerPort = c_uint(1726)
#timestamp = c_float(0.0)
#option = c_int(0)
state = c_int(0)


Expand All @@ -59,7 +59,7 @@ def __init__(self):
self.stop=False

def logEmoState(self,userID,eState):
print "Accion: ",ES_CognitivGetCurrentAction(eState),"\n"
#print "Accion: ",ES_CognitivGetCurrentAction(eState),"\n"
if(ES_CognitivGetCurrentAction(eState)==0x0020):
self.izquierda()
if(ES_CognitivGetCurrentAction(eState)==0x0002):
Expand All @@ -68,9 +68,7 @@ def logEmoState(self,userID,eState):
self.derecha()
if(ES_CognitivGetCurrentAction(eState)==0x0001):
self.neutro()
print ES_CognitivGetCurrentActionPower(eState)
print "poder: ",ES_CognitivGetCurrentActionPower(eState),"\n"
print '\n'
#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def izquierda(self):
Expand All @@ -80,14 +78,13 @@ def derecha(self):
print "derecha\n"

def neutro(self):
print "neutral\n"
pass

def accion(self):
print "push\n"

def conectar(self):
if libEDK.EE_EngineRemoteConnect("127.0.0.1",3008)!=0:
print "Emotiv Engine start up failed."
eProfile = libEDK.EE_ProfileEventCreate()
libEDK.EE_GetBaseProfile(eProfile)
libEDK.EE_GetUserProfile(userID, eProfile)
Expand All @@ -100,18 +97,14 @@ def run(self):
if state == 0:
eventType = libEDK.EE_EmoEngineEventGetType(eEvent)
libEDK.EE_EmoEngineEventGetUserId(eEvent, user)
if eventType == 64: #libEDK.EE_Event_enum.EE_EmoStateUpdated
if eventType == 64:
libEDK.EE_EmoEngineEventGetEmoState(eEvent,eState)
timestamp = ES_GetTimeFromStart(eState)
print "%10.3f New EmoState from user %d ...\r" %(timestamp,userID.value)
self.logEmoState(userID,eState)
elif state != 0x0600:
print "Internal error in Emotiv Engine ! "
time.sleep(0.1)
if self.stop==True:
break
self.desconectar()
print "TERMINE"


def desconectar(self):
Expand Down
20 changes: 9 additions & 11 deletions nivel1.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ def paintEvent(self, event):
paint.setPen(pen)
paint.drawLine(650,520,650+corxPuente,520-coryPuente) # dibuja el puente
self.pintarPalanca(paint)
self.dibujarVidas(paint)
if (self.jugador!=None):
self.pintarJugador(paint)
paint.end()
Expand Down Expand Up @@ -101,13 +100,12 @@ def setAngle(self,angulo):
def derecha(self):
if self.mover :
self.trasladarJugador()
self.repaint()

if self.mover:
self.repaint()
def izquierda(self):
if self.mover:
if self.jugador.getPosX()>20 and self.mover:
self.jugador.retroceder()
self.repaint()

def accion(self):
if self.mover:
self.flaqPalanca=True
Expand All @@ -117,9 +115,10 @@ def accion(self):
def keyPressEvent(self,e):
if self.mover and e.key()==QtCore.Qt.Key_Right:
self.trasladarJugador()
self.repaint()
if self.mover:
self.repaint()

elif self.mover and e.key()==QtCore.Qt.Key_Left:
elif self.jugador.getPosX()>20 and self.mover and e.key()==QtCore.Qt.Key_Left:
self.jugador.retroceder()
self.repaint()

Expand Down Expand Up @@ -161,8 +160,7 @@ def Perdio(self):
print("perdiste")
self.mover=False
self.close()
self.p.show()
self.observer.update(None)
self.observer.perder()


def Gano(self):
Expand Down Expand Up @@ -218,16 +216,16 @@ def run(self):
else:
if (self.escenario.jugador.vidas!=0):
self.escenario.jugador.disminuirVidas()
self.escenario.reiniciar()
print ("ha perdido")
break
self.escenario.reiniciar()


'''
if __name__=="__main__":
app=QApplication(sys.argv)
jugador=Jugador(0,0,Qt.white,5)
escenario=EscenarioUno(jugador,None)
escenario=EscenarioUno(jugador)
escenario.show()
sys.exit(app.exec_())
'''
Loading

0 comments on commit 9664bdb

Please sign in to comment.