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/Snake/Snake.cpp
- Revision:
- 23:5a8f75e93508
- Parent:
- 22:7abf4581bc9b
- Child:
- 27:a1b41626f57c
--- a/Entity/Snake/Snake.cpp Thu Apr 25 05:53:30 2019 +0000
+++ b/Entity/Snake/Snake.cpp Thu Apr 25 23:15:44 2019 +0000
@@ -9,6 +9,7 @@
_prev_face = 0;
face = 0;
hp = 4;
+ attack = 1;
hitbox.width = 6;
hitbox.height = 5;
position.x = pos_x;
@@ -30,7 +31,7 @@
}
// Member Mutator
-void Snake::update_hitbox(int hitbox_width, int hitbox_height, int hitbox_offset_x, int hitbox_offset_y, int sprite_size_width, int sprite_size_height, int sprite_size_offset_x, int sprite_size_offset_y, int max_frame) // Offset, Hitbox and Frame Count update
+void Snake::update_hitbox(int hitbox_width, int hitbox_height, int sprite_size_width, int sprite_size_height, int sprite_size_offset_x, int sprite_size_offset_y, int max_frame) // Offset, Hitbox and Frame Count update
{
if (_prev_face != face) {
frame.number = 0;
@@ -71,23 +72,23 @@
// Movement
if (face == 0) {
position.y += velocity;
- update_hitbox(4, 7, 0, 0, 6, 12, 1, 6, 6);
+ update_hitbox(4, 7, 6, 12, 1, 6, 6);
} else if (face == 1) {
position.x += velocity;
- update_hitbox(7, 4, 0, 0, 12, 7, 3, 4, 4);
+ update_hitbox(7, 4, 12, 7, 6, 4, 4);
} else if (face == 2) {
position.y -= velocity;
- update_hitbox(4, 7, 0, 0, 6, 12, 1, 5, 6);
+ update_hitbox(4, 7, 6, 12, 1, 5, 6);
} else if (face == 3) {
position.x -= velocity;
- update_hitbox(7, 4, 0, 0, 12, 7, 2, 4, 4);
+ update_hitbox(7, 4, 12, 7, 0, 4, 4);
}
undo_move_x(matrix_collision_test(position.x, prev_pos.y, 0));
undo_move_y(matrix_collision_test(prev_pos.x, position.y, 0));
frame.count++;
- if (frame.count >= 5) {
+ if (frame.count >= 10) {
frame.count = 0;
_velocity_index++;
frame.number++;
@@ -100,6 +101,11 @@
}
}
+void Snake::take_damage(int damage)
+{
+ hp -= damage;
+}
+
int * Snake::get_frame()
{
if(face == 0) {