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.
Dependencies: mbed MotionSensor
Diff: Entity/Player/Player.cpp
- Revision:
- 22:7abf4581bc9b
- Parent:
- 16:ddb203a74dfc
- Child:
- 23:5a8f75e93508
diff -r 3c030560e31d -r 7abf4581bc9b Entity/Player/Player.cpp
--- a/Entity/Player/Player.cpp Thu Apr 25 03:32:36 2019 +0000
+++ b/Entity/Player/Player.cpp Thu Apr 25 05:53:30 2019 +0000
@@ -2,7 +2,8 @@
#include "math.h"
// Constructor
-Player::Player(float pos_x, float pos_y){
+Player::Player(float pos_x, float pos_y)
+{
moving = false;
face = 0;
hp = 3;
@@ -17,75 +18,81 @@
frame.count = 0;
frame.number = 0;
frame.max = 4;
- for (int i = 0; i < bullets_max; i++){valid_bullets[i] = false;}
+ for (int i = 0; i < bullets_max; i++) {
+ valid_bullets[i] = false;
+ }
fire_rate_counter = 0;
-
+
// Upgradable status
- fire_rate_delay = 12;
+ fire_rate_delay = 3;
velocity = 1.4;
+ _bullet_speed = 2;
}
// Accessors
-int Player::get_attack(){return 1;};
+int Player::get_attack()
+{
+ return 1;
+};
+
+int Player::get_bullet_speed()
+{
+ return _bullet_speed;
+};
// Functions
-void Player::move(float mapped_x, float mapped_y){
- if(!matrix_collision_test(position.x + velocity*mapped_x, position.y, 0)){
+void Player::move(float mapped_x, float mapped_y)
+{
+ if(!matrix_collision_test(position.x + velocity*mapped_x, position.y, 0)) {
position.x += velocity*mapped_x;
}
- if(!matrix_collision_test(position.x, position.y - velocity*mapped_y, 0)){
+ if(!matrix_collision_test(position.x, position.y - velocity*mapped_y, 0)) {
position.y -= velocity*mapped_y;
}
moving = false;
- if (abs(mapped_x) + abs(mapped_y) > 0.1f){
+ if (abs(mapped_x) + abs(mapped_y) > 0.1f) {
moving = true;
- if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)){
+ if (mapped_y < 0 && abs(mapped_y) > abs(mapped_x)) {
face = 2;
- }
- else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)){
+ } else if (mapped_y > 0 && abs(mapped_y) > abs(mapped_x)) {
face = 0;
- }
- else if (mapped_x > 0 && abs(mapped_x) > abs(mapped_y)){
+ } else if (mapped_x > 0 && abs(mapped_x) > abs(mapped_y)) {
face = 1;
- }
- else if (mapped_x < 0 && abs(mapped_x) > abs(mapped_y)){
+ } else if (mapped_x < 0 && abs(mapped_x) > abs(mapped_y)) {
face = 3;
}
-
- if (frame.number < frame.max){
+
+ if (frame.number < frame.max) {
frame.count++;
- }
- else {
+ } else {
frame.count = 0;
}
- }
- else{
+ } else {
frame.count = 0;
}
frame.number = (frame.count/4) % frame.max;
}
-int * Player::get_frame(){
+int * Player::get_frame()
+{
return (int *) sprite_player[face][frame.number];
}
-void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X){
+void Player::buttons(bool button_A, bool button_B, bool button_Y, bool button_X)
+{
fire_rate_counter++;
- if (button_Y){
+ if (button_Y) {
face = 0;
- }
- else if (button_B){
+ } else if (button_B) {
face = 1;
- }
- else if (button_A){
+ } else if (button_A) {
face = 2;
- }
- else if (button_X){
+ } else if (button_X) {
face = 3;
}
- if (button_Y || button_B || button_A || button_X){
- for (int i = 0; i < bullets_max; i++){
- if (!valid_bullets[i] && fire_rate_counter > fire_rate_delay){
+ if (button_Y || button_B || button_A || button_X) {
+ for (int i = 0; i < bullets_max; i++) {
+ if (!valid_bullets[i] && (fire_rate_counter >= fire_rate_delay)) {
bullets_array[i] = new Bullets(position.x+2, position.y-2, face);
valid_bullets[i] = true;
fire_rate_counter = 0;