# -*- coding: utf-8 -*- import pygame import random import api.Image as Image from api.Game import CGame from api.GameState import CGameState from api.Button import CButton from api.Sprite2 import CSprite from api.Points import CPoints from api.Globe import Globe import HallState from gettext import gettext as _ from assets.data import area1game3_data class CArea1Game3(CGameState): def __init__(self): CGameState.__init__(self) self.mBackground = None self.mButtonBack = None self.mLabelQuestion = None self.mButtonTrue = None self.mButtonFalse = None self.mBoy = None self.mGirl = None self.mDialogBoy1 = None self.mDialogGirl1 = None self.mDialogBoy2 = None self.mDialogGood = None self.mDialogBad = None self.mActualQuestionN = None self.mTupleQuestion = None self.mQuestionAnswered = False self.mQuestionShowed = False self.mQuestionCorrect = False self.mActiveDialog = None self.mboy_list = [] self.mgirl_list = [] self.mCurrentState = 0 self.time = 0 self.mBad = 0 self.mGood = 0 self.mBackground = Image.loadImage('assets/images/a1g3/a1game3.png', False) CGame().setBackground(self.mBackground) # get a list of the keys of dict BOY and GIRL self.mboy_list = area1game3_data.BOY.keys() self.mBoyDict = {} for i in self.mboy_list: t = area1game3_data.BOY[i] q = (unicode(t[0], 'UTF-8'), t[1]) self.mBoyDict[i] = q self.mgirl_list = area1game3_data.GIRL.keys() self.mGirlDict = {} for i in self.mgirl_list: t = area1game3_data.GIRL[i] q = (unicode(t[0], 'UTF-8'), t[1]) self.mGirlDict[i] = q self.mDialog = [] for e in area1game3_data.DIALOG: self.mDialog.append(unicode(e, 'UTF-8')) self.mInitB = unicode(area1game3_data.INITB, 'UTF-8') self.mInitG = unicode(area1game3_data.INITG, 'UTF-8') self.mGoodA = unicode(area1game3_data.GOOD, 'UTF-8') self.mBadA = unicode(area1game3_data.BAD, 'UTF-8') # randomize it random.shuffle(self.mboy_list) random.shuffle(self.mgirl_list) self.mBsetted = False self.mNsetted = True self.mBackImageN = Image.loadImage('assets/images/back.png') self.mBackImageB = Image.loadImage('assets/images/back_big.png') self.mButtonBack = CSprite() self.mButtonBack.setRegistrationPointOffset(22, 22) self.mButtonBack.setXY(1170, 30) self.mButtonBack.setImage(self.mBackImageN) CGame().addChild(self.mButtonBack) self.mLabelQuestion = Globe((500, 250), pico='None', text=' ') self.mLabelQuestion.set_center((600, 250)) self.mButtonTrue = CButton() self.mButtonTrue.set_bgColor((125, 255, 125)) self.mButtonTrue.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 28) self.mButtonTrue.set_center((460, 400)) self.mButtonTrue.set_size((200, 40)) self.mButtonTrue.set_text(_('Verdadero')) self.mButtonFalse = CButton() self.mButtonFalse.set_bgColor((125, 255, 125)) self.mButtonFalse.font = pygame.font.Font('assets/fonts/DejaVuSans.ttf', 28) self.mButtonFalse.set_center((740, 400)) self.mButtonFalse.set_size((200, 40)) self.mButtonFalse.set_text(_('Falso')) self.mBoy = CSprite() self.mBoy.loadImage('assets/images/a1g3/Juan-chico-costado-parado.png') self.mBoy.setXY(100, 400) CGame().addChild(self.mBoy) elisa = Image.loadImage('assets/images/a1g3/Elisa-chica-costado-parada.png') elisa_rotated = pygame.transform.flip(elisa, True, False) self.mGirl = CSprite() self.mGirl.setImage(elisa_rotated) self.mGirl.setXY(900, 400) CGame().addChild(self.mGirl) # sabes que le pasa self.mDialogBoy1 = Globe((300, 170), text=self.mDialog[0]) self.mDialogBoy1.set_center((300, 300)) CGame().addChild(self.mDialogBoy1) # mmm.. no... self.mDialogGirl1 = Globe((200, 100), pico='right', text=self.mDialog[1]) self.mDialogGirl1.set_center((900, 300)) # a ver.. self.mDialogBoy2 = Globe((200, 100), pico='left', text=self.mDialog[2]) self.mDialogBoy2.set_center((300, 300)) self.mDialogGood = Globe((200, 75), pico='left', text=self.mGoodA) self.mDialogGood.set_center((300, 300)) self.mDialogBad = Globe((200, 75), pico='left', text=self.mBadA) self.mDialogBad.set_center((300, 300)) self.mPoints = CPoints() self.mPoints.setXY(250, 10) CGame().addChild(self.mPoints) #self.mTime = self.mDialogBoy1.getTimeState() self.mCurrentState = 0 self.time = 0 def update(self): CGameState.update(self) self.time = self.time + 1 if self.mButtonBack.mouseOver(): if not(self.mBsetted): self.mBsetted = True self.mNsetted = False self.mButtonBack.setRegistrationPointOffset(27, 27) self.mButtonBack.setImage(self.mBackImageB) else: if not(self.mNsetted): self.mBsetted = False self.mNSetted = True self.mButtonBack.setRegistrationPointOffset(22, 22) self.mButtonBack.setImage(self.mBackImageN) if self.mButtonBack.clicked(): #print "clicked back of a1g3" hs = HallState.CHallState() CGame().setState(hs) hs.setCurrentGame(2) return if self.mCurrentState == 0: #self.time = self.mListDialogs[0].getTimeState() if self.time > 4*30: CGame().removeChild(self.mDialogBoy1) CGame().addChild(self.mDialogGirl1) self.mCurrentState = 1 self.time = 0 #self.mListDialogs[1].setTimeState(0) elif self.mCurrentState == 1: #self.time = self.mListDialogs[1].getTimeState() if self.time > 3*30: CGame().removeChild(self.mDialogGirl1) CGame().addChild(self.mDialogBoy2) self.mCurrentState = 2 self.time = 0 #self.mListDialogs[2].setTimeState(0) elif self.mCurrentState == 2: #self.time = self.mListDialogs[2].getTimeState() if self.time > 3*30: CGame().removeChild(self.mDialogBoy2) self.mCurrentState = 3 # Pregunta elif self.mCurrentState == 3: if self.mQuestionShowed == False: self.next_questionB() CGame().addChild(self.mLabelQuestion) CGame().addChild(self.mButtonTrue) CGame().addChild(self.mButtonFalse) self.mQuestionShowed = True elif (self.mQuestionAnswered == False): if self.mButtonTrue.clicked(): CGame().removeChild(self.mLabelQuestion) CGame().removeChild(self.mButtonTrue) CGame().removeChild(self.mButtonFalse) if self.mTupleQuestion[1] == True: CGame().addChild(self.mDialogGood) self.mGood = self.mGood + 1 self.mPoints.set_goods(self.mGood) else: CGame().addChild(self.mDialogBad) self.mBad = self.mBad + 1 self.mPoints.set_bads(self.mBad) self.mQuestionAnswered = True self.time = 0 elif self.mButtonFalse.clicked(): CGame().removeChild(self.mLabelQuestion) CGame().removeChild(self.mButtonTrue) CGame().removeChild(self.mButtonFalse) if self.mTupleQuestion[1] == False: CGame().addChild(self.mDialogGood) self.mGood = self.mGood + 1 self.mPoints.set_goods(self.mGood) else: CGame().addChild(self.mDialogBad) self.mBad = self.mBad + 1 self.mPoints.set_bads(self.mBad) self.mQuestionAnswered = True self.time = 0 elif self.mQuestionAnswered == True: #self.time = self.mActiveDialog.getTimeState() if self.time > 3*30: CGame().removeChild(self.mDialogGood) CGame().removeChild(self.mDialogBad) self.mQuestionShowed = False self.mQuestionAnswered = False self.mActiveDialog = None def next_questionB(self): if not(self.mboy_list == []): self.mActualQuestionN = self.mboy_list.pop() self.mTupleQuestion = self.mBoyDict[self.mActualQuestionN] text = self.mInitB + '\n' + self.mTupleQuestion[0] self.mLabelQuestion.set_text(text) return True else: return False def next_questionG(self): if not(self.mgirl_list == []): self.mActualQuestionN = self.mgirl_list.pop() self.mTupleQuestion = self.mGirlDict[self.mActualQuestionN] text = self.mInitG + '\n' + self.mTupleQuestion[0] self.mLabelQuestion.setText(text) return True else: return False def destroy(self): CGameState.destroy(self) CGame().removeChild(self.mButtonBack) CGame().removeChild(self.mLabelQuestion) CGame().removeChild(self.mButtonTrue) CGame().removeChild(self.mButtonFalse) CGame().removeChild(self.mBoy) CGame().removeChild(self.mGirl) CGame().removeChild(self.mDialogBoy1) CGame().removeChild(self.mDialogGirl1) CGame().removeChild(self.mDialogBoy2) CGame().removeChild(self.mDialogGood) CGame().removeChild(self.mDialogBad) CGame().removeChild(self.mPoints) self.mButtonBackA1G3 = None self.mLabelQuestion = None self.mButtonTrue = None self.mButtonFalse = None self.mBoy = None self.mGirl = None self.mDialogBoy1 = None self.mDialogGirl1 = None self.mDialogBoy2 = None self.mDialogGood = None self.mDialogBad = None self.mPoints = None