예제 #1
0
    def __init__(self, background, cursor, pointer):
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        # Background
        self.back = background

        # Level
        self.level = Level_Tutorial(background)

        # Graphic components
        #Blackboard
        self.blackboard = OnscreenImage(image="./tex/blackboard_empty.png",
                                        pos=(0, 0, 0),
                                        hpr=None,
                                        scale=(1.25, 1.0, 0.90),
                                        color=None,
                                        parent=None,
                                        sort=0)
        self.blackboard.setTransparency(TransparencyAttrib.MAlpha)
        self.blackboard.hide()
        #Main Character
        self.char = CMain(-18, -5, 59)
        #Energy Bar
        self.energyBar = BEnergy()
        self.energyBar.increase(50)
        #Abilies Bar
        self.grainAbility = BAbility("GRAIN")
        self.fruitAbility = BAbility("FRUIT")
        self.milkAbility = BAbility("MILK")
        self.vegetableAbility = BAbility("VEGETABLE")
        self.fishAbility = BAbility("FISH")
        #Shape
        self.shape = OnscreenImage(image="./tex/cereal_ability_shape.png",
                                   pos=(-0.75, 0, 0),
                                   hpr=None,
                                   scale=0.25,
                                   color=None,
                                   parent=None,
                                   sort=1)
        self.shape.setTransparency(TransparencyAttrib.MAlpha)
        self.shape.hide()
        #Item
        self.item = OnscreenImage(image="./tex/rice.png",
                                  pos=(-0.75, 0, -0.4),
                                  hpr=None,
                                  scale=0.09,
                                  color=None,
                                  parent=None,
                                  sort=1)
        self.item.setTransparency(TransparencyAttrib.MAlpha)
        self.item.hide()
        #Texts
        self.text = OnscreenImage(image="./tex/tryToDrawThisShape.png",
                                  pos=(-0.75, 0, 0.6),
                                  hpr=None,
                                  scale=0.35,
                                  color=None,
                                  parent=None,
                                  sort=1)
        self.text.setTransparency(TransparencyAttrib.MAlpha)
        self.text.hide()
        self.grassText = OnscreenImage(image="./tex/moveThroughTheGrass.png",
                                       pos=(0, 0, 0),
                                       hpr=None,
                                       scale=0.7,
                                       color=None,
                                       parent=None,
                                       sort=1)
        self.grassText.setTransparency(TransparencyAttrib.MAlpha)
        #Info
        self.infError = OnscreenImage(image="./tex/wrong_attack.png",
                                      pos=(0.4, 0, 0),
                                      hpr=None,
                                      scale=(0.47, 1.0, 0.55),
                                      color=None,
                                      parent=None,
                                      sort=5)
        self.infError.setTransparency(TransparencyAttrib.MAlpha)
        self.infError.hide()
        self.infCereal = OnscreenImage(image="./tex/cereal_attack.png",
                                       pos=(0.4, 0, 0),
                                       hpr=None,
                                       scale=0.45,
                                       color=None,
                                       parent=None,
                                       sort=5)
        self.infCereal.setTransparency(TransparencyAttrib.MAlpha)
        self.infCereal.hide()
        self.infFish = OnscreenImage(image="./tex/fish_attack.png",
                                     pos=(0.4, 0, 0),
                                     hpr=None,
                                     scale=0.5,
                                     color=None,
                                     parent=None,
                                     sort=5)
        self.infFish.setTransparency(TransparencyAttrib.MAlpha)
        self.infFish.hide()
        self.infMilk = OnscreenImage(image="./tex/milk_attack.png",
                                     pos=(0.4, 0, 0),
                                     hpr=None,
                                     scale=0.5,
                                     color=None,
                                     parent=None,
                                     sort=5)
        self.infMilk.setTransparency(TransparencyAttrib.MAlpha)
        self.infMilk.hide()
        self.infVege = OnscreenImage(image="./tex/vege_attack.png",
                                     pos=(0.4, 0, 0),
                                     hpr=None,
                                     scale=0.4,
                                     color=None,
                                     parent=None,
                                     sort=5)
        self.infVege.setTransparency(TransparencyAttrib.MAlpha)
        self.infVege.hide()
        self.infFruit = OnscreenImage(image="./tex/fruit_attack.png",
                                      pos=(0.4, 0, 0),
                                      hpr=None,
                                      scale=0.4,
                                      color=None,
                                      parent=None,
                                      sort=5)
        self.infFruit.setTransparency(TransparencyAttrib.MAlpha)
        self.infFruit.hide()
        #Logo
        self.logo = OnscreenImage(image="./tex/laSalleAlpha.png",
                                  pos=(1.05, 0, -0.85),
                                  hpr=None,
                                  scale=(0.22, 1.0, 0.075),
                                  color=None,
                                  parent=None,
                                  sort=5)
        self.logo.setTransparency(TransparencyAttrib.MAlpha)

        # Others
        self.shapeNum = 0
        self.drawedOK = 0
        self.finished = False
        self.drawing = False
        self.readyForGame = False
        self.inGame = False
        self.busy = False

        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #----------------------------------------------------------TUTORIAL INIT------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        # Glove gestures configuration
        self.cursor = cursor
        self.gestureHandler = GestureRecognition(
            "Gesture_Handler",
            [
                ("1", 0),
                ("2", 0),
                ("3", 0),
                ("4", 0),
                ("6", 0),
                ("7", 0),
                ("8", 0),
                ("9", 0),  #NONE
                ("12", 0),
                ("13", 0),
                ("16", 0),
                ("18", 0),
                ("17", 0),
                ("14", 0),  #NONE
                ("23", 0),
                ("26", 0),
                ("29", 0),
                ("27", 0),
                ("24", 0),
                ("21", 0),  #NONE
                ("36", 0),
                ("39", 0),
                ("38", 0),
                ("34", 0),
                ("31", 0),
                ("32", 0),  #NONE
                ("41", 0),
                ("42", 0),
                ("43", 0),
                ("49", 0),
                ("48", 0),
                ("47", 0),  #NONE
                ("69", 0),
                ("68", 0),
                ("67", 0),
                ("61", 0),
                ("62", 0),
                ("63", 0),  #NONE
                ("74", 0),
                ("71", 0),
                ("72", 0),
                ("76", 0),
                ("79", 0),
                ("78", 0),  #NONE
                ("87", 0),
                ("84", 0),
                ("81", 0),
                ("83", 0),
                ("86", 0),
                ("89", 0),  #NONE
                ("98", 0),
                ("97", 0),
                ("94", 0),
                ("92", 0),
                ("93", 0),
                ("96", 0),  #NONE
                ("93934", 1),  #FRUIT
                ("7624", 2),  #MILK
                ("67616", 3),  #VEGETABLE
                ("183", 4),  #FISH
                ("3434", 5)
            ],  #CEREAL
            self.cursor,
            True,
            1,
            0,
            0)

        self.accept("Gesture_Handler", self.gestureProcessing)

        self.pointer = pointer

        # Events declaration
        self.accept("WM_BUTTON_PRESSED", self.handleBtnPress)
        self.accept("WM_BUTTON_RELEASED", self.handleBtnRelease)

        taskMgr.add(self.taskMove, 'taskMove')
        taskMgr.add(self.taskCollision, 'taskCollision')
        taskMgr.add(self.taskTextGrass, 'taskTextGrass')
예제 #2
0
파일: Game.py 프로젝트: PlumpMath/Glooveth
    def __init__(self, background, cursor, pointer):
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        # Timers
        self.jumpTiming = 0
        self.jumpTime = 0
        self.lastTimeEnergy = 0
        self.energyTimer = None

        # Booleans
        self.jumping = False
        self.drawing = False
        self.attacking = False
        self.busy = False  #true if there are some image on screen making note something
        self.isGameOver = False

        # Auxiliar calculations
        self.vecX = 0
        self.vecY = 0

        # Graphic components
        #Blackboard
        self.blackboard = OnscreenImage(image="./tex/blackboard.png",
                                        pos=(0, 0, 0),
                                        hpr=None,
                                        scale=(1.25, 1.0, 0.90),
                                        color=None,
                                        parent=None,
                                        sort=0)
        self.blackboard.setTransparency(TransparencyAttrib.MAlpha)
        self.blackboard.hide()
        self.distXPointDraw = 0.0
        self.distYPointDraw = 0.0
        #Level
        self.level = Level_1(background)
        #Main Character
        self.char = CMain(-18, -5, 59)
        #Energy Bar
        self.energyBar = BEnergy()
        self.energyBar.increase(50)
        #Life Bar
        self.lifes = BLifes()
        self.lifes.increase(1)
        self.lifes.increase(1)
        self.lifes.increase(1)
        #Special Items Bar
        self.specialItems = BSpecial()
        #Abilies Bar
        self.grainAbility = BAbility("GRAIN")
        self.fruitAbility = BAbility("FRUIT")
        self.milkAbility = BAbility("MILK")
        self.vegetableAbility = BAbility("VEGETABLE")
        self.fishAbility = BAbility("FISH")
        #Info
        self.infError = OnscreenImage(image="./tex/wrong_attack.png",
                                      pos=(0.4, 0, 0),
                                      hpr=None,
                                      scale=(0.47, 1.0, 0.55),
                                      color=None,
                                      parent=None,
                                      sort=5)
        self.infError.setTransparency(TransparencyAttrib.MAlpha)
        self.infError.hide()
        self.infCereal = OnscreenImage(image="./tex/cereal_attack.png",
                                       pos=(0.4, 0, 0),
                                       hpr=None,
                                       scale=0.45,
                                       color=None,
                                       parent=None,
                                       sort=5)
        self.infCereal.setTransparency(TransparencyAttrib.MAlpha)
        self.infCereal.hide()
        self.infCerealError = OnscreenImage(
            image="./tex/cereal_not_attack.png",
            pos=(0.4, 0, 0),
            hpr=None,
            scale=0.45,
            color=None,
            parent=None,
            sort=5)
        self.infCerealError.setTransparency(TransparencyAttrib.MAlpha)
        self.infCerealError.hide()
        self.infFish = OnscreenImage(image="./tex/fish_attack.png",
                                     pos=(0.4, 0, 0),
                                     hpr=None,
                                     scale=0.5,
                                     color=None,
                                     parent=None,
                                     sort=5)
        self.infFish.setTransparency(TransparencyAttrib.MAlpha)
        self.infFish.hide()
        self.infFishError = OnscreenImage(image="./tex/fish_not_attack.png",
                                          pos=(0.4, 0, 0),
                                          hpr=None,
                                          scale=0.5,
                                          color=None,
                                          parent=None,
                                          sort=5)
        self.infFishError.setTransparency(TransparencyAttrib.MAlpha)
        self.infFishError.hide()
        self.infMilk = OnscreenImage(image="./tex/milk_attack.png",
                                     pos=(0.4, 0, 0),
                                     hpr=None,
                                     scale=0.5,
                                     color=None,
                                     parent=None,
                                     sort=5)
        self.infMilk.setTransparency(TransparencyAttrib.MAlpha)
        self.infMilk.hide()
        self.infMilkError = OnscreenImage(image="./tex/milk_not_attack.png",
                                          pos=(0.4, 0, 0),
                                          hpr=None,
                                          scale=0.5,
                                          color=None,
                                          parent=None,
                                          sort=5)
        self.infMilkError.setTransparency(TransparencyAttrib.MAlpha)
        self.infMilkError.hide()
        self.infVege = OnscreenImage(image="./tex/vege_attack.png",
                                     pos=(0.4, 0, 0),
                                     hpr=None,
                                     scale=0.4,
                                     color=None,
                                     parent=None,
                                     sort=5)
        self.infVege.setTransparency(TransparencyAttrib.MAlpha)
        self.infVege.hide()
        self.infVegeError = OnscreenImage(image="./tex/vege_not_attack.png",
                                          pos=(0.4, 0, 0),
                                          hpr=None,
                                          scale=0.4,
                                          color=None,
                                          parent=None,
                                          sort=5)
        self.infVegeError.setTransparency(TransparencyAttrib.MAlpha)
        self.infVegeError.hide()
        self.infFruit = OnscreenImage(image="./tex/fruit_attack.png",
                                      pos=(0.4, 0, 0),
                                      hpr=None,
                                      scale=0.4,
                                      color=None,
                                      parent=None,
                                      sort=5)
        self.infFruit.setTransparency(TransparencyAttrib.MAlpha)
        self.infFruit.hide()
        self.infFruitError = OnscreenImage(image="./tex/fruit_not_attack.png",
                                           pos=(0.4, 0, 0),
                                           hpr=None,
                                           scale=0.4,
                                           color=None,
                                           parent=None,
                                           sort=5)
        self.infFruitError.setTransparency(TransparencyAttrib.MAlpha)
        self.infFruitError.hide()
        #Logo
        self.logo = OnscreenImage(image="./tex/laSalleAlpha.png",
                                  pos=(1.05, 0, -0.85),
                                  hpr=None,
                                  scale=(0.22, 1.0, 0.075),
                                  color=None,
                                  parent=None,
                                  sort=5)
        self.logo.setTransparency(TransparencyAttrib.MAlpha)

        # Sounds
        self.winMusic = base.loadMusic('./sound/win.wav')
        self.winMusic.setVolume(.5)
        self.winMusic.setLoopCount(1)
        self.gameOverMusic = base.loadMusic('./sound/lose.wav')
        self.gameOverMusic.setVolume(.5)
        self.gameOverMusic.setLoopCount(1)
        self.allSpecial = base.loadSfx('./sound/win_mysterious.wav')
        self.allSpecial.setVolume(.7)
        self.allSpecialPlayed = False

        # Others
        self.type = "NONE"
        self.gameover = None
        self.gameActive = True

        #-----------------------------------------------------------------------------------------------------------------------------------------------
        #----------------------------------------------------------------GAME INIT----------------------------------------------------------------------
        #-----------------------------------------------------------------------------------------------------------------------------------------------
        # Glove gestures configuration
        self.cursor = cursor
        self.gestureHandler = GestureRecognition(
            "Gesture_Handler",
            [
                ("1", 0),
                ("2", 0),
                ("3", 0),
                ("4", 0),
                ("6", 0),
                ("7", 0),
                ("8", 0),
                ("9", 0),  #NONE
                ("12", 0),
                ("13", 0),
                ("16", 0),
                ("18", 0),
                ("17", 0),
                ("14", 0),  #NONE
                ("23", 0),
                ("26", 0),
                ("29", 0),
                ("27", 0),
                ("24", 0),
                ("21", 0),  #NONE
                ("36", 0),
                ("39", 0),
                ("38", 0),
                ("34", 0),
                ("31", 0),
                ("32", 0),  #NONE
                ("41", 0),
                ("42", 0),
                ("43", 0),
                ("49", 0),
                ("48", 0),
                ("47", 0),  #NONE
                ("69", 0),
                ("68", 0),
                ("67", 0),
                ("61", 0),
                ("62", 0),
                ("63", 0),  #NONE
                ("74", 0),
                ("71", 0),
                ("72", 0),
                ("76", 0),
                ("79", 0),
                ("78", 0),  #NONE
                ("87", 0),
                ("84", 0),
                ("81", 0),
                ("83", 0),
                ("86", 0),
                ("89", 0),  #NONE
                ("98", 0),
                ("97", 0),
                ("94", 0),
                ("92", 0),
                ("93", 0),
                ("96", 0),  #NONE
                ("93934", 1),  #FRUIT
                ("7624", 2),  #MILK
                ("67616", 3),  #VEGETABLE
                ("183", 4),  #FISH
                ("3434", 5)
            ],  #CEREAL
            self.cursor,
            True,
            1,
            0,
            0)

        self.accept("Gesture_Handler", self.gestureProcessing)

        # Cursor init
        self.pointer = pointer

        # Start tasks
        taskMgr.add(self.taskMove, 'taskMove')
        taskMgr.add(self.taskCollision, 'taskCollision')
        taskMgr.add(self.taskEnergy, 'taskEnergy')
        taskMgr.add(self.taskLevels, 'taskLevels')

        # Events declaration
        self.accept("WM_BUTTON_PRESSED", self.handleBtnPress)
        self.accept("WM_BUTTON_RELEASED", self.handleBtnRelease)