3 #include "spritemaps.h"
10 static void draw_world(const struct palpic
*w
, int x
, int y
) {
11 blit_sprite(x
*SCALE
, y
*SCALE
, &video
, SCALE
, w
, 0, 0);
14 static unsigned map_ticks
;
15 static struct { int x
, y
; } cursor
;
16 static enum map_index
cursor_on_map(int x
, int y
) {
17 enum map_index i
, ret
= MI_INVALID
;
18 vec2f c
= { .x
= cursor
.x
- x
*SCALE
, .y
= cursor
.y
- y
*SCALE
};
20 for(i
= 0; i
< MI_MAX
; i
++) {
21 p
= vecadd(&maps
[i
]->worldmap_coords
, &VEC(2,2));
24 p
= vecadd(&p
, &VEC(SCALE
/2,SCALE
/2));
25 if(vecdist(&p
, &c
) <= 3*SCALE
) { ret
= i
; goto done
; }
31 static void draw_blinky(const struct palpic
*b
, int x
, int y
) {
34 for(i
= 0; i
< MI_MAX
; i
++) {
35 p
= maps
[i
]->worldmap_coords
;
36 blit_sprite((x
+p
.x
)*SCALE
, (y
+p
.y
)*SCALE
, &video
, SCALE
, b
, map_ticks
%7, 0);
40 static void draw_face(const struct map
*map
) {
45 blit_sprite(FACE_X
*SCALE
, FACE_Y
*SCALE
, &video
, SCALE
, spritemaps
[SI_CLIENTS
], map
->client_face
, 0);
48 static void draw_maptext(const struct map
*map
) {
51 #define TEXT_Y (FACE_Y - 6)
53 for(i
= 0; i
< 5; i
++) {
54 font_print(TEXT_X
*SCALE
, TEXT_Y
*SCALE
+ i
*(TEXT_H
+1)*SCALE
,
55 map
->mission_text
[i
], 33, SCALE
, PRGB(0xdd,0xbb,0x00));
59 static void draw_frame() {
60 blit_sprite((FACE_X
-2)*SCALE
, (FACE_Y
-2)*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_HORIZ
], 0, 0);
61 blit_sprite((FACE_X
-2)*SCALE
, (FACE_Y
+FACE_H
)*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_HORIZ
], 1, 0);
62 blit_sprite((FACE_X
-2)*SCALE
, FACE_Y
*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_VERT
], 0, 0);
63 blit_sprite((FACE_X
+FACE_W
)*SCALE
, FACE_Y
*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_VERT
], 1, 0);
66 static void draw_stuff(const struct palpic
*world
, int x
, int y
) {
68 draw_world(world
, x
, y
);
69 const struct palpic
*blinky
= spritemaps
[SI_MAPBLINK
];
70 draw_blinky(blinky
, x
, y
);
71 enum map_index m
= cursor_on_map(x
, y
);
73 const struct map
*map
= maps
[m
];
81 static void map_tick(const struct palpic
*world
, int x
, int y
) {
83 draw_stuff(world
, x
, y
);
84 if(tc
%6==0) map_ticks
++;
86 if (audio_process() == -1) music_restart();
90 enum map_index
choose_mission() {
91 const struct palpic
*world
= spritemaps
[SI_WORLDMAP
];
92 int x
= (320 - palpic_getspritewidth(world
))/2;
93 int y
= ((240 - palpic_getspriteheight(world
))/2)+16;
94 enum map_index ret
= MI_INVALID
;
98 while (SDL_PollEvent(&sdl_event
)) {
100 switch (sdl_event
.type
) {
101 case SDL_MOUSEMOTION
:
102 cursor
.x
= sdl_event
.motion
.x
;
103 cursor
.y
= sdl_event
.motion
.y
;
105 case SDL_MOUSEBUTTONDOWN
:
106 dprintf(2, "click on %d,%d\n", cursor
.x
/SCALE
-x
, cursor
.y
/SCALE
-y
);
107 if((ret
= cursor_on_map(x
, y
)) != MI_INVALID
) goto dun_goofed
;
112 switch(sdl_event
.key
.keysym
.sym
) {
114 if((sdl_event
.key
.keysym
.mod
& KMOD_LALT
) ||
115 (sdl_event
.key
.keysym
.mod
& KMOD_RALT
)) {
130 map_tick(world
, x
, y
);