5 move_parrot_logo.pir - move a Parrot logo with the SDL Parrot bindings
9 To run this file, run the following command from the Parrot directory:
11 $ parrot examples/sdl/move_parrot_logo.pir
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"
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'()
38 black = new ['SDL'; 'Color']
39 black.'init'( 'r' => 0, 'g' => 0, 'b' => 0 )
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
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
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'
72 event = new ['SDL'; 'Event']
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 )
85 .namespace [ 'MoveLogo::EventHandler' ]
87 .sub draw_screen :method
94 rect_array = new 'ResizablePMCArray'
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 )
106 .sub key_down_down :method
107 .param pmc event_args
112 screen = event_args[ 'screen' ]
113 sprite = event_args[ 'sprite' ]
117 if y == 424 goto _draw
122 self.'draw_screen'( screen, sprite )
126 .sub key_down_up :method
127 .param pmc event_args
132 screen = event_args[ 'screen' ]
133 sprite = event_args[ 'sprite' ]
142 self.'draw_screen'( screen, sprite )
146 .sub key_down_left :method
147 .param pmc event_args
152 screen = event_args[ 'screen' ]
153 sprite = event_args[ 'sprite' ]
162 self.'draw_screen'( screen, sprite )
166 .sub key_down_right :method
167 .param pmc event_args
172 screen = event_args[ 'screen' ]
173 sprite = event_args[ 'sprite' ]
177 if x == 540 goto _draw
182 self.'draw_screen'( screen, sprite )
186 .sub key_down_escape :method
187 .param pmc event_args
194 chromatic, E<lt>chromatic at wgz dot orgE<gt>.
198 Copyright (C) 2004-2008, Parrot Foundation.
206 # vim: expandtab shiftwidth=4 ft=pir: