commit 989b1f7f1620efd7e949daa9941c1fd08ca73c1b
parent 6533d405743a388096f4ca2c1afbfad1a9ebdffd
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 4 Jan 2023 10:35:01 +0900
add vertical scroll
Diffstat:
M | ex9/main.c | | | 34 | ++++++++++++++++++++-------------- |
M | ex9/world_map.h | | | 122 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
2 files changed, 81 insertions(+), 75 deletions(-)
diff --git a/ex9/main.c b/ex9/main.c
@@ -12,6 +12,8 @@
#define SUB_TICK (4)
#define NUM_BLOCK (200)
#define GRAVITY (1000)
+#define WIN_WIDTH (800)
+#define WIN_HEIGHT (600)
/*
#define COUNT_FPS
@@ -62,12 +64,12 @@ start_menu(void)
x_clear_area();
x_draw_string(0x00FFFF,
- WORLD_WIDTH * BLOCK_SIZE/2 - 10 * strlen(menu_char_q)/2,
- WORLD_HEIGHT * BLOCK_SIZE/2,
+ WIN_WIDTH / 2 - 10 * strlen(menu_char_q)/2,
+ WIN_HEIGHT / 2,
menu_char_q, strlen(menu_char_q));
x_draw_string(0x00FFFF,
- WORLD_WIDTH * BLOCK_SIZE/2 - 10 * strlen(menu_char_s)/2,
- WORLD_HEIGHT * BLOCK_SIZE/2 + 20,
+ WIN_WIDTH / 2 - 10 * strlen(menu_char_s)/2,
+ WIN_HEIGHT / 2 + 20,
menu_char_s, strlen(menu_char_s));
while (next_menu == START_MENU) {
@@ -77,12 +79,12 @@ start_menu(void)
switch (event) {
case XEXPOSE:
x_draw_string(0x00FFFF,
- WORLD_WIDTH * BLOCK_SIZE/2 - 10 * strlen(menu_char_q)/2,
- WORLD_HEIGHT * BLOCK_SIZE/2,
+ WIN_WIDTH / 2 - 10 * strlen(menu_char_q)/2,
+ WIN_HEIGHT / 2,
menu_char_q, strlen(menu_char_q));
x_draw_string(0x00FFFF,
- WORLD_WIDTH * BLOCK_SIZE/2 - 10 * strlen(menu_char_s)/2,
- WORLD_HEIGHT * BLOCK_SIZE/2 + 20,
+ WIN_WIDTH / 2 - 10 * strlen(menu_char_s)/2,
+ WIN_HEIGHT / 2 + 20,
menu_char_s, strlen(menu_char_s));
break;
@@ -118,6 +120,7 @@ game_play(void)
struct timespec ts;
struct OH *blh[WORLD_WIDTH]; // block list header
struct OL *blc;
+ int scroll_dst = 35;
for (int xi = 0; xi < WORLD_WIDTH; xi++)
blh[xi] = create_ol();
@@ -165,6 +168,8 @@ game_play(void)
player->body.rectangle.w;
}
+ // scrolling
+
struct OH *collidings;
collidings = create_ol();
@@ -212,18 +217,19 @@ game_play(void)
#endif
x_clear_area();
- for (int xi = 0; xi < WORLD_WIDTH; xi++) {
+ for (int xi = scroll_dst / BLOCK_SIZE;
+ xi < (WIN_WIDTH + scroll_dst) / BLOCK_SIZE; xi++) {
blc = blh[xi]->first;
while (blc != NULL) {
x_draw_rectangle(0x00FF00,
- blc->o->p.x, blc->o->p.y, // position
+ blc->o->p.x - scroll_dst, blc->o->p.y, // position
blc->o->body.rectangle.w,
blc->o->body.rectangle.h);
blc = blc->next;
}
}
x_draw_rectangle(0x009FFF,
- player->p.x, player->p.y, // position
+ player->p.x - scroll_dst, player->p.y, // position
player->body.rectangle.w, player->body.rectangle.h);
char status_string[128];
snprintf(status_string, 128, "falling: %d", player_is_falling);
@@ -243,8 +249,8 @@ game_over(void)
x_clear_area();
x_draw_string(0x00FFFF,
- WORLD_WIDTH * BLOCK_SIZE/2 - 10 * strlen(menu_char)/2,
- WORLD_HEIGHT * BLOCK_SIZE/2,
+ WIN_WIDTH / 2 - 10 * strlen(menu_char)/2,
+ WIN_HEIGHT / 2,
menu_char, strlen(menu_char));
x_flush();
@@ -384,7 +390,7 @@ int
main(void)
{
x_setup_window(0, 0,
- WORLD_WIDTH * BLOCK_SIZE, WORLD_HEIGHT * BLOCK_SIZE,
+ WIN_WIDTH, WIN_HEIGHT,
0x000000, "UNKO");
while (next_menu != QUIT){
switch (next_menu){
diff --git a/ex9/world_map.h b/ex9/world_map.h
@@ -1,65 +1,65 @@
-#define WORLD_WIDTH (80)
+#define WORLD_WIDTH (240)
#define WORLD_HEIGHT (60)
#define BLOCK_SIZE (10)
char world_map[WORLD_WIDTH * WORLD_HEIGHT + 1] =
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................b..............................................................."
-"..........................................................b..........b.........."
-"................................................................................"
-".......................b........................................................"
-"...........................................b...................................."
-"...........................................b...................................."
-"................................................................................"
-"..................b............................................................."
-"................................................................................"
-"...........................................b...................................."
-"................................................................................"
-"................................................................................"
-"...........................b...................................................."
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"....................................bbbbbbbbbb.................................."
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"..............................................bbbbbbbbbb........................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"....................................bbbbbbbbbb.................................."
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"..........................bbbbbbbbbb............................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................................................................................"
-"................bbbbbbbbbb......................................................"
-"................................................................................"
-"................................................................................"
-"...p............................................................................"
-"bbbbbbbbbbbbbbbbbbbbbbbbb.......bbbbbbbbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbbbb"
-"........................b.......b......................b...b...................."
-"........................b.......b......................b...b...................."
-"........................b.......b......................b...b...................."
-"........................b.......b......................b...b....................";
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................b..............................................................................................................................................................................................................................."
+"..........................................................b..........b.........................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+".......................b........................................................................................................................................................................................................................"
+"...........................................b...................................................................................................................................................................................................."
+"...........................................b...................................................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+"..................b............................................................................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+"...........................................b...................................................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"...........................b...................................................................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"....................................bbbbbbbbbb.................................................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"..............................................bbbbbbbbbb........................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"....................................bbbbbbbbbb.................................................................................................................................................................................................."
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"..........................bbbbbbbbbb............................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................bbbbbbbbbb......................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"................................................................................................................................................................................................................................................"
+"...p............................................................................................................................................................................................................................................"
+"bbbbbbbbbbbbbbbbbbbbbbbbb.......bbbbbbbbbbbbbbbbbbbbbbbb...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
+"........................b.......b......................b...b...................................................................................................................................................................................."
+"........................b.......b......................b...b...................................................................................................................................................................................."
+"........................b.......b......................b...b...................................................................................................................................................................................."
+"........................b.......b......................b...b....................................................................................................................................................................................";