Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/example.py
blob: 41c794eee093501e83bbd158153b7fcd1e456a45 (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
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
#! /usr/bin/env python
# Rayito example
# Copyright (C) 2011 Gabriel Eirea
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact information:
# Gabriel Eirea geirea@gmail.com
# Ceibal Jam http://ceibaljam.org


import pygame
import rayito

if __name__ == "__main__":

    pygame.init()
    screen = pygame.display.set_mode((800,600))
    clock = pygame.time.Clock()

    bicho_image = pygame.image.load('bicho.png').convert_alpha()
    bicho = rayito.RtoImage(bicho_image, (50, 50))
    bicho2 = rayito.RtoImage(bicho_image, (100, 100))

    font24 = pygame.font.Font(None, 24)
    txts = ["Hola, yo soy Pancho",
            "No creo que consigas\nnada siguiendome",
            "Pero si te sirve de consuelo,\nsomos apenas unos sprites\natrapados en una grilla"]
    dia = rayito.RtoDialog(txts, font24, (200, 200, 0), (0, 0, 200), (170,130))
    txts = ["Nada que ver",
            "Yo estoy muy\ncontento aca"]
    dia2 = rayito.RtoDialog(txts, font24, (255, 255, 0), (0, 0, 100), (450,130))

    b1 = rayito.RtoButton("Apretame", font24, (255, 200, 0), (0, 100, 150), (70,60))

    images = []
    master_image = pygame.image.load('xoxi-ninios-sprite-01.png').convert_alpha()
    master_width, master_height = master_image.get_size()
    w = int(master_width/4)
    h = int(master_height/4)
    for i in xrange(4):
        images.append(master_image.subsurface((i*w, 0, w, h)))
    for i in xrange(4):
        images.append(master_image.subsurface((i*w, h, w, h)))
    for i in xrange(4):
        images.append(master_image.subsurface((i*w, 2*h, w, h)))
    for i in xrange(4):
        images.append(master_image.subsurface((i*w, 3*h, w, h)))
    fms = [0, 1, 0, 2, 0, 1, 0, 3, # up
           4, 5, 4, 6, 4, 5, 4, 7, # down
           8, 9, 8, 10, 8, 9, 8, 11, # left
           15, 13, 15, 14, 15, 13, 15, 12, # right
           0, 4, 8, 15] # stopped in 4 directions
    nf = [1, 2, 3, 4, 5, 6, 7, 0,
          9, 10, 11, 12, 13, 14, 15, 8,
          17, 18, 19, 20, 21, 22, 23, 16,
          25, 26, 27, 28, 29, 30, 31, 24,
          32, 33, 34, 35]
    dxs = [0, 0, 0, 0, 0, 0, 0, 0,
           0, 0, 0, 0, 0, 0, 0, 0, 
           -8, -8, -8, -8, -8, -8, -8, -8,
           8, 8, 8, 8, 8, 8, 8, 8,
           0, 0, 0, 0]
    dys = [-6, -6, -6, -6, -6, -6, -6, -6,
            6, 6, 6, 6, 6, 6, 6, 6,
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0]
    sp = rayito.RtoSprite(images, fms, nf, dxs, dys, (50, 200))
    sp2 = rayito.RtoSprite(images, fms, nf, dxs, dys, (420, 200))

    sound = pygame.mixer.Sound('junggle_btn045.wav')
    snd = rayito.RtoSound(sound, 1)

    tl = rayito.RtoTimeLine()
    tl.add_event(0, sp, 'update_frame', 35)
    tl.add_event(0, sp2, 'update_frame', 34)
    tl.add_event(0, dia, 'restart')
    tl.add_event(0, dia2, 'restart')
    tl.add_event(0, sp, 'show')
    tl.add_event(0, sp2, 'show')
    tl.add_event(1000, sp, 'update_frame', 24)
    tl.add_event(3000, sp, 'update_frame', 35)
    tl.add_event(3500, snd, 'play')
    tl.add_event(3500, dia, 'show')
    tl.add_event(5500, dia, 'next_text')
    tl.add_event(7500, dia, 'next_text')
    tl.add_event(9500, dia, 'next_text')
    tl.add_event(10000, dia2, 'show')
    tl.add_event(10000, snd, 'play')
    tl.add_event(12000, dia2, 'next_text')
    tl.add_event(14000, dia2, 'next_text')
    tl.add_event(15000, sp, 'update_frame', 16)
    tl.add_event(17000, sp, 'update_frame', 34)
    tl.add_event(19000, sp, 'hide')
    tl.add_event(19000, b1, 'show')

    tl2 = rayito.RtoTimeLine()
    tl2.add_event(0, bicho, 'show')
    tl2.add_event(2000, bicho, 'move_start', (.06, .06))
    tl2.add_event(6000, bicho, 'hide')

    bg = pygame.image.load('derechos-plaza-fondo.jpg').convert_alpha()

    pl = rayito.RtoPlayer((600, 500), (50, 50), tl, loop = False, bg_image = bg)
    pl.play()

    playing = True
    global_time = 0
    scene = 0
    
    while playing:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                playing = False
            elif event.type == pygame.MOUSEBUTTONDOWN:
                pressed = pl.pressed(event.pos)
                if pressed and pl.is_finished():
                    pl.new_timeline(tl2)
                    pl.play()
                    scene = 1
                    global_time = 0
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    if pl.is_paused():
                        pl.play()
                    else:
                        pl.pause()
                elif event.key == pygame.K_ESCAPE:
                    playing = False
        
        time_passed = clock.tick(20)
        global_time += time_passed

#        screen.fill((0, 0, 0))

        pl.update(global_time)
        pl.render(screen)
       
        pygame.display.flip()

        if pl.is_finished():
            if scene == 1:
                playing = False