Ejemplo n.º 1
0
    def generateSprites(self):

        for row in range(len(self.board)):
            for column in range(len(self.board[row])):
                widthP = 0
                heightP = 0
                if self.board[row][column] == 'P' and self.board[row][
                        column - 1] != 'P' and self.board[
                            row -
                            1][column] != 'P':  #Hittat ett övre vänster hörn
                    i = column
                    k = row
                    while self.board[row][i] == 'P':
                        widthP += 32
                        i += 1
                    while self.board[k][column] == 'P' and len(
                            self.board) > k + 1:
                        heightP += 32
                        k += 1

                    print(widthP, heightP)
                    self.platforms.add(
                        Platform(widthP, heightP, column * self.boxSize,
                                 row * self.boxSize, 'Wood'))

                if self.board[row][column] == 'A':  #Apple
                    self.collectibles.add(
                        Collectible(column * self.boxSize, row * self.boxSize))
                if self.board[row][column] == 'F':  #Flag
                    self.checkpoints.add(
                        Checkpoint(column * self.boxSize, row * self.boxSize))
Ejemplo n.º 2
0
 def generateSpritesFromFile(self): 
     f = open("Levels/One/world"+str(self.worldNbr)+".txt",'r')
     for entry in f:
         data = entry.split()
         if "Platform" in entry: 
             self.platforms.add(Platform(int(data[2]), int(data[3]), int(data[0]), int(data[1])))
         if "Collectible" in entry: 
             self.collectibles.add(Collectible(int(data[0]), int(data[1])))
         if "Checkpoint" in entry: 
             self.checkpoints.add(Checkpoint(int(data[0]), int(data[1])))
Ejemplo n.º 3
0
    def __init__(self, player, lvl_type='Blue', ter_type='Wood'):

        self.platforms = pg.sprite.Group()
        self.enemies = pg.sprite.Group()
        self.bots = pg.sprite.Group()
        self.player = player
        self.collectibles = pg.sprite.Group()
        self.checkpoints = pg.sprite.Group()
        self.level_type = lvl_type
        self.terrain_type = ter_type

        for width, height, x, y in self._platforms():
            self.platforms.add(Platform(width, height, x, y, ter_type))

        for x, y in self._collectibles():
            self.collectibles.add(Collectible(x, y))

        for x, y in self._checkpoints():
            self.checkpoints.add(Checkpoint(x, y))
Ejemplo n.º 4
0
from pyomegle import OmegleClient
from CustomHandler import CustomHandler
from CustomClient import CustomClient
from Checkpoints import Checkpoint
from telegram import Telegram
import threading
import time

# Class used to store variables to let the autoMode work
checkpoint = Checkpoint()

# Checks updates from the bot's chat each 0.5 seconds
# /start = starts a new conversation
# /next = disconnects from current stranger and starts a new conversation
# /stop = stops automatically starting new conversations
# /auto = the bot will automatically look for strangers and will notify
#         the user when a stranger meets the user's requirements.
#         You can edit the bot's behavior in CustomHandler.py
# /manual = turns automatic mode off
bol = True


def getUpdates():
    while bol:
        answer = t.getUpdates()
        if answer != '':
            t.update_id += 1
            if answer == '/start':
                h.loop = True
                client.start()
                t.send('Looking for someone you can chat with...')
Ejemplo n.º 5
0
def game_loop():
    #Variables
    buildMode = "apple"  #Decides what happens when mouse button is pressed
    ongoingPlatform = False
    platformX = 0
    platformY = 0
    mouseIsDown = False

    tempItem = None

    #Screen settings
    screen = pg.display.set_mode(SCREEN['SIZE'])
    pg.display.set_caption("Ai-game the world builder")

    # Create all the levels
    level_list = []
    for i in range(3):
        level_list.append(
            Level(lvl_type=random.choice(BACKGROUND['NAME']),
                  ter_type=random.choice(TERRAIN['NAME']),
                  worldNbr=i))

    current_level_no = 0
    current_level = level_list[current_level_no]

    #All the sprite groups in the game

    # Used to manage how fast the screen updates
    clock = pg.time.Clock()

    # -------- Main Program Loop -----------¨
    done = False
    while not done:
        for event in pg.event.get():

            #When game is over
            if event.type == pg.QUIT:
                for lvl in level_list:
                    lvl.save()
                    print("save made")
                done = True

            #All mouse actions
            if event.type == pg.MOUSEBUTTONDOWN:
                mouseIsDown = True
                if event.button == 1:
                    if buildMode == "apple":
                        current_level.collectibles.add(
                            Collectible(
                                int(pg.mouse.get_pos()[0] // 32) * 32,
                                int(pg.mouse.get_pos()[1] // 32) * 32))
                    if buildMode == "flag":
                        current_level.checkpoints.add(
                            Checkpoint(
                                int(pg.mouse.get_pos()[0] // 32) * 32 - 32,
                                int(pg.mouse.get_pos()[1] // 32) * 32 -
                                128 / 2))
                    if buildMode == "platform" and not ongoingPlatform:
                        platformX = (pg.mouse.get_pos()[0] // 32) * 32
                        platformY = (pg.mouse.get_pos()[1] // 32) * 32
                        ongoingPlatform = True

                print(current_level_no, len(current_level.collectibles))

                if event.button == 3:
                    if buildMode == "apple":
                        for item in current_level.collectibles:
                            if item.rect.collidepoint(pg.mouse.get_pos()[0],
                                                      pg.mouse.get_pos()[1]):
                                current_level.collectibles.remove(item)

                    if buildMode == "flag":
                        for item in current_level.checkpoints:
                            if item.rect.collidepoint(pg.mouse.get_pos()[0],
                                                      pg.mouse.get_pos()[1]):
                                current_level.checkpoints.remove(item)

                    if buildMode == "platform":
                        for item in current_level.platforms:
                            if item.rect.collidepoint(pg.mouse.get_pos()[0],
                                                      pg.mouse.get_pos()[1]):
                                current_level.platforms.remove(item)

            if event.type == pg.MOUSEBUTTONUP:
                mouseIsDown = False
                if event.button == 1:
                    if buildMode == "platform" and ongoingPlatform:
                        current_level.platforms.add(
                            Platform(
                                abs(platformX -
                                    (pg.mouse.get_pos()[0] // 32) * 32),
                                abs(platformY -
                                    (pg.mouse.get_pos()[1] // 32) * 32),
                                platformX, platformY))
                        ongoingPlatform = False
                        current_level.tempItems.empty()

        #Handles keyboard
        keys = pg.key.get_pressed()
        if keys:
            allActions = ''
            somethingDone = False

            if keys[pg.K_LCTRL]:
                print("left control")
                if keys[pg.K_1]:
                    print("1")
                    current_level_no = 0
                if keys[pg.K_2]:
                    current_level_no = 1
                if keys[pg.K_3]:
                    current_level_no = 2

            else:
                if keys[pg.K_LEFT] or keys[pg.K_a]:
                    current_level.shift_world(10)
                if keys[pg.K_RIGHT] or keys[pg.K_d]:
                    current_level.shift_world(-10)
                if keys[pg.K_1]:
                    print("platform")
                    buildMode = "platform"
                if keys[pg.K_2]:
                    buildMode = "apple"
                    print("apple")
                if keys[pg.K_3]:
                    buildMode = "flag"
                    print("flag")

            if keys[pg.K_q]:  #To quit without saving
                done = True

        #To make a ghost of the item you are currently working with
        current_level.tempItems.empty()
        if buildMode == "apple":
            current_level.tempItems.add(
                Collectible(
                    int(pg.mouse.get_pos()[0] // 32) * 32,
                    int(pg.mouse.get_pos()[1] // 32) * 32))
        if buildMode == "flag":
            current_level.tempItems.add(
                Checkpoint(
                    int(pg.mouse.get_pos()[0] // 32) * 32 - 32,
                    int(pg.mouse.get_pos()[1] // 32) * 32 - 128 / 2))
        if buildMode == "platform" and ongoingPlatform:
            current_level.tempItems.add(
                Platform(abs(platformX - (pg.mouse.get_pos()[0] // 32) * 32),
                         abs(platformY - (pg.mouse.get_pos()[1] // 32) * 32),
                         platformX, platformY))

        #Changes level
        current_level = level_list[current_level_no]

        # Update the player and level.
        current_level.update(tempItem)

        # Calculate levelchange and what sprites to draw
        sprites_to_draw = pg.sprite.Group()

        # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT
        current_level.draw(screen)
        # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT

        # Limit to 60 frames per second
        clock.tick(FPS)

        # Go ahead and update the screen with what we've drawn.
        pg.display.flip()