This is test version of Pokemongo game. ELEC 2645 final project.

Dependencies:   Tone

Committer:
shalwego
Date:
Thu Apr 15 15:35:12 2021 +0000
Revision:
0:819c2d6a69ac
Issue about music playing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shalwego 0:819c2d6a69ac 1 #include "Rocket.h"
shalwego 0:819c2d6a69ac 2
shalwego 0:819c2d6a69ac 3 void Rocket::init(int x, int y, int size, int speed){
shalwego 0:819c2d6a69ac 4 _x = x;
shalwego 0:819c2d6a69ac 5 _y = y;
shalwego 0:819c2d6a69ac 6 _size = size;
shalwego 0:819c2d6a69ac 7
shalwego 0:819c2d6a69ac 8 _velocity.x = speed;
shalwego 0:819c2d6a69ac 9 _velocity.y = speed;
shalwego 0:819c2d6a69ac 10 }
shalwego 0:819c2d6a69ac 11
shalwego 0:819c2d6a69ac 12 void Rocket::draw(N5110 &lcd){
shalwego 0:819c2d6a69ac 13 lcd.drawRect(_x,_y,_size,_size,FILL_BLACK);
shalwego 0:819c2d6a69ac 14 }
shalwego 0:819c2d6a69ac 15
shalwego 0:819c2d6a69ac 16 void Rocket::update(Position2D pokeball_pos){
shalwego 0:819c2d6a69ac 17 if (
shalwego 0:819c2d6a69ac 18 (_x <= pokeball_pos.x) && (_y <= pokeball_pos.y) )
shalwego 0:819c2d6a69ac 19 {
shalwego 0:819c2d6a69ac 20 _x += _velocity.x;
shalwego 0:819c2d6a69ac 21 _y += _velocity.y;}
shalwego 0:819c2d6a69ac 22 if (
shalwego 0:819c2d6a69ac 23 (_x > pokeball_pos.x) && (_y < pokeball_pos.y) )
shalwego 0:819c2d6a69ac 24 {
shalwego 0:819c2d6a69ac 25 _x -= _velocity.x;
shalwego 0:819c2d6a69ac 26 _y += _velocity.y;}
shalwego 0:819c2d6a69ac 27 if (
shalwego 0:819c2d6a69ac 28 (_x > pokeball_pos.x) && (_y > pokeball_pos.y) )
shalwego 0:819c2d6a69ac 29 {
shalwego 0:819c2d6a69ac 30 _x -= _velocity.x;
shalwego 0:819c2d6a69ac 31 _y -= _velocity.y;}
shalwego 0:819c2d6a69ac 32 if (
shalwego 0:819c2d6a69ac 33 (_x < pokeball_pos.x) && (_y > pokeball_pos.y) )
shalwego 0:819c2d6a69ac 34 {
shalwego 0:819c2d6a69ac 35 _x += _velocity.x;
shalwego 0:819c2d6a69ac 36 _y -= _velocity.y;}
shalwego 0:819c2d6a69ac 37
shalwego 0:819c2d6a69ac 38 if (_y < 1) _y = 1;
shalwego 0:819c2d6a69ac 39 if (_x < 1) _x = 1;
shalwego 0:819c2d6a69ac 40 if (_x > WIDTH - 1) _x = WIDTH - 1;
shalwego 0:819c2d6a69ac 41 if (_y > HEIGHT - 1) _y = HEIGHT - 1;
shalwego 0:819c2d6a69ac 42 }
shalwego 0:819c2d6a69ac 43
shalwego 0:819c2d6a69ac 44 void Rocket::set_velocity(Position2D v){
shalwego 0:819c2d6a69ac 45 _velocity.x = v.x;
shalwego 0:819c2d6a69ac 46 _velocity.y = v.y;
shalwego 0:819c2d6a69ac 47 }
shalwego 0:819c2d6a69ac 48
shalwego 0:819c2d6a69ac 49 void Rocket::set_pos(Position2D p){
shalwego 0:819c2d6a69ac 50 _x = p.x;
shalwego 0:819c2d6a69ac 51 _y = p.y;
shalwego 0:819c2d6a69ac 52 }
shalwego 0:819c2d6a69ac 53
shalwego 0:819c2d6a69ac 54 void Rocket::rocket_crash(){
shalwego 0:819c2d6a69ac 55 _x = rand() % 84 ;
shalwego 0:819c2d6a69ac 56 _y = rand() % 48 ;
shalwego 0:819c2d6a69ac 57 }
shalwego 0:819c2d6a69ac 58
shalwego 0:819c2d6a69ac 59 Position2D Rocket::get_velocity(){ return {_velocity.x,_velocity.y}; }
shalwego 0:819c2d6a69ac 60
shalwego 0:819c2d6a69ac 61
shalwego 0:819c2d6a69ac 62 int Rocket::get_size() { return _size; }
shalwego 0:819c2d6a69ac 63
shalwego 0:819c2d6a69ac 64
shalwego 0:819c2d6a69ac 65 Position2D Rocket::get_pos() { return {_x,_y}; }