This file is indexed.

/usr/share/pymt-examples/games/bubblebomb/bubblebomb.py is in python-pymt 0.5.1-0ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# PYMT Plugin integration
IS_PYMT_PLUGIN = True
PLUGIN_TITLE = 'Bubble-o-Bomb !'
PLUGIN_AUTHOR = 'Mathieu Virbel'
PLUGIN_DESCRIPTION = 'Secure Bubble Bomb before explosion !'

import os
from pymt import *
from OpenGL.GL import *
from random import random, randint

current_dir = os.path.dirname(__file__)

class Bomb(MTWidget):
    def __init__(self, **kwargs):
        super(Bomb, self).__init__(**kwargs)
        self.r = 30
        self.moved = False
        self.speed = 200
        self.level = kwargs.get('level')
        self.dx, self.dy = map(lambda x: randint(-self.speed, self.speed), xrange(2))
        self.lifetime = 8
        self.initial_lifetime = self.lifetime
        self.life = 1
        self.start = True
        self.saved = False
        self.color = kwargs.get('color')
        self.label = MTLabel(font_size=20, font_bold=True, anchor_x='center',
                anchor_y='center')

    def draw(self):
        # border
        linewidth = self.r - (self.lifetime / float(self.initial_lifetime) * (self.r))
        if self.color == 'red':
            set_color(.75, .4, .4, .9)
        else:
            set_color(.4, .4, .75, .9)
        drawCircle(pos=self.pos, radius=self.r + 3, linewidth=linewidth + 3)
        # background
        if self.color == 'red':
            set_color(.75, 0, 0, .7)
        else:
            set_color(0, 0, .75, .7)
        drawCircle(pos=self.pos, radius=self.r)
        # text
        self.label.label = str(int(self.lifetime+1))
        self.label.pos = (self.pos[0]-self.label.width/2,self.pos[1]-self.label.height/2)
        self.label.draw()

    def animate(self, world):
        dt = getFrameDt()
        if self.saved:
            return True
        self.lifetime -= dt
        if self.lifetime < 0:
            return
        return True

class DropBase(MTWidget):
    def __init__(self, **kwargs):
        super(DropBase, self).__init__(**kwargs)
        self.r = 100
        self.color = kwargs.get('color')

    def draw(self):
        # border
        if self.color == 'red':
            set_color(.75, .4, .4, .7)
        else:
            set_color(.4, .4, .75, .7)
        drawCircle(pos=self.pos, radius=self.r + 3, linewidth=3)
        # background
        if self.color == 'red':
            set_color(.75, 0, 0, .7)
        else:
            set_color(0, 0, .75, .7)
        drawCircle(pos=self.pos, radius=self.r)

class GameOver(MTWidget):
    def __init__(self, **kwargs):
        self.world = kwargs.get('world')
        super(GameOver, self).__init__(**kwargs)
        self.layout = MTBoxLayout(orientation='vertical', uniform_width=True,
                                  uniform_height=True, padding=100,
                                  spacing=20, invert_y=True)
        k = {'font_size': 48}
        self.text = MTLabel(label='GAME OVER', **k)
        self.textlevel = MTLabel(label='Your level is %d' % self.world.level, **k)
        self.textscore = MTLabel(label='Your score is %d' % self.world.highscore, **k)
        self.restart = MTButton(label='Restart')
        self.layout.add_widget(self.text)
        self.layout.add_widget(self.textlevel)
        self.layout.add_widget(self.textscore)
        self.layout.add_widget(self.restart)
        self.restart.push_handlers(on_press=self.handle_restart)
        self.add_widget(self.layout)

    def handle_restart(self, *largs):
        self.world.reset()
        self.parent.remove_widget(self)

    def on_touch_down(self, touch):
        super(GameOver, self).on_touch_down(touch)
        return True

    def on_touch_move(self, touch):
        super(GameOver, self).on_touch_move(touch)
        return True

    def on_touch_up(self, touch):
        super(GameOver, self).on_touch_up(touch)
        return True

    def draw(self):
        w = self.get_parent_window()
        self.layout.x = (w.width - self.layout.width) / 2.
        self.layout.y = (w.height - self.layout.height) / 2.
        set_color(0.2, 0.2, 0.2, .5)
        drawRectangle(size=w.size)

class World(MTWidget):
    def __init__(self, **kwargs):
        super(World, self).__init__(**kwargs)
        self.reset()
        self.s_gameover = SoundLoader.load(os.path.join(current_dir, 'gameover.wav'))
        self.s_touch = SoundLoader.load(os.path.join(current_dir, 'touch.wav'))
        self.s_nextlevel = SoundLoader.load(os.path.join(current_dir, 'level.wav'))
        self.s_gameover.volume = .5
        self.s_touch.volume = .5
        self.s_nextlevel.volume = .5

    def sound(self, name):
        if name == 'gameover':
            self.s_gameover.stop()
            self.s_gameover.seek(0)
            self.s_gameover.play()
        elif name == 'touch':
            self.s_touch.stop()
            self.s_touch.seek(0)
            self.s_touch.play()
        elif name == 'nextlevel':
            self.s_nextlevel.stop()
            self.s_nextlevel.seek(0)
            self.s_nextlevel.play()

    def reset(self):
        self.bomb = []
        self.touches = {}
        self.score = 0
        self.nextspawn = 0
        self.spawnspeed = 1
        self.levelscore = 10
        self.level = 1
        self.highscore = 0
        self.isgameover = False
        self.alphalevel = 1
        self.bases = (DropBase(color='red'), DropBase(color='blue'))

    def animate(self):
        if self.isgameover:
            return

        w = self.get_parent_window()
        dt = getFrameDt()

        # background
        self.alphalevel -= getFrameDt() * 3

        # animate enemies
        for b in self.bomb:
            if not b.animate(self):
                self.gameover()

            for base in self.bases:
                if Vector(b.pos).distance(Vector(base.pos)) > b.r + base.r:
                    continue
                if not b.saved:
                    b.dx = - b.dx
                    b.dy = - b.dy
                    b.x += b.dx * dt
                    b.y -= b.dy * dt

            # advance enemy
            if b.moved:
                continue

            b.x += b.dx * dt
            b.y -= b.dy * dt

            if b.x < b.r:
                if b.dx < 0:
                    b.dx = -b.dx
                b.x = b.r + b.dx * dt
            elif b.x > w.width - b.r:
                if b.dx > 0:
                    b.dx = -b.dx
                b.x = w.width - b.r + b.dx * dt
            elif b.y < b.r:
                if b.dy > 0:
                    b.dy = -b.dy
                b.y = b.r + b.dy * dt
            elif b.y > w.height - b.r:
                if b.dy < 0:
                    b.dy = -b.dy
                b.y = w.height - b.r + b.dy * dt
            elif b.saved and Vector(b.pos).distance(b.savedbase.pos) >= b.savedbase.r - b.r:
                b.dx = - b.dx
                b.dy = - b.dy
                b.x += b.dx * dt
                b.y -= b.dy * dt

    def nextlevel(self):
        if self.score > self.highscore:
            self.highscore = self.score
        if self.score < 0:
            self.gameover()
        if self.score < self.levelscore:
            return
        self.sound('nextlevel')
        self.level += 1
        self.levelscore = self.levelscore * 2
        self.spawnspeed += .5
        self.alphalevel = 1
        b_delete = [b for b in self.bomb if b.saved]
        [self.bomb.remove(b) for b in b_delete if b in self.bomb]

    def spawn(self):
        self.nextspawn -= (getFrameDt() * .5) * self.spawnspeed
        if self.nextspawn < 0:
            c = ('red', 'blue')[randint(0, 1)]
            b = Bomb(color=c, level=self.level)
            self.nextspawn = 1.
            w = self.get_parent_window()
            redo = True
            while redo:
                x = w.width * random()
                y = w.height * random()
                redo = False
                for base in self.bases:
                    if Vector(base.pos).distance(Vector(x, y)) < base.r + b.r:
                        redo = True
            b.pos = x, y
            self.bomb.append(b)

    def gameover(self):
        self.stop()
        if not self.isgameover:
            self.sound('gameover')
            self.isgameover = True
            self.get_parent_window().add_widget(GameOver(world=self))

    def stop(self):
        self.spawnspeed = 0

    def on_touch_down(self, touch):
        # search a bomb
        for b in self.bomb:
            if b.saved:
                continue
            if Vector(b.pos).distance(Vector(touch.x, touch.y)) > b.r:
                continue
            self.sound('touch')
            self.touches[touch.id] = b
            b.pos = touch.x, touch.y
            b.moved = True
            touch.grab(self)
            return True

    def on_touch_move(self, touch):
        if touch.id not in self.touches:
            return
        self.touches[touch.id].pos = touch.x, touch.y
        return True

    def on_touch_up(self, touch):
        if touch.id not in self.touches:
            return
        self.touches[touch.id].pos = touch.x, touch.y
        b = self.touches[touch.id]
        b.moved = False
        for base in self.bases:
            if Vector(b.pos).distance(Vector(base.pos)) > b.r + base.r:
                continue
            if b.color != base.color:
                self.gameover()
                return
            elif not b.saved:
                self.sound('touch')
                self.score += 1
                b.saved = True
                b.savedbase = base
                b.pos = base.pos
                return True

    def draw(self):
        w = self.get_parent_window()
        step = w.width / (1+len(self.bases))
        x = step
        for b in self.bases:
            b.pos = x, w.height / 2
            x += step

        # game
        self.spawn()
        self.animate()
        self.nextlevel()

        # background
        if self.alphalevel > 0:
            set_color(1, .4, .4, self.alphalevel)
            drawRectangle(size=w.size)

        # enemies + bariers
        for b in reversed(self.bases):
            b.draw()
        for b in reversed(self.bomb):
            b.draw()

        # score
        w2 = w.width / 2.
        set_color(.5, .5, .5, .5)
        drawRoundedRectangle(pos=(w2/2, w.height - 35), size=(w2, 50))
        set_color(.5, .5, .5, .5)
        drawRoundedRectangle(pos=(w2/2, w.height - 35), size=(w2, 50), style=GL_LINE_LOOP)
        label = 'Level %d ~ Score: %-5d / %5d' % (self.level, self.score, self.levelscore)
        drawLabel(label=label, pos=(w2, w.height - 15), color=(255, 255, 255, 200))

def pymt_plugin_activate(w, ctx):
    ctx.c = World()
    w.add_widget(ctx.c)

def pymt_plugin_deactivate(w, ctx):
    w.remove_widget(ctx.c)

if __name__ == '__main__':
    w = MTWindow()
    ctx = MTContext()
    pymt_plugin_activate(w, ctx)
    runTouchApp()
    pymt_plugin_deactivate(w, ctx)