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
Revision 16:ddb203a74dfc, committed 2019-04-24
- Comitter:
- el17sm
- Date:
- Wed Apr 24 21:21:37 2019 +0000
- Parent:
- 15:44d5cc33d389
- Child:
- 17:99e533f7f2fb
- Child:
- 19:bfe410c82b45
- Commit message:
- Screen clear error;
Changed in this revision
--- a/Entity/Entity.h Wed Apr 24 06:28:14 2019 +0000
+++ b/Entity/Entity.h Wed Apr 24 21:21:37 2019 +0000
@@ -37,6 +37,7 @@
FrameCount frame;
int hp;
int face;
+ float velocity;
public:
// Function
--- a/Entity/Headless/Headless.cpp Wed Apr 24 06:28:14 2019 +0000
+++ b/Entity/Headless/Headless.cpp Wed Apr 24 21:21:37 2019 +0000
@@ -5,7 +5,7 @@
Headless::Headless(float pos_x, float pos_y){
moving = true;
face = 0;
- hp = 3;
+ hp = 4;
hitbox.width = 6;
hitbox.height = 5;
position.x = pos_x;
@@ -17,18 +17,13 @@
frame.count = 0;
frame.number = 0;
frame.max = 4;
+ velocity = 0.5;
}
void Headless::move(float player_x, float player_y){
std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector
- position.x += headless_velocity * pos_diff.real() / std::abs(pos_diff);
- position.y += headless_velocity * pos_diff.imag() / std::abs(pos_diff);
-
-// if(!matrix_collision_test(position.x + mapped_x, position.y, 0)){
-// position.x += mapped_x;
-// }
-// if(!matrix_collision_test(position.x, position.y - mapped_y, 0)){
-// position.y -= mapped_y;
+ position.x += velocity * pos_diff.real() / std::abs(pos_diff);
+ position.y += velocity * pos_diff.imag() / std::abs(pos_diff);
if (pos_diff.imag() / std::abs(pos_diff) < 0 && abs(pos_diff.imag() / std::abs(pos_diff)) > abs(pos_diff.real() / std::abs(pos_diff))){
face = 2;
@@ -43,6 +38,9 @@
face = 3;
}
+ undo_move_x(matrix_collision_test(position.x, prev_pos.y, 0));
+ undo_move_y(matrix_collision_test(prev_pos.x, position.y, 0));
+
if (frame.number < frame.max){
frame.count++;
}
--- a/Entity/Headless/Headless.h Wed Apr 24 06:28:14 2019 +0000
+++ b/Entity/Headless/Headless.h Wed Apr 24 21:21:37 2019 +0000
@@ -14,8 +14,6 @@
};
-const float headless_velocity = 0.4;
-
const int sprite_headless[4][4][9][6] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
{ // Up
{
--- a/Entity/Player/Player.cpp Wed Apr 24 06:28:14 2019 +0000
+++ b/Entity/Player/Player.cpp Wed Apr 24 21:21:37 2019 +0000
@@ -5,7 +5,7 @@
Player::Player(float pos_x, float pos_y){
moving = false;
face = 0;
- hp = 1;
+ hp = 3;
hitbox.width = 6;
hitbox.height = 5;
position.x = pos_x;
@@ -19,7 +19,10 @@
frame.max = 4;
for (int i = 0; i < bullets_max; i++){valid_bullets[i] = false;}
fire_rate_counter = 0;
- fire_rate_delay = 5;
+
+ // Upgradable status
+ fire_rate_delay = 12;
+ velocity = 1.4;
}
// Accessors
@@ -27,11 +30,11 @@
// Functions
void Player::move(float mapped_x, float mapped_y){
- if(!matrix_collision_test(position.x + player_speed*mapped_x, position.y, 0)){
- position.x += player_speed*mapped_x;
+ 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 - player_speed*mapped_y, 0)){
- position.y -= player_speed*mapped_y;
+ 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){
--- a/Entity/Player/Player.h Wed Apr 24 06:28:14 2019 +0000
+++ b/Entity/Player/Player.h Wed Apr 24 21:21:37 2019 +0000
@@ -25,8 +25,6 @@
int fire_rate_delay;
};
-const float player_speed = 1.2;
-
const int sprite_player [4][4][12][6] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
{ // Up
{
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Snake/Snake.cpp Wed Apr 24 21:21:37 2019 +0000
@@ -0,0 +1,75 @@
+#include "Snake.h"
+#include "math.h"
+#include <complex>
+
+Snake::Snake(float pos_x, float pos_y) {
+ moving = true;
+ face = 0;
+ hp = 4;
+ hitbox.width = 6;
+ hitbox.height = 5;
+ position.x = pos_x;
+ position.y = pos_y;
+ sprite_size.width = 6;
+ sprite_size.height = 9;
+ sprite_size.offset_x = 0;
+ sprite_size.offset_y = 4;
+ frame.count = 0;
+ frame.number = 0;
+ frame.max = 6;
+ velocity = 0.1;
+}
+
+void Snake::move(float player_x, float player_y) {
+ std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector
+ velocity = velocity_pattern[frame.number]; // Creating slithering effect, changing velocity of movement
+
+ // Setting Face
+ if (frame.number == 0) {
+ if (abs(pos_diff.real()) > abs(pos_diff.imag())) {
+ if (pos_diff.real() > 0) {
+ face = 1;
+ }
+ else {
+ face = 3;
+ }
+ }
+ else {
+ if (pos_diff.imag() > 0) {
+ face = 0;
+ }
+ else {
+ face = 2;
+ }
+ }
+ }
+
+ // Movement, Offset and Update
+ if (face == 0){
+ position.y += velocity;
+ }
+ else if (face == 1){
+ position.x += velocity;
+ }
+ else if (face == 2){
+ position.y -= velocity;
+ }
+ else if (face == 3){
+ position.x -= velocity;
+ }
+
+ undo_move_x(matrix_collision_test(position.x, prev_pos.y, 0));
+ undo_move_y(matrix_collision_test(prev_pos.x, position.y, 0));
+
+ if (frame.number < frame.max) {
+ frame.count++;
+ }
+ else {
+ frame.count = 0;
+ }
+ frame.number = (frame.count/5) % frame.max;
+}
+
+int * Snake::get_frame() {
+ return (int *) sprite_snake[face][frame.number];
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Snake/Snake.h Wed Apr 24 21:21:37 2019 +0000
@@ -0,0 +1,294 @@
+#ifndef SNAKE_H
+#define SNAKE_H
+#include "Entity.h"
+
+class Snake : public Entity {
+
+ public:
+ // Constructor
+ Snake(float, float);
+
+ // Functions
+ virtual void move(float, float);
+ virtual int * get_frame();
+
+};
+
+const float velocity_pattern[6] = {0, 0.3, 0.5, 0.7, 0.5, -0.2};
+
+const int sprite_snake[4][6][12][6] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
+ { // Up
+ {
+ {0,0,0,0,0,0,},
+ {1,0,0,0,0,0,},
+ {0,1,1,1,1,0,},
+ {1,0,1,1,0,1,},
+ {0,0,1,1,0,0,},
+ {0,0,1,1,0,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,}
+ },
+ {
+ {0,0,0,0,0,0,},
+ {0,0,0,1,0,0,},
+ {0,1,1,1,1,0,},
+ {1,0,1,1,0,1,},
+ {0,0,1,1,0,0,},
+ {0,0,1,1,0,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,},
+ {0,0,0,0,1,0,}
+ },
+ {
+ {0,0,0,0,1,0,},
+ {0,0,1,0,0,0,},
+ {0,1,1,1,1,0,},
+ {1,0,1,1,0,1,},
+ {0,0,1,1,0,0,},
+ {0,0,1,1,0,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,}
+ },
+ {
+ {0,1,0,0,0,0,},
+ {0,0,0,0,0,0,},
+ {0,1,1,1,1,0,},
+ {1,0,1,1,0,1,},
+ {0,0,1,1,0,0,},
+ {0,0,1,1,0,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,0,0,}
+ },
+ {
+ {0,0,0,0,1,0,},
+ {0,0,1,0,0,0,},
+ {0,1,1,1,1,0,},
+ {1,0,1,1,0,1,},
+ {0,0,1,1,0,0,},
+ {0,0,1,1,0,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,},
+ {0,1,0,0,1,0,}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0,},
+ {1,0,0,0,1,0,}
+ }
+ }
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp Wed Apr 24 06:28:14 2019 +0000
+++ b/main.cpp Wed Apr 24 21:21:37 2019 +0000
@@ -86,12 +86,12 @@
bool valid_enemies[no_of_enemies];
for (int i = 0; i < no_of_enemies; i++){valid_enemies[i] = false;}
Entity *enemies[no_of_enemies];
- enemies[0] = new Headless(20, 20);
- valid_enemies[0] = true;
- enemies[1] = new Headless(20, 30);
- valid_enemies[1] = true;
- enemies[2] = new Headless(60, 30);
- valid_enemies[2] = true;
+ //enemies[0] = new Snake(20, 20);
+// valid_enemies[0] = true;
+// enemies[1] = new Snake(20, 30);
+// valid_enemies[1] = true;
+// enemies[2] = new Snake(60, 30);
+// valid_enemies[2] = true;
while(1){
int pos_x = player.get_pos_x();
@@ -112,6 +112,7 @@
enemies[j]->take_damage(player.get_attack());
player.valid_bullets[i] = false;
player.bullets_array[i]->~Bullets;
+ goto multiple_damage_prevention;
}
}
if (player.bullets_array[i]->out_of_bounds_check()){
@@ -119,6 +120,7 @@
player.bullets_array[i]->~Bullets;
}
};
+ multiple_damage_prevention:{}
}
};
@@ -206,7 +208,7 @@
counter++;
}
- gameover:
+ gameover:{
lcd.clear();
lcd.printString("Game Over", 0, 0);
lcd.printString("Retry?", 0, 1);
@@ -220,6 +222,7 @@
};
wait(0.05);
while(gamepad.check_event(Gamepad::A_PRESSED)){
- };
+ };
+ }
};
}
\ No newline at end of file