コード例 #1
0
def starting(data):
    x = data.me.x
    y = data.me.y + data.characterHeight/4 + data.platformHeight/2
    Platforms(x, y, data)
    Platforms(x + data.platformWidth, y + data.platformHeight/2, data)
    Platforms(x + 2* data.platformWidth, y + data.platformHeight, data)
    Platforms(x + 2*data.platformWidth, y + data.platformHeight*1.5, data)
コード例 #2
0
def init(data):
    data.start = False
    data.message = "None" # for login
    data.drawn = 0
    data.temp = 0 
    data.mode = "start"
    data.timeLimit = 20000 # 30 seconds 
    loadImages(data) 
    data.time = 0
    data.level = 1
    data.numPlayers = -1
    data.numPlayerClicks = 0
    data.myClicks = 0
    data.highScore = 0
    data.play = False
    data.nextClicks = 0
    data.minTotalScrollX, data.minTotalScrollY = 0, 0 # for last player
    data.maxTotalScrollX, data.maxTotalScrollY = 0, 0 # for first player
    createObjects(data) # all objects of the game (except the characters)
    data.scrollX = data.width//50 # speed of horizontal scrolling
    data.scrollY = data.scrollX # speed of vertical scrolling
    data.jump, data.speed = data.height//5, data.width//20
    data.jumpStep = data.jump//15
    data.platforms = set()
    Platforms(0, 0, data)
    data.platforms.clear()
    data.me = FlyingCharacter("Lonely", data)
    Patronus(0, 0, data)
    data.bullets.clear()
    data.others = dict() # other players
コード例 #3
0
def drawPlatforms(canvas, data):
    # updated = all platforms between players
    # drawn = platforms in the current player's screen
    updatedPlatforms, drawnPlatforms = set(), set()
    for platform in data.platforms:
        x, y = platform.x - data.minTotalScrollX, platform.y - data.minTotalScrollY
        if (-platform.width/2 <= x): updatedPlatforms.add(platform)
        x, y = platform.x - data.me.totalScrollX, platform.y - data.me.totalScrollY
        if ((-platform.width/2 <= x <= data.width + platform.width/2)
            and (-platform.height/2 <= y <= data.height + platform.height/2)):
            drawnPlatforms.add(platform)
    # temporarily set all platforms to only seen platforms in player's screen
    data.platforms = drawnPlatforms 
    # draw all platforms in screen
    Platforms.draw(canvas, data)
    # reset platforms to all platforms between players
    data.platforms = updatedPlatforms
コード例 #4
0
 def get_level(self, background, level, P1):
     with open(level) as test:
         lines = test.readlines()
         for line in lines:
             plat_type, x_size, y_size, x_coord, y_coord = line.split(" ")
             background.add(
                 Platforms(int(plat_type), int(x_size), int(y_size),
                           int(y_coord), int(x_coord), P1))
     return background
コード例 #5
0
def newPlatformOtherBelow(data, x, scrollY, ratio):
    msg = ""
    y = random.choice([int(i*data.jump) for i in range(1, ratio*3, 2)])
    y += scrollY
    x, y = int(x), int(y)
    msg = "newPlatform %d %d\n" % (x, y)
    print("sending: ", msg,)
    data.server.send(msg.encode())
    Platforms(x, y, data)
    placeItem(x, y, data)
コード例 #6
0
def newPlatformBelow(data, x, ratio):
    msg = ""
    y = random.choice([int(i*data.jump) for i in range(1, ratio*3, 2)])
    y += data.me.totalScrollY
    x, y = int(x), int(y)
    Platforms(x, y, data) # new platform
    placeItem(x, y, data) # place item on platform
    msg = "newPlatform %d %d\n" % (x, y)
    print("sending: ", msg,)
    data.server.send(msg.encode())
    newPlatformOther(data, x)
コード例 #7
0
def newPlatformOther(data, x):
    x = int(x)
    for i in data.others:
        player = data.others[i]
        ratio = int(data.height//data.jump)
        y = random.choice([int(i*data.jump) for i in range(1, ratio, 2)])
        y += player.totalScrollY
        x, y = int(x), int(y)
        msg = "newPlatform %d %d\n" % (x, y)
        print("sending: ", msg,)
        data.server.send(msg.encode())
        Platforms(x, y, data) # new platform
        placeItem(x, y, data) # place item on platform
        newPlatformOtherBelow(data, x, player.totalScrollY, ratio)
コード例 #8
0
def newPlatform(data):
    if (data.numPlayers > 1): 
        for i in data.others:
            player = data.others[i]
            if (data.me.totalScrollX < player.totalScrollX): return
    if (data.time % 1000 == 0):
        msg = ""
        x = data.width + data.me.totalScrollX + data.platformWidth//2
        ratio = int(data.height//data.jump)
        y = random.choice([int(i*data.jump) for i in range(1, ratio, 2)])
        y += data.me.totalScrollY
        x, y = int(x), int(y)
        Platforms(x, y, data) # new platform
        placeItem(x, y, data) # place item on platform
        newMonster(x, data) # new monster
        msg = "newPlatform %d %d\n" % (x, y)
        print("sending: ", msg,)
        data.server.send(msg.encode())
        newPlatformBelow(data, x, ratio) # makes new platforms below player 
コード例 #9
0
ファイル: game.py プロジェクト: olesya-privetuli/DOODLE
# картинка облака
cloud = pygame.transform.scale(load_image('cloud.png', -1), (90, 60))
# платформа из земли
platf = pygame.transform.scale(load_image('platf.png', -1), (90, 20))
# земля
earth = load_image('land.png', -1)

# длина и ширина doodle в игре
doodle_size = dood_w, dood_h = 90, 60

# главный персонаж игры
main = Doodle()
# класс ведет счет игры
result = Result()
# класс, отвечающий за платформы
plate = Platforms()
# класс, унаследованный от класса платформ, для земли
land = Land()
# класс, создающий платформы при новой игре
plate_coor = Plate_coor()
#
class_monster = Monster()
# список со всеми выводимыми платформами
platforms = [land]
for _ in range(numb_of_plate):
    platforms.append(plate)

# состояние персонажа
fall = False

# Загрузка звука прыжка
コード例 #10
0
ファイル: Level.py プロジェクト: ruixuanz/JumpKingAtHome
    def __init__(self, screen):

        self.max_level = 42

        self.current_level = 0

        self.current_level_name = None

        self.screen = screen

        # Objects

        self.platforms = Platforms()

        self.background = Backgrounds("BG").backgrounds

        self.midground = Backgrounds("MG").backgrounds

        self.foreground = Backgrounds("FG").backgrounds

        self.props = Props().props

        self.weather = Weathers().weather

        self.hiddenwalls = HiddenWalls().hiddenwalls

        self.scrollers = Scrollers()

        self.npcs = NPCs().npcs

        self.names = Names()

        self.readables = Readables().readables

        self.flyers = Flyers()

        self.Ending_Animation = Ending_Animation()

        # Audio

        self.background_audio = BackgroundAudio().level_audio

        self.channels = [
            pygame.mixer.Channel(2),
            pygame.mixer.Channel(3),
            pygame.mixer.Channel(4),
            pygame.mixer.Channel(5)
        ]

        for channel in self.channels:

            channel.set_volume(1.0)

        # Movement

        self.shake_var = 0

        self.shake_levels = [39, 40, 41]

        self.wind = Wind(self.screen)

        self.levels = {}

        self._load_levels()

        # Ending

        self.ending = False

        self.END = False
コード例 #11
0
ファイル: Level.py プロジェクト: ruixuanz/JumpKingAtHome
class Levels:
    def __init__(self, screen):

        self.max_level = 42

        self.current_level = 0

        self.current_level_name = None

        self.screen = screen

        # Objects

        self.platforms = Platforms()

        self.background = Backgrounds("BG").backgrounds

        self.midground = Backgrounds("MG").backgrounds

        self.foreground = Backgrounds("FG").backgrounds

        self.props = Props().props

        self.weather = Weathers().weather

        self.hiddenwalls = HiddenWalls().hiddenwalls

        self.scrollers = Scrollers()

        self.npcs = NPCs().npcs

        self.names = Names()

        self.readables = Readables().readables

        self.flyers = Flyers()

        self.Ending_Animation = Ending_Animation()

        # Audio

        self.background_audio = BackgroundAudio().level_audio

        self.channels = [
            pygame.mixer.Channel(2),
            pygame.mixer.Channel(3),
            pygame.mixer.Channel(4),
            pygame.mixer.Channel(5)
        ]

        for channel in self.channels:

            channel.set_volume(1.0)

        # Movement

        self.shake_var = 0

        self.shake_levels = [39, 40, 41]

        self.wind = Wind(self.screen)

        self.levels = {}

        self._load_levels()

        # Ending

        self.ending = False

        self.END = False

    def blit1(self):

        try:

            current_level = self.levels[self.current_level]

            if current_level.background:
                current_level.background.blitme(self.screen)

            if current_level.scrollers:
                for scroller in current_level.scrollers:
                    scroller.blitme(self.screen, "bg")

            if current_level.midground:
                current_level.midground.blitme(self.screen)

            if current_level.props:
                for prop in current_level.props:
                    prop.blitme(self.screen)

            if current_level.flyer:
                current_level.flyer.blitme(self.screen)

            if current_level.npc:
                current_level.npc.blitme(self.screen)

            if current_level.weather:
                current_level.weather.blitme(self.screen, self.wind.rect)

        except Exception as e:

            print("BLIT1 ERROR: ", e)

    def blit2(self):

        try:

            current_level = self.levels[self.current_level]

            if current_level.foreground:
                current_level.foreground.blitme(self.screen)

            if current_level.hiddenwalls:
                for hiddenwall in current_level.hiddenwalls:
                    hiddenwall.blitme(self.screen)

            if current_level.scrollers:
                for scroller in current_level.scrollers:
                    scroller.blitme(self.screen, "fg")

            if current_level.npc:
                current_level.npc.blitmetext(self.screen)

            if current_level.readable:
                current_level.readable.blitmetext(self.screen)

            if self.names.active:
                self.names.blitme(self.screen)

            if os.environ.get("hitboxes"):
                if current_level.platforms:
                    for platform in current_level.platforms:
                        pygame.draw.rect(self.screen, (255, 0, 0),
                                         platform.rect, 1)

            if self.END:

                self.Ending_Animation.blitme(self.screen)

        except Exception as e:

            print("BLIT2 ERROR: ", e)

    def update_levels(self, king, babe, agentCommand=None):

        self.update_wind(king)

        self.update_hiddenwalls(king)

        self.update_npcs(king)

        self.update_readables(king)

        self.update_flyers(king)

        self.update_discovery(king)

        self.update_audio()

        if self.ending:

            self.END = self.Ending_Animation.update(
                self.levels[self.current_level], king, babe)

        else:

            king.update(agentCommand=agentCommand)

            babe.update(king)

    def update_flyers(self, king):

        try:

            current_level = self.levels[self.current_level]

            if current_level.flyer:

                current_level.flyer.update(king)

        except Exception as e:

            print("UPDATEFLYERS ERROR: ", e)

    def update_audio(self):

        try:

            if not self.ending:

                current_level = self.levels[self.current_level]

                for index, audio in enumerate(current_level.background_audio):

                    if not audio:

                        self.channels[index].stop()

                    elif audio != [
                            channel.get_sound() for channel in self.channels
                    ][index]:

                        self.channels[index].play(audio)

                self.names.play_audio()

            else:

                for channel in self.channels:

                    channel.stop()

                self.Ending_Animation.update_audio()

        except Exception as e:

            print("UPDATEAUDIO ERROR: ", e)

    def update_discovery(self, king):

        try:

            if not king.isFalling:

                if self.levels[
                        self.current_level].name != self.current_level_name:

                    self.current_level_name = self.levels[
                        self.current_level].name

                    if self.current_level_name:

                        self.names.opacity = 255

                        self.names.active = True

                        self.names.blit_name = self.current_level_name

                        self.names.blit_type = self.levels[
                            self.current_level].found

                self.levels[self.current_level].found = True

        except Exception as e:

            print("UPDATEDISCOVERY ERROR: ", e)

    def update_readables(self, king):

        try:

            if self.levels[self.current_level].readable:

                self.levels[self.current_level].readable.update(king)

        except Exception as e:

            print("UPDATEREADABLES ERROR:", e)

    def update_npcs(self, king):

        try:

            for npc in self.npcs.values():

                npc.update(king)

        except Exception as e:

            print("UPDATENPCS ERROR:", e)

    def update_hiddenwalls(self, king):

        try:

            if self.levels[self.current_level].hiddenwalls:

                for hiddenwall in self.levels[self.current_level].hiddenwalls:

                    hiddenwall.check_collision(king)

        except Exception as e:

            print("UPDATEHIDDENWALLS ERROR: ", e)

    def update_wind(self, king):

        try:

            wind = self.wind.calculate_wind(king)

            if self.levels[self.current_level].weather:

                if self.levels[self.current_level].weather.hasWind:

                    if not king.lastCollision:

                        king.angle, king.speed = king.physics.add_vectors(
                            king.angle, king.speed, math.pi / 2, wind / 50)

                    elif not king.lastCollision.type == "Snow":

                        king.angle, king.speed = king.physics.add_vectors(
                            king.angle, king.speed, math.pi / 2, wind / 50)

        except Exception as e:

            print("UPDATEWIND ERROR: ", e)

    def _load_levels(self):

        try:

            for i in range(0, self.max_level + 1):

                self.levels[i] = Level(self.screen, i)

                try:
                    self.levels[i].background = self.background[i]
                except:
                    pass

                try:
                    self.levels[i].midground = self.midground[i]
                except:
                    pass

                try:
                    self.levels[i].foreground = self.foreground[i]
                except:
                    pass

                try:
                    self.levels[i].platforms = self.platforms.platforms(i)
                except:
                    pass

                try:
                    self.levels[i].props = self.props[i]
                except:
                    pass

                try:
                    self.levels[i].weather = self.weather[i]
                except:
                    pass
                try:
                    self.levels[i].hiddenwalls = self.hiddenwalls[i]
                except:
                    pass
                try:
                    self.levels[i].scrollers = self.scrollers.scrollers[i]
                except:
                    pass

                try:
                    if i in self.shake_levels:
                        self.levels[i].shake = True
                except:
                    pass

                try:
                    self.levels[i].background_audio = self.background_audio[i]
                except:
                    pass

                try:
                    self.levels[i].npc = self.npcs[i]
                except:
                    pass

                try:
                    self.levels[i].name = self.names.names[i]
                except:
                    pass

                try:
                    self.levels[i].readable = self.readables[i]
                except:
                    pass

                try:
                    self.levels[i].flyer = self.flyers.flyers[i]
                except:
                    pass

        except Exception as e:

            print("LOAD LEVELS ERROR: ", e)

    def reset(self, cheating_level):

        self.current_level = cheating_level

        self.wind.__init__(self.screen)

        self.scrollers.__init__()

        self.flyers.__init__()
コード例 #12
0
def playTimerFired(data): 
    if (data.mode == "play"):
        if (data.time == data.timeLimit): data.me.gameOver = True
        if data.me.gameOver: gameOver(data)
    data.temp += data.timerDelay
    if (data.myClicks == 1 and data.numPlayers > 1):
        if (data.temp % 225): data.waitingIndex = (data.waitingIndex + 1) % 3
    if (data.nextClicks == data.numPlayers) and (data.mode == "play"): 
        data.myClicks = 0
        starting(data) # starting platforms on screen
        data.start = True
    if (data.start == True): play(data)
    if (data.mode == "instructions"): animateInstructions(data)           
    # timerFired receives instructions and executes them
    while (serverMsg.qsize() > 0):
        msg = serverMsg.get(False)
        try:
            print("received: ", msg, "\n")
            msg = msg.split()
            command = msg[0]

            if (command == "myIDis"):
                myPID = msg[1]
                data.me.changePID(myPID)
            
            elif (command == "points"):
                PID = msg[1]
                otherScore = int(msg[2])
                myScore = int(msg[3])
                for i in data.others:
                    data.others[PID].score = otherScore
                data.me.score = myScore
                
            elif (command == "updatePosition"):
                PID = msg[1]
                scrollX, scrollY = int(msg[2]), int(msg[3])
                data.others[PID].totalScrollX = scrollX
                data.other[PID].totalScrollY = scrollY
                
            elif (command == "time"):
                time = int(msg[2])
                data.otherTime = time
            
            elif (command == "nextClick"):
                num = int(msg[2])
                data.nextClicks += num
                
            elif (command == "startGame"):
                data.play = True
                
            elif (command == "nameChanged"):
                PID = msg[1]
                name = msg[2]
                data.others[PID].changePID(name)
            
            elif (command == "newPlayer"):
                newPID = msg[1]
                data.others[newPID] = FlyingCharacter(newPID, data)
            
            elif (command == "newUser"):
                username, password = msg[2], msg[3]
                newUser(data, username, password)
                
            elif (command == "changeHouse"):
                PID = msg[1]
                house = msg[2]
                data.others[PID].house = house
                
            elif (command == "playerMoved"):
                PID = msg[1]
                dx = int(msg[2])
                dy = int(msg[3])
                data.others[PID].move(dx, dy, data)
                
            elif (command == "newPlatform"):
                x, y = int(msg[2]), int(msg[3])
                Platforms(x, y, data)
                
            elif (command == "newGoldCoin"):
                x, y = int(msg[2]), int(msg[3])
                GoldCoin(x, y, data)
                
            elif (command == "newSilverCoin"):
                x, y = int(msg[2]), int(msg[3])
                SilverCoin(x, y, data)
            
            elif (command == "newBronzeCoin"):
                x, y = int(msg[2]), int(msg[3])
                BronzeCoin(x, y, data)
            
            elif (command == "newResurrectionStone"):
                x, y = int(msg[2]), int(msg[3])
                ResurrectionStone(x, y, data)
            
            elif (command == "newSnitch"):
                x, y = int(msg[2]), int(msg[3])
                Snitch(x, y, data)
                
            elif (command == "newEgg"):
                x, y = int(msg[2]), int(msg[3])
                Egg(x, y, data)
                
            elif (command == "newMuggle"):
               x, y = int(msg[2]), int(msg[3])
               Muggle(x, y, data)
               data.monsterCollisions += [False]
            
            elif (command == "newDementor"):
                x, y = int(msg[2]), int(msg[3])
                Dementor(x, y, data)
                data.monsterCollisions += [False]
                
            elif (command == "newDragon"):
                x, y = int(msg[2]), int(msg[3])
                dragonType = msg[4]
                Dragon(x, y, dragonType, data)
                data.monsterCollisions += [False]
                
            elif (command == "newSpell"):
                x, y = int(msg[2]), int(msg[3])
                Spell(x, y, data)
                
            elif (command == "newPatronus"):
                x, y = int(msg[2]), int(msg[3])
                Patronus(x, y, data)
        except:
            print("failed")
        serverMsg.task_done()