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.
My_game_clases/Objects.cpp
- Committer:
- thestudent
- Date:
- 2020-04-01
- Revision:
- 6:33bdb54c2c88
- Child:
- 7:82079de8bcd6
File content as of revision 6:33bdb54c2c88:
//includes #include "Objects.h" #include "Gamepad.h" #include "N5110.h" #include "mbed.h" int _cannon[6][6] = { { 0,0,1,1,0,0 }, { 0,0,1,1,0,0 }, { 0,1,1,1,1,0 }, { 0,1,1,1,1,0 }, { 1,1,1,1,1,1 }, { 1,1,1,1,1,1 }, }; Objects::Objects() { _cannon_pos = 0; //sets the speed counter to 0 _initial_shot_pos = 37;// sets the vertical position of the shot which is one above the cannon _shot_incrementer = 2; _shot_y_pos.push_back(_initial_shot_pos); _shot_x_pos.push_back(_cannon_pos + 2); _radiuss = 2; }; void Objects::draw_base(N5110 &lcd) { lcd.drawRect(0,46,84,2,FILL_BLACK); }; void Objects::cannon_position(Gamepad &pad) { float joy_mag = pad.get_mag(); float joy_angle = pad.get_angle(); if(joy_mag < 0.5 && _cannon_pos > 1 && joy_angle > 180.0) { _cannon_pos += -1; } else if(joy_mag < 1.01 && _cannon_pos > 0 && joy_angle > 180.0) { _cannon_pos += -2; } else if(joy_mag < 0.5 && _cannon_pos < 78 && joy_angle > 0.0) { _cannon_pos += 1; } else if (joy_mag <= 1.01 && _cannon_pos < 77 && joy_angle > 0.0) { _cannon_pos += 2; } else { _cannon_pos = _cannon_pos; } } void Objects::draw_cannon(N5110 &lcd) { lcd.drawSprite(_cannon_pos,40,6,6,(int *)_cannon); } void Objects::draw_shots(N5110 &lcd) { for (int i = 0; i < _shot_y_pos.size(); i++) { lcd.drawRect(_shot_x_pos[i],_shot_y_pos[i],2,2,FILL_BLACK); // printf( " %d || %d \n",_shot_x_pos.size(),_shot_y_pos.size()); _shot_y_pos[i] -= _shot_incrementer; // moves the shots upwards } //adds another shot if the distance between //y pos of the initial pos and previous shot pos is more than 5 if(_shot_y_pos[_shot_y_pos.size() - 1 ] + 5 < _initial_shot_pos && _shot_y_pos.size() < 10) { _shot_y_pos.push_back(_initial_shot_pos); _shot_x_pos.push_back(_cannon_pos + 2); } //erasing a shot if the y position is below 0 if(_shot_y_pos[0] <= 0) { _shot_y_pos.erase(_shot_y_pos.begin()); _shot_x_pos.erase(_shot_x_pos.begin()); } } void Objects::draw_ball(N5110 &lcd,int ball_x, int ball_y, int delta_r) { lcd.drawCircle(ball_x,ball_y,_radiuss + delta_r,FILL_BLACK); }