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/Mobs/Snake/Snake.cpp
- Revision:
- 36:92d131695e7c
- Parent:
- 35:06cd6be999ad
- Child:
- 37:a404860171a9
--- a/Entity/Mobs/Snake/Snake.cpp Mon May 06 20:05:14 2019 +0000
+++ b/Entity/Mobs/Snake/Snake.cpp Tue May 07 01:11:07 2019 +0000
@@ -37,7 +37,7 @@
{
if (_prev_face != face) {
frame.number = 0;
- hitbox.width = sprite_size.offset_y;
+ hitbox.width = hitbox_width;
hitbox.height = hitbox_height;
sprite_size.width = sprite_size_width;
sprite_size.height = sprite_size_height;
@@ -50,23 +50,24 @@
// Functions
void Snake::move(float player_x, float player_y, char * map, bool * doorways)
{
- std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector
- velocity = velocity_pattern[_velocity_index]; // Creating slithering effect, changing velocity of movement
+ float diff_x = player_x - position.x; // defining difference in position as a vector
+ float diff_y = player_y - position.y;
+ velocity = snake_velocity_pattern[_velocity_index]; // Creating slithering effect, changing velocity of movement
update_prev_face();
// Setting Face
if (_velocity_index == 0) {
- if (abs(pos_diff.real()) > abs(pos_diff.imag())) {
- if (pos_diff.real() > 0) {
+ if (abs(diff_x) > abs(diff_y)) {
+ if (diff_x > 0) {
face = 1;
} else {
face = 3;
}
} else {
- if (pos_diff.imag() > 0) {
+ if (diff_y > 0) {
+ face = 2;
+ } else {
face = 0;
- } else {
- face = 2;
}
}
}
@@ -83,7 +84,7 @@
update_hitbox(4, 7, 6, 12, -1, -5, 6);
} else if (face == 3) {
position.x -= velocity;
- update_hitbox(7, 4, 12, 7, -0, -4, 4);
+ update_hitbox(7, 4, 12, 7, 0, -4, 4);
}
undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
@@ -111,11 +112,11 @@
char * Snake::get_frame()
{
if(face == 0) {
- return (char *) sprite_snake_y[1][frame.number];
+ return (char *) sprite_snake_y[0][frame.number];
} else if(face == 1) {
return (char *) sprite_snake_x[0][frame.number];
} else if(face == 2) {
- return (char *) sprite_snake_y[0][frame.number];
+ return (char *) sprite_snake_y[1][frame.number];
} else if(face == 3) {
return (char *) sprite_snake_x[1][frame.number];
}
@@ -124,10 +125,9 @@
void Snake::draw(N5110 &lcd)
{
-// lcd.drawSpriteTransparent(position.x+sprite_size.offset_x,
-// position.y+sprite_size.offset_y,
-// sprite_size.height,
-// sprite_size.width,
-// get_frame());
- lcd.drawRect(position.x, position.y, hitbox.width, hitbox.height, FILL_BLACK);
+ lcd.drawSpriteTransparent(get_pos_x()+sprite_size.offset_x,
+ get_pos_y()+sprite_size.offset_y,
+ sprite_size.height,
+ sprite_size.width,
+ get_frame());
}
\ No newline at end of file