ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Tue Apr 16 19:51:12 2019 +0000
Revision:
9:5e53bca2a4c2
Parent:
8:90e789413e0b
Child:
10:e1d2289705ef
Changed the values of the positions and velocities to vectors so that they are easier to manipulate. I made use of the float absolute function (fabs) function to make the ball decelerate to a zero velocity while going upwards.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 1:0001cb3eb053 1 #include "Floors.h"
el17m2h 1:0001cb3eb053 2
el17m2h 1:0001cb3eb053 3 Floors::Floors(){
el17m2h 1:0001cb3eb053 4 }
el17m2h 1:0001cb3eb053 5 Floors::~Floors(){
el17m2h 1:0001cb3eb053 6 }
el17m2h 3:116913e97fd7 7
el17m2h 3:116913e97fd7 8 void Floors::init(int x, int y, int width, int height){
el17m2h 1:0001cb3eb053 9 _height = height;
el17m2h 1:0001cb3eb053 10 _width = width;
el17m2h 3:116913e97fd7 11
el17m2h 9:5e53bca2a4c2 12 _pos.x = x;
el17m2h 9:5e53bca2a4c2 13 _pos.y = y;
el17m2h 1:0001cb3eb053 14
el17m2h 1:0001cb3eb053 15 _velocity.x = 0;
el17m2h 3:116913e97fd7 16 _velocity.y = 0;
el17m2h 1:0001cb3eb053 17 }
el17m2h 1:0001cb3eb053 18
el17m2h 1:0001cb3eb053 19 void Floors::draw(N5110 &lcd){
el17m2h 9:5e53bca2a4c2 20 lcd.drawRect(_pos.x, _pos.y, _width, _height, FILL_BLACK);
el17m2h 1:0001cb3eb053 21 }
el17m2h 1:0001cb3eb053 22
el17m2h 9:5e53bca2a4c2 23 void Floors::update(Vector2D current_pos, Vector2D current_vel){
el17m2h 9:5e53bca2a4c2 24 _current_pos = current_pos;
el17m2h 9:5e53bca2a4c2 25 _current_vel = current_vel;
el17m2h 9:5e53bca2a4c2 26 // if they are below the y bottom then they re-appear at top in a random place
el17m2h 8:90e789413e0b 27
el17m2h 9:5e53bca2a4c2 28 }
el17m2h 9:5e53bca2a4c2 29
el17m2h 9:5e53bca2a4c2 30 Vector2D Floors::get_velocity(){
el17m2h 9:5e53bca2a4c2 31 Vector2D v = {_velocity.x,_velocity.y};
el17m2h 9:5e53bca2a4c2 32 return v;
el17m2h 9:5e53bca2a4c2 33 }
el17m2h 9:5e53bca2a4c2 34
el17m2h 9:5e53bca2a4c2 35 Vector2D Floors::get_pos(){
el17m2h 9:5e53bca2a4c2 36 Vector2D p = {_pos.x,_pos.y};
el17m2h 9:5e53bca2a4c2 37 return p;
el17m2h 5:8814d6de77d0 38 }
el17m2h 5:8814d6de77d0 39
el17m2h 1:0001cb3eb053 40
el17m2h 1:0001cb3eb053 41 void Floors::set_velocity(Vector2D v){
el17m2h 1:0001cb3eb053 42 _velocity.x = v.x;
el17m2h 1:0001cb3eb053 43 _velocity.y = v.y;
el17m2h 1:0001cb3eb053 44 }
el17m2h 1:0001cb3eb053 45
el17m2h 1:0001cb3eb053 46 void Floors::set_pos(Vector2D p){
el17m2h 9:5e53bca2a4c2 47 _pos.x = p.x;
el17m2h 9:5e53bca2a4c2 48 _pos.y = p.y;
el17m2h 1:0001cb3eb053 49 }