2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
53 unsigned char brush_tile
;
58 //if screen exists change tile
59 //else create new screen
60 zone
* z
= game
.current_zone
;
63 struct screen
* scr
= ZONE_LOOKUP(z
,si
,sj
);
66 scr
= xmalloc(sizeof(struct screen
));
67 z
->screens
[si
+z
->w
*sj
] = scr
;
70 scr
->tiles
[cursor_x
-si
*20][cursor_y
-sj
*15] = brush_tile
;
74 void cursor_control(int key
){
76 case LEFT_KEY
: cursor_x
--; break;
77 case RIGHT_KEY
: cursor_x
++; break;
78 case UP_KEY
: cursor_y
--; break;
79 case DOWN_KEY
: cursor_y
++; break;
82 if(cursor_x
< 0){cursor_x
= 0;}
83 if(cursor_y
< 0){cursor_y
= 0;}
85 /*check for crossing a zone exit*/
87 if(cursor_x
< camera_x
){
89 point_camera(camera_x
*16, camera_y
*16);
91 if(cursor_x
>= camera_x
+20){
93 point_camera(camera_x
*16, camera_y
*16);
95 if(cursor_y
< camera_y
){
97 point_camera(camera_x
*16, camera_y
*16);
99 if(cursor_y
>= camera_y
+15){
101 point_camera(camera_x
*16, camera_y
*16);
104 screen_x
= cursor_x
/20;
105 screen_y
= cursor_y
/15;
106 if(cursor_x
< 0){screen_x
--;}
107 if(cursor_y
< 0){screen_y
--;}
111 cursor
->x
= cursor_x
*16;
112 cursor
->y
= cursor_y
*16;
114 if(hold_fire
) press_fire();
118 void edit_keydown(int key
){
120 if(key
== ESCAPE_KEY
){
148 void edit_keyup(int key
){
149 if(key
== repeat
.key
){
152 if(key
== FIRE_KEY
) hold_fire
= 0;
155 void edit_joymovex(int joy
, int x
){
156 printf("you moved joystick %d x axis to %d\n",joy
,x
);
159 void edit_joymovey(int joy
, int y
){
160 printf("you moved joystick %d y axis to %d\n",joy
,y
);
163 void edit_joypress(int joy
, int button
){
164 printf("you pressed joystick %d button %d\n",joy
,button
);
167 void edit_joyrelease(int joy
, int button
){
168 printf("you released joystick %d button %d\n",joy
,button
);
175 printf_small(1,1,"zone: %s",game
.zones
[0]->name
);
176 printf_small(1,10,"screen: %d,%d",screen_x
,screen_y
);
177 printf_small(1,19,"cursor: %d,%d",cursor_x
,cursor_y
);
178 printf_small(1,28,"camera: %d,%d",camera_x
,camera_y
);
181 struct handler edit_handler
= {
182 edit_keydown
, edit_keyup
, edit_joymovex
,
183 edit_joymovey
, edit_joypress
, edit_joyrelease
189 void main_init(int argc
, char* argv
[]){
190 backend_init(argc
, argv
);
197 set_handler(edit_handler
);
199 game
.draw
= edit_draw
;
201 char** list
= loader_readdir("zones");
202 for(int i
=0; list
[i
]; i
++){
203 printf("loading zone \"%s\"\n",list
[i
]);
206 loader_freedirlist(list
);
208 game
.current_zone
= game
.zones
[0];
214 load_sprite("box.spr",SPR_BOX
);
215 cursor
= enable_sprite(SPR_BOX
);
228 if(repeat
.timer
> 40){
230 cursor_control(repeat
.key
);
248 for(int i
=0; i
<T
/dt
; i
++){
261 int main(int argc
, char* argv
[]){
263 main_init(argc
, argv
);