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.
Dependencies: mbed
Revision 3:1a134243e2f0, committed 2018-04-15
- Comitter:
- RickYu
- Date:
- Sun Apr 15 17:36:29 2018 +0000
- Parent:
- 2:421fb0670c5c
- Child:
- 4:55d904040636
- Commit message:
- boom fall;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/boom/boom.cpp Sun Apr 15 17:36:29 2018 +0000
@@ -0,0 +1,52 @@
+#include "boom.h"
+
+boom::boom()
+{
+
+}
+
+boom::~boom()
+{
+
+}
+
+
+void boom::init(int x,int y)
+{
+ boom_x = x;
+ boom_y = y;
+ //boom_speed = 5; // default speed
+
+
+}
+
+void boom::draw(N5110 &lcd)
+{
+ lcd.drawCircle(boom_x+3,boom_y+3,3,FILL_TRANSPARENT);
+
+
+}
+
+void boom::update(Direction d,float mag)
+{
+ boom_speed = rand()%10;
+ boom_y+= boom_speed;
+
+
+ // check the y origin to ensure that the paddle doesn't go off screen
+ if (boom_y < 1) {
+ boom_y = 0;
+ }
+ if (boom_y > 48) {
+ boom_y = 45;
+ }
+
+ if (boom_x < 1) {
+ boom_x = 0;
+ }
+ if (boom_x > 84) {
+ boom_x = 81;
+ }
+}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/boom/boom.h Sun Apr 15 17:36:29 2018 +0000
@@ -0,0 +1,28 @@
+#ifndef BOOM_H
+#define BOOM_H
+
+#include "mbed.h"
+#include "N5110.h"
+#include "Gamepad.h"
+class boom{
+
+public:
+ boom();
+ ~boom();
+ void init(int x,int y);
+ void draw(N5110 &lcd);
+ void update(Direction d,float mag);
+ Vector2D get_pos();
+
+private:
+ int boom_x;
+ int boom_y;
+ int boom_speed;
+
+
+
+
+};
+
+
+#endif
\ No newline at end of file
--- a/engine/engine.cpp Thu Apr 12 22:46:30 2018 +0000
+++ b/engine/engine.cpp Sun Apr 15 17:36:29 2018 +0000
@@ -13,20 +13,17 @@
void engine::init(int rect_height,int speed,int rect_width)
{
// initialise the game parameters
- _rect_height = rect_height;
- _rect_width = rect_width;
_speed = speed;
- // puts rects and ball in middle
- //rect.init(_rectx,_rect_height);
}
void engine::draw(N5110 &lcd)
{
_rect.draw(lcd);
+ _boom.draw(lcd);
}
@@ -41,6 +38,7 @@
void engine::update(Gamepad &pad)
{
_rect.update(_d,_mag);
+ _boom.update(_d,_mag);
}
--- a/engine/engine.h Thu Apr 12 22:46:30 2018 +0000
+++ b/engine/engine.h Sun Apr 15 17:36:29 2018 +0000
@@ -5,9 +5,11 @@
#include "N5110.h"
#include "Gamepad.h"
#include "rect.h"
+#include "boom.h"
#define GAP 2
+
class engine
{
public:
@@ -24,8 +26,12 @@
int _speed;
int _recx;
- int _rect_height;
- int _rect_width;
+
+ boom _boom;
+
+
+
+
--- a/main.cpp Thu Apr 12 22:46:30 2018 +0000
+++ b/main.cpp Sun Apr 15 17:36:29 2018 +0000
@@ -1,9 +1,8 @@
#include "mbed.h"
-#include "stdio.h"
-#include "stdlib.h"
#include "Gamepad.h"
#include "N5110.h"
#include "rect.h"
+#include "boom.h"
#include "engine.h"
DigitalOut gpo(D0);
@@ -11,8 +10,11 @@
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
+
Gamepad pad;
-engine rect;
+
+engine engine;
+
void init();
void welcome();
@@ -23,23 +25,18 @@
int main()
{
- int fps = 10;
+ int fps = 12;
init();
welcome();
-
- //lcd.clear();
- //lcd.refresh();
-
render();
wait(1.0f/fps);
while(1){
- rect.read_input(pad);
- rect.update(pad);
+ engine.read_input(pad);
+ engine.update(pad);
render();
-
wait(1.0f/fps);
}
@@ -72,6 +69,6 @@
{
// clear screen, re-draw and refresh
lcd.clear();
- rect.draw(lcd);
+ engine.draw(lcd);
lcd.refresh();
}
--- a/rec/rect.cpp Thu Apr 12 22:46:30 2018 +0000
+++ b/rec/rect.cpp Sun Apr 15 17:36:29 2018 +0000
@@ -9,44 +9,33 @@
{
}
-
-void rect::init(int x)
+void rect::init(int x,int y)
{
- rect_x = x; // x value on screen is fixed
- rect_speed = 1; // default speed
-
-
+ //rect_x = x; // x value on screen is fixed
+ //rect_y = y;
+ rect_speed = 0.7; // default speed
}
void rect::draw(N5110 &lcd)
{
- lcd.drawRect(rect_x,rect_y,4,4,FILL_BLACK);
- lcd.drawRect(bullet_x,bullet_y,3,3,FILL_BLACK);
-
+ lcd.drawRect(rect_x,rect_y,5,5,FILL_BLACK);
+
}
void rect::update(Direction d,float mag)
{
rect_speed = int(mag*10.0f); // scale is arbitrary, could be changed in future
-
- bullet_x+=2;
- wait(0.02);
- bullet_y = rect_y;
-
- if (bullet_x >84){
- bullet_x = rect_x;
- }
+ if (d == N) {
-
- // 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) {
rect_y-=rect_speed;
+
} else if (d == S) {
+
rect_y+=rect_speed;
+
}
- if (d == W) {
+ if (d == W) {
rect_x-=rect_speed;
} else if (d == E) {
rect_x+=rect_speed;
@@ -72,4 +61,4 @@
Vector2D rect::get_pos() {
Vector2D p = {rect_x,rect_y};
return p;
-}
\ No newline at end of file
+}
--- a/rec/rect.h Thu Apr 12 22:46:30 2018 +0000
+++ b/rec/rect.h Sun Apr 15 17:36:29 2018 +0000
@@ -9,7 +9,7 @@
public:
rect();
~rect();
- void init(int x);
+ void init(int x,int y);
void draw(N5110 &lcd);
void update(Direction d,float mag);
Vector2D get_pos();
@@ -18,12 +18,7 @@
int rect_x;
int rect_y;
int rect_speed;
-
- int bullet_x;
- int bullet_y;
- int bullet_speed;
-
-
+
};