Ahmed Adamjee
/
SnakeVSBlock
Snake vs Block Game to be run upon K64F.
Diff: SnakevsBlock/SnakevsBlock.cpp
- Revision:
- 49:441c32f6603e
- Parent:
- 48:d774bb162c61
- Child:
- 50:3cf9a94a264e
diff -r d774bb162c61 -r 441c32f6603e SnakevsBlock/SnakevsBlock.cpp --- a/SnakevsBlock/SnakevsBlock.cpp Fri Apr 26 12:46:42 2019 +0000 +++ b/SnakevsBlock/SnakevsBlock.cpp Fri Apr 26 17:16:22 2019 +0000 @@ -19,15 +19,8 @@ send_block_number = 0; blockgap = 300; blockbuff = -50; - for(int i=0; i<=14; i++) { - b[i] = 1; - } - _l.init(); //length calc object initialisation. - _s.init(); //snake object initialisation. - _f.init(); //food 1 object initialisation. - _ff.init(); //food 2 object initialisation. - _fff.init(); //food 3 object initialisation. - _b.init(); //block object initialisation. + for(int i=0; i<=14; i++) {b[i] = 1;} //makes all the snake beads move by default. + SnakevsBlock::object_initialisations(); } void SnakevsBlock::reset() @@ -39,12 +32,17 @@ food_pos[i].y = 0; } if(blockgap >= 50) {blockgap -= 40;} //to make progressive levels harder by making the blocks drop more frequently. - _l.init(); - _s.init(); - _f.init(); - _ff.init(); - _fff.init(); - _b.init(); + SnakevsBlock::object_initialisations(); +} + +void SnakevsBlock::object_initialisations() +{ + _l.init(); //length calc object initialisation. + _s.init(); //snake object initialisation. + _f.init(); //food 1 object initialisation. + _ff.init(); //food 2 object initialisation. + _fff.init(); //food 3 object initialisation. + _b.init(); //block object initialisation. } void SnakevsBlock::read_input(Gamepad &pad, FXOS8700CQ &device, int g_mode) @@ -78,7 +76,7 @@ //printf("%f",device.get_roll_angle()); } -void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad, SDFileSystem &sd) { +void SnakevsBlock::draw(N5110 &lcd, Gamepad &pad) { _length = _l._getLength(); _s.draw(pad, lcd, _length, level); //Draws the Snake. //Make these snake buffs relative to the snake drops which in turn relate to the game speed if(foodbuff >= 0) { @@ -99,18 +97,9 @@ } //Code to print length on game screen. _l.print_length_on_screen(lcd); - - if(_length >= 20) { - SnakevsBlock::reset(); - level = _wl.LevelComplete(lcd, pad, level); - _statset.write(level, sd); - } - if(_length == 0) { - _wl.GameOver(lcd,pad); - } } -int SnakevsBlock::update(Gamepad &pad) //Updates objects on screen. +int SnakevsBlock::update(N5110 &lcd, Gamepad &pad, SDFileSystem &sd) //Updates objects on screen. { send_block_number = 0; //this is for the game to decide wether to remember the number on the block for the current itteration. //we dont need to remember if it has already gone past the screen. @@ -126,9 +115,17 @@ if(blockbuff >= blockgap) { //this makes blockbuff reset every time the new set of blocks appear. blockbuff = -11; } - if(pad.check_event(Gamepad::BACK_PRESSED)){ //Waits for Back button to be pressed. + //_statset.read(sd); //to read the currently stored value. + if(_length >= 20) { + SnakevsBlock::reset(); + level = _wl.LevelComplete(lcd, pad, level); + _Setstats.write(level, sd); + } + if(_length == 0) { + _wl.GameOver(lcd,pad); + } + if((pad.check_event(Gamepad::BACK_PRESSED))||(_length == 0)){ //Waits for Back button to be pressed. back = 1; - //add some warning here and use A as the button to confirm SnakevsBlock::init(); } else {