Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Enemy5.cpp
00001 #include "Enemy5.h" 00002 00003 Enemy5::Enemy5() 00004 { 00005 } 00006 00007 Enemy5::~Enemy5() 00008 { 00009 } 00010 00011 00012 // Initializion method: 00013 00014 void Enemy5::init(int speed) 00015 { 00016 _x = rand() % 63 + 84; // Starting x position is randomized off screen. Creates a random ship generation. 00017 _y = 27; // Starting y position (fixed, fifth 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 fifth enemy ship onto LCD: 00025 00026 void Enemy5::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 fifth enemy ship's position: 00037 00038 void Enemy5::update() 00039 { 00040 // X and y positions depend on velocity: 00041 _x += _velocity.x; 00042 _y += _velocity.y; 00043 } 00044 00045 00046 // Obtains fifth enemy ship's current position: 00047 00048 Vector2D Enemy5::get_pos() 00049 { 00050 Vector2D p = {_x,_y}; 00051 return p; 00052 }
Generated on Thu Jul 14 2022 07:50:58 by
1.7.2