コード例 #1
0
    def __init__(self, char_id, enemy_id):
        super().__init__(char_id, [10, 100], [530, 150])

        self.bg = colours.dodger_blue

        i = 0
        while i < 640:
            if i > 200:
                self.elements.append(objects.Image('dirtBlock.png'))
                self.element_locations.append([-30 + i, 430])

                self.ground.append(pygame.Rect(-30 + i, 340, 70, 70))
                self.walls.append(pygame.Rect(-30 + i, 340, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 360])

            else:
                self.ground.append(pygame.Rect(-30 + i, 410, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 430])
            i += 70

        self.enemies.append(objects.Enemy(enemy_id, 100, 350, False))
        self.enemies.append(objects.Enemy(enemy_id, 300, 350, False))

        self.elements.append(objects.Text('And as I move forward . . .', 48))
        self.element_locations.append([10, 10])
コード例 #2
0
    def __init__(self, char_id, enemy_id):
        super().__init__(char_id, [10, 100], [550, 100])

        self.bg = colours.dodger_blue

        i = 0
        while i < 640:
            if 200 < i <= 270:
                self.elements.append(objects.Image('dirtBlock.png'))
                self.element_locations.append([-30 + i, 430])
                self.elements.append(objects.Image('dirtBlock.png'))
                self.element_locations.append([-30 + i, 360])

                self.ground.append(pygame.Rect(-30 + i, 270, 70, 70))
                self.walls.append(pygame.Rect(-30 + i, 270, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 290])

            elif 270 < i <= 410:
                self.elements.append(objects.Image('dirtBlock.png'))
                self.element_locations.append([-30 + i, 430])

                self.elements.append(objects.Image('spikes.png'))
                self.spikes.append(pygame.Rect(-30 + i, 395, 70, 35))
                self.element_locations.append([-30 + i, 360])

            elif 410 < i <= 480:
                self.ground.append(pygame.Rect(-30 + i, 410, 70, 70))
                self.walls.append(pygame.Rect(-30 + i, 410, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 430])

            else:
                self.elements.append(objects.Image('dirtBlock.png'))
                self.element_locations.append([-30 + i, 430])

                self.ground.append(pygame.Rect(-30 + i, 340, 70, 70))
                self.walls.append(pygame.Rect(-30 + i, 340, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 360])

            i += 70

        self.enemies.append(objects.Enemy(enemy_id, 100, 350, False))
        self.enemies.append(objects.Enemy(enemy_id, 380, 350, False))
        self.enemies.append(objects.Enemy(enemy_id, 530, 350, False))

        self.elements.append(objects.Text('more and more appear.', 48))
        self.element_locations.append([10, 10])
コード例 #3
0
    def __init__(self, char_id, enemy_id):
        super().__init__(char_id, [70, -10], [550, 350])

        self.bg = colours.medium_blue

        i = 0
        while i < 640:
            if i <= 500:
                self.ground.append(pygame.Rect(-30 + i, 70, 70, 70))
                self.walls.append(pygame.Rect(-30 + i, 70, 70, 70))
                self.roof.append(pygame.Rect(-30 + i, 70, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 90])

            if 140 <= i:
                self.ground.append(pygame.Rect(-30 + i, 245, 70, 70))
                self.walls.append(pygame.Rect(-30 + i, 245, 70, 70))
                self.roof.append(pygame.Rect(-30 + i, 245, 70, 70))
                self.elements.append(objects.Image('grass.png'))
                self.element_locations.append([-30 + i, 265])

            self.ground.append(pygame.Rect(-30 + i, 410, 70, 70))
            self.walls.append(pygame.Rect(-30 + i, 410, 70, 70))
            self.elements.append(objects.Image('grass.png'))
            self.element_locations.append([-30 + i, 430])
            i += 70

        self.elements.append(objects.Text('Some of them chase me.', 48))
        self.element_locations.append([10, 50])

        self.enemies.append(objects.Enemy(enemy_id, -50, 0, True))
        self.enemies.append(objects.Enemy(enemy_id, 600, 100, True))
        self.enemies.append(objects.Enemy(enemy_id, -30, 300, True))

        self.was_shown1 = False
        self.was_shown2 = False
コード例 #4
0
    def __init__(self, char_id, enemy_id):
        super().__init__(char_id, [10, 100], [530, 200])

        self.bg = colours.deep_sky_blue

        i = 0
        while i < 640:
            self.ground.append(pygame.Rect(-30 + i, 410, 70, 70))
            self.elements.append(objects.Image('grass.png'))
            self.element_locations.append([-30 + i, 430])
            i += 70

        self.elements.append(objects.Text('Sometimes, I find others', 48))
        self.element_locations.append([10, 10])
        self.elements.append(objects.Text('who look just like me . . .', 48))
        self.element_locations.append([55, 56])

        self.enemies.append(objects.Enemy(enemy_id, 320, 340, False))

        self.has_died = False
        self.message_shown = False
コード例 #5
0
def start(level):
    '''declaring all the objects and spawning them before game start'''
    # ------------------------------------------------------------------------------------
    h, w = 40, 500
    enemies = []
    bricks = []
    coins = []
    pipe = []
    springs = []
    bd = Board(h, w)
    over = Board(h, w)
    pipe.append(objects.pipe(bd))
    protag = objects.Mario()
    clouds = objects.Cloud(h, w)
    clouds.shape(bd)
    protag.spawn(bd, 1)
    run, t = True, 0
    springs.append(objects.spring(25, 30))
    if level == 4: springs.append(objects.spring(375, 30))
    for i in range(0, 3 + 6 * level):
        enemies.append(objects.Enemy(randint(200, 365), 30))
        enemies[i].spawn(bd)
    for i in range(0, 6 + 7 * level):
        bricks.append(objects.brick(randint(50, 365), 25))
        bricks[i].generate(bd, 0)
    for i in range(0, 5 + 3 * level):
        coins.append(objects.Coin(randint(50, 365), 23))
        coins[i].spawn(bd)
    for i in range(0, len(springs)):
        springs[i].generate(bd, protag)

    if level >= 2:
        smart = []
        for i in range(0, 2 + 2 * level):
            smart.append(objects.S_Enemy(randint(300, 380), 30))
            smart[i].spawn(bd)
    if level >= 3:
        ebricks = []
        for i in range(0, 6 + level):
            ebricks.append(objects.ebrick(randint(100, 365), 21))
            ebricks[len(ebricks) - 1].generate(bd)
        pits = objects.pitfall(70)

    if level == 4:
        pit2 = objects.pitfall(300)
        boss = objects.Boss()


# ------------------------------------------------------------------------------------
    stime = time()
    '''running the game'''
    while run:

        if level == 4:
            if bd.die(protag.x, protag.y) == True:
                objects.game.over(over, curr - stime)  # for game over
        curr = time()
        if protag.y > 30:
            objects.game.over(over, curr - stime)
        t += 1
        '''detectint each collision'''
        for i in range(len(enemies) - 1, -1, -1):
            var = bd.destroy(enemies[i].x, enemies[i].y, protag)
            if (var != 'kill'):
                if level <= 2:
                    enemies[i].update(bd, t, protag, over, curr - stime)
                else:
                    enemies[i].supdate(bd, t, protag, over, curr - stime)
            elif enemies[i].x < 15:
                enemies[i].clear(bd)
                del enemies[i]

            elif enemies[i].x > 450:
                del enemies[i]
            else:
                objects.game.change('en')
                enemies[i].clear(bd)
                del enemies[i]

        for i in range(len(coins) - 1, -1, -1):
            if coins[i].col(bd, protag) == 1:
                objects.game.change('coin')
                coins[i].clear(bd)
                protag.spawn(bd, 1)
                del coins[i]

        for i in range(len(bricks) - 1, -1, -1):
            bricks[i].update(protag, bd)
            if bricks[i].kuchbhi == 1: objects.game.change('brick1')
            if bricks[i].kuchbhi >= 2:
                objects.game.change('brick0')
                del bricks[i]

        for i in range(0, len(springs)):
            springs[i].generate(bd, protag)

        if (level >= 2):
            for i in range(len(smart) - 1, -1, -1):
                smart[i].update(bd, t, protag, over, curr - stime)

        if (level >= 3):
            for i in range(len(ebricks) - 1, -1, -1):
                ebricks[i].update(protag, bd, over, curr - stime)
        if (level == 4):
            pit2.generate(bd, protag)
            boss.spawn(bd)
        '''after checking collisions spawning objects with new co ordinates'''
        if level >= 3:
            pits.generate(bd, protag)
        bd.printb(int(protag.w))
        protag.movemario(bd, t, pipe)
        protag.walkoverbricks(bd)
        protag.spri(bd)
        protag.jump(bd)
        protag.orig(bd)
        '''increasing the level'''
        if bd.detpip(protag.x, protag.y, pipe[0]) == 'proceed':
            level = pipe[0].movelevel(level, protag)
            if (level > 4):
                clear()
                objects.game.end(curr - stime)
            start(level)

        sleep(0.01)
コード例 #6
0
        def get_objects(self, map):

            for obj_name in object_list_prob['objects']:
                prop = object_list_prob['objects'][obj_name]
                for i in range(
                        random.randint(prop['min-count'], prop['max-count'])):
                    print(obj_name)
                    coord = (random.randint(1, 39), random.randint(1, 39))
                    intersect = True
                    while intersect:
                        intersect = False
                        if map[coord[1]][coord[0]] == wall:
                            intersect = True
                            coord = (random.randint(1,
                                                    39), random.randint(1, 39))
                            continue
                        for obj in self.objects:
                            if coord == obj.position or coord == (1, 1):
                                intersect = True
                                coord = (random.randint(1, 39),
                                         random.randint(1, 39))

                    self.objects.append(
                        objects.Ally(prop['sprite'], prop['action'], coord))
            for obj_name in object_list_prob['ally']:
                prop = object_list_prob['ally'][obj_name]
                for i in range(
                        random.randint(prop['min-count'], prop['max-count'])):
                    print(obj_name)
                    coord = (random.randint(1, 39), random.randint(1, 39))
                    intersect = True
                    while intersect:
                        intersect = False
                        if map[coord[1]][coord[0]] == wall:
                            intersect = True
                            coord = (random.randint(1,
                                                    39), random.randint(1, 39))
                            continue
                        for obj in self.objects:
                            if coord == obj.position or coord == (1, 1):
                                intersect = True
                                coord = (random.randint(1, 39),
                                         random.randint(1, 39))
                    self.objects.append(
                        objects.Ally(prop['sprite'], prop['action'], coord))

            for obj_name in object_list_prob['enemies']:
                prop = object_list_prob['enemies'][obj_name]
                for i in range(random.randint(0, 5)):
                    print(obj_name)
                    coord = (random.randint(1, 30), random.randint(1, 22))
                    intersect = True
                    while intersect:
                        intersect = False
                        if map[coord[1]][coord[0]] == wall:
                            intersect = True
                            coord = (random.randint(1,
                                                    39), random.randint(1, 39))
                            continue
                        for obj in self.objects:
                            if coord == obj.position or coord == (1, 1):
                                intersect = True
                                coord = (random.randint(1, 39),
                                         random.randint(1, 39))

                    self.objects.append(
                        objects.Enemy(prop['sprite'], prop, prop['experience'],
                                      coord))

            return self.objects
コード例 #7
0
ファイル: test.py プロジェクト: crosse331/postApoc
SCREEN_SIZE = (32, 32)
LIMIT_FPS = 30
exit_game = False

tdl.set_font('arial10x10.png', greyscale=True, altLayout=True)
console = tdl.init(SCREEN_SIZE[0],
                   SCREEN_SIZE[1],
                   title="Roguelike",
                   fullscreen=False)
tdl.set_fps(LIMIT_FPS)

room = gameplay.RoomController(logic.Vector(3, 3), logic.Vector(15, 15))
player = objects.Player("@", (255, 255, 255), logic.Vector(8, 8), room, 10)

en = objects.Enemy("E", (255, 0, 0), logic.Vector(1, 1), room, 5)

for i in range(7):
    #it = It.Item("test" + str(i), 65 + i)
    it = It.get_random_item(i)
    objects.ItemObject(
        it,
        logic.Vector(random.randint(0, room.size.x - 1),
                     random.randint(0, room.size.y - 1)), room)

while not tdl.event.is_window_closed():
    for event in tdl.event.get():
        if event.type == "KEYDOWN" and event.key == "ESCAPE":
            exit_game = True
        if event.type == "MOUSEMOTION":
            continue