Game designed for project

Dependencies:   mbed Gamepad2

Files at this revision

API Documentation at this revision

Comitter:
vaib
Date:
Sun May 24 09:15:25 2020 +0000
Parent:
2:e67ca889c81b
Commit message:
Created a class for the balls's movement and am now working of the obstacles/blocks

Changed in this revision

MyClasses/Ball.cpp Show diff for this revision Revisions of this file
MyClasses/Ball.h Show diff for this revision Revisions of this file
MyClasses/Ball/Ball.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses/Ball/Ball.h Show annotated file Show diff for this revision Revisions of this file
MyClasses/Blocks.cpp Show diff for this revision Revisions of this file
MyClasses/Blocks.h Show diff for this revision Revisions of this file
MyClasses/Blocks/Blocks.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses/Blocks/Blocks.h Show annotated file Show diff for this revision Revisions of this file
MyClasses/PaddleControl.cpp Show diff for this revision Revisions of this file
MyClasses/PaddleControl.h Show diff for this revision Revisions of this file
MyClasses/PaddleControl/PaddleControl.cpp Show annotated file Show diff for this revision Revisions of this file
MyClasses/PaddleControl/PaddleControl.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyClasses/Ball/Ball.cpp	Sun May 24 09:15:25 2020 +0000
@@ -0,0 +1,61 @@
+#include "Ball.h"
+
+void Ball::init(int radius, int height, int speed)
+{
+    _radius = radius;
+
+    _x = WIDTH/2 -  _radius;
+    _y = height;
+
+    srand(time(NULL));
+    int direction = rand() % 2; // randomise initial direction. 
+
+    // 4 possibilities. Get random modulo and set velocities accordingly
+    if (direction == 0) {
+        _velocity.x = speed;
+        _velocity.y = speed;
+    } else (direction == 1) {
+        _velocity.x = -speed;
+        _velocity.y = speed;
+    } 
+}
+
+void Ball::print_lcd(N5110 &lcd)
+{
+    lcd.drawCircle(_x, _y, _radius, FILL_BLACK);
+}
+
+void Ball::set_size(int radius)
+{
+    _radius = radius;
+}
+
+void Ball::set_position(int x, int y)
+{
+    _x = x;
+    _y = y;
+}
+
+void Ball::set_velocity(Vector2D velocity)
+{
+    _velocity.x = velocity.x;
+    _velocity.y = velocity.y;
+}
+
+void Ball::update_position()
+{
+    _x += _velocity.x;
+    _y += _velocity.y;
+}
+
+void Ball::get_position()
+{
+    Vector2D position = {_x, _y};
+    return position;
+}
+
+void Ball:get_velocity()
+{
+    Vector2D velocity = {_velocity.x, _velocity.y};
+    return velocity
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyClasses/Ball/Ball.h	Sun May 24 09:15:25 2020 +0000
@@ -0,0 +1,29 @@
+#ifndef BALL_H
+#define BALL_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+class Ball 
+{
+    public:
+    
+        void init(int radius, int height, int speed);
+        void print_lcd(N5110 &lcd);
+        void set_size(int radius);
+        void set_position(int x, int y);
+        void set_velocity(Vector2D velocity);
+        void update_position();
+        Vector2D get_position();
+        Vector2D get_velocity();
+   
+    private:
+    
+        int _radius;
+        int _x;
+        int _y;
+        Vector2D _velocity;
+    
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyClasses/Blocks/Blocks.h	Sun May 24 09:15:25 2020 +0000
@@ -0,0 +1,23 @@
+#ifndef BLOCKS_H
+#define BLOCKS_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+class Blocks
+{
+    public:
+    
+        void init(int length, int height);
+        void place_block(int x, int y, string block_type);
+        void print_lcd(N5110 &lcd);
+        Vector2D get_blockposition(); 
+        string get_blocktype();
+    
+    private:
+    
+        
+    
+}
+#endif
\ No newline at end of file
--- a/MyClasses/PaddleControl.cpp	Tue May 19 09:51:13 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-
-#include "PaddleControl.h"
-
-
-void Paddle::init(int y,int length,int height)
-{
-    _y = y;  // x value on screen is fixed
-    _x = WIDTH/2 - length/2;  // y depends on height of screen and height of paddle
-    _height = height;
-    _length = length;
-    _speed = 1;  // default speed
-}
-
-void Paddle::print_lcd(N5110 &lcd)
-{
-    lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
-}
-
-void Paddle::update(char direction)
-{
-    if (direction == 'R') {
-        _x-=_speed;
-    } else if (direction == 'L') {
-        _x+=_speed;
-    }
-
-    if (_x < 1) {
-        _x = 1;
-    }
-    if (_x > WIDTH - _length - 1) {
-        _x = WIDTH - _length - 1;
-    }
-}
-
-Vector2D Paddle::get_pos() {
-    Vector2D p = {_x,_y};
-    return p;    
-}
\ No newline at end of file
--- a/MyClasses/PaddleControl.h	Tue May 19 09:51:13 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#ifndef PADDLECONTROL_H
-#define PADDLECONTROL_H
-
-#include "mbed.h"
-#include "N5110.h"
-#include "Gamepad.h"
-
-
-class PaddleControl 
-{
-    public:
-    
-        void init(int y,int length,int height);
-        void print_lcd(N5110 &lcd);
-        void setsize(int length. int height);
-        void setspeed();
-        void update(char direction);
-        Vector 2D position();
-        
-        
-    private:
-        
-        
-
-};
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyClasses/PaddleControl/PaddleControl.cpp	Sun May 24 09:15:25 2020 +0000
@@ -0,0 +1,44 @@
+
+#include "PaddleControl.h"\
+
+void PaddleControl::init(int y,int length,int height)
+{
+    _y = y;  
+    _x = WIDTH/2 - length/2;  
+    _height = height;
+    _length = length;
+    _speed = 1;  
+}
+
+void PaddleControl::print_lcd(N5110 &lcd)
+{
+    lcd.drawRect(_x,_y,_length,_height,FILL_BLACK);
+}
+
+void PaddleControl::update_direction(char direction)
+{
+    if (direction == 'R') {
+        _x-=_speed;
+    } else if (direction == 'L') {
+        _x+=_speed;
+    }
+
+    if (_x < 1) {
+        _x = 1;
+    }
+    if (_x > WIDTH - _length - 1) {
+        _x = WIDTH - _length - 1;
+    }
+}
+
+void PaddleControl::set_speed(int speed)
+{
+    _speed = speed;
+}
+
+
+Vector2D PaddleControl::get_position() 
+{
+    Vector2D p = {_x,_y};
+    return p;    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MyClasses/PaddleControl/PaddleControl.h	Sun May 24 09:15:25 2020 +0000
@@ -0,0 +1,28 @@
+#ifndef PADDLECONTROL_H
+#define PADDLECONTROL_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+
+class PaddleControl 
+{
+    public:
+    
+        void init(int y, int length, int height);
+        void print_lcd(N5110 &lcd);
+        void set_size(int length, int height);
+        void set_speed(int speed);
+        void update_direction(char direction);
+        Vector2D get_position();
+         
+    private:
+        
+        int _height;
+        int _length;
+        int _x;
+        int _y;
+        int _speed;
+};
+#endif
\ No newline at end of file