1111111112

Files at this revision

API Documentation at this revision

Comitter:
Jenny121
Date:
Mon May 06 06:24:24 2019 +0000
Commit message:
ZHANGXINYU55

Changed in this revision

CXK.cpp Show annotated file Show diff for this revision Revisions of this file
CXK.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CXK.cpp	Mon May 06 06:24:24 2019 +0000
@@ -0,0 +1,83 @@
+#include "CXK.h"
+
+// nothing doing in the constructor and destructor
+CXK::CXK()
+{
+
+}
+
+CXK::~CXK()
+{
+
+}
+
+void CXK::init(int x,int y,int height,int width)
+{
+    _x = 67 - width/2;  
+    _y = 25 - height/2;  // y depends on height of screen and height of CXK
+    _height = height;
+    _width = width;
+    _speed = 1;  // default speed
+    _score = 0;  // start score from zero
+
+}
+
+void CXK::draw(N5110 &lcd)
+{
+    // draw CXK in screen buffer. 
+  lcd.drawCircle(_x,_y,3,FILL_TRANSPARENT);
+              lcd.drawRect(_x-3,_y-5,3,1,FILL_TRANSPARENT);
+            lcd.drawRect(_x+4,_y-5,3,1,FILL_TRANSPARENT);
+            lcd.drawRect(_x-1,_y-1,1,1,FILL_TRANSPARENT);
+            lcd.drawRect(_x+1,_y-1,1,1,FILL_TRANSPARENT);
+            lcd.drawRect(_x,_y+2,4,1,FILL_TRANSPARENT);
+}
+
+
+void CXK::update(Direction d,float vara)
+{
+    _speed = int(vara*10.0f);  // scale is arbitrary, could be changed in future
+
+    // update y value depending on direction of movement
+    // North is decrement as origin is at the top-left so decreasing moves up
+    if (d == N) {
+        _y-=_speed;
+    } else if (d == S) {
+        _y+=_speed;
+    } else if (d == E) {
+        _x+=_speed;
+    } else if (d == W){
+        _x-=_speed; 
+        }
+
+    
+    // check the y origin to ensure that the CXK doesn't go off screen
+    if (_y < 1) {
+        _y = 1;
+    }
+    if (_y > HEIGHT - _height - 1) {
+        _y = HEIGHT - _height - 1;
+    }
+    
+    if (_x < 1) {
+        _x = 1;
+    }
+    if (_x > WIDTH - _width-3 ) {
+        _x = WIDTH - 3;
+    }
+      
+}
+
+void CXK::add_score()
+{
+    _score++;
+}
+int CXK::get_score()
+{
+    return _score;
+}
+
+Vector2D CXK::get_pos() {
+    Vector2D p = {_x,_y};
+    return p;    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CXK.h	Mon May 06 06:24:24 2019 +0000
@@ -0,0 +1,69 @@
+#ifndef CXK_H
+#define CXK_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+
+/** CXK Class
+* @brief defined the cxk and the add score funvtion
+* @author Zhang Xinyu
+* @school EE of  SWJTU &leeds joint school
+* @date  MAY  2019
+*/ 
+
+class CXK
+{
+public:
+/** Constructor */
+    CXK();
+    
+    /** Destrctor */
+    ~CXK();
+    
+      /** Set the CXKinit  
+       * @ param value that updated (x,y,height, width)
+       * @ details the (x,y) mean the centre point figure of cxk ,height meansheight of CXK
+    */
+    void init(int x,int y,int height,int width);
+    
+    
+      /** Set the CXKdraw  
+       * @ param value that updated _x is x, _y is y (_x,_y)
+       */
+    void draw(N5110 &lcd);
+    
+     /** Set the CXKupdate  
+       * @ param  drection of movement (direction)
+       * @ vara means magenitude of the jiysticks 
+       * @ details  North is decrement as origin is at the top-left so decreasing moves up 
+    */
+    void update(Direction d,float vara);
+    
+    /** Set the CXKscore
+       * @ param  the score of the game palyer (score)
+       * @ details add the score when meet the order of the code
+    */
+    void add_score();
+    
+    /** Set the CXKscore
+       * @ returns the score (score)
+       * @ details score = 0
+       */
+    int get_score();
+    
+    
+    Vector2D get_pos();
+
+private:
+
+    int _height;
+    int _width;
+    int _x;
+    int _y;
+    int _speed;
+    int _score;
+
+};
+#endif
\ No newline at end of file