Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Frogger/Frogger.cpp
- Committer:
- el19tb
- Date:
- 2020-05-18
- Revision:
- 43:2cd1cfe07770
- Parent:
- 42:04e326dcf09b
- Child:
- 44:f02510eeb165
File content as of revision 43:2cd1cfe07770:
#include "Frogger.h" #include "Menu.h" #include "GraphicEngine.h" #include <vector> #include <stdio.h> #include <cstddef> bool frogLog = false; bool frogDie = false; // whenever the frog is above safety lane in the middle bool attach = false; // level one initiailization has already been done Frogger::Frogger(GraphicEngine *engine, Level *levelptr, Frog *frog, int grid, int w, int h) { this->graphics = engine; // get the renderer in place this->level = levelptr; // one level object per engine this->frog = frog; // one frog object per run current_level = 1; initializeParams(w, h, grid); // initialize the software parameters initializeEmbeddedSystem(); // initialize the hardware paramaters } void Frogger::initializeParams(int w, int h, int grid) { // screen sizes lcd_w = w; // width lcd_h = h; // height // grid values grid = 4; // size of game grid system grid_width = 22; // size of screen width in grid units } void Frogger::initializeLevelTwo() { level->setupLevelTwo(); } void Frogger::initializeEmbeddedSystem() { //game setup graphics->init(); // initialize the LCD object graphics->contrast(); // set the contrast to 0.4 graphics->backLightOn(); // turn on the backlight gamepad.init(); // initialize the actual embedded system } //main function that starts the game void Frogger::start() { //keep reading and processing user input while(1) { graphics->clear(); // clear the lcd screen runCurrentLevel(); // add velocity to level vehicles and logs graphics->drawSafetyLanes(); graphics->showFrog(frog->x, frog->y, frog->width, 4); // display current position of frog process_input(); // user controls the frog object checkCurrentLevelCollision(); // check if the frog is alive level->checkFrogOnWater(); // check if the frog is in the water level graphics->refresh(); // refresh the lcd screen wait_ms(75); // fpms } } void Frogger::runCurrentLevel() { switch (current_level) { case 1: level->levelOne(); break; case 2: level->levelTwo(); break; } } void Frogger::checkCurrentLevelCollision() { switch (current_level) { case 1: level->levelOneCollision(); break; case 2: level->levelTwoCollision(); break; } } void Frogger::process_input() { //determine the input /* make this a switch statement */ if(gamepad.A_pressed()){ moveFrog(1,0); level->frogOnLog = false; } else if(gamepad.X_pressed()){ moveFrog(0,-1); level->frogOnLog = false; } else if(gamepad.B_pressed()){ moveFrog(0,1); level->frogOnLog = false; } else if(gamepad.Y_pressed()){ moveFrog(-1,0); level->frogOnLog = false; } } //moves the frog around the grid void Frogger::moveFrog(int xWay, int yWay) { //increment the left side of the chicken by a value of the grid size frog->x += xWay * 4; //increment the top side by a value of grid sizw frog->y += yWay * 4; // change rect parameters frog->left_side = frog->x; frog->right_side = grid + frog->x; frog->up = frog->y; frog->down = grid + frog->y; } void Frogger::createGoalPost() { //graphics->drawGoalPost(); }