Mochu Yao explorer game

Dependencies:   mbed

Surface/surface.cpp

Committer:
el17my
Date:
2020-04-29
Revision:
33:ea83f08fa466
Parent:
32:47d98959b4ef

File content as of revision 33:ea83f08fa466:

#include "surface.h"

// Constructor and destructor.
Surface::Surface() {}
Surface::~Surface() {}

void Surface::init(int y1, int y2) {
    //makesure that each line can not be constant or it will be too easy
_line_1.left = 0;
_line_1.right = 25;
_line_1.y = y1;
_line_1.length = 25;
_line_2.left = 30;
_line_2.right = 50;
_line_2.y = y1;
_line_2.length = 20;
_line_3.left = 65;
_line_3.right = 80;
_line_3.y = y1;
_line_3.length = 15;
//the line 1 to line 3 is on the lower level and than the line 4 to line 5 is on the upper level
// ---line 4---  ---line 5---  ---line 6---
// ---line 3---  ---line 2---  ---line 1---
_line_4.left = 0;
_line_4.right = 20;
_line_4.y = y2;
_line_4.length = 20;
_line_5.left = 25;
_line_5.right = 50;
_line_5.y = y2;
_line_5.length = 25;
_line_6.left = 60;
_line_6.right = 80;
_line_6.y = y2;
_line_6.length = 20;
};
//the line need to move form right to left so the line_1 function should have these functions
//1 the leftside of the line move toward right then the rightside should also move to the right to keep the length
//2 the line will be random length but must be suitable
//3 makesure there are two surface for player to stay
void Surface::line_1() {
    if(_line_1.left > 0) {
        _line_1.left-- ;}
        //the left side will keep moving until it disappear on the screen which also means equal to zero
    if (_line_1.left + _line_1.length < 80) {
        _line_1.right-- ;}
        //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge
    if (_line_1.left <= 0) { 
        _line_1.left = 0; }
        //if the left edge of the line is zero it will keep zero until the right edge equals to zero
    if (_line_1.right <= 0) {
            _line_1.left = 80;
            _line_1.right = 80;}
    _line_1.length = (rand() %10) + 10; } 

void Surface::line_2() {
    if(_line_2.left > 0) {
        _line_2.left-- ;}
        //the left side will keep moving until it disappear on the screen which also means equal to zero
    if (_line_2.left + _line_1.length < 80) {
        _line_2.right-- ;}
        //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge
    if (_line_2.left <= 0) { 
        _line_2.left = 0;}
        //if the left edge of the line is zero it will keep zero until the right edge equals to zero
    if (_line_2.right <= 0) {
            _line_2.left = 80;
            _line_2.right = 80;}
    _line_2.length = (rand() %10) + 10; } 
            
void Surface::line_3() {
    if(_line_3.left > 0) {
        _line_3.left-- ;}
        //the left side will keep moving until it disappear on the screen which also means equal to zero
    if (_line_3.left + _line_1.length < 80) {
        _line_3.right-- ;}
        //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge
    if (_line_3.left <= 0) { 
        _line_3.left = 0;}
        //if the left edge of the line is zero it will keep zero until the right edge equals to zero
    if (_line_3.right <= 0) {
            _line_3.left = 80;
            _line_3.right = 80;}
    _line_3.length = (rand() %10) + 10; }
            
void Surface::line_4() {
    if(_line_4.left > 0) {
        _line_4.left-- ;}
        //the left side will keep moving until it disappear on the screen which also means equal to zero
    if (_line_4.left + _line_1.length < 80) {
        _line_4.right-- ;}
        //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge
    if (_line_4.left <= 0) { 
        _line_4.left = 0;}
        //if the left edge of the line is zero it will keep zero until the right edge equals to zero
    if (_line_4.right <= 0) {
            _line_4.left = 80;
            _line_4.right = 80;}
    _line_4.length = (rand() %10) + 10; }
            
void Surface::line_5() {
    if(_line_5.left > 0) {
        _line_5.left-- ;}
        //the left side will keep moving until it disappear on the screen which also means equal to zero
    if (_line_5.left + _line_1.length < 80) {
        _line_5.right-- ;}
        //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge
    if (_line_5.left <= 0) { 
        _line_5.left = 0;}
        //if the left edge of the line is zero it will keep zero until the right edge equals to zero
    if (_line_5.right <= 0) {
            _line_5.left = 80;
            _line_5.right = 80;}
    _line_5.length = (rand() %10) + 10; }
            
void Surface::line_6() {
    if(_line_6.left > 0) {
        _line_6.left-- ;}
        //the left side will keep moving until it disappear on the screen which also means equal to zero
    if (_line_6.left + _line_1.length < 80) {
        _line_6.right-- ;}
        //this line is mainly for regeneration of the line because I want the line to first disapper and then appear on the another edge
    if (_line_6.left <= 0) { 
        _line_6.left = 0;}
        //if the left edge of the line is zero it will keep zero until the right edge equals to zero
    if (_line_6.right <= 0) {
            _line_6.left = 80;
            _line_6.right = 80;}
    _line_6.length = (rand() %10) + 10; }

Line Surface::getline_1(){return _line_1;}
Line Surface::getline_2(){return _line_2;}
Line Surface::getline_3(){return _line_3;}
Line Surface::getline_4(){return _line_4;}
Line Surface::getline_5(){return _line_5;}
Line Surface::getline_6(){return _line_6;}