File: menu_levels.py

package info (click to toggle)
krank 0.7%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 67,880 kB
  • ctags: 460
  • sloc: python: 3,417; sh: 31; makefile: 13
file content (84 lines) | stat: -rw-r--r-- 3,330 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import k, levels
from Krank  import *
from Part import *

def init():
    k.sound.loadTheme('menu')
    k.world.setBackground('menu-levels')
    
    cx, w, h = k.world.rect.centerx, k.world.rect.width, k.world.rect.height
        
    num = min(levels.numLevels, k.config.numAvailableLevels())
    max = num
    num = min(10, num)
    pos = []
    cols = 5
    rows = math.ceil(num/cols)

    icons = []
    for i in range(num):
        row, col = math.floor((i%cols))+1.5, math.floor((i/cols))+0.8
        pos.append((row*w/(cols+2), col*h/4.7))
        
        icon = pygame.image.load('levels/unera-icons/level%03d.tga' % (i+1))
        if h < 768:
            icon = pygame.transform.scale(icon, (88, 66))
        icons.append(icon)
        
    for i in range(num):
        k.particles.add(Switch({ 'text': '%d' % (i+1),
                                 'action': 'k.level.startExit(%d)' % i,
                                 'align': 'bottom',
                                 'size': 'small', 
                                 'offset': icons[i].get_height()*0.6,
                                 'radius': icons[i].get_height()/8,
                                 'image': icons[i],
                                 'pos': pos[i]}))

    if num < 16:
        k.particles.add(Switch({ 'text': 'Back',
                                 'align': 'bottom',
                                 'action': 'k.level.menuExit("menu_play")',
                                 'size': 'small', 
                                 'pos': vector((cx-2*w/7, h*0.61))}))

    offset   = 38
    y        = k.world.rect.height >= 1024 and h*0.81 or h*0.79 
    k.particles.add(Switch({ 'text': 'Easy',
                             'align': 'bottom',
                             'action': 'k.config.setStage(1)',
                             'textsize': 'small',
                             'offset': offset,
                             'color': k.config.stage==1 and 'orange' or 'white', 
                             'pos': vector((cx-1*w/7, y))}))

    k.particles.add(Switch({ 'text': 'Hard',
                             'align': 'bottom',
                             'action': 'k.config.setStage(2)',
                             'textsize': 'small', 
                             'offset': offset,
                             'color': k.config.stage==2 and 'orange' or 'white', 
                             'pos': vector((cx, y))}))

    k.particles.add(Switch({ 'text': 'Extreme',
                             'align': 'bottom',
                             'action': 'k.config.setStage(3)',
                             'textsize': 'small', 
                             'offset': offset,
                             'color': k.config.stage==3 and 'orange' or 'white', 
                             'pos': vector((cx+1*w/7, y))}))
    
    if max > 10:
        k.particles.add(Switch({ 'text': 'Next 10',
                                 'align': 'bottom',
                                 'action': 'k.level.menuExit("menu_levels2")',
                                 'size': 'small', 
                                 'pos': vector((cx+2*w/7, h*0.61))}))
    
    # player
    k.player.setPos(vector((cx, h*0.61)))
    k.player.setTailNum(2, -1)

    k.screen.blit(k.world.image, k.world.rect)
    pygame.display.update()