Working!

Dependencies:   4DGL-uLCD-SE DebounceIn LSM9DS1_Library_cal SDFileSystem TextLCD mbed-rtos mbed wave_player_appbd

Committer:
taylornichols
Date:
Sun Oct 30 02:55:24 2016 +0000
Revision:
5:bc2247ee09b9
Parent:
3:1688f7a77ed8
Child:
6:81ddcbe69054
just ship

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taylornichols 5:bc2247ee09b9 1 #include <stdio.h>
taylornichols 5:bc2247ee09b9 2 #include <stdlib.h>
taylornichols 5:bc2247ee09b9 3 #include <time.h>
taylornichols 0:f29cfb036e34 4
taylornichols 5:bc2247ee09b9 5 #include "init.cpp"
taylornichols 0:f29cfb036e34 6
taylornichols 5:bc2247ee09b9 7 class Ship
taylornichols 5:bc2247ee09b9 8 {
taylornichols 5:bc2247ee09b9 9 enum
taylornichols 5:bc2247ee09b9 10 {
taylornichols 5:bc2247ee09b9 11 base = 5 , height = 15 , color = WHITE
taylornichols 5:bc2247ee09b9 12 };
taylornichols 5:bc2247ee09b9 13
taylornichols 5:bc2247ee09b9 14 public:
taylornichols 5:bc2247ee09b9 15 Ship( int unsigned x , int unsigned dx , int unsigned y , int unsigned dy ) :
taylornichols 5:bc2247ee09b9 16 _x( x ) , _dx( dx ) , _y( y ) , _dy( dy )
taylornichols 5:bc2247ee09b9 17 {
taylornichols 5:bc2247ee09b9 18 }
taylornichols 5:bc2247ee09b9 19
taylornichols 5:bc2247ee09b9 20 void draw( )
taylornichols 5:bc2247ee09b9 21 {
taylornichols 5:bc2247ee09b9 22 lcd.triangle(
taylornichols 5:bc2247ee09b9 23 _x , _y - height ,
taylornichols 5:bc2247ee09b9 24 _x - base , _y ,
taylornichols 5:bc2247ee09b9 25 _x + base , _y ,
taylornichols 5:bc2247ee09b9 26 color
taylornichols 5:bc2247ee09b9 27 );
taylornichols 5:bc2247ee09b9 28 }
taylornichols 5:bc2247ee09b9 29
taylornichols 5:bc2247ee09b9 30 private:
taylornichols 5:bc2247ee09b9 31 int unsigned _x , _dx ; // center of triangle
taylornichols 5:bc2247ee09b9 32 int unsigned _y , _dy ; // bottom of triangle
taylornichols 5:bc2247ee09b9 33 };
taylornichols 2:047c9c4b8db3 34
taylornichols 5:bc2247ee09b9 35 class Bullet
taylornichols 5:bc2247ee09b9 36 {
taylornichols 5:bc2247ee09b9 37 enum
taylornichols 5:bc2247ee09b9 38 {
taylornichols 5:bc2247ee09b9 39 width = 2 , height = 3
taylornichols 5:bc2247ee09b9 40 };
taylornichols 5:bc2247ee09b9 41
taylornichols 5:bc2247ee09b9 42 private:
taylornichols 5:bc2247ee09b9 43 int unsigned _x , _dx ;
taylornichols 5:bc2247ee09b9 44 int unsigned _y , _dy ;
taylornichols 5:bc2247ee09b9 45 };
taylornichols 2:047c9c4b8db3 46
taylornichols 5:bc2247ee09b9 47 class Enemy
taylornichols 5:bc2247ee09b9 48 {
taylornichols 5:bc2247ee09b9 49 enum
taylornichols 5:bc2247ee09b9 50 {
taylornichols 5:bc2247ee09b9 51 width = 16, height = 10
taylornichols 5:bc2247ee09b9 52 };
taylornichols 5:bc2247ee09b9 53 Enemy( int unsigned x , int unsigned dx , int unsigned y , int unsigned dy , int color ) :
taylornichols 5:bc2247ee09b9 54 _x( x ) , _dx( dx ) , _y( y ) , _dy( dy ) , _color( color )
taylornichols 5:bc2247ee09b9 55 {
taylornichols 5:bc2247ee09b9 56 }
taylornichols 5:bc2247ee09b9 57 private:
taylornichols 5:bc2247ee09b9 58 int unsigned _x , _dx ;
taylornichols 5:bc2247ee09b9 59 int unsigned _y , _dy ;
taylornichols 5:bc2247ee09b9 60 int unsigned const _color ;
taylornichols 5:bc2247ee09b9 61 };
taylornichols 2:047c9c4b8db3 62
taylornichols 5:bc2247ee09b9 63 class Game
taylornichols 5:bc2247ee09b9 64 {
taylornichols 5:bc2247ee09b9 65 static int const enemy_colors [4];
taylornichols 5:bc2247ee09b9 66 enum
taylornichols 5:bc2247ee09b9 67 {
taylornichols 5:bc2247ee09b9 68 screen_width = 128 , screen_height = 128 ,
taylornichols 5:bc2247ee09b9 69 enemy_count = sizeof(enemy_colors) / sizeof(enemy_colors[0])
taylornichols 5:bc2247ee09b9 70 };
taylornichols 5:bc2247ee09b9 71
taylornichols 5:bc2247ee09b9 72 public:
taylornichols 2:047c9c4b8db3 73
taylornichols 5:bc2247ee09b9 74 Game( ) :
taylornichols 5:bc2247ee09b9 75 _ship( screen_width/2 , 0 , screen_height-1 , 0 )
taylornichols 5:bc2247ee09b9 76 {
taylornichols 5:bc2247ee09b9 77 }
taylornichols 5:bc2247ee09b9 78 void read( )
taylornichols 5:bc2247ee09b9 79 {
taylornichols 5:bc2247ee09b9 80 }
taylornichols 5:bc2247ee09b9 81 void draw( )
taylornichols 5:bc2247ee09b9 82 {
taylornichols 5:bc2247ee09b9 83 _ship.draw( );
taylornichols 5:bc2247ee09b9 84 }
taylornichols 5:bc2247ee09b9 85 void wait( )
taylornichols 5:bc2247ee09b9 86 {
taylornichols 5:bc2247ee09b9 87 Thread::wait( 100 );
taylornichols 5:bc2247ee09b9 88 }
taylornichols 5:bc2247ee09b9 89 private:
taylornichols 5:bc2247ee09b9 90 Ship _ship ;
taylornichols 5:bc2247ee09b9 91 // Enemy _enemy [ enemy_count ] ;
taylornichols 5:bc2247ee09b9 92 };
taylornichols 5:bc2247ee09b9 93 int const Game::enemy_colors [4] = {
taylornichols 5:bc2247ee09b9 94 RED , GREEN , BLUE , RED|GREEN
taylornichols 5:bc2247ee09b9 95 };
taylornichols 2:047c9c4b8db3 96
taylornichols 5:bc2247ee09b9 97 //
taylornichols 1:d1d12f229b9a 98 int main( )
taylornichols 1:d1d12f229b9a 99 {
taylornichols 3:1688f7a77ed8 100 pc.printf( " -- INIT -- \n" );
taylornichols 5:bc2247ee09b9 101 srand( time( NULL ) );
taylornichols 5:bc2247ee09b9 102 pb.set_debounce_us( 1000 );
taylornichols 5:bc2247ee09b9 103 pb.mode( PullUp );
taylornichols 5:bc2247ee09b9 104
taylornichols 5:bc2247ee09b9 105 Game game;
taylornichols 5:bc2247ee09b9 106
taylornichols 5:bc2247ee09b9 107 while ( 1 )
taylornichols 5:bc2247ee09b9 108 {
taylornichols 5:bc2247ee09b9 109 game.read( );
taylornichols 5:bc2247ee09b9 110 game.draw( );
taylornichols 5:bc2247ee09b9 111 game.wait( );
taylornichols 5:bc2247ee09b9 112 }
taylornichols 2:047c9c4b8db3 113
taylornichols 3:1688f7a77ed8 114 pc.printf( " -- DONE -- \n" );
taylornichols 0:f29cfb036e34 115 }