Helios Lyons 201239214
Embed:
(wiki syntax)
Show/hide line numbers
Invader.cpp
00001 #include "Invader.h" 00002 #include "Bitmap.h" 00003 #include <vector> 00004 00005 Invader::Invader() 00006 { 00007 00008 } 00009 00010 Invader::~Invader() 00011 { 00012 00013 } 00014 00015 void Invader::init(int sprite, int hitpoints) 00016 { 00017 //_y = y; 00018 // _x = x; 00019 _height = 8; 00020 _width = 11; 00021 _death = false; 00022 _sprite = sprite; 00023 _hitpoints = hitpoints; 00024 } 00025 00026 void Invader::draw(N5110 &lcd) 00027 { 00028 //lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); 00029 static int invader1_data[] = { 00030 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#.. 00031 0,0,0,1,0,0,0,1,0,0,0, // ...#...#... 00032 0,0,1,1,1,1,1,1,1,0,0, // ..#######.. 00033 0,1,1,0,1,1,1,0,1,1,0, // .##.###.##. 00034 1,1,1,1,1,1,1,1,1,1,1, // ########### 00035 1,0,1,1,1,1,1,1,1,0,1, // #.#######.# 00036 1,0,1,0,0,0,0,0,1,0,1, // #.#.....#.# 00037 0,0,0,1,1,0,1,1,0,0,0 // ...##.##... 00038 }; 00039 00040 static int invader2_data[] = { 00041 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#.. 00042 1,0,0,1,0,0,0,1,0,0,1, // #..#...#..# 00043 1,0,1,1,1,1,1,1,1,0,1, // #.#######.# 00044 1,1,1,0,1,1,1,0,1,1,1, // ###.###.### 00045 1,1,1,1,1,1,1,1,1,1,1, // ########### 00046 0,1,1,1,1,1,1,1,1,1,0, // .#########. 00047 0,0,1,0,0,0,0,0,1,0,0, // ..#.....#.. 00048 0,1,0,0,0,0,0,0,0,1,0 // .#.......#. 00049 }; 00050 00051 static int invader3_data[] = { 00052 0,0,0,0,1,1,1,0,0,0,0, // ....###.... 00053 0,0,0,1,1,1,1,1,0,0,0, // ...#####... 00054 0,0,1,1,1,1,1,1,1,0,0, // ..#######.. 00055 1,1,0,0,1,1,1,0,0,1,1, // ##..###..## 00056 1,1,1,1,1,1,1,1,1,1,1, // ########### 00057 0,0,1,1,0,0,0,1,1,0,0, // ..##...##.. 00058 0,1,0,0,1,1,1,0,0,1,0, // .#..###..#. 00059 1,0,1,1,0,0,0,1,1,0,1 // #.##...##.# 00060 }; 00061 00062 if (_sprite == 1 && _death == false) { 00063 Bitmap invader1(invader1_data,11,8); 00064 invader1.render(lcd,_x,_y); 00065 } 00066 else if (_sprite == 2 && _death == false) { 00067 Bitmap invader2(invader2_data,11,8); 00068 invader2.render(lcd,_x,_y); 00069 } 00070 else if (_sprite == 3 && _death == false) { 00071 Bitmap invader3(invader3_data,11,8); 00072 invader3.render(lcd,_x,_y); 00073 } 00074 else if (_death == true) {printf("Alien is dead");} 00075 else {printf("Incorrect Sprite Value");} 00076 } 00077 00078 /*void Invader::set_hitpoints(int hitpoints){ 00079 _hitpoints = hitpoints; 00080 } 00081 */ 00082 /* int Invader::get_hitpoints(){ // Shouldn't be necessary - use get_death method 00083 00084 return _hitpoints; 00085 } 00086 */ 00087 00088 int Invader::hit(){ 00089 _hitpoints--; 00090 return _hitpoints; 00091 } 00092 00093 /*void Invader::set_death(bool death){ // Likewise not necessary 00094 _death = death; 00095 } 00096 */ 00097 00098 bool Invader::get_death(){ 00099 if (_hitpoints == 0) { 00100 _death = true; 00101 } 00102 return _death; 00103 } 00104 /* 00105 void Invader::set_sprite(int sprite){ 00106 _sprite = sprite; 00107 } 00108 */ 00109 00110 Vector2D Invader::get_pos() { 00111 Vector2D p = {_x,_y}; 00112 return p; 00113 }
Generated on Thu Jul 14 2022 22:11:37 by
1.7.2