deemo1

Dependencies:   mbed

Committer:
haoyan
Date:
Mon May 11 06:50:18 2020 +0000
Revision:
1:8c48fb8ca5e0
Finish

Who changed what in which revision?

UserRevisionLine numberNew contents of line
haoyan 1:8c48fb8ca5e0 1 #include "Laser.h"
haoyan 1:8c48fb8ca5e0 2
haoyan 1:8c48fb8ca5e0 3 Laser::Laser()
haoyan 1:8c48fb8ca5e0 4 {
haoyan 1:8c48fb8ca5e0 5
haoyan 1:8c48fb8ca5e0 6 }
haoyan 1:8c48fb8ca5e0 7
haoyan 1:8c48fb8ca5e0 8 Laser::~Laser()
haoyan 1:8c48fb8ca5e0 9 {
haoyan 1:8c48fb8ca5e0 10
haoyan 1:8c48fb8ca5e0 11 }
haoyan 1:8c48fb8ca5e0 12
haoyan 1:8c48fb8ca5e0 13 void Laser::init(int height,int width,int speed)
haoyan 1:8c48fb8ca5e0 14 {
haoyan 1:8c48fb8ca5e0 15 Vector2D Battleship_pos = _Battleship.get_pos();
haoyan 1:8c48fb8ca5e0 16 _width = width;
haoyan 1:8c48fb8ca5e0 17 _height = height;
haoyan 1:8c48fb8ca5e0 18 // Set laser's position
haoyan 1:8c48fb8ca5e0 19 _x = Battleship_pos.x + 3;
haoyan 1:8c48fb8ca5e0 20 _y = Battleship_pos.y - 1;
haoyan 1:8c48fb8ca5e0 21
haoyan 1:8c48fb8ca5e0 22 srand(time(NULL));
haoyan 1:8c48fb8ca5e0 23
haoyan 1:8c48fb8ca5e0 24 _velocity.x = 0;
haoyan 1:8c48fb8ca5e0 25 _velocity.y = 2*speed;
haoyan 1:8c48fb8ca5e0 26
haoyan 1:8c48fb8ca5e0 27 }
haoyan 1:8c48fb8ca5e0 28
haoyan 1:8c48fb8ca5e0 29 void Laser::draw(N5110 &lcd)
haoyan 1:8c48fb8ca5e0 30 {
haoyan 1:8c48fb8ca5e0 31 lcd.drawRect(_x,_y,_width,_height,FILL_BLACK);
haoyan 1:8c48fb8ca5e0 32 }
haoyan 1:8c48fb8ca5e0 33
haoyan 1:8c48fb8ca5e0 34 void Laser::update()
haoyan 1:8c48fb8ca5e0 35 {
haoyan 1:8c48fb8ca5e0 36 _x += _velocity.x;
haoyan 1:8c48fb8ca5e0 37 _y -= _velocity.y;
haoyan 1:8c48fb8ca5e0 38 }
haoyan 1:8c48fb8ca5e0 39
haoyan 1:8c48fb8ca5e0 40 void Laser::set_velocity(Vector2D v)
haoyan 1:8c48fb8ca5e0 41 {
haoyan 1:8c48fb8ca5e0 42 _velocity.x = v.x;
haoyan 1:8c48fb8ca5e0 43 _velocity.y = v.y;
haoyan 1:8c48fb8ca5e0 44 }
haoyan 1:8c48fb8ca5e0 45
haoyan 1:8c48fb8ca5e0 46 Vector2D Laser::get_velocity()
haoyan 1:8c48fb8ca5e0 47 {
haoyan 1:8c48fb8ca5e0 48 Vector2D v = {_velocity.x,_velocity.y};
haoyan 1:8c48fb8ca5e0 49 return v;
haoyan 1:8c48fb8ca5e0 50 }
haoyan 1:8c48fb8ca5e0 51
haoyan 1:8c48fb8ca5e0 52 Vector2D Laser::get_pos()
haoyan 1:8c48fb8ca5e0 53 {
haoyan 1:8c48fb8ca5e0 54 Vector2D p = {_x,_y};
haoyan 1:8c48fb8ca5e0 55 return p;
haoyan 1:8c48fb8ca5e0 56 }
haoyan 1:8c48fb8ca5e0 57
haoyan 1:8c48fb8ca5e0 58 void Laser::set_pos(Vector2D p)
haoyan 1:8c48fb8ca5e0 59 {
haoyan 1:8c48fb8ca5e0 60 _x = p.x;
haoyan 1:8c48fb8ca5e0 61 _y = p.y;
haoyan 1:8c48fb8ca5e0 62 }
haoyan 1:8c48fb8ca5e0 63
haoyan 1:8c48fb8ca5e0 64
haoyan 1:8c48fb8ca5e0 65
haoyan 1:8c48fb8ca5e0 66
haoyan 1:8c48fb8ca5e0 67
haoyan 1:8c48fb8ca5e0 68
haoyan 1:8c48fb8ca5e0 69
haoyan 1:8c48fb8ca5e0 70
haoyan 1:8c48fb8ca5e0 71
haoyan 1:8c48fb8ca5e0 72
haoyan 1:8c48fb8ca5e0 73