pocket tanks

Dependencies:   4DGL-uLCD-SE pockettanks SDFileSystem mbed wave_player

Fork of ECE2035_FroggerGame_SUM1025 by Le Tran

robot/robot.cpp

Committer:
ece2035ta
Date:
2015-10-22
Revision:
3:8f68c00dd75a
Parent:
1:172fbc00199c

File content as of revision 3:8f68c00dd75a:

#include "mbed.h"
#include "globals.h"
#include "map_public.h"
#include "robot.h"

// Following code will only draw the Robot on the screen. You are expected to modify most of the functions here.
// All other necessary functions will be implemented by you. Ex: the movement of Robot, calculate the score ... etc.
/////////////////new///////////////////////
/*DigitalIn right_pb(p21); // push bottom
  int main()
  {
      right_pb.mode(PullUp); // The variable rightt_pb will be zero when the pushbutton for moving the player right is pressed
 }*/
//////////////////////////////////////////////

void robot_init(int grid_x, int grid_y, double &score, bool& end){

    map_eat_candy(grid_x,grid_y,score); //clear the cookie on the grid.
    robot_draw(grid_x,grid_y);
 
    end = map_the_end(grid_x,grid_y);
}
void robot_init1(int grid_a, int grid_b, double &score, bool& end){

    map_eat_candy(grid_a,grid_b,score); //clear the cookie on the grid.
    robot_draw(grid_a,grid_b);
 
    end = map_the_end(grid_a,grid_b);
}
void robot_shoot(int grid_x, int grid_y, int p){
    
    GRID grid_info = map_get_grid_status(grid_x,grid_y);
    // Calculate the actual position of the grid
    int tank_x = grid_info.x + GRID_RADIUS;
    int tank_y = grid_info.y + GRID_RADIUS;
                                //MOVE RIGHT
            robot_clear(tank_x,tank_y);
             map_draw_grid(tank_x,tank_y);
                    //x+=1;
 
                    uLCD.line(tank_x+6,tank_y + 4,tank_x + 12, tank_y+p-1 , 0x00ffdf);
                   // p++;
                    uLCD.line(tank_x+7,tank_y + 4,tank_x + 12, tank_y+p , BLACK);
                
                
                wait(0.1);
      // robot_init(tank_x,tank_y,0,0,move);
           
            }

void robot_draw(int grid_x, int grid_y){
    
    GRID grid_info = map_get_grid_status(grid_x,grid_y);
    // Calculate the actual position of the grid
    int tank_x = grid_info.x + GRID_RADIUS;
    int tank_y = grid_info.y + GRID_RADIUS;

    
    uLCD.filled_rectangle(tank_x, tank_y, tank_x + 6, tank_y +8, RED);
    uLCD.filled_circle(tank_x, tank_y+2, 2, BLACK);
    uLCD.filled_circle(tank_x, tank_y+5, 2, BLACK);
    uLCD.line(tank_x+6,tank_y + 4,tank_x + 12, tank_y+4 , BLACK);
}

void robot_draw1(int grid_a, int grid_b){
    
    GRID grid_info = map_get_grid_status(grid_a,grid_b);
    // Calculate the actual position of the grid
    int tank_a = grid_info.x + GRID_RADIUS;
    int tank_b = grid_info.y + GRID_RADIUS;

    
    uLCD.filled_rectangle(tank_a, tank_b, tank_a + 6, tank_b + 8, RED);
    uLCD.filled_circle(tank_a, tank_b+2, 2, BLACK);
    uLCD.filled_circle(tank_a, tank_b+5, 2, BLACK);
    uLCD.line(tank_a+6,tank_b + 4,tank_a + 12, tank_b+4 , BLACK);
}

void robot_clear(int grid_x, int grid_y){
    
    GRID grid_info = map_get_grid_status(grid_x,grid_y);
    //Fill the grid (a rectangle) with BACKGROUND_COLOR to clear the pacman
    uLCD.filled_rectangle(grid_info.x, grid_info.y, grid_info.x+GRID_SIZE-1, grid_info.y+GRID_SIZE-1, 0x00ffdf);
    
}
void robot_clear1(int grid_a, int grid_b){
    
    GRID grid_info = map_get_grid_status(grid_a,grid_b);
    //Fill the grid (a rectangle) with BACKGROUND_COLOR to clear the pacman
    uLCD.filled_rectangle(grid_info.x, grid_info.y, grid_info.x+GRID_SIZE-1, grid_info.y+GRID_SIZE-1, 0x00ffdf);
    
}