2020/5/15
useless. I don't know how to delete it.
Revision 0:b67855547a78, committed 2020-05-14
- Comitter:
- amamiya2376
- Date:
- Thu May 14 21:51:54 2020 +0000
- Commit message:
- 2020/5/15
Changed in this revision
Bomb.cpp | Show annotated file Show diff for this revision Revisions of this file |
Bomb.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r b67855547a78 Bomb.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bomb.cpp Thu May 14 21:51:54 2020 +0000 @@ -0,0 +1,71 @@ +#include "Bomb.h" + +Bomb::Bomb() +{ + +} + +Bomb::~Bomb() +{ + +} + +void Bomb::init(int size,int speed) +{ + _size = size; + + _x = WIDTH/2 - _size/2; + _y = HEIGHT/2 - _size/2; + + srand(time(NULL)); + int direction = rand() % 4; + + if (direction == 0) { + _velocity.x = speed; + _velocity.y = speed; + } else if (direction == 1) { + _velocity.x = speed; + _velocity.y = -speed; + } else if (direction == 2) { + _velocity.x = speed; + _velocity.y = speed; + } else { + _velocity.x = -speed; + _velocity.y = -speed; + } +} + +void Bomb::draw(N5110 &lcd) +{ + lcd.drawRect(_x,_y,_size,_size,FILL_BLACK); +} + +void Bomb::update() +{ + _x += _velocity.x; + _y += _velocity.y; +} + +void Bomb::set_velocity(Vector2D v) +{ + _velocity.x = v.x; + _velocity.y = v.y; +} + +Vector2D Bomb::get_velocity() +{ + Vector2D v = {_velocity.x,_velocity.y}; + return v; +} + +Vector2D Bomb::get_pos() +{ + Vector2D p = {_x,_y}; + return p; +} + +void Bomb::set_pos(Vector2D p) +{ + _x = p.x; + _y = p.y; +}
diff -r 000000000000 -r b67855547a78 Bomb.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Bomb.h Thu May 14 21:51:54 2020 +0000 @@ -0,0 +1,31 @@ +#ifndef BOMB_H +#define BOMB_H + +#include "mbed.h" +#include "N5110.h" +#include "Gamepad.h" +#include "Racket.h" + +class Bomb +{ + +public: + Bomb(); + ~Bomb(); + void init(int size,int speed); + void draw(N5110 &lcd); + void update(); + + void set_velocity(Vector2D v); + Vector2D get_velocity(); + Vector2D get_pos(); + void set_pos(Vector2D p); + +private: + + Vector2D _velocity; + int _size; + int _x; + int _y; +}; +#endif