예제 #1
0
파일: preGame.py 프로젝트: nchpmn/S-kuru
def parseLevel(screen):

    title = Module_text.basicText(((400-(int(Module_text.calculateSize("Player Name", 1)[0])/2)),100), "Player Name", 1, screen)
    playerName = ""
    current_string = []
    screen.fill((146,146,146))
    while 1:
        screen.fill((146,146,146))
        title.updateText()
        
        event = pygame.event.poll()
        if event.type == pygame.KEYDOWN:
            inkey = event.key
            if inkey == pygame.K_BACKSPACE:
                current_string = current_string[0:-1]
            elif inkey == pygame.K_RETURN:
                break
            elif inkey == pygame.K_MINUS:
                current_string.append("_")
            elif inkey <= 127:
                current_string.append(chr(inkey))
        else:
            pass
        
        textBoxDisplay(screen, string.join(current_string,""))
        
        pygame.display.flip()
    
    playerName = string.join(current_string,"")
    
    
    
    
    levelNumb = module_fileHandling.loadPlayer(playerName) # This will need to be changed
    loadText, loadCircles, loadBalls, loadExits = module_fileHandling.loadLevel(levelNumb)
    
    # loadText = [LevelName, HintText, [WinType, WinCondition]]

    playGame.play(loadText, loadCircles, loadBalls, loadExits, screen)
예제 #2
0
파일: playGame.py 프로젝트: nchpmn/S-kuru
def play(loadText, loadCircles, loadBalls, loadExits, screen):

    # Clear the lists from a previous player
    clearPreviousData(circles, balls, exits, staticText)
    
# loadText = [LevelName, HintText, [WinType, WinCondition]]
    # Level Name
    newText = Module_text.basicText((15, 5), loadText[0], 2, screen)
    staticText.append(newText)

    # Hint Text
    newText = Module_text.basicText((5, (585-Module_text.calculateSize(loadText[1], 4)[1])), loadText[1], 4, screen)
    staticText.append(newText)
    hintRect = Module_graphics.simpleBox((0, 560), 800, 40, (225, 128, 0), screen)
    
    # Goal Text
    circleGoal = loadText[2][1]
    newText = Module_text.basicText((100,100), "Goal: < " + str(circleGoal), 3, screen)
    staticText.append(newText)
    
    # Game Type
    gameType = loadText[2]
    print gameType


# loadCircles = [ [List Per Circle --> [PosX, PosY], CircleSize, [R, G, B] ] ]
    for cir in loadCircles: # Create objects from the list
        print cir
        newCircle = Circle(cir[0], cir[1], cir[2])
        circles.append(newCircle)
    print "Circles parsed"
    originalCircles = len(circles)

# load Balls = [ [List Per Ball --> [PosX, PosY], BallSize, BallColourID] ] ]
    for ba in loadBalls:
        newBall = Ball(ba[0], ba[1], ba[2])
        balls.append(newBall)
    print "Balls parsed"
    
# loadExits = [ [List Per Exit --> [PosX, PosY], Size, ExitColourID ] ]
    for ex in loadExits:
        newExit = Exit(ex[0], ex[1], ex[2])
        exits.append(newExit)
    print "Exits parsed"

# Set up variables
    levelClock = pygame.time.Clock() # Need new clock - new main loop
    print "Reset runningLevel"
    runningLevel = True
    circleCentre = (0,0)
    mouseIsDown = False
    currentColourID = 0
    r = 10
    circleCount = 0
    
    # --- MAIN LOOP -----------------------------------------
    while runningLevel:
        levelClock.tick(60)

        screen.fill((146,146,146))
        
        # Draw objects to the screen
        for c in circles:
            c.display(screen)
        for b in balls:
            b.move()
            for i, ball in enumerate(balls):
                for ball2 in balls[i+1:]:
                    collideBalls(ball, ball2)
            collideCircle(b)
            collideExit(b)
            b.display(screen)
            
        for e in exits:
            e.display(screen)
        hintRect.update() # Draw static before dynamic
        for t in staticText:
            t.updateText()
        
        print "WhileLoop after collisions", runningLevel
        
        # Dynamic Text
        Module_text.updateDynamic("Circles: " + str(circleCount), 2, (50,50), screen)

        # User Interaction
        if mouseIsDown == True:
            pygame.draw.circle(screen, setCircleColour(currentColourID), circleCentre, r, 2)
            r += 1

        # Get events and act upon them
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                runningLevel = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                print "MouseDown", pygame.mouse.get_pos()
                circleCentre = pygame.mouse.get_pos()
                mouseIsDown = True
            elif event.type == pygame.MOUSEBUTTONUP:
                print "MouseUp", pygame.mouse.get_pos()
                mouseIsDown = False
                newCircle = Circle(circleCentre, r, currentColourID)
                circles.append(newCircle)
                circleCount += 1
                r = 10
            elif event.type == pygame.KEYDOWN:
                currentKey = event.key
                if currentKey == pygame.K_1:
                    currentColourID = 0
                elif currentKey == pygame.K_2:
                    currentColourID = 1
                elif currentKey == pygame.K_3:
                    currentColourID = 2
                elif currentKey == pygame.K_4:
                    currentColourID = 3
                else:
                    pass
        
        pygame.display.flip()
        
        # Check if the user has won the level
        runningLevel, playerScore = winCheck(balls, gameType, originalCircles)
    
    print "Player Score:", playerScore