Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Thu Apr 23 07:49:39 2020 +0000
Revision:
7:88c4ba6bb37b
Parent:
3:672d4bd8225d
Child:
8:201ef0618b7d
start to creat game enginee

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17my 2:89f04cd3bf45 1 #include "explorer.h"
el17my 2:89f04cd3bf45 2 //the explorer.cpp need to defined the module and movement of the explorer including the restarted point
el17my 3:672d4bd8225d 3 int move_right_sprite[10][10] = {
el17my 2:89f04cd3bf45 4 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 5 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 6 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 7 { 0,0,0,0,1,0,1,0,0,0 },
el17my 2:89f04cd3bf45 8 { 0,0,1,1,1,1,1,0,0,0 },
el17my 2:89f04cd3bf45 9 { 0,0,1,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 10 { 0,0,0,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 11 { 0,0,0,0,1,1,1,0,0,0 },
el17my 2:89f04cd3bf45 12 { 0,0,0,1,0,0,0,1,0,0 },
el17my 2:89f04cd3bf45 13 { 1,0,1,0,0,0,0,0,1,0 },
el17my 2:89f04cd3bf45 14 };
el17my 2:89f04cd3bf45 15
el17my 3:672d4bd8225d 16 int move_left_sprite[10][10] = {
el17my 2:89f04cd3bf45 17 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 18 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 19 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 20 { 0,0,1,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 21 { 0,0,1,1,1,1,1,0,0,0 },
el17my 2:89f04cd3bf45 22 { 0,0,0,0,1,0,1,0,0,0 },
el17my 2:89f04cd3bf45 23 { 0,0,0,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 24 { 0,0,0,1,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 25 { 0,0,1,0,0,1,0,0,0,0 },
el17my 3:672d4bd8225d 26 { 0,1,0,0,0,0,1,0,0,0 },
el17my 2:89f04cd3bf45 27 };
el17my 2:89f04cd3bf45 28
el17my 3:672d4bd8225d 29 int stand_right_sprite[10][10] = {
el17my 2:89f04cd3bf45 30 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 31 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 32 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 33 { 0,0,0,0,1,0,1,0,0,0 },
el17my 2:89f04cd3bf45 34 { 0,0,1,1,1,1,1,0,0,0 },
el17my 2:89f04cd3bf45 35 { 0,0,1,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 36 { 0,0,0,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 37 { 0,0,0,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 38 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 39 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 40 };
el17my 2:89f04cd3bf45 41
el17my 3:672d4bd8225d 42 int stand_left_sprite[10][10] = {
el17my 2:89f04cd3bf45 43 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 44 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 45 { 0,0,0,1,1,1,0,0,0,0 },
el17my 2:89f04cd3bf45 46 { 0,0,1,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 47 { 0,0,1,1,1,1,1,0,0,0 },
el17my 2:89f04cd3bf45 48 { 0,0,0,0,1,0,1,0,0,0 },
el17my 2:89f04cd3bf45 49 { 0,0,0,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 50 { 0,0,0,0,1,0,0,0,0,0 },
el17my 2:89f04cd3bf45 51 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 52 { 0,0,0,1,0,1,0,0,0,0 },
el17my 2:89f04cd3bf45 53 };
el17my 2:89f04cd3bf45 54
el17my 3:672d4bd8225d 55 Explorer::Explorer() {}
el17my 2:89f04cd3bf45 56
el17my 3:672d4bd8225d 57 Explorer::~Explorer() {}
el17my 2:89f04cd3bf45 58
el17my 3:672d4bd8225d 59 void Explorer::set_x_coordinate(float joy_x, int speed, Player_direction direction)
el17my 2:89f04cd3bf45 60 {
el17my 2:89f04cd3bf45 61 //this process is to set x and make sure the player can move
el17my 2:89f04cd3bf45 62 _player_direction = direction;
el17my 3:672d4bd8225d 63 _speed = speed;
el17my 7:88c4ba6bb37b 64 if (joy_x < float(-0.5)) {
el17my 3:672d4bd8225d 65 _speed = _speed--;//
el17my 3:672d4bd8225d 66 _player_direction = left;
el17my 7:88c4ba6bb37b 67 _explorer_sprite = Move_left;//makesure the value is the Move_left value in the enum
el17my 3:672d4bd8225d 68 //now x is moving to the right than add to the X position
el17my 7:88c4ba6bb37b 69 } else if (joy_x > float(0.5)) {
el17my 3:672d4bd8225d 70 _speed = _speed++;
el17my 3:672d4bd8225d 71 _player_direction = right;
el17my 7:88c4ba6bb37b 72 _explorer_sprite = Move_right;//makesure the value is the Move_right value in the enum
el17my 3:672d4bd8225d 73 } else if (_player_direction == right) {
el17my 7:88c4ba6bb37b 74 _explorer_sprite = Stand_right;// not moving so equals to enum Stand_right.
el17my 3:672d4bd8225d 75 } else {
el17my 7:88c4ba6bb37b 76 _explorer_sprite = Stand_left;//the least situation is equals to enum Stand_right.
el17my 3:672d4bd8225d 77 }
el17my 3:672d4bd8225d 78 _x = 0.5*_speed + 30;//this equation decides how fast the player move later I will update differnet modes to choose different speed
el17my 3:672d4bd8225d 79 }
el17my 3:672d4bd8225d 80 //this function is easy to understand because this is just choosing different sprite according to the direction
el17my 3:672d4bd8225d 81 int * Explorer::get_form(explorer_sprite sprite){
el17my 3:672d4bd8225d 82 if (sprite == Move_right) {
el17my 3:672d4bd8225d 83 return *move_right_sprite;
el17my 3:672d4bd8225d 84 } else if (sprite == Move_left) {
el17my 3:672d4bd8225d 85 return *move_left_sprite;
el17my 3:672d4bd8225d 86 } else if (sprite == Stand_left) {
el17my 3:672d4bd8225d 87 return *stand_right_sprite;
el17my 3:672d4bd8225d 88 } else {
el17my 3:672d4bd8225d 89 return *stand_left_sprite;
el17my 3:672d4bd8225d 90 }
el17my 2:89f04cd3bf45 91 }
el17my 2:89f04cd3bf45 92
el17my 3:672d4bd8225d 93 Player_direction Explorer::get_direction() {
el17my 3:672d4bd8225d 94 return _player_direction;
el17my 3:672d4bd8225d 95 }
el17my 2:89f04cd3bf45 96
el17my 7:88c4ba6bb37b 97 explorer_sprite get_explorer_sprite() {
el17my 7:88c4ba6bb37b 98 return _explorer_sprite;
el17my 2:89f04cd3bf45 99 }
el17my 2:89f04cd3bf45 100
el17my 3:672d4bd8225d 101 void Explorer::set_y_coordinate(bool ifjump, int jump_height, int level) {
el17my 2:89f04cd3bf45 102 _level = level;
el17my 3:672d4bd8225d 103 _jump_height = jump_height;
el17my 2:89f04cd3bf45 104 // jump need to have this function
el17my 2:89f04cd3bf45 105 // when you jump makesure the module will not be offscreen also if you fall from the surface you can not jump back again
el17my 3:672d4bd8225d 106 if (ifjump == 1) {
el17my 3:672d4bd8225d 107 _jump_height = 30; //the player can jump up to 30 height and then fall down
el17my 3:672d4bd8225d 108 else if (_jumpheight !=0) {
el17my 3:672d4bd8225d 109 _jumpheight-- }
el17my 3:672d4bd8225d 110 };
el17my 2:89f04cd3bf45 111 //not offscreen and back to the surface
el17my 2:89f04cd3bf45 112 if (_level == 1 && ifjump){
el17my 2:89f04cd3bf45 113 _level = ;
el17my 2:89f04cd3bf45 114 } else if (_level == 0) {
el17my 2:89f04cd3bf45 115 _level = ;
el17my 2:89f04cd3bf45 116 }
el17my 3:672d4bd8225d 117 _y = _level - 0.5*_jumpheight;
el17my 3:672d4bd8225d 118 }
el17my 2:89f04cd3bf45 119 int Explorer::get_y() {
el17my 2:89f04cd3bf45 120 return _y;
el17my 2:89f04cd3bf45 121 }
el17my 2:89f04cd3bf45 122
el17my 2:89f04cd3bf45 123 int Explorer::get_x() {
el17my 2:89f04cd3bf45 124 return _x;
el17my 2:89f04cd3bf45 125 }
el17my 2:89f04cd3bf45 126
el17my 3:672d4bd8225d 127 int Explorer::get_speed() {
el17my 3:672d4bd8225d 128 return _speed;
el17my 3:672d4bd8225d 129 }
el17my 2:89f04cd3bf45 130
el17my 3:672d4bd8225d 131 int Explorer::get_jumptime() {
el17my 3:672d4bd8225d 132 return _jumptime;
el17my 2:89f04cd3bf45 133 }
el17my 2:89f04cd3bf45 134
el17my 3:672d4bd8225d 135 void Explorer::reset_flag(bool flag) {
el17my 3:672d4bd8225d 136 _r_flag = flag
el17my 3:672d4bd8225d 137 if (flag) {
el17my 3:672d4bd8225d 138 _r_flag = true;
el17my 3:672d4bd8225d 139 } else {
el17my 3:672d4bd8225d 140 _r_flag = false;
el17my 2:89f04cd3bf45 141 }
el17my 2:89f04cd3bf45 142 }
el17my 2:89f04cd3bf45 143
el17my 2:89f04cd3bf45 144 void Explorer::fall(bool f_flag, Gamepad &gamepad) {
el17my 2:89f04cd3bf45 145 _f_flag = f_flag;
el17my 3:672d4bd8225d 146 if (f_flag == true) {
el17my 7:88c4ba6bb37b 147 gamepad.tone(int(1500+0.5*_y), 0.05); // decending equation
el17my 3:672d4bd8225d 148 _y--;
el17my 3:672d4bd8225d 149 else if(_y == -80) { // Stop falling function
el17my 2:89f04cd3bf45 150 _f_flag = false;
el17my 2:89f04cd3bf45 151 _r_flag = true;
el17my 3:672d4bd8225d 152 game.tone(1000, 0.05);
el17my 3:672d4bd8225d 153 wait(0.01);
el17my 3:672d4bd8225d 154 }
el17my 2:89f04cd3bf45 155 }
el17my 3:672d4bd8225d 156 }
el17my 3:672d4bd8225d 157
el17my 3:672d4bd8225d 158 bool Explorer::get_fall_flag() {
el17my 3:672d4bd8225d 159 return _f_flag;
el17my 3:672d4bd8225d 160 }
el17my 3:672d4bd8225d 161
el17my 3:672d4bd8225d 162 bool Explorer::get_reset_flag() {
el17my 3:672d4bd8225d 163 return _r_flag;
el17my 2:89f04cd3bf45 164 }