I am learning OOP using c++ on a MicroBit by developing this simple game

Dependencies:   microbit

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Screen.h Source File

Screen.h

00001 #ifndef SCREEN_H
00002 #define SCREEN_H
00003 
00004 #include "MicroBit.h"
00005 #include "Sprite.h"
00006 
00007 class Screen{
00008     private:
00009     MicroBit *m_ubit;
00010     uint8_t buf[5][5];
00011     public:
00012     Screen(MicroBit *ubit){
00013         m_ubit = ubit;
00014         clearBuffer();
00015     }
00016     void clearBuffer(){
00017         for(int row = 0; row < 5; row++)
00018             for(int col = 0; col < 5; col++)
00019                 buf[row][col] = 0;
00020     }
00021     
00022     void draw(Sprite sprite){
00023         buf[sprite.getX()][sprite.getY()] = 255;
00024     }
00025     void refresh(){
00026         m_ubit->display.clear();
00027         for(int row = 0; row < 5; row++){
00028             for(int col = 0; col < 5; col++){
00029                 m_ubit->display.image.setPixelValue(row, col, buf[row][col]);      
00030             }
00031         }
00032         clearBuffer();
00033     }
00034 };
00035 
00036 #endif