[PDD] Add docs for the Parrot_PMC_push_* and Parrot_PMC_pop_* functions
[parrot.git] / examples / sdl / move_parrot_logo.pir
blob7bda908d7b8144a75ef2814d82c1bae233084bae
1 # $Id$
3 =head1 TITLE
5 move_parrot_logo.pir - move a Parrot logo with the SDL Parrot bindings
7 =head1 SYNOPSIS
9 To run this file, run the following command from the Parrot directory:
11         $ parrot examples/sdl/move_parrot_logo.pir
12         $
14 =cut
16 .sub _main :main
17         load_bytecode "SDL/App.pir"
18         load_bytecode "SDL/Color.pir"
19         load_bytecode "SDL/Rect.pir"
20         load_bytecode "SDL/Image.pir"
21         load_bytecode "SDL/Sprite.pir"
22         load_bytecode "SDL/EventHandler.pir"
23         load_bytecode "SDL/Event.pir"
25         .local pmc app
26         .local int app_type
28         app = new ['SDL'; 'App']
30         app.'init'( 'width' => 640, 'height' => 480, 'bpp' => 0, 'flags' => 0 )
32         .local pmc main_screen
33         main_screen = app.'surface'()
35         .local pmc black
36         .local int color_type
38         black = new ['SDL'; 'Color']
39         black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
41         .local pmc    image
42         .local int    image_type
43         .local string filename
46         image    = new ['SDL'; 'Image']
48         filename = 'examples/sdl/parrot_small.png'
49         image.'init'( 'file' => filename )
51         .local pmc sprite_args
53         .local pmc sprite
54         .local int sprite_type
56         sprite = new ['SDL'; 'Sprite']
57         sprite.'init'( 'surface'  => image, 'source_x' =>     0, 'source_y' =>     0, 'dest_x'   =>   270, 'dest_y'   =>   212, 'bgcolor'  => black )
59         .local pmc parent_class
60         .local pmc class_type
61         get_class parent_class, ['SDL'; 'EventHandler']
62         subclass class_type, parent_class, 'MoveLogo::EventHandler'
64         .local pmc event_handler
65         .local int handler_type
67         event_handler = new 'MoveLogo::EventHandler'
69         .local pmc event
70         .local int event_type
72         event = new ['SDL'; 'Event']
73         event.'init'()
75         .local pmc handler_args
76         handler_args = new 'Hash'
77         handler_args[ 'screen' ] = main_screen
78         handler_args[ 'sprite' ] = sprite
80         event_handler.'init'( handler_args )
81         event_handler.'draw_screen'( main_screen, sprite )
82         event.'process_events'( event_handler, handler_args )
83 .end
85 .namespace [ 'MoveLogo::EventHandler' ]
87 .sub draw_screen :method
88         .param pmc screen
89         .param pmc sprite
91         .local pmc prev_rect
92         .local pmc rect
93         .local pmc rect_array
94         rect_array = new 'ResizablePMCArray'
95         set rect_array, 2
97         (prev_rect, rect) = sprite.'draw_undraw'( screen )
99         set rect_array[ 0 ], prev_rect
100         set rect_array[ 1 ], rect
102         screen.'update_rects'( rect_array )
103         .return()
104 .end
106 .sub key_down_down :method
107         .param pmc event_args
109         .local pmc screen
110         .local pmc sprite
112         screen = event_args[ 'screen' ]
113         sprite = event_args[ 'sprite' ]
115         .local int y
116         y = sprite.'y'()
117         if y == 424 goto _draw
118         inc y
119         sprite.'y'( y )
121 _draw:
122         self.'draw_screen'( screen, sprite )
124 .end
126 .sub key_down_up :method
127         .param pmc event_args
129         .local pmc screen
130         .local pmc sprite
132         screen = event_args[ 'screen' ]
133         sprite = event_args[ 'sprite' ]
135         .local int y
136         y = sprite.'y'()
137         if y == 0 goto _draw
138         dec y
139         sprite.'y'( y )
141 _draw:
142         self.'draw_screen'( screen, sprite )
144 .end
146 .sub key_down_left :method
147         .param pmc event_args
149         .local pmc screen
150         .local pmc sprite
152         screen = event_args[ 'screen' ]
153         sprite = event_args[ 'sprite' ]
155         .local int x
156         x = sprite.'x'()
157         if x == 0 goto _draw
158         dec x
159         sprite.'x'( x )
161 _draw:
162         self.'draw_screen'( screen, sprite )
164 .end
166 .sub key_down_right :method
167         .param pmc event_args
169         .local pmc screen
170         .local pmc sprite
172         screen = event_args[ 'screen' ]
173         sprite = event_args[ 'sprite' ]
175         .local int x
176         x = sprite.'x'()
177         if x == 540 goto _draw
178         inc x
179         sprite.'x'( x )
181 _draw:
182         self.'draw_screen'( screen, sprite )
184 .end
186 .sub key_down_escape :method
187         .param pmc event_args
189         end
190 .end
192 =head1 AUTHOR
194 chromatic, E<lt>chromatic at wgz dot orgE<gt>.
196 =head1 COPYRIGHT
198 Copyright (C) 2004-2008, Parrot Foundation.
200 =cut
202 # Local Variables:
203 #   mode: pir
204 #   fill-column: 100
205 # End:
206 # vim: expandtab shiftwidth=4 ft=pir: