5

Dependents:   Labirint

Files at this revision

API Documentation at this revision

Comitter:
fy14ta
Date:
Thu May 04 06:39:31 2017 +0000
Parent:
3:c054c5e52370
Commit message:
lab is for the vertical walls

Changed in this revision

Paddle.cpp Show diff for this revision Revisions of this file
Paddle.h Show diff for this revision Revisions of this file
lab.cpp Show annotated file Show diff for this revision Revisions of this file
lab.h Show annotated file Show diff for this revision Revisions of this file
diff -r c054c5e52370 -r 19e1f1be1864 Paddle.cpp
--- a/Paddle.cpp	Sun Mar 05 23:10:27 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-#include "Paddle.h"
-
-Paddle::Paddle()
-{
-
-}
-
-Paddle::~Paddle()
-{
-
-}
-
-void Paddle::init(int x,int height,int width)
-{
-    _x = x;  // x value on screen is fixed
-    _y = HEIGHT/2 - height/2;  // y depends on height of screen and height of paddle
-    _height = height;
-    _width = width;
-    _speed = 1;  // default speed
-    _score = 0;
-
-}
-
-void Paddle::draw(N5110 &lcd)
-{
-    // draw paddle in screen buffer. 
-    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
-}
-
-void Paddle::update(Direction d,float mag)
-{
-    _speed = int(mag*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;
-    }
-
-    // check the y origin to ensure that the paddle doesn't go off screen
-    if (_y < 1) {
-        _y = 1;
-    }
-    if (_y > HEIGHT - _height - 1) {
-        _y = HEIGHT - _height - 1;
-    }
-}
-
-void Paddle::add_score()
-{
-    _score++;
-}
-int Paddle::get_score()
-{
-    return _score;
-}
-
-Vector2D Paddle::get_pos() {
-    Vector2D p = {_x,_y};
-    return p;    
-}
\ No newline at end of file
diff -r c054c5e52370 -r 19e1f1be1864 Paddle.h
--- a/Paddle.h	Sun Mar 05 23:10:27 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-#ifndef PADDLE_H
-#define PADDLE_H
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-
-class Paddle
-{
-public:
-
-    Paddle();
-    ~Paddle();
-    void init(int x,int height,int width);
-    void draw(N5110 &lcd);
-    void update(Direction d,float mag);
-    void add_score();
-    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
diff -r c054c5e52370 -r 19e1f1be1864 lab.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lab.cpp	Thu May 04 06:39:31 2017 +0000
@@ -0,0 +1,102 @@
+#include "lab.h"
+
+lab::lab()
+{
+
+}
+
+lab::~lab()
+{
+
+}
+
+void lab::init(int x, int y, int height,int width, int speed)
+{
+    _x = x;  // x value on screen is fixed
+    _y = y;  // y depends on height of screen and height of paddle
+    _height = height;
+    _width = width;  
+
+    
+    
+    // default speed
+    _score = 0;
+
+        _velocity.x = speed;
+        _velocity.y = speed;
+
+
+}
+
+void lab::draw(N5110 &lcd)
+{
+    // draw paddle in screen buffer. 
+    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
+}
+
+void lab::update(Direction d,float mag)
+{
+                         _velocity.x = int(mag*0.0f); 
+                _velocity.y = int(mag*0.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-=_velocity.y;
+    } else if (d == S) {
+        _y+=_velocity.y;
+        }
+
+    if (d == W) {
+        _x-=_velocity.x;
+    } else if (d == E) {
+        _x+=_velocity.x;
+        }   
+
+
+    // check the y origin to ensure that the paddle 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 - 1) {
+        _x = WIDTH - _width - 1;
+    }
+}
+
+
+void lab::set_velocity(Vector2D v)
+{
+    _velocity.x = v.x;
+    _velocity.y = v.y;
+}
+
+Vector2D lab::get_velocity()
+{
+    Vector2D v = {_velocity.x,_velocity.y};
+    return v;
+}
+
+void lab::add_score()
+{
+    _score++;
+}
+int lab::get_score()
+{
+    return _score;
+}
+
+Vector2D lab::get_pos() {
+    Vector2D p = {_x,_y};
+    return p;    
+}
+
+
diff -r c054c5e52370 -r 19e1f1be1864 lab.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lab.h	Thu May 04 06:39:31 2017 +0000
@@ -0,0 +1,36 @@
+#ifndef LAB_H
+#define LAB_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "Ball.h"
+
+class lab
+{
+public:
+
+    lab();
+    ~lab();
+    void init(int x, int y, int height,int width, int speedp);
+    void draw(N5110 &lcd);
+    void update(Direction d,float mag);
+    void set_velocity(Vector2D v);
+    void add_score();
+    int get_score();
+    Vector2D get_pos();
+    Vector2D get_velocity();
+    
+    
+private:
+
+    Vector2D _velocity;
+    int _height;
+    int _width;
+    int _x;
+    int _y;
+    int _speedp;
+    int _score;
+
+};
+#endif
\ No newline at end of file