Working!
Dependencies: 4DGL-uLCD-SE DebounceIn LSM9DS1_Library_cal SDFileSystem TextLCD mbed-rtos mbed wave_player_appbd
Diff: main.cpp
- Revision:
- 5:bc2247ee09b9
- Parent:
- 3:1688f7a77ed8
- Child:
- 6:81ddcbe69054
--- a/main.cpp Sun Oct 30 01:23:21 2016 +0000 +++ b/main.cpp Sun Oct 30 02:55:24 2016 +0000 @@ -1,41 +1,115 @@ -#include "mbed.h" -#include "TextLCD.h" +#include <stdio.h> +#include <stdlib.h> +#include <time.h> -// LEDs on mbed -DigitalOut led1( LED1 ); -DigitalOut led2( LED2 ); -DigitalOut led3( LED3 ); -DigitalOut led4( LED4 ); +#include "init.cpp" -// debugging via pc -Serial pc( USBTX , USBRX ); +class Ship +{ + enum + { + base = 5 , height = 15 , color = WHITE + }; + +public: + Ship( int unsigned x , int unsigned dx , int unsigned y , int unsigned dy ) : + _x( x ) , _dx( dx ) , _y( y ) , _dy( dy ) + { + } + + void draw( ) + { + lcd.triangle( + _x , _y - height , + _x - base , _y , + _x + base , _y , + color + ); + } + +private: + int unsigned _x , _dx ; // center of triangle + int unsigned _y , _dy ; // bottom of triangle +}; -// SD card -SDFileSystem sd( p5 , p6 , p7 , p8 , "sd" ); - -// text display ( rs , e , d4-d7 ) -//TextLCD txt( p22 , p23 , p24 , p25 , p26 , p27 ); +class Bullet +{ + enum + { + width = 2 , height = 3 + }; + +private: + int unsigned _x , _dx ; + int unsigned _y , _dy ; +}; -// LCD ( tx , rx , reset ) -uLCD_4DGL lcd( p28 , p27 , p30 ); - -// speaker -AnalogOut DACout( p18 ); -PwmOut PWMout( p26 ); -wave_player waver( & DACout , & PWMout ); +class Enemy +{ + enum + { + width = 16, height = 10 + }; + Enemy( int unsigned x , int unsigned dx , int unsigned y , int unsigned dy , int color ) : + _x( x ) , _dx( dx ) , _y( y ) , _dy( dy ) , _color( color ) + { + } +private: + int unsigned _x , _dx ; + int unsigned _y , _dy ; + int unsigned const _color ; +}; -// pushbutton -DebounceIn pb( p15 ); -pb.set_debounce_us( 1000 ); -pb.mode( PullUp ); +class Game +{ + static int const enemy_colors [4]; + enum + { + screen_width = 128 , screen_height = 128 , + enemy_count = sizeof(enemy_colors) / sizeof(enemy_colors[0]) + }; + +public: -// IMU ( sda , scl , ... ) -LSM9DS1 imu( p9 , p10 , 0xD6 , 0x3C ); + Game( ) : + _ship( screen_width/2 , 0 , screen_height-1 , 0 ) + { + } + void read( ) + { + } + void draw( ) + { + _ship.draw( ); + } + void wait( ) + { + Thread::wait( 100 ); + } +private: + Ship _ship ; +// Enemy _enemy [ enemy_count ] ; +}; +int const Game::enemy_colors [4] = { + RED , GREEN , BLUE , RED|GREEN +}; - +// int main( ) { pc.printf( " -- INIT -- \n" ); + srand( time( NULL ) ); + pb.set_debounce_us( 1000 ); + pb.mode( PullUp ); + + Game game; + + while ( 1 ) + { + game.read( ); + game.draw( ); + game.wait( ); + } pc.printf( " -- DONE -- \n" ); }