Nemesis game third enemy
Embed:
(wiki syntax)
Show/hide line numbers
Enemy3.cpp
00001 #include "Enemy3.h" 00002 00003 Enemy3::Enemy3() 00004 { 00005 } 00006 00007 Enemy3::~Enemy3() 00008 { 00009 } 00010 00011 00012 // Initializion method: 00013 00014 void Enemy3::init(int speed) 00015 { 00016 _x = rand() % 63 + 84; // Starting x position is randomized off screen. Creates a random ship generation. 00017 _y = 13; // Starting y position (fixed, third lane) 00018 00019 _velocity.x = -speed; // Velocity is based on the speed, which is input when method is used. 00020 _velocity.y = 0; 00021 } 00022 00023 00024 // Draws third enemy ship onto LCD: 00025 00026 void Enemy3::draw(N5110 &lcd) 00027 { 00028 lcd.drawLine(_x,_y,_x,_y+5,1); 00029 lcd.drawLine(_x-1,_y,_x-1,_y+5,1); 00030 lcd.drawLine(_x-2,_y+1,_x-2,_y+4,1); 00031 lcd.drawLine(_x-3,_y+1,_x-3,_y+4,1); 00032 lcd.drawLine(_x-4,_y+2,_x-4,_y+3,1); 00033 } 00034 00035 00036 // Updates third enemy ship's position: 00037 00038 void Enemy3::update() 00039 { 00040 // X and y positions depend on velocity: 00041 _x += _velocity.x; 00042 _y += _velocity.y; 00043 } 00044 00045 00046 // Obtains third enemy ship's current position: 00047 00048 Vector2D Enemy3::get_pos() 00049 { 00050 Vector2D p = {_x,_y}; 00051 return p; 00052 }
Generated on Tue Jul 19 2022 22:37:17 by
1.7.2