Helios Lyons 201239214
Embed:
(wiki syntax)
Show/hide line numbers
Canon.cpp
00001 #include "Canon.h" 00002 #include "Bitmap.h" 00003 #include <vector> 00004 00005 Canon::Canon() 00006 { 00007 00008 } 00009 00010 Canon::~Canon() 00011 { 00012 00013 } 00014 00015 void Canon::init(int y,int height,int width) 00016 { 00017 _y = y; // y value on screen is fixed 00018 _x = WIDTH/2 - width/2; // x depends on width of screen and width of canon 00019 _height = height; 00020 _width = width; 00021 _speed = 1; // init speed, add in options – accessible? 00022 _score = 0; // start all at 0 00023 _inv1_kill = 0; 00024 _inv2_kill = 0; 00025 _inv3_kill = 0; 00026 _total_kill = 0; 00027 _life = 3; 00028 } 00029 00030 void Canon::draw(N5110 &lcd) 00031 { 00032 // draw canon in screen buffer – need to replace with a different shape 00033 //lcd.drawRect(_x,_y,_width,_height,FILL_BLACK); 00034 static int sprite_data[] = { 00035 0,0,0,1,1,0,0,0, 00036 0,0,0,1,1,0,0,0, 00037 1,1,1,1,1,1,1,1, 00038 1,1,1,1,1,1,1,1 00039 }; 00040 Bitmap canon_sprite(sprite_data, 8, 4); 00041 canon_sprite.render(lcd, _x,_y); 00042 } 00043 00044 void Canon::update(Direction d,float mag) 00045 { 00046 _speed = int(mag*10.0f); // scale is arbitrary, could be changed in future – add in options menu 00047 00048 // update x value based on direction 00049 // North is decrement as origin is at the top-left so decreasing moves up 00050 if (d == W) { 00051 _x-=_speed; 00052 } else if (d == E) { 00053 _x+=_speed; 00054 } 00055 00056 // check the x origin to set boundaries 00057 if (_x < 1) { 00058 _x = 1; 00059 } 00060 if (_x > WIDTH - _width - 1) { 00061 _x = WIDTH - _width - 1; 00062 } 00063 } 00064 00065 int Canon::add_inv1_kill(int n) 00066 { 00067 _inv1_kill = _inv1_kill + n; 00068 return _inv1_kill; 00069 } 00070 00071 int Canon::add_inv2_kill(int n) 00072 { 00073 _inv2_kill = _inv2_kill + n; 00074 return _inv2_kill; 00075 } 00076 00077 int Canon::add_inv3_kill(int n) 00078 { 00079 _inv3_kill = _inv3_kill + n; 00080 return _inv3_kill; 00081 } 00082 00083 int Canon::add_boss_kill() 00084 { 00085 _boss_kill++; 00086 return _boss_kill; 00087 } 00088 00089 int Canon::get_total_kill() 00090 { 00091 _total_kill = _inv1_kill + _inv2_kill + _inv3_kill + _boss_kill; 00092 return _total_kill; 00093 } 00094 00095 int Canon::get_score() 00096 { 00097 _score = (_inv1_kill * 10) + (_inv2_kill * 20) + (_inv1_kill * 30) + (_boss_kill * 100); 00098 return _score; 00099 } 00100 00101 Vector2D Canon::get_pos() { 00102 Vector2D p = {_x,_y}; 00103 return p; 00104 } 00105 00106 int Canon::get_life() 00107 { 00108 return _life; 00109 } 00110 00111 int Canon::remove_life() 00112 { 00113 _life--; 00114 return _life; 00115 } 00116 00117 int Canon::reset_life() 00118 { 00119 _life = 3; 00120 return _life; 00121 }
Generated on Thu Jul 14 2022 22:11:37 by
1.7.2