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.
Winch.cpp
00001 #include "Winch.h" 00002 00003 // nothing doing in the constructor and destructor 00004 Winch::Winch() 00005 { 00006 00007 } 00008 Winch::~Winch() 00009 { 00010 00011 } 00012 00013 //initialise the winch 00014 void Winch::init(int height,int width) 00015 { 00016 _height = height; 00017 _width = width; 00018 _y = 8; // 00019 _x = WIDTH/2 - _width/2; 00020 _speed_x = 1; // default speed 00021 _highest_score = 0; // start score from zero 00022 00023 } 00024 00025 //draw the winch 00026 void Winch::draw(N5110 &lcd) 00027 { 00028 // draw Winch in screen buffer. 00029 lcd.drawRect(_x,_y,_width,_height,FILL_TRANSPARENT); 00030 lcd.drawLine(_x+1,_y,_x+1,_y+5,1); 00031 lcd.drawLine(_x+3,_y,_x+3,_y+5,1); 00032 lcd.drawLine(_x+5,_y,_x+5,_y+5,1); 00033 lcd.drawLine(_x+7,_y,_x+7,_y+5,1); 00034 lcd.drawLine(_x+9,_y,_x+9,_y+5,1); 00035 } 00036 00037 //update the position of the winch 00038 void Winch::update(Direction d,float mag) 00039 { 00040 _speed_x = int(mag*5.0f); // scale is arbitrary, could be changed in future 00041 // update x value depending on direction of movement 00042 //W is left and E is right 00043 if (d == W) { 00044 _x-=_speed_x; 00045 } else if (d == E) { 00046 _x+=_speed_x; 00047 } 00048 // check the x to ensure that the Winch doesn't go off screen 00049 if (_x < 1) { 00050 _x = 1; 00051 } 00052 if (_x > WIDTH - _width - 1) { 00053 _x = WIDTH - _width - 1; 00054 } 00055 } 00056 00057 //add highest score 00058 void Winch::add_highest_score() 00059 { 00060 _highest_score++; 00061 } 00062 00063 //return highest score 00064 int Winch::get_highest_score() 00065 { 00066 return _highest_score; 00067 } 00068 00069 //return position of winch 00070 Vector2D Winch::get_pos() { 00071 Vector2D p = {_x,_y}; 00072 return p; 00073 } 00074 00075 //set the position of the winch 00076 void Winch::set_pos(Vector2D p) { 00077 _x = p.x; 00078 _y = p.y; 00079 } 00080 00081 //return the speed of winch 00082 float Winch::get_speed() { 00083 float speed_winch=_speed_x; 00084 return speed_winch; 00085 }
Generated on Sat Jul 16 2022 10:18:04 by
1.7.2