Haoyan Zhang / Mbed 2 deprecated el17h2z1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Swarm.cpp Source File

Swarm.cpp

00001 #include "Swarm.h"
00002 
00003 Swarm::Swarm()
00004 {
00005     
00006 }
00007 
00008 Swarm::~Swarm()
00009 {
00010     
00011 }
00012 
00013 int Swarmm[6][6] = {
00014     {0,0,1,1,0,0},
00015     {0,0,1,1,0,0},
00016     {1,1,1,1,1,1},
00017     {1,1,1,1,1,1},
00018     {0,0,1,1,0,0},
00019     {0,0,1,1,0,0},
00020 };
00021 
00022 void Swarm::init(int height, int width, int speed)
00023 {
00024      _height = height;
00025      _width = width;
00026      _x = rand() % 64;
00027      _y = 2;
00028      
00029      srand(time(NULL));
00030      
00031      _velocity.x = 0;
00032      _velocity.y = speed;
00033 }    
00034      
00035 void Swarm::draw(N5110 &lcd)     
00036 {
00037      lcd.drawSprite(_x,_y,_height,_width,(int*)Swarmm);  
00038 }
00039 
00040 void Swarm::update()
00041 {
00042     _x += _velocity.x;
00043     _y += _velocity.y;
00044 }   
00045      
00046 void Swarm::set_velocity(Vector2D v)
00047 {
00048     _velocity.x = v.x;
00049     _velocity.y = v.y;
00050 }
00051 
00052 Vector2D Swarm::get_velocity()
00053 {
00054     Vector2D v = {_velocity.x,_velocity.y};
00055     return v;
00056 }
00057  
00058 Vector2D Swarm::get_pos()
00059 {
00060     Vector2D p = {_x,_y};
00061     return p;
00062 }
00063  
00064 void Swarm::set_pos(Vector2D p)
00065 {
00066     _x = p.x;
00067     _y = p.y;
00068 }
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078