Ejemplo n.º 1
0
 def jump(self, game):
     ##Vermutlich nicht notwendig
     # game.checkCollision(self)
     if (jngl.keyDown(jngl.key.Up) or jngl.keyDown(jngl.key.Space)) and self.canJump:
         self.yspeed = -self.jumpSpeed + random.randint(0, 5) / 10.0
         game.sound.addToQueue(self.getSound(self.sound_jump))
     else:
         ##if self.canJump != True: self.game.sound.sound_queue.add(self.getSound(self.sound_land)) ##Play the landing sound, doesnt work right because it gets called ~4times
         self.canJump = True
         self.yspeed = 0
Ejemplo n.º 2
0
    def playSounds(self):

        self.somyeol_count = len(self.game.level.somyeols)
        self.updateSoundsPlaying()

        #Sounds that are used by alot of Somyeols get a special treatment (walking and jumping)

        if jngl.keyDown(jngl.key.Up):
            #Stop other sounds if jumping
            for sound in Somyeol.Somyeol.sound_walk:
                jngl.stop(sound)
            for sound in Somyeol.Somyeol.sound_walk_crowd:
                jngl.stop(sound)

        #play other sounds...
        for sound in self.sound_queue:
            if sound in Somyeol.Somyeol.sound_walk:
                if self.walk_sounds_playing >= self.somyeol_count:
                    continue
            else:
                if self.sounds_playing >= self.somyeol_count:
                    continue
            if not sound in self.playing_sounds:
                jngl.play(sound)
            else:
                #use the crowd sounds
                if sound in Somyeol.Somyeol.sound_jump:
                    sound = Somyeol.Somyeol.sound_jump_crowd[random.randint(0,len(Somyeol.Somyeol.sound_jump_crowd)-1)]
                    if not jngl.isPlaying(sound):
                        jngl.play(sound)
                elif sound in Somyeol.Somyeol.sound_walk:
                    sound = Somyeol.Somyeol.sound_walk_crowd[random.randint(0,len(Somyeol.Somyeol.sound_walk_crowd)-1)]
                    if not jngl.isPlaying(sound):
                        jngl.play(sound)
        self.sound_queue.clear()
Ejemplo n.º 3
0
    def move(self, game):
        self.oldX = self.x
        self.oldY = self.y
        moveSpeed = self.moveSpeed + random.randint(0, 5) / 100.0
        if self.inverted:
            moveSpeed = -moveSpeed
        if jngl.keyDown(jngl.key.Right):
            self.xspeed += moveSpeed
        if jngl.keyDown(jngl.key.Left):
            self.xspeed -= moveSpeed
        self.yspeed += 0.2
        self.xspeed *= 0.97

        self.x += self.xspeed
        # self.y += self.yspeed
        # game.checkCollision(self)
        # self.y -= self.yspeed
        # For boxes we have to check both direction movements individually
        # since we want to know if we can jump
        # if game.checkBoxCollision(self):
        #   self.x -= self.xspeed
        #   self.xspeed = -self.xspeed
        self.y += self.yspeed
        game.checkCollision(self)
        self.collidable.x = self.x
        self.collidable.y = self.y + self.height
        if game.checkBoxCollision(self.collidable):
            if self.yspeed > 0:
                self.y -= self.yspeed + self.error_correction_y
            self.jump(game)

            # if self.yspeed >= 0:
            #    self.jump(game)
            # else:
            #    self.yspeed = -self.yspeed
        else:
            self.canJump = False
        ##Needed to get walking sounds
        # if self.canJump and (self.xspeed > 0.2 or self.xspeed < -0.2):
        #    game.sound.addToQueue(self.getSound(self.sound_walk))
        if self.y + self.height > self.windowHeight:
            self.kill()
        self.error_correction_x = 0
        self.error_correction_y = 0
Ejemplo n.º 4
0
 def jump(self, game):
     self.yspeed = 0
     if jngl.keyDown(jngl.key.Up):
         self.game.sound.addToQueue(self.getSound(self.sound_jump))
Ejemplo n.º 5
0
    def run(self):
        self.camera = 0
        lastTime = jngl.getTime()
        needDraw = True
        timePerStep = 0.01
        counter = 0
        fps = 0
        self.box = None
        self.port1 = None

        while jngl.running():
            x = jngl.getMouseX() - self.camerax
            y = jngl.getMouseY() - self.cameray
            if self.gridEnabled:
                x = int(x / self.gridSize) * self.gridSize
                y = int(y / self.gridSize) * self.gridSize
                if self.box:
                    x += self.gridSize
                    y += self.gridSize
            if jngl.getTime() - lastTime > timePerStep:
                lastTime += timePerStep
                needDraw = True
                if jngl.keyDown("z"):
                    if not self.zoom:
                        self.camerax += self.windowWidth / 2
                        self.cameray += self.windowHeight / 2
                        self.zoom = True
                    # self.gridEnabled = False
                    self.scale = 0.5
                elif self.zoom:
                    self.zoom = False
                    self.camerax -= self.windowWidth / 2
                    self.cameray -= self.windowHeight / 2
                jngl.scale(self.scale)
                self.scale = 1
                if jngl.keyPressed("s"):  # and jngl.keyDown(jngl.key.ControlL):
                    jngl.hideWindow()
                    file = asksaveasfile(mode="wb", defaultextension=".slv", filetypes=[("Somyeol Level", "*.slv")])
                    if file != None:
                        self.level.saveLevel(file)
                        file.close()
                    self.showWindow()

                if jngl.keyPressed("g"):
                    self.toggleGrid()

                if jngl.keyPressed(jngl.key.ControlL) and jngl.keyPressed("n"):
                    self.camerax = 0
                    self.cameray = 0
                    self.level = Map.Map()
                    self.gridEnabled = True
                    self.add10 = False
                    self.scale = 1
                    self.zoom = False

                if jngl.keyPressed("l"):  # and jngl.keyDown(jngl.key.ControlL):
                    jngl.hideWindow()
                    self.level.loadLevel()
                    self.showWindow()

                if jngl.keyPressed("i"):
                    self.addImage(x, y)

                if jngl.keyPressed("t"):
                    jngl.hideWindow()
                    from Game import Game

                    game = Game()
                    tempMap = copy.deepcopy(self.level)
                    game.setMap(tempMap)
                    game.enable_credits = False
                    game.testmode = True
                    game.run()
                    jngl.hideWindow()
                    self.showWindow()
                if jngl.keyPressed("m"):
                    self.add10 = not self.add10

                # Change the Placeable
                if jngl.mousePressed(jngl.mouse.Right) or jngl.keyPressed(jngl.key.PageUp):
                    self.box = None
                    self.port1 = None
                    self.placeable_count += 1
                    if self.placeable_count >= len(self.placeable):
                        self.placeable_count = 0

                if jngl.keyPressed(jngl.key.PageDown):
                    self.box = None
                    self.port1 = None
                    self.placeable_count -= 1
                    if self.placeable_count < 0:
                        self.placeable_count = len(self.placeable) - 1

                for i in range(len(self.quickselect) - 1):
                    if jngl.keyPressed(self.quickselect[i]):
                        self.box = None
                        self.port1 = None
                        self.placeable_count = i % (len(self.placeable))

                if jngl.mousePressed(jngl.mouse.Middle) or jngl.keyPressed(jngl.key.Delete):
                    obj = self.getObjectAt(x, y)
                    lists = (self.level.somyeols, self.level.objects, self.level.images)
                    for l in lists:
                        if obj in l:
                            l.remove(obj)

                if jngl.keyDown(jngl.key.ShiftL) or jngl.keyDown(jngl.key.ShiftR):
                    if jngl.mouseDown(jngl.mouse.Left):
                        self.moveObject(x, y)
                else:
                    self.obj = None
                    if jngl.mousePressed(jngl.mouse.Left):
                        self.addObject(x, y)

                if jngl.keyDown(jngl.key.Right):
                    self.camerax -= 4
                if jngl.keyDown(jngl.key.Left):
                    self.camerax += 4
                if jngl.keyDown(jngl.key.Up):
                    self.cameray += 4
                if jngl.keyDown(jngl.key.Down):
                    self.cameray -= 4

                if (
                    self.cameray / self.scale + self.windowHeight
                ) * self.scale <= self.windowHeight:  # Kamera immer über dem Boden?
                    self.cameray = (self.windowHeight / self.scale - self.windowHeight) * self.scale

                if jngl.keyPressed(jngl.key.Escape):
                    jngl.hideWindow()
                    quit = tkMessageBox.askyesno("Close Editor?", "Do you really want to quit?")
                    if quit:
                        return
                    self.showWindow()
                    jngl.swapBuffers()

            elif needDraw:
                needDraw = False
                jngl.pushMatrix()
                jngl.translate(self.camerax, self.cameray)
                self.level.drawEditor()
                if not self.zoom:
                    if not jngl.keyDown(jngl.key.ShiftL) and not jngl.keyDown(jngl.key.ShiftR):
                        self.placeable[self.placeable_count](x, y).drawPreview()
                        jngl.print(self.placeable[self.placeable_count](x, y).__str__(), x + 40, y)
                        if self.add10:
                            jngl.print("10x", x - 40, y + 10)
                    if self.box:
                        jngl.setColor(100, 100, 100, 100)
                        if len(self.box) > 2:
                            jngl.setColor(255, 100, 100, 100)
                        jngl.drawRect(self.box[0], self.box[1], x - self.box[0], y - self.box[1])
                    elif self.port1:
                        jngl.setColor(255, 50, 50, 100)
                        jngl.drawLine(self.port1.x + 16, self.port1.y + 33, x + 16, y + 33)

                jngl.popMatrix()
                jngl.pushMatrix()
                jngl.translate(self.camerax % self.gridSize, self.cameray % self.gridSize)
                if self.gridEnabled and not self.zoom:
                    jngl.setColor(0, 0, 0, 40)
                    for x in range(0, self.windowWidth, self.gridSize):
                        jngl.drawLine(x, -self.gridSize, x, self.windowHeight)
                    for y in range(0, self.windowHeight, self.gridSize):
                        jngl.drawLine(-self.gridSize, y, self.windowWidth, y)
                jngl.popMatrix()
                jngl.setFontColor(0, 0, 0, 200)
                if jngl.keyDown("h"):
                    jngl.print(
                        "L - load file\nS - save file\nI - insert image\nLeft Mouse Button - add object\nMiddle Mouse Button - remove object\nRight Mouse Button or Page Up/Down - change object to add\nShift + Left Mouse Button - Move object\nG - change grid size\nT - test level\nM - add 10 somyeols at once\nZ Zoom out\nCtrl+N New Level (deletes everything!)",
                        10,
                        10,
                    )
                else:
                    jngl.print(
                        "Press H to show help text.   X = {0}   Y = {1}".format(-self.camerax, self.cameray), 10, 10
                    )
                jngl.print(
                    "Somyeols: {0} Objects: {1}".format(len(self.level.somyeols), len(self.level.objects)), 10, 30
                )
                fps += jngl.getFPS() / 50
                counter -= 1
                if counter < 0:
                    counter = 50
                    jngl.setTitle("Somyeol2D - LevelEditor {0} - FPS: {1}".format(self.version, int(fps)))
                    fps = 0
                jngl.swapBuffers()
            else:
                jngl.sleep(1)
Ejemplo n.º 6
0
        elif jngl.keyPressed(jngl.key.Left):
            level -= 1
            if level < 0: level = len(levels)-1
        elif jngl.keyPressed(jngl.key.Escape):
            #import sys
            #jngl.hideWindow()
            running = False
            break
            #sys.exit()
        bouncingEnterButton((game.windowWidth/2) + 320, (game.windowHeight/2)+100)
        bouncingButton((game.windowWidth/2)-225, (game.windowHeight/2) + 115, "img/World/key_left_64.png")
        bouncingButton((game.windowWidth/2)+180, (game.windowHeight/2) + 115, "img/World/key_right_64.png")
        jngl.setFontSize(20)
        jngl.print(levels[level], int((game.windowWidth/2) - jngl.getTextWidth(levels[level]) / 2), (game.windowHeight/2)+138)
        jngl.print("Press F1 for Help", 10, game.windowHeight-30)
        if jngl.keyDown(jngl.key.F1):
            jngl.draw(HELPSCREEN, (game.windowWidth/2)-jngl.getWidth(HELPSCREEN)/2, (game.windowHeight/2)-jngl.getHeight(HELPSCREEN)/2)
        jngl.print("www.somyeol.com", game.windowWidth-180, game.windowHeight-30)
        jngl.swapBuffers()
        jngl.translate(-jngl.getScreenWidth()/2, -jngl.getScreenHeight()/2)
        jngl.updateInput()
        selected = 0


    #Level select dialog
    files = os.listdir("data/maps/" + levels[level])
    screen = 0
    screenAnimation = 0
    screenAnimationGoal = screenAnimation
    levellist = []
Ejemplo n.º 7
0
    def run(self):
        self.levelpack_finished = False
        self.highscore.loadHighscore(self.levelpack)
        self.levelpack_finished = False
        lastTime = jngl.getTime()
        needDraw = True
        timePerStep = 0.01
        counter = 0
        fps = 0
        start_time = time.time()
        seconds = 0
        min_fps_count = MIN_FPS
        self.moveCamera()
        while self.running:
            if min_fps_count and jngl.getTime() - lastTime > timePerStep:
                lastTime += timePerStep
                needDraw = True
                if jngl.keyPressed(jngl.key.Escape):
                    self.sound.stopSounds()
                    self.running = False
                if jngl.keyPressed("r"):
                    self.level.somyeols = []
                    self.level.points = 0

                self.moveCamera()
                self.calculateCollisionBounds()
                if not self.finish:
                    self.level.step()
                else:
                    for a in self.level.animations:
                        a.step(self.level.animations)
                    for o in self.level.objects:
                        o.step()

            elif needDraw:
                if not min_fps_count:
                    lastTime = jngl.getTime()
                min_fps_count = MIN_FPS
                self.sound.playSounds()
                self.checkMusic()
                jngl.setFontSize(20)
                needDraw = False

                self.level.drawBackground(self.cameray)
                jngl.pushMatrix()
                jngl.translate(self.windowWidth/2, self.windowHeight)
                jngl.scale(1 + (self.scale - 1) / 2)
                jngl.translate(self.camerax / 2, -self.windowHeight + self.cameray / 2)
                for i in range(-2, 3):
                    jngl.draw(RESOURCEWORLD + "mountains.png", i*1024, self.windowHeight-300)
                jngl.popMatrix()
                jngl.pushMatrix()
                jngl.scale(self.scale)
                jngl.translate(self.camerax, self.cameray)
                self.level.draw()
                #uncomment for visualization of boundingbox
##                jngl.setColor(255,0,0,150)
##                jngl.drawRect(self.bounds.x,self.bounds.y,self.bounds.width,self.bounds.height)
                jngl.popMatrix()

                jngl.pushSpriteAlpha(150)
                jngl.draw("img/World/canvas.png", -80, -100)
                jngl.print("Somyeols: {0}".format(len(self.level.somyeols)), 10, 10)
                jngl.draw("img/World/canvas.png", self.windowWidth - 200, -120)
                jngl.print("Level: {0}".format(self.levelNr), self.windowWidth - 140, 10)
                jngl.popSpriteAlpha()

                jngl.print("Time: %.2f"%(seconds), 10, 40)

                if self.finish:
                    if not self.testmode:
                        def printCentered(t, x, y):
                            jngl.print(t, int(x-jngl.getTextWidth(t) / 2), y)

                        def printHighscore():
                            x,y = (self.windowWidth/2) - 207, (self.windowHeight/2) - 140
                            jngl.draw("img/World/highscore.png", x,y)
                            hs = self.highscore.getLevelScore(self.levelNr)
                            jngl.print("#".format(len(self.level.somyeols)), x+30, y+80)
                            jngl.print("Score".format(len(self.level.somyeols)), x+100, y+80)
                            jngl.print("Seconds".format(len(self.level.somyeols)), x+200, y+80)
                            jngl.print("Rank".format(len(self.level.somyeols)), x+300, y+80)
                            i = 1
                            best_rank = hs[0].getRank()
                            for score in hs:
                                jngl.setFontColor(0,0,0)
                                if new_score:
                                    if new_score == score:
                                        jngl.setFontColor(255,50,50)
                                jngl.print(str(i)+".", x+30, y+90+(30*i))
                                #jngl.print(str(score.score), x+120, y+90+(30*i))
                                jngl.print("{0}".format(score.score), x+100, y+90+(30*i))
                                jngl.print("{0:.2f}".format(score.time), x+200, y+90+(30*i))
                                jngl.print("{0:.2%}".format(score.getRank()/best_rank), x+300, y+90+(30*i))
                                i += 1
                            jngl.setFontColor(0,0,00)
                        if self.finish_highscore:
                            printHighscore()
                        else:
                            x,y = (self.windowWidth/2) - (jngl.getWidth("img/World/canvas.png")/2), (self.windowHeight/2) - (jngl.getHeight("img/World/canvas.png")/2)
                            jngl.draw("img/World/canvas.png", self.windowWidth/2 - 137, self.windowHeight/2 - 92)
                            printCentered("FINAL SCORE", x+(jngl.getWidth("img/World/canvas.png")/2), y+20)
                            printCentered("NEEDED: 100", x+(jngl.getWidth("img/World/canvas.png")/2), y+140)
                            jngl.setFontSize(50)
                            printCentered(str(self.level.points), x+(jngl.getWidth("img/World/canvas.png")/2), y+70)
                        bouncingEnterButton(x+50, y+jngl.getHeight("img/World/canvas.png")+50)
                        if jngl.keyPressed(jngl.key.Return) and self.finish_highscore:
                            self.levelpack_finished = not self.loadNextLevel()
                            start_time = time.time()

                        elif jngl.keyPressed(jngl.key.Return):
                            if self.level.points < self.level.needed_points:
                                self.levelNr -= 1
                                self.levelpack_finished = not self.loadNextLevel()
                                start_time = time.time()
                            else:
                                self.finish_highscore = True
                                # HIGHSCORE
                                new_score = self.highscore.newHighscore(self.levelNr, seconds, self.level.points)
                                if new_score:
                                    self.highscore.saveHighscore(self.levelpack)
                                time.sleep(.5)
                    else:self.running=False
                else:
                    seconds = time.time()-start_time

                fps += jngl.getFPS() / 50
                counter -= 1
                if counter < 0:
                    counter = 50
                    jngl.setTitle("Somyeol2D {0} - FPS: {1}".format(self.version, int(fps)))
                    fps = 0
                jngl.setFontSize(20)
                jngl.print("Press F1 for Help", 10, self.windowHeight-30)
                if jngl.keyDown(jngl.key.F1):
                    jngl.draw(HELPSCREEN, (self.windowWidth/2)-jngl.getWidth(HELPSCREEN)/2, (self.windowHeight/2)-jngl.getHeight(HELPSCREEN)/2)

                #uncomment for visualization of collision-count
                #colcount = 0
                #for o in self.level.objects:
                #    if o.canCollide:
                #        colcount+=1
                #jngl.print(str(colcount), self.windowWidth-680, self.windowHeight-50)
                jngl.print("www.somyeol.com", self.windowWidth-180, self.windowHeight-30)

                jngl.swapBuffers()
                jngl.translate(-jngl.getScreenWidth()/2, -jngl.getScreenHeight()/2)
                jngl.updateInput()
            else:
                jngl.sleep(1)
            min_fps_count-=1
        self.sound.stopSounds()