test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
Revision 39:e8d6dd3c75c7, committed 2016-12-13
- Comitter:
- kaku_jyoko
- Date:
- Tue Dec 13 11:55:17 2016 +0000
- Parent:
- 38:63b99151e218
- Child:
- 40:ec5c1b305b9a
- Commit message:
- change convert, jump speed
Changed in this revision
--- a/Converter.cpp Tue Dec 13 07:34:07 2016 +0000 +++ b/Converter.cpp Tue Dec 13 11:55:17 2016 +0000 @@ -4,7 +4,25 @@ #include "C12832_lcd.h" #include <math.h> -char* Converter::convert(int map[][LCD_X]){ +int pow(int x, int y){ + int ans = 1; + for(int i = 0; i < y; i++){ + ans *= x; + } + return ans; +} + +int binary(int bina){ + int ans = 0; + for (int i = 0; bina>0 ; i++) + { + ans = ans+(bina%2)*pow(10,i); + bina = bina/2; + } + return ans; +} + +Bitmap Converter::convert(int map[][LCD_X]){ int len = LCD_Y*LCD_X/CHAR_SIZE; int count = 0; int tmp = 0; @@ -12,12 +30,35 @@ for(int i = 0; i < len; i++ ){ char_map[i] = 0; } + +// for(int i = 0; i < LCD_X; i++){ +// printf("line %d height: ",i); +// for(int j = 0; j < LCD_Y; j++){ +// printf("%d ",map[j][i]); +// } +// printf("\n"); +// } +// printf("\n"); + + for(int i = 0; i < LCD_Y; i++){ for(int j = 0; j < LCD_X; j++){ int index = (i*LCD_X + j)/CHAR_SIZE; - char_map[index] |= map[i][j] << ((CHAR_SIZE - 1) - index % CHAR_SIZE); + //char_map[index] |= map[i][j] << ((CHAR_SIZE - 1) - index % CHAR_SIZE); + char_map[index] |= map[i][j] << ((CHAR_SIZE - 1) - (i*LCD_X + j) % CHAR_SIZE); } } + +// for(int i = 0; i < len; i++){ +// if(i % 16 == 0){ +// printf("\n"); +// printf("line %d ", i); +// } +// printf("%d ", char_map[i]); +// } +// +// printf("\n"); + //return char_map; Bitmap bitmap_converted = { LCD_X, @@ -25,6 +66,8 @@ LCD_X/CHAR_SIZE, char_map, }; - //return bitmap_converted; - return char_map; + return bitmap_converted; } + + +
--- a/Person.cpp Tue Dec 13 07:34:07 2016 +0000 +++ b/Person.cpp Tue Dec 13 11:55:17 2016 +0000 @@ -38,5 +38,6 @@ } bool Person::isGround(int height){ + printf("height: %d, person: %d \n", height, p.y + PERSON_SIZE - 1); return height == (p.y + PERSON_SIZE - 1); } \ No newline at end of file
--- a/convert.h Tue Dec 13 07:34:07 2016 +0000 +++ b/convert.h Tue Dec 13 11:55:17 2016 +0000 @@ -6,7 +6,7 @@ class Converter { public: - char* convert(int map[][LCD_X]); + Bitmap convert(int map[][LCD_X]); }; #endif \ No newline at end of file
--- a/main.cpp Tue Dec 13 07:34:07 2016 +0000 +++ b/main.cpp Tue Dec 13 11:55:17 2016 +0000 @@ -40,11 +40,21 @@ wall_height = stage.getStage(); for(int i = 0; i < LCD_Y; i++){ for(int j = 0; j < LCD_X ; j++){ - if(wall_height[i] > (LCD_Y - 1 - j)){ + if(wall_height[j] > (LCD_Y - 1 - i)){ white_board[i][j] = 1; } } } + //print wall int +// for(int i = 0; i < LCD_X; i++){ +// printf("line %d height: %d ",i, wall_height[i]); +// for(int j = 0; j < LCD_Y; j++){ +// printf("%d ",white_board[j][i]); +// } +// printf("\n"); +// } +// printf("\n"); + } void a(){ @@ -88,8 +98,8 @@ } int corrision_judge(point p_person, point p_bullet){ - printf("bullet x: %d, y: %d \n", p_bullet.x,p_bullet.y); - printf("person x: %d, y: %d \n", p_person.x,p_person.y); + //printf("bullet x: %d, y: %d \n", p_bullet.x,p_bullet.y); +// printf("person x: %d, y: %d \n", p_person.x,p_person.y); return (line_judge(p_person.x, p_person.x + PERSON_SIZE, p_bullet.x, p_bullet.x + BULLET_SIZE) && line_judge(p_person.y, p_person.y + PERSON_SIZE, p_bullet.y - 1, p_bullet.x - 4)); @@ -103,36 +113,25 @@ lcd.setmode(XOR); int gameOver = 0; srand((int)(aIn * 100)); -<<<<<<< local Converter converter; -======= - Converter converter(); - int len = LCD_Y*LCD_X/8; - char char_map[len]; ->>>>>>> other -// Bitmap picture; + Bitmap picture; while(true){ update_mtx.lock(); reset_white_board(); make_wall(); - p_person = h.update(1); + p_person = h.update(wall_height[3]); if(b != NULL){ p_bullet = b->update(); } //printf("bullet x: %d, y: %d \n", p_bullet.x,p_bullet.y); //printf("person x: %d, y: %d \n", p_person.x,p_person.y); corrision_judge(p_person, p_bullet); - Bitmap bitmap_converted = { - LCD_X, - LCD_Y, - LCD_X/8, - char_map, - }; + picture = converter.convert(white_board); update_mtx.unlock(); lcd.cls(); lcd.print_bm(bitmPlayer,p_person.x,p_person.y); - lcd.print_bm(bitmap_converted,0,0); + lcd.print_bm(picture,0,0); if(b != NULL){ lcd.print_bm(bitmBullet_graphics, p_bullet.x, p_bullet.y); } @@ -140,7 +139,7 @@ wait(0.02); lcd.cls(); lcd.print_bm(bitmPlayerB,p_person.x,p_person.y); - lcd.print_bm(bitmap_converted,0,0); + lcd.print_bm(picture,0,0); if(b != NULL){ lcd.print_bm(bitmBullet_graphics, p_bullet.x, p_bullet.y); }
--- a/models.h Tue Dec 13 07:34:07 2016 +0000 +++ b/models.h Tue Dec 13 11:55:17 2016 +0000 @@ -8,7 +8,7 @@ #define LCD_Y 32 //Stage params -#define ONE_STEP_SIZE 10 +#define ONE_STEP_SIZE 20 //#define STEP_NUM LCD_X/ONE_STEP_SIZE+1 #define ALL_LENGTH 1000 //stage all length #define STAGE_V 1 @@ -19,7 +19,7 @@ #define DEFAULT_Y 25 //31-7+1 #define MAX_JUMP_TIME 7 #define MAX_JUMP_COUNT 2 -#define JUMP_SIZE 2 +#define JUMP_SIZE 1 #define GAME_OVER -1 //Bullet params