deemo1

Dependencies:   mbed

Committer:
haoyan
Date:
Tue May 12 15:13:22 2020 +0000
Revision:
3:1db91ad3ab84
Parent:
2:03cd3bb32511
Child:
5:32dbfaf578dd
finish2

Who changed what in which revision?

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