diff options
Diffstat (limited to 'src/states/Area1Game1.py')
-rwxr-xr-x | src/states/Area1Game1.py | 118 |
1 files changed, 99 insertions, 19 deletions
diff --git a/src/states/Area1Game1.py b/src/states/Area1Game1.py index f00b409..7485e1a 100755 --- a/src/states/Area1Game1.py +++ b/src/states/Area1Game1.py @@ -1,17 +1,38 @@ +import pygame + import api.Sprite from api.Sprite import CSprite +from api.Vector import CVector + +import api.Game +from api.Game import CGame + +import states.GameState +from states.GameState import CGameState + +import api.Button +from api.Button import CButton + +import api.Image as Image + +import MenuState +from MenuState import * + +STATE_STALE = 0 +STATE_DRAG = 1 +STATE_ADJUST = 2 +STATE_RETURN = 3 +STATE_OK = 4 + #Piece class hereda de CSprite class Piece(CSprite): - STATE_STALE = 0 - STATE_DRAG = 1 - STATE_ADJUST = 2 - STATE_RETURN = 3 - STATE_OK = 4 - mState = STATE_NONE + + #mState = STATE_NONE + mState = None MIN_DISTANCE = 40 @@ -24,10 +45,8 @@ class Piece(CSprite): def init(self, aXOrigin, aYOrigin, aXDest, aYDest): setState(STATE_STALE) - mXOrigin = aXOrigin - mYOrigin = aYOrigin - mXDest = aXDest - mYDest = aYdest + self.mOrigin = CVector(aXOrigin, aYOrigin) + self.mDest = VCector(aXDest, aYDest) setMaxVel(10, 10) @@ -37,15 +56,15 @@ class Piece(CSprite): def update(self): if (aState == STATE_STALE): - if (mouse se cliquea encima del objeto): + if self.mouseDown(): self.setState(STATE_DRAG) return - if (aState = STATE_DRAG): - x = mouse x - y = mouse y - if (se suelta el mouse): - if CMath.dist(x, y, mXDest, mYDest) < MIN_DISTANCE): + if (aState == STATE_DRAG): + #x = self.mPos + pass + if self.clicked(): + if (CMath.dist(x, y, mXDest, mYDest) < MIN_DISTANCE): self.setState(STATE_ADJUST) else: self.setState(STATE_RETURN) @@ -57,7 +76,7 @@ class Piece(CSprite): if (aState == STATE_RETURN): if (CMath.dist(x, y, mXOrigin, mYOrigin) < RADIUS_COLLISION): - play(Sonido mal) + #play(Sonido mal) self.setState(STATE_STALE) if (aState == STATE_OK): return @@ -72,14 +91,14 @@ class Piece(CSprite): #eliminar la imagen creada - def setState(aState): + def setState(self, aState): if (aState == STATE_STALE): x = mXOrigin y = mYOrigin velX = 0 velY = 0 - if (aState = STATE_DRAG): + if (aState == STATE_DRAG): velX = 0 velY = 0 if (aState == STATE_ADJUST): @@ -102,3 +121,64 @@ class Piece(CSprite): return mState +class CArea1Game1(CGameState): + + mBackground = None + mInstructions = None + #mX = 10 + mButtonPlay = None + + #def __init__(self): + # ''' + # Constructor + # ''' + + def init(self): + CGameState.init(self) + #self.mInstructions = CMultiLabel() + #CGame().addChild(self.mInstructions) + #print self.mX + + self.mButtonBack = CButton() + #TODO: Create a function to create image. + self.mButtonBack.bgColor = (0x99, 0x99, 0x66) + self.mButtonBack.font = pygame.font.Font('assets/fonts/fipps.ttf', 20) + self.mButtonBack.center = (110, 420) + self.mButtonBack.size = (200, 40) + self.mButtonBack.text = "Volver" + CGame().addChild(self.mButtonBack) + + self.mBackground = Image.loadImage('assets/images/back_game.png', False) + CGame().setBackground(self.mBackground) + + # load the zone 1 and 2 for the objects + self.mArea1 = CSprite() + self.mArea1.setImage('assets/images/area1.png', False) + CGame().addChild(self.mArea1) + + def update(self): + #print "menu update" + CGameState.update(self) + + if self.mButtonBack.clicked: + print "clicked menu" + #cs = CHelpState() + ms = MenuState.CMenuState() + CGame().setState(ms) + + #def render(self): + # CGameState.render(self) + # print "CMenuState render" + + def destroy(self): + CGameState.destroy(self) + #self.mInstructions.destroy() + self.mInstructions = None + CGame().removeChild(self.mButtonPlay) + #self.mButtonPlay.destroy() + self.mButtonBack = None + self.mBackground = None + print "CMenuState destroy" + + def doEvents(self, aEvent): + print aEvent.type |