XJEL2645 (19/20)
/
el17ll
Liu Liting 201199465
Diff: Engine/Engine.cpp
- Revision:
- 13:a57a48e5e256
- Parent:
- 12:3b7811c3502c
--- a/Engine/Engine.cpp Thu May 14 14:10:49 2020 +0000 +++ b/Engine/Engine.cpp Thu May 14 15:42:14 2020 +0000 @@ -12,14 +12,14 @@ void Engine::init(int wall_width,int wall_gap,int foods_bulk,int velocity) { - // initialise the game parameters + // initialise for the game parameters _wall_width = wall_width; - _wall_gap = wall_gap; // wall gap presents the distance between the top wall and the bottom wall, which is licked to difficulty + _wall_gap = wall_gap; // the wall gap presents and the distance between the top wall and the bottom wall, which is licked to difficulty _foods_bulk = foods_bulk; // larger foods means it will have larger area to trigger it "_rocket.add_score();" _velocity = velocity; - // x position on screen - WIDTH is defined in N5110.h - _w0x = WIDTH; // there is total 5 types of wall in the game, all are placed in distributed positions + // x locations on screen - WIDTH is defined in N5110.h + _w0x = WIDTH; // there is total 5 types of wall in the game, all are placed in distributed locationss _w1x = WIDTH + 30; _w2x = WIDTH + 60; _w3x = WIDTH + 90; @@ -32,11 +32,11 @@ _w2.init(_w2x,_wall_gap,_wall_width,_velocity); _w3.init(_w3x,_wall_gap,_wall_width,_velocity); _w4.init(_w4x,_wall_gap,_wall_width,_velocity); - _rocket.init(_rocketx); // set the rocket in the middle - _foods.init(_foodsx,_foods_bulk,_velocity); // initiate foods bulk and a random y position + _rocket.init(_rocketx); // seting the rocket in the middle location + _foods.init(_foodsx,_foods_bulk,_velocity); // initiate foods bulk and a random locations of the y } -void Engine::read_input(Gamepad &pad) { // get joystick reading +void Engine::read_input(Gamepad &pad) { // reading the joystick finction _d = pad.get_direction(); _mag = pad.get_mag(); @@ -44,10 +44,10 @@ } void Engine::draw(N5110 &lcd) { - // draw the elements in the LCD buffer - // pitch + // draw all elements on the LCD buffer + // the pitch lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); - // walls + // all walls _w0.draw1(lcd); _w0.draw2(lcd); _w1.draw1(lcd); @@ -60,18 +60,18 @@ _w4.draw2(lcd); // the rocket _rocket.draw(lcd); - // foods + // all foods _foods.draw(lcd); } -void Engine::check_score(Gamepad &pad) { //check the score to trigger how many leds should be turned on +void Engine::check_score(Gamepad &pad) { //checking the score to trigger and how many leds should be turned on - int rocket_score = _rocket.get_final_score(); // get score + int rocket_score = _rocket.get_final_score(); // get the final score - if (rocket_score == 0) { // 7 if statements represents 7 conditions + if (rocket_score == 0) { // 7 if statements to the represents 7 conditions pad.leds_off(); } - if (rocket_score == 1) { // getting one food turns on 1 led + if (rocket_score == 1) { // when getting one food,you can turn on 1 led pad.led(1,1.0f); pad.led(2,0.0f); pad.led(2,0.0f); @@ -79,7 +79,7 @@ pad.led(2,0.0f); pad.led(2,0.0f); } - if (rocket_score == 2) { // two foodds, two led + if (rocket_score == 2) { // when you get two foods, you will light lcd1 and lcd6 pad.led(1,1.0f); pad.led(2,0.0f); pad.led(3,0.0f); @@ -87,7 +87,7 @@ pad.led(5,0.0f); pad.led(6,1.0f); } - if (rocket_score == 3) { + if (rocket_score == 3) {// when you get two foods, you will light lcd1, lcd6 and lcd2 pad.led(1,1.0f); pad.led(2,1.0f); pad.led(3,0.0f); @@ -95,7 +95,7 @@ pad.led(5,0.0f); pad.led(6,1.0f); } - if (rocket_score == 4) { + if (rocket_score == 4) {// when you get two foods, you will light led1, led6,led5 and led2 pad.led(1,1.0f); pad.led(2,1.0f); pad.led(3,0.0f); @@ -103,7 +103,7 @@ pad.led(5,1.0f); pad.led(6,1.0f); } - if (rocket_score == 5) { + if (rocket_score == 5) {// when you get two foods, you will light leds except led4 pad.led(1,1.0f); pad.led(2,1.0f); pad.led(3,1.0f); @@ -111,7 +111,7 @@ pad.led(5,1.0f); pad.led(6,1.0f); } - if (rocket_score == 6) { + if (rocket_score == 6) {// when you get two foods, you will light all led pad.led(1,1.0f); pad.led(2,1.0f); pad.led(3,1.0f); @@ -120,9 +120,9 @@ pad.led(6,1.0f); } - Vector2D rocket_pos = _rocket.get_pos(); // This section also checks the contact between the rocket and the food, where the current position of the rocket and the food is obtained + Vector2D rocket_pos = _rocket.get_locations(); // the goal of this section is checking the contact between the rocket and the food, where the current locations of the rocket and the food is obtained - Vector2D foods_pos = _foods.get_pos(); + Vector2D foods_pos = _foods.get_locations(); if (foods_pos.x <= 1) { // if the food leaves the left side of the screen, replace it to the right side for the next foods retrieval _foods.replace(); @@ -130,10 +130,10 @@ if ( (rocket_pos.y + 4 >= foods_pos.y - _foods_bulk) && (rocket_pos.y + 2 <= foods_pos.y + _foods_bulk) // check if rrocket and the foods are overlap - && //bottom + && //aat the bottom (rocket_pos.x + 10 >= foods_pos.x) && (rocket_pos.x + 10 <= foods_pos.x + 1) //right ) { - // if it has, fix position and reflect x velocity + // if it happen this situation , fixing locations and reflecting x velocity _rocket.add_score(); pad.tone(550.0,0.25); wait(0.25); @@ -159,17 +159,17 @@ void Engine::collision(Gamepad &pad) { - // read the position of rocket - Vector2D rocket_pos = _rocket.get_pos(); + // reading the right locations of rocket + Vector2D rocket_pos = _rocket.get_locations(); - //read all of these positions of the FIVE wall + //read all of these locationss of the FIVE wall int w0_x = _w0.get_x(); int w1_x = _w1.get_x(); int w2_x = _w2.get_x(); int w3_x = _w3.get_x(); int w4_x = _w4.get_x(); - if (w0_x <= 1) { // When the rocket passes behind the wall, it will reset to its original position to continue the game + if (w0_x <= 1) { // When the rocket passes behind the wall, it will reset to its original locations to continue the game _w0.reset(); } if (w1_x <= 1) { @@ -256,6 +256,6 @@ -int Engine::get_final_score() { // get score for the main function to determine the ending +int Engine::get_final_score() { // get thefinal score for the main function to determine the ending return _rocket.get_final_score(); } \ No newline at end of file