From e70e694af8a486df171f575dd6105700dbce6eca Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 14 Sep 2017 15:12:38 -0400 Subject: [PATCH] tfv: allow entering city map --- gr-sim/Makefile | 7 +- gr-sim/tfv_backgrounds.h | 2 +- gr-sim/tfv_citymap.c | 142 +++++++++++++++++++++++++++++++++++++++ gr-sim/tfv_worldmap.c | 5 ++ gr-sim/tfv_zp.h | 3 + 5 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 gr-sim/tfv_citymap.c diff --git a/gr-sim/Makefile b/gr-sim/Makefile index 3f055898..17c6b935 100644 --- a/gr-sim/Makefile +++ b/gr-sim/Makefile @@ -87,6 +87,9 @@ tfv_backgrounds.o: tfv_backgrounds.c tfv_backgrounds.h tfv_battle.o: tfv_battle.c $(CC) $(CFLAGS) -c tfv_battle.c +tfv_citymap.o: tfv_citymap.c + $(CC) $(CFLAGS) -c tfv_citymap.c + tfv_flying.o: tfv_flying.c $(CC) $(CFLAGS) -c tfv_flying.c @@ -117,8 +120,8 @@ tfv_worldmap.o: tfv_worldmap.c tfv.o: tfv.c gr-sim.h tfv_backgrounds.h tfv_sprites.h $(CC) $(CFLAGS) -c tfv.c -tfv: tfv.o tfv_backgrounds.o tfv_battle.o tfv_flying.o tfv_info.o tfv_multiply.o tfv_opener.o tfv_sprites.o tfv_textentry.o tfv_title.o tfv_utils.o tfv_worldmap.o gr-sim.o - $(CC) $(LFLAGS) $(SDL_LIBS) -o tfv tfv.o tfv_backgrounds.o tfv_battle.o tfv_flying.o tfv_info.o tfv_multiply.o tfv_opener.o tfv_sprites.o tfv_textentry.o tfv_title.o tfv_utils.o tfv_worldmap.o gr-sim.o +tfv: tfv.o tfv_backgrounds.o tfv_battle.o tfv_citymap.o tfv_flying.o tfv_info.o tfv_multiply.o tfv_opener.o tfv_sprites.o tfv_textentry.o tfv_title.o tfv_utils.o tfv_worldmap.o gr-sim.o + $(CC) $(LFLAGS) $(SDL_LIBS) -o tfv tfv.o tfv_backgrounds.o tfv_battle.o tfv_citymap.o tfv_flying.o tfv_info.o tfv_multiply.o tfv_opener.o tfv_sprites.o tfv_textentry.o tfv_title.o tfv_utils.o tfv_worldmap.o gr-sim.o ### diff --git a/gr-sim/tfv_backgrounds.h b/gr-sim/tfv_backgrounds.h index 17fccb37..6fa7e92f 100644 --- a/gr-sim/tfv_backgrounds.h +++ b/gr-sim/tfv_backgrounds.h @@ -3,6 +3,6 @@ extern unsigned char map_rle[]; extern unsigned char landing_rle[]; extern unsigned char collegep_rle[]; extern unsigned char harfco_rle[]; - +extern unsigned char umcp_rle[]; diff --git a/gr-sim/tfv_citymap.c b/gr-sim/tfv_citymap.c new file mode 100644 index 00000000..84b0450d --- /dev/null +++ b/gr-sim/tfv_citymap.c @@ -0,0 +1,142 @@ +#include +#include +#include +#include + +#include "gr-sim.h" +#include "tfv_utils.h" +#include "tfv_zp.h" + +#include "tfv_sprites.h" +#include "tfv_backgrounds.h" + +/* In Town */ + +int city_map(void) { + + int ch; + int direction=1; + int newx=0,newy=0,moved; + + gr(); + + color_equals(COLOR_BLACK); + + direction=1; + int odd=0; + int refresh=1; + + while(1) { + moved=0; + newx=tfv_x; + newy=tfv_y; + + ch=grsim_input(); + + if ((ch=='q') || (ch==27)) break; + + if ((ch=='w') || (ch==APPLE_UP)) { + newy=tfv_y-2; + moved=1; + } + if ((ch=='s') || (ch==APPLE_DOWN)) { + newy=tfv_y+2; + moved=1; + } + if ((ch=='a') || (ch==APPLE_LEFT)) { + if (direction>0) { + direction=-1; + odd=0; + } + else { + newx=tfv_x-1; + moved=1; + } + } + if ((ch=='d') || (ch==APPLE_RIGHT)) { + if (direction<0) { + direction=1; + odd=0; + } + else { + newx=tfv_x+1; + moved=1; + } + } + + if (ch=='h') print_help(); + if (ch=='b') do_battle(); + if (ch=='i') print_info(); + if (ch=='m') { + show_map(); + refresh=1; + } + + + /* Collision detection + Movement */ + if (moved) { + odd=!odd; + steps++; + +// if (collision(newx,newy+10,ground_color)) { +// } +// else { + tfv_x=newx; + tfv_y=newy; +// } + + if (tfv_x>36) { + map_x++; + tfv_x=0; + refresh=1; + } + else if (tfv_x<=0) { + map_x--; + tfv_x=35; + refresh=1; + } + + if ((tfv_y<4) && (map_x>=4)) { + map_x-=4; + tfv_y=28; + refresh=1; + } + else if (tfv_y>=28) { + map_x+=4; + tfv_y=4; + refresh=1; + } + } + + if (refresh) { + grsim_unrle(umcp_rle,0xc00); + refresh=0; + } + + gr_copy_to_current(0xc00); + + if (direction==-1) { + if (odd) grsim_put_sprite(tfv_walk_left,tfv_x,tfv_y); + else grsim_put_sprite(tfv_stand_left,tfv_x,tfv_y); + } + if (direction==1) { + if (odd) grsim_put_sprite(tfv_walk_right,tfv_x,tfv_y); + else grsim_put_sprite(tfv_stand_right,tfv_x,tfv_y); + } + + page_flip(); + + if (steps>=60) { + steps=0; + time_minutes++; + if (time_minutes>=60) { + time_hours++; + time_minutes=0; + } + } + + usleep(10000); + } + + return 0; +} diff --git a/gr-sim/tfv_worldmap.c b/gr-sim/tfv_worldmap.c index 0a6e439a..04c61b83 100644 --- a/gr-sim/tfv_worldmap.c +++ b/gr-sim/tfv_worldmap.c @@ -226,6 +226,11 @@ int world_map(void) { } } + if (ch==13) { + city_map(); + refresh=1; + } + if (ch=='h') print_help(); if (ch=='b') do_battle(); if (ch=='i') print_info(); diff --git a/gr-sim/tfv_zp.h b/gr-sim/tfv_zp.h index d27aa296..9bcaefef 100644 --- a/gr-sim/tfv_zp.h +++ b/gr-sim/tfv_zp.h @@ -80,3 +80,6 @@ int name_screen(void); int do_battle(void); int world_map(void); + +int city_map(void); +