Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/g.py
blob: 4233b0b4fafc9ef0d0a5a8c19c8b97493ac6910e (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# g.py - globals
import pygame,utils,random,imgClick

app='Follow Me'; ver='1.0'
ver='1.1'
# new bgd
# ladder
ver='1.2'
# scaled font @ imgf
# man on ladder
# green bgd -> new buttons
ver='1.3'
# star separate & left @ top
ver='1.4' #<<<< Release 3
# added magician pic
ver='1.5'
# magician -> object
# speed slider
# change green button colour
ver='1.5'
# rationalised g.py
# no Esc on XO
# simon.py - delay also controlled by slider
# save level
ver='2.0'
# sugar coated
# got this to work ok BUT cursor flickers
ver='2.1'
# added journal switch
# swapped me & grapes
# added version display for right click
ver='2.2'
# cf Boxes
ver='2.3'
# app title
ver='2.4'
# yellow glow for player & longer
# increased glow size
# random seed
ver='3.0'
# redraw implemented
ver='4.0'
# new sugar cursor etc
ver='21'
# bigger white glow
# no pointer or rectangle while leading
ver='22'
# flush_queue() doesn't use gtk on non-XO

UP=(264,273)
DOWN=(258,274)
LEFT=(260,276)
RIGHT=(262,275)
CROSS=(259,120)
CIRCLE=(265,111)
SQUARE=(263,32)
TICK=(257,13)

def init(): # called by main()
    random.seed()
    global redraw
    global screen,w,h,font1,font2,clock,click_snd
    global factor,offset,imgf,message,version_display
    global pos,pointer
    redraw=True
    version_display=False
    screen = pygame.display.get_surface()
    pygame.display.set_caption(app)
    screen.fill((70,0,70))
    pygame.display.flip()
    w,h=screen.get_size()
    if float(w)/float(h)>1.5: #widescreen
        offset=(w-4*h/3)/2 # we assume 4:3 - centre on widescreen
    else:
        h=int(.75*w) # allow for toolbar - works to 4:3
        offset=0
    clock=pygame.time.Clock()
    factor=float(h)/24 # measurement scaling factor (32x24 = design units)
    offset=(w-4*h/3)/2 # we assume 4:3 - centre on widescreen
    imgf=float(h)/900 # image scaling factor - all images built for 1200x900
    if pygame.font:
        t=int(54*imgf); font1=pygame.font.Font(None,t)
        t=int(48*imgf); font2=pygame.font.Font(None,t)
    message=''
    pos=pygame.mouse.get_pos()
    pointer=utils.load_image('pointer.png',True)
    pygame.mouse.set_visible(False)
    
    # this activity only
    global imgs,glow,glowy,wrong_img,man,ladder,star,score
    global man_x0,man_y0,man_dx,man_dy,man_sc_dx,man_sc_dy
    global wrong,player_n,best,level
    global max_w,max_h,green
    wrong_img=utils.load_image('wrong.png',True); wrong_ind=0; right_ind=0
    man=utils.load_image('man.png',True)
    man_x0=sx(25.5); man_y0=sy(18.31)
    man_dx=(sx(27.87)-man_x0)/11.0; man_dy=(sy(12.15)-man_y0)/11.0
    man_sc_dx=sx(25.38)-man_x0; man_sc_dy=sy(18.61)-man_y0
    ladder=utils.load_image('ladder.png',True)
    star=utils.load_image('star.png',True)
    cy=sy(3.2); dx=sy(6.4); dy=sy(6.2); i=1
    score=0; best=0; level=1
    imgs=[]; glow=[]; glowy=[]; max_w=0; max_h=0
    for r in range(1,4):
        cx=sx(3.2)
        for c in range(1,6):
            img=utils.load_image(str(i)+'.png',True)
            imgC=imgClick.ImgClick(img,(cx,cy),True)
            if imgC.w>max_w: max_w=imgC.w
            if imgC.h>max_h: max_h=imgC.h
            imgs.append(imgC)
            glow.append(utils.load_image(str(i)+'.png',True,'glow'))
            glowy.append(utils.load_image(str(i)+'.png',True,'glowy'))
            cx+=dx; i+=1
            if i==15: break
        cy+=dy
    player_n=0 # player click counter
    wrong=False
    green=0
    imgs[green].mouse_set()

def sx(f): # scale x function
    return int(f*factor+offset+.5)

def sy(f): # scale y function
    return int(f*factor+.5)