Yufan Zhong / Mbed 2 deprecated GOLD_MINER

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Claw.cpp Source File

Claw.cpp

00001 #include "Claw.h"
00002 
00003 Claw::Claw()
00004 {
00005 
00006 }
00007 
00008 Claw::~Claw()
00009 {
00010 
00011 }
00012 // print the claw
00013 int claw[4][7] = {
00014     {0,0,0,1,0,0,0},
00015     {0,0,1,1,1,0,0},
00016     {0,1,0,0,0,1,0},
00017     {1,0,0,0,0,0,1},
00018 };
00019 
00020 //initialise the claw
00021 void Claw::init(int winch_width)
00022 {   
00023     _winch_width = winch_width;
00024     _x0 = WIDTH/2; // the x0,y0 are the upper point
00025     _y0 = 14;
00026     _x1 = _x0;  // the x1,y1 are the lower claw point
00027     _y1 = _y0;
00028     _velocity_y = 0.0; // 0(stop);1(down);-1(up)
00029     _now_score = 0;
00030     _speed_x = 1; // horizontal speed of claw
00031 }
00032 
00033 //draw the claw and wire
00034 void Claw::draw(N5110 &lcd)
00035 {
00036     lcd.drawSprite(_x1-3,_y1,4,7,(int *)claw);
00037     lcd.drawLine(_x0,_y0,_x1,_y1,1);
00038 }
00039 
00040 void Claw::update(Vector2D winch_pos)
00041 {
00042     _x0 = winch_pos.x+6; //follow the winch
00043     _x1 = _x0;
00044     _y1+=_velocity_y; //update the position
00045 }
00046 
00047 //add current score
00048 void Claw::add_now_score()
00049 {
00050     _now_score++;
00051 }
00052 
00053 //return current score
00054 int Claw::get_now_score()
00055 {
00056     return _now_score;
00057 }
00058 
00059 //set the velosity
00060 void Claw::set_velocity(float v)
00061 {
00062     _velocity_y = v;
00063 }
00064 
00065 //return velocity
00066 float Claw::get_velocity()
00067 {
00068     float v = _velocity_y;
00069     return v;
00070 }
00071 
00072 //get position
00073 Vector2D Claw::get_pos()
00074 {
00075     Vector2D p = {_x1,_y1};
00076     return p;
00077 }
00078 
00079 //set position
00080 void Claw::set_pos(Vector2D p)
00081 {
00082     _x1 = p.x;
00083     _y1 = p.y;
00084 }