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