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
, uint8_t*completed
) {
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 if(completed
[i
]) continue;
22 p
= vecadd(&maps
[i
]->worldmap_coords
, &VEC(2,2));
25 p
= vecadd(&p
, &VEC(SCALE
/2,SCALE
/2));
26 if(vecdist(&p
, &c
) <= 3*SCALE
) { ret
= i
; goto done
; }
32 static void draw_blinky(const struct palpic
*b
, int x
, int y
, uint8_t*completed
) {
35 for(i
= 0; i
< MI_MAX
; i
++) {
36 if(completed
[i
]) continue;
37 p
= maps
[i
]->worldmap_coords
;
38 blit_sprite((x
+p
.x
)*SCALE
, (y
+p
.y
)*SCALE
, &video
, SCALE
, b
, map_ticks
%7, 0);
42 static void draw_face(const struct map
*map
) {
47 blit_sprite(FACE_X
*SCALE
, FACE_Y
*SCALE
, &video
, SCALE
, spritemaps
[SI_CLIENTS
], map
->client_face
, 0);
50 static void draw_maptext(const struct map
*map
) {
53 #define TEXT_Y (FACE_Y - 6)
55 for(i
= 0; i
< 5; i
++) {
56 font_print(TEXT_X
*SCALE
, TEXT_Y
*SCALE
+ i
*(TEXT_H
+1)*SCALE
,
57 map
->mission_text
[i
], 33, SCALE
, PRGB(0xdd,0xbb,0x00));
61 static void draw_frame() {
62 blit_sprite((FACE_X
-2)*SCALE
, (FACE_Y
-2)*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_HORIZ
], 0, 0);
63 blit_sprite((FACE_X
-2)*SCALE
, (FACE_Y
+FACE_H
)*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_HORIZ
], 1, 0);
64 blit_sprite((FACE_X
-2)*SCALE
, FACE_Y
*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_VERT
], 0, 0);
65 blit_sprite((FACE_X
+FACE_W
)*SCALE
, FACE_Y
*SCALE
, &video
, SCALE
, spritemaps
[SI_PICFRAME_VERT
], 1, 0);
68 static void draw_stuff(const struct palpic
*world
, int x
, int y
, uint8_t *completed
) {
70 draw_world(world
, x
, y
);
71 const struct palpic
*blinky
= spritemaps
[SI_MAPBLINK
];
72 draw_blinky(blinky
, x
, y
, completed
);
73 enum map_index m
= cursor_on_map(x
, y
, completed
);
75 const struct map
*map
= maps
[m
];
83 static void map_tick(const struct palpic
*world
, int x
, int y
, uint8_t *completed
) {
85 draw_stuff(world
, x
, y
, completed
);
86 if(tc
%6==0) map_ticks
++;
88 if (audio_process() == -1) music_restart();
92 enum map_index
choose_mission(uint8_t* completed
) {
93 const struct palpic
*world
= spritemaps
[SI_WORLDMAP
];
94 int x
= (320 - palpic_getspritewidth(world
))/2;
95 int y
= ((240 - palpic_getspriteheight(world
))/2)+16;
96 enum map_index ret
= MI_INVALID
;
100 while (SDL_PollEvent(&sdl_event
)) {
102 switch (sdl_event
.type
) {
103 case SDL_MOUSEMOTION
:
104 cursor
.x
= sdl_event
.motion
.x
;
105 cursor
.y
= sdl_event
.motion
.y
;
107 case SDL_MOUSEBUTTONDOWN
:
108 dprintf(2, "click on %d,%d\n", cursor
.x
/SCALE
-x
, cursor
.y
/SCALE
-y
);
109 if((ret
= cursor_on_map(x
, y
, completed
)) != MI_INVALID
) goto dun_goofed
;
114 switch(sdl_event
.key
.keysym
.sym
) {
116 if((sdl_event
.key
.keysym
.mod
& KMOD_LALT
) ||
117 (sdl_event
.key
.keysym
.mod
& KMOD_RALT
)) {
132 map_tick(world
, x
, y
, completed
);