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.h
- Revision:
- 17:99e533f7f2fb
- Parent:
- 16:ddb203a74dfc
- Child:
- 18:3c030560e31d
--- a/Entity/Snake/Snake.h Wed Apr 24 21:21:37 2019 +0000
+++ b/Entity/Snake/Snake.h Wed Apr 24 23:56:32 2019 +0000
@@ -12,281 +12,271 @@
virtual void move(float, float);
virtual int * get_frame();
+ private:
+ // Member Function
+ void update_prev_face();
+
+ // Member Mutator
+ void 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);
+
+ // Member Variable
+ int _velocity_index;
+ int _prev_face;
+
};
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
+const int sprite_snake_x[2][4][7][12] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
+ { // Right
{
- {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,1,1,1,0,},
+ {0,0,0,0,0,0,0,1,1,1,2,1,},
+ {0,0,0,0,0,0,0,1,1,1,1,1,},
+ {0,0,0,0,0,0,0,1,1,1,0,0,},
+ {0,0,0,0,0,0,0,0,1,1,1,0,},
+ {0,0,1,1,1,1,0,1,1,1,1,0,},
+ {1,1,1,0,1,1,1,1,1,1,0,0,},
+ },
+ {
+ {0,0,0,0,0,0,0,0,1,1,1,0,},
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,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,0,1,1,0,0,},
+ {0,0,0,1,1,0,},
+ {0,0,0,1,1,0,},
+ {0,0,1,1,0,0,},
+ {0,1,1,0,0,0,},
{0,1,1,1,1,0,},
- {1,0,1,1,0,1,},
+ {1,1,1,1,1,1,},
+ {1,2,1,1,2,1,},
+ {0,1,1,1,1,0,},
{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,}
- }
- },
- { // Left
- {
- {0,0,0,0,0,0,},
- {0,0,0,1,0,0,},
- {0,0,1,1,0,0,},
- {1,1,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,0,1,0,0,},
- {0,0,0,1,0,0,},
- {0,0,1,1,0,0,}
- },
- {
- {0,0,0,0,1,0,},
- {0,0,1,0,0,0,},
- {0,0,1,1,0,0,},
- {1,1,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,1,0,1,0,0,},
- {0,1,0,1,0,0,},
- {1,0,0,0,1,0,}
},
{
- {0,1,0,0,0,0,},
- {0,0,0,0,0,0,},
{0,0,1,1,0,0,},
- {1,1,1,1,0,0,},
- {0,0,1,1,0,0,},
+ {0,0,0,0,1,0,},
+ {0,0,0,1,1,0,},
{0,0,1,1,0,0,},
- {0,0,0,1,0,0,},
- {0,0,0,1,0,0,},
- {0,0,1,1,0,0,}
- },
- {
- {0,0,0,0,0,0,},
- {1,0,0,0,0,0,},
- {0,0,1,1,0,0,},
- {1,1,1,1,0,0,},
+ {0,1,1,0,0,0,},
+ {0,1,1,0,0,0,},
+ {0,1,1,1,1,0,},
+ {1,1,1,1,1,1,},
+ {1,2,1,1,2,1,},
+ {0,1,1,1,1,0,},
{0,0,1,1,0,0,},
{0,0,1,1,0,0,},
- {0,1,0,1,0,0,},
- {0,1,0,1,0,0,},
- {1,0,0,0,1,0,}
},
{
- {0,1,0,0,0,0,},
- {0,0,0,0,0,0,},
+ {0,0,0,1,0,0,},
+ {0,0,0,0,1,0,},
{0,0,1,1,0,0,},
- {1,1,1,1,0,0,},
+ {0,1,1,0,0,0,},
+ {0,1,1,0,0,0,},
+ {0,0,1,1,0,0,},
+ {0,1,1,1,1,0,},
+ {1,1,1,1,1,1,},
+ {1,2,1,1,2,1,},
+ {0,1,1,1,1,0,},
{0,0,1,1,0,0,},
{0,0,1,1,0,0,},
- {0,0,0,1,0,0,},
- {0,0,0,1,0,0,},
- {0,0,1,1,0,0,}
- },
- {
- {0,0,0,0,0,0,},
- {1,0,0,0,0,0,},
- {0,0,1,1,0,0,},
- {1,1,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,1,0,1,0,0,},
- {0,1,0,1,0,0,},
- {1,0,0,0,1,0,}
}
}
};