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 32:fe6359ef9916, committed 2019-05-06
- Comitter:
- el17sm
- Date:
- Mon May 06 08:56:48 2019 +0000
- Parent:
- 31:ab24d028ddfd
- Child:
- 33:4f3948dcd2f7
- Commit message:
- A bit of code cleanup;; Draw functions are now inside the classes;; Moved classes into it's folders;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Entity/Bosses/Skull/Skull.cpp Mon May 06 08:56:48 2019 +0000 @@ -0,0 +1,2 @@ +//#include "Skull.h" +//
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Bosses/Skull/Skull.h Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,89 @@
+//#ifndef SKULL_H
+//#define SKULL_H
+//
+//class Skull : public Entity {
+//
+//public:
+// // Constructor
+// Skull(float, float);
+//
+// // Functions
+// virtual void move(float player_x, float player_y, int * map, bool * doorways);
+// virtual int * get_frame();
+// virtual void take_damage(int damage);
+//
+//};
+//
+//const int skull_sprite[2][23][21] = //skull_sprite[mouthclose/mouthopen][Size_Y][Size_X]
+//{
+// {
+// {0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
+// {0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0},
+// {0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0},
+// {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
+// {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0},
+// {0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0},
+// {0,1,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,0,0,1,0},
+// {1,0,0,1,1,1,1,1,0,0,0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,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
+// {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+// {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0},
+// {0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0},
+// {0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0}
+// }
+//}
+//
+//#endif
\ No newline at end of file
--- a/Entity/Bullets/Bullets.cpp Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,52 +0,0 @@
-#include "Bullets.h"
-
-Bullets::Bullets(float pos_x, float pos_y, int dir)
-{
- _damage_self_upon_collision = false;
- moving = true;
- face = 0;
- hp = 1;
- hitbox.width = 3;
- hitbox.height = 3;
- position.x = pos_x;
- position.y = pos_y;
- sprite_size.width = 3;
- sprite_size.height = 3;
- sprite_size.offset_x = 0;
- sprite_size.offset_y = 1;
- direction = dir;
-}
-
-void Bullets::move(float speed, float unused, int * unused2, bool * unused3)
-{
- if (direction == 0) {
- position.y -= speed;
- } else if (direction == 1) {
- position.x += speed;
- } else if (direction == 2) {
- position.y += speed;
- } else if (direction == 3) {
- position.x -= speed;
- }
-}
-
-void Bullets::take_damage(int damage)
-{
- hp -= damage;
-}
-
-int * Bullets::get_frame()
-{
- return (int *) bullets_sprite;
-}
-
-bool Bullets::out_of_bounds_check(int * map, bool * doorways)
-{
- if (entity_to_map_collision_test(position.x, position.y, map, doorways)) {
- return true;
- }
- if ((0 > position.x) || (position.x > 84) || (0 > position.y) || (position.y > 48)) {
- return true;
- }
- return false;
-}
\ No newline at end of file
--- a/Entity/Bullets/Bullets.h Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#ifndef BULLETS_H
-#define BULLETS_H
-#include "Entity.h"
-
-class Bullets : public Entity
-{
-
-public:
- // Constructor
- Bullets(float, float, int);
-
- // Functions
- virtual void move(float, float, int * map, bool * doorways);
- virtual int * get_frame();
- virtual void take_damage(int);
- bool out_of_bounds_check(int * map, bool * doorways);
-
-private:
- // Member Variable
- int direction;
-};
-
-const int bullets_sprite[3][3] = {{1,1,1},
- {1,1,1},
- {1,1,1}
-};
-
-#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Collectibles/Health/Health.cpp Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,43 @@
+#include "Health.h"
+
+Health::Health(float pos_x, float pos_y)
+{
+ _damage_self_upon_collision = true;
+ _hp_drop_chance = 0; // out of 10
+ moving = true;
+ face = 0;
+ hp = 1;
+ attack = -1;
+ hitbox.width = 7;
+ hitbox.height = 7;
+ position.x = pos_x;
+ position.y = pos_y;
+ sprite_size.width = 7;
+ sprite_size.height = 7;
+ sprite_size.offset_x = 0;
+ sprite_size.offset_y = 0;
+}
+
+void Health::move(float unused, float unused1, int * unused2, bool * unused3)
+{
+
+}
+
+void Health::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());
+}
+
+int * Health::get_frame()
+{
+ return (int *) health_sprite;
+}
+
+void Health::take_damage(int damage)
+{
+ hp -= damage;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Collectibles/Health/Health.h Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,31 @@
+#ifndef HEALTH_H
+#define HEALTH_H
+#include "Entity.h"
+
+class Health : public Entity
+{
+public:
+ // Constructor
+ Health(float, float);
+
+ // Functions
+ virtual void move(float, float, int * map, bool * doorways);
+ virtual void draw(N5110 &unused);
+ virtual void take_damage(int);
+
+private:
+ // Private Functions
+ int * get_frame();
+};
+
+const int health_sprite[7][7] = {
+ {0,1,1,0,1,1,0},
+ {1,1,1,1,1,1,1},
+ {1,0,1,1,1,1,1},
+ {1,0,1,1,1,1,1},
+ {0,1,0,1,1,1,0},
+ {0,0,1,1,1,0,0},
+ {0,0,0,1,0,0,0}
+};
+
+#endif
\ No newline at end of file
--- a/Entity/Entity.h Sun May 05 18:37:23 2019 +0000
+++ b/Entity/Entity.h Mon May 06 08:56:48 2019 +0000
@@ -2,6 +2,7 @@
#define ENTITY_H
#include "sprites.h"
#include "math.h"
+#include "N5110.h"
class Entity
{
@@ -45,8 +46,8 @@
public:
// Function
virtual void move(float, float, int * map, bool * doorways) = 0; // movement control and miscellaneous updates
- virtual int * get_frame() = 0;
virtual void take_damage(int) = 0;
+ virtual void draw(N5110 &lcd) = 0;
void undo_move_x(bool);
void undo_move_y(bool);
void update_prev_pos();
--- a/Entity/Headless/Headless.cpp Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-#include "Headless.h"
-#include "math.h"
-#include <complex>
-
-Headless::Headless(float pos_x, float pos_y)
-{
- _damage_self_upon_collision = false;
- _hp_drop_chance = 10; // out of 100
- moving = true;
- face = 0;
- hp = 4;
- attack = 1;
- 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 = 4;
- velocity = 0.25;
-}
-
-void Headless::move(float player_x, float player_y, int * map, bool * doorways)
-{
- std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector
- 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;
- } else 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 = 0;
- } else if (pos_diff.real() / std::abs(pos_diff) > 0 && abs(pos_diff.real() / std::abs(pos_diff)) > abs(pos_diff.imag() / std::abs(pos_diff))) {
- face = 1;
- } else if (pos_diff.real() / std::abs(pos_diff) < 0 && abs(pos_diff.real() / std::abs(pos_diff)) > abs(pos_diff.imag() / std::abs(pos_diff))) {
- face = 3;
- }
-
- undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
- undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
-
- if (frame.number < frame.max) {
- frame.count++;
- } else {
- frame.count = 0;
- }
- frame.number = (frame.count/16) % frame.max;
-}
-
-void Headless::take_damage(int damage)
-{
- hp -= damage;
-}
-
-int * Headless::get_frame()
-{
- return (int *) sprite_headless[face][frame.number];
-}
\ No newline at end of file
--- a/Entity/Headless/Headless.h Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,210 +0,0 @@
-#ifndef HEADLESS_H
-#define HEADLESS_H
-#include "Entity.h"
-
-class Headless : public Entity
-{
-
-public:
- // Constructor
- Headless(float, float);
-
- // Functions
- virtual void move(float player_x, float player_y, int * map, bool * doorways);
- virtual int * get_frame();
- virtual void take_damage(int damage);
-
-};
-
-const int sprite_headless[4][4][9][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,}
- }
- },
- {
- // Right
- {
- {0,0,0,0,0,0,},
- {0,0,1,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,1,1,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,0,0,0,},
- {0,0,1,0,0,0,},
- {0,0,1,1,0,0,}
- },
- {
- {0,1,0,0,0,0,},
- {0,0,0,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,1,1,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,0,1,0,},
- {0,0,1,0,1,0,},
- {0,1,0,0,0,1,}
- },
- {
- {0,0,0,0,1,0,},
- {0,0,0,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,1,1,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,0,0,0,},
- {0,0,1,0,0,0,},
- {0,0,1,1,0,0,}
- },
- {
- {0,0,0,0,0,0,},
- {0,0,0,0,0,1,},
- {0,0,1,1,0,0,},
- {0,0,1,1,1,1,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,0,1,0,1,0,},
- {0,0,1,0,1,0,},
- {0,1,0,0,0,1,}
- }
- },
- {
- // Down
- {
- {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,}
- }
- },
- {
- // 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,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,}
- }
- }
-};
-
-#endif
\ No newline at end of file
--- a/Entity/Health/Health.cpp Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,34 +0,0 @@
-#include "Health.h"
-
-Health::Health(float pos_x, float pos_y)
-{
- _damage_self_upon_collision = true;
- _hp_drop_chance = 0; // out of 10
- moving = true;
- face = 0;
- hp = 1;
- attack = -1;
- hitbox.width = 7;
- hitbox.height = 7;
- position.x = pos_x;
- position.y = pos_y;
- sprite_size.width = 7;
- sprite_size.height = 7;
- sprite_size.offset_x = 0;
- sprite_size.offset_y = 0;
-}
-
-void Health::move(float unused, float unused1, int * unused2, bool * unused3)
-{
-
-}
-
-int * Health::get_frame()
-{
- return (int *) health_sprite;
-}
-
-void Health::take_damage(int damage)
-{
- hp -= damage;
-}
\ No newline at end of file
--- a/Entity/Health/Health.h Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-#ifndef HEALTH_H
-#define HEALTH_H
-#include "Entity.h"
-
-class Health : public Entity
-{
-public:
- // Constructor
- Health(float, float);
-
- // Functions
- virtual void move(float, float, int * map, bool * doorways);
- virtual int * get_frame();
- virtual void take_damage(int);
-
-private:
-};
-
-const int health_sprite[7][7] = {
- {0,1,1,0,1,1,0},
- {1,1,1,1,1,1,1},
- {1,0,1,1,1,1,1},
- {1,0,1,1,1,1,1},
- {0,1,0,1,1,1,0},
- {0,0,1,1,1,0,0},
- {0,0,0,1,0,0,0}
-};
-
-#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Mobs/Headless/Headless.cpp Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,71 @@
+#include "Headless.h"
+#include "math.h"
+#include <complex>
+
+Headless::Headless(float pos_x, float pos_y)
+{
+ _damage_self_upon_collision = false;
+ _hp_drop_chance = 10; // out of 100
+ moving = true;
+ face = 0;
+ hp = 4;
+ attack = 1;
+ 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 = 4;
+ velocity = 0.25;
+}
+
+void Headless::move(float player_x, float player_y, int * map, bool * doorways)
+{
+ std::complex<double> pos_diff(player_x - position.x, player_y - position.y); // defining difference in position as a vector
+ 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;
+ } else 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 = 0;
+ } else if (pos_diff.real() / std::abs(pos_diff) > 0 && abs(pos_diff.real() / std::abs(pos_diff)) > abs(pos_diff.imag() / std::abs(pos_diff))) {
+ face = 1;
+ } else if (pos_diff.real() / std::abs(pos_diff) < 0 && abs(pos_diff.real() / std::abs(pos_diff)) > abs(pos_diff.imag() / std::abs(pos_diff))) {
+ face = 3;
+ }
+
+ undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
+ undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
+
+ if (frame.number < frame.max) {
+ frame.count++;
+ } else {
+ frame.count = 0;
+ }
+ frame.number = (frame.count/16) % frame.max;
+}
+
+void Headless::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());
+}
+
+void Headless::take_damage(int damage)
+{
+ hp -= damage;
+}
+
+int * Headless::get_frame()
+{
+ return (int *) sprite_headless[face][frame.number];
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Mobs/Headless/Headless.h Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,213 @@
+#ifndef HEADLESS_H
+#define HEADLESS_H
+#include "Entity.h"
+
+class Headless : public Entity
+{
+
+public:
+ // Constructor
+ Headless(float, float);
+
+ // Functions
+ virtual void move(float player_x, float player_y, int * map, bool * doorways);
+ virtual void draw(N5110 &lcd);
+ virtual void take_damage(int damage);
+
+private:
+ // Private Functions
+ int * get_frame();
+};
+
+const int sprite_headless[4][4][9][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,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 1970 +0000
+++ b/Entity/Mobs/Snake/Snake.cpp Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,132 @@
+#include "Snake.h"
+#include "math.h"
+#include <complex>
+
+// Constructor
+Snake::Snake(float pos_x, float pos_y)
+{
+ _damage_self_upon_collision = false;
+ _hp_drop_chance = 10; // out of 100
+ moving = true;
+ _prev_face = 0;
+ face = 0;
+ hp = 4;
+ attack = 1;
+ hitbox.width = 4;
+ hitbox.height = 7;
+ position.x = pos_x;
+ position.y = pos_y;
+ sprite_size.width = 6;
+ sprite_size.height = 12;
+ sprite_size.offset_x = 1;
+ sprite_size.offset_y = 6;
+ frame.count = 0;
+ frame.number = 0;
+ frame.max = 6;
+ velocity = 0;
+ _velocity_index = 0;
+}
+// Member Function
+void Snake::update_prev_face()
+{
+ _prev_face = face;
+}
+
+// Member Mutator
+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;
+ hitbox.width = sprite_size.offset_y;
+ hitbox.height = hitbox_height;
+ sprite_size.width = sprite_size_width;
+ sprite_size.height = sprite_size_height;
+ sprite_size.offset_x = sprite_size_offset_x;
+ sprite_size.offset_y = sprite_size_offset_y;
+ frame.max = max_frame;
+ }
+}
+
+// Functions
+void Snake::move(float player_x, float player_y, int * 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
+ update_prev_face();
+
+ // Setting Face
+ if (_velocity_index == 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
+ if (face == 0) {
+ position.y += velocity;
+ update_hitbox(4, 7, 6, 12, 1, 6, 6);
+ } else if (face == 1) {
+ position.x += velocity;
+ update_hitbox(7, 4, 12, 7, 6, 4, 4);
+ } else if (face == 2) {
+ position.y -= velocity;
+ 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);
+ }
+
+ undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
+ undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
+
+ frame.count++;
+ if (frame.count >= 10) {
+ frame.count = 0;
+ _velocity_index++;
+ frame.number++;
+ if (_velocity_index >= 6) {
+ _velocity_index = 0;
+ }
+ if (frame.number >= frame.max) {
+ frame.number = 0;
+ }
+ }
+}
+
+void Snake::take_damage(int damage)
+{
+ hp -= damage;
+}
+
+int * Snake::get_frame()
+{
+ if(face == 0) {
+ return (int *) sprite_snake_y[1][frame.number];
+ } else if(face == 1) {
+ return (int *) sprite_snake_x[0][frame.number];
+ } else if(face == 2) {
+ return (int *) sprite_snake_y[0][frame.number];
+ } else if(face == 3) {
+ return (int *) sprite_snake_x[1][frame.number];
+ }
+ return 0;
+}
+
+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());
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Mobs/Snake/Snake.h Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,291 @@
+#ifndef SNAKE_H
+#define SNAKE_H
+#include "Entity.h"
+
+class Snake : public Entity
+{
+
+public:
+ // Constructor
+ Snake(float, float);
+
+ // Functions
+ virtual void move(float, float, int * map, bool * doorways);
+ virtual void take_damage(int);
+ virtual void draw(N5110 &lcd);
+
+private:
+ // Member Function
+ void update_prev_face();
+ int * get_frame();
+
+ // Member Mutator
+ void update_hitbox(int, int, int, int, int, int, int);
+
+ // Member Variable
+ int _velocity_index;
+ int _prev_face;
+
+};
+
+const float velocity_pattern[6] = {0, 0.15, 0.25, 0.35, 0.25, -0.1};
+
+const int sprite_snake_x[2][4][7][12] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
+ {
+ // Right
+ {
+ {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,},
+ {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,1,1,1,1,0,1,1,1,1,1,0,},
+ {1,0,0,1,1,1,1,1,1,1,0,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,},
+ {1,0,0,0,0,0,0,0,1,1,1,0,},
+ {0,1,0,0,1,1,1,1,1,1,1,0,},
+ {0,0,1,1,1,0,1,1,1,1,0,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,},
+ {1,1,0,1,1,1,1,1,1,1,1,0,},
+ {0,0,1,1,0,1,1,1,1,1,0,0,},
+ }
+ },
+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,0,0,},
+ {0,0,0,0,1,0,},
+ {0,0,0,1,1,0,},
+ {0,0,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,0,0,1,0,0,},
+ {0,0,0,0,1,0,},
+ {0,0,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,},
+ }
+ }
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Player/Bullets/Bullets.cpp Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,61 @@
+#include "Bullets.h"
+
+Bullets::Bullets(float pos_x, float pos_y, int dir)
+{
+ _damage_self_upon_collision = false;
+ moving = true;
+ face = 0;
+ hp = 1;
+ hitbox.width = 3;
+ hitbox.height = 3;
+ position.x = pos_x;
+ position.y = pos_y;
+ sprite_size.width = 3;
+ sprite_size.height = 3;
+ sprite_size.offset_x = 0;
+ sprite_size.offset_y = 1;
+ direction = dir;
+}
+
+void Bullets::move(float speed, float unused, int * unused2, bool * unused3)
+{
+ if (direction == 0) {
+ position.y -= speed;
+ } else if (direction == 1) {
+ position.x += speed;
+ } else if (direction == 2) {
+ position.y += speed;
+ } else if (direction == 3) {
+ position.x -= speed;
+ }
+}
+
+void Bullets::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());
+}
+
+void Bullets::take_damage(int damage)
+{
+ hp -= damage;
+}
+
+bool Bullets::out_of_bounds_check(int * map, bool * doorways)
+{
+ if (entity_to_map_collision_test(position.x, position.y, map, doorways)) {
+ return true;
+ }
+ if ((0 > position.x) || (position.x > 84) || (0 > position.y) || (position.y > 48)) {
+ return true;
+ }
+ return false;
+}
+
+int * Bullets::get_frame()
+{
+ return (int *) bullets_sprite;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Entity/Player/Bullets/Bullets.h Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,30 @@
+#ifndef BULLETS_H
+#define BULLETS_H
+#include "Entity.h"
+
+class Bullets : public Entity
+{
+
+public:
+ // Constructor
+ Bullets(float, float, int);
+
+ // Functions
+ virtual void move(float, float, int * map, bool * doorways);
+ virtual void draw(N5110 &lcd);
+ virtual void take_damage(int damage);
+ bool out_of_bounds_check(int * map, bool * doorways);
+
+private:
+ // Private Functions
+ int * get_frame();
+ // Member Variable
+ int direction;
+};
+
+const int bullets_sprite[3][3] = {{1,1,1},
+ {1,1,1},
+ {1,1,1}
+};
+
+#endif
\ No newline at end of file
--- a/Entity/Player/Player.cpp Sun May 05 18:37:23 2019 +0000
+++ b/Entity/Player/Player.cpp Mon May 06 08:56:48 2019 +0000
@@ -154,11 +154,7 @@
{
for (int i = 0; i < bullets_max; i++) {
if (valid_bullets[i]) {
- lcd.drawSpriteTransparent(bullets_array[i]->get_pos_x()-bullets_array[i]->get_offset_x(),
- bullets_array[i]->get_pos_y()-bullets_array[i]->get_offset_y(),
- bullets_array[i]->get_sprite_height(),
- bullets_array[i]->get_sprite_width(),
- bullets_array[i]->get_frame());
+ bullets_array[i]->draw(lcd);
}
}
}
--- a/Entity/Player/Player.h Sun May 05 18:37:23 2019 +0000
+++ b/Entity/Player/Player.h Mon May 06 08:56:48 2019 +0000
@@ -2,7 +2,6 @@
#define PLAYER_H
#include "Entity.h"
#include "Bullets.h"
-#include "N5110.h"
const int bullets_max = 20;
@@ -18,9 +17,12 @@
int invulnerability_counter;
// Private Functions
+ void move_player(float mapped_x, float mapped_y, int * map, bool * doorways);
void move_bullets();
- void move_player(float mapped_x, float mapped_y, int * map, bool * doorways);
void increment_frames(float mapped_x, float mapped_y);
+ int * get_frame();
+ void draw_player(N5110 &lcd);
+ void draw_bullets(N5110 &lcd);
public:
// Constructors
@@ -30,7 +32,6 @@
// Accessors
int get_bullet_speed();
-
int get_hearts_width();
int get_hearts_height();
int * get_hearts_sprite();
@@ -38,11 +39,8 @@
// Functions
virtual void move(float, float, int * map, bool * doorways);
virtual void take_damage(int damage);
- virtual int * get_frame();
+ virtual void draw(N5110 &lcd);
bool update_bullets(int * map, bool * doorways);
- void draw(N5110 &lcd);
- void draw_player(N5110 &lcd);
- void draw_bullets(N5110 &lcd);
void delete_bullets();
void buttons(bool button_A, bool button_B, bool button_Y, bool button_X);
--- a/Entity/Snake/Snake.cpp Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,123 +0,0 @@
-#include "Snake.h"
-#include "math.h"
-#include <complex>
-
-// Constructor
-Snake::Snake(float pos_x, float pos_y)
-{
- _damage_self_upon_collision = false;
- _hp_drop_chance = 10; // out of 100
- moving = true;
- _prev_face = 0;
- face = 0;
- hp = 4;
- attack = 1;
- hitbox.width = 4;
- hitbox.height = 7;
- position.x = pos_x;
- position.y = pos_y;
- sprite_size.width = 6;
- sprite_size.height = 12;
- sprite_size.offset_x = 1;
- sprite_size.offset_y = 6;
- frame.count = 0;
- frame.number = 0;
- frame.max = 6;
- velocity = 0;
- _velocity_index = 0;
-}
-// Member Function
-void Snake::update_prev_face()
-{
- _prev_face = face;
-}
-
-// Member Mutator
-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;
- hitbox.width = sprite_size.offset_y;
- hitbox.height = hitbox_height;
- sprite_size.width = sprite_size_width;
- sprite_size.height = sprite_size_height;
- sprite_size.offset_x = sprite_size_offset_x;
- sprite_size.offset_y = sprite_size_offset_y;
- frame.max = max_frame;
- }
-}
-
-// Functions
-void Snake::move(float player_x, float player_y, int * 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
- update_prev_face();
-
- // Setting Face
- if (_velocity_index == 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
- if (face == 0) {
- position.y += velocity;
- update_hitbox(4, 7, 6, 12, 1, 6, 6);
- } else if (face == 1) {
- position.x += velocity;
- update_hitbox(7, 4, 12, 7, 6, 4, 4);
- } else if (face == 2) {
- position.y -= velocity;
- 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);
- }
-
- undo_move_x(entity_to_map_collision_test(position.x, prev_pos.y, map, doorways));
- undo_move_y(entity_to_map_collision_test(prev_pos.x, position.y, map, doorways));
-
- frame.count++;
- if (frame.count >= 10) {
- frame.count = 0;
- _velocity_index++;
- frame.number++;
- if (_velocity_index >= 6) {
- _velocity_index = 0;
- }
- if (frame.number >= frame.max) {
- frame.number = 0;
- }
- }
-}
-
-void Snake::take_damage(int damage)
-{
- hp -= damage;
-}
-
-int * Snake::get_frame()
-{
- if(face == 0) {
- return (int *) sprite_snake_y[1][frame.number];
- } else if(face == 1) {
- return (int *) sprite_snake_x[0][frame.number];
- } else if(face == 2) {
- return (int *) sprite_snake_y[0][frame.number];
- } else if(face == 3) {
- return (int *) sprite_snake_x[1][frame.number];
- }
- return 0;
-}
\ No newline at end of file
--- a/Entity/Snake/Snake.h Sun May 05 18:37:23 2019 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,290 +0,0 @@
-#ifndef SNAKE_H
-#define SNAKE_H
-#include "Entity.h"
-
-class Snake : public Entity
-{
-
-public:
- // Constructor
- Snake(float, float);
-
- // Functions
- virtual void move(float, float, int * map, bool * doorways);
- virtual int * get_frame();
- virtual void take_damage(int);
-
-private:
- // Member Function
- void update_prev_face();
-
- // Member Mutator
- void update_hitbox(int, int, int, int, int, int, int);
-
- // Member Variable
- int _velocity_index;
- int _prev_face;
-
-};
-
-const float velocity_pattern[6] = {0, 0.15, 0.25, 0.35, 0.25, -0.1};
-
-const int sprite_snake_x[2][4][7][12] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
- {
- // Right
- {
- {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,},
- {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,1,1,1,1,0,1,1,1,1,1,0,},
- {1,0,0,1,1,1,1,1,1,1,0,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,},
- {1,0,0,0,0,0,0,0,1,1,1,0,},
- {0,1,0,0,1,1,1,1,1,1,1,0,},
- {0,0,1,1,1,0,1,1,1,1,0,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,},
- {1,1,0,1,1,1,1,1,1,1,1,0,},
- {0,0,1,1,0,1,1,1,1,1,0,0,},
- }
- },
- {
- // Left
- {
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {1,2,1,1,1,0,0,0,0,0,0,0,},
- {1,1,1,1,1,0,0,0,0,0,0,0,},
- {0,0,1,1,1,0,0,0,0,0,0,0,},
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {0,1,1,1,1,0,1,1,1,1,0,0,},
- {0,0,1,1,1,1,1,1,0,1,1,1,},
- },
- {
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {1,2,1,1,1,0,0,0,0,0,0,0,},
- {1,1,1,1,1,0,0,0,0,0,0,0,},
- {0,0,1,1,1,0,0,0,0,0,0,0,},
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {0,1,1,1,1,1,0,1,1,1,1,0,},
- {0,0,1,1,1,1,1,1,1,0,0,1,},
- },
- {
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {1,2,1,1,1,0,0,0,0,0,0,0,},
- {1,1,1,1,1,0,0,0,0,0,0,0,},
- {0,0,1,1,1,0,0,0,0,0,0,0,},
- {0,1,1,1,0,0,0,0,0,0,0,1,},
- {0,1,1,1,1,1,1,1,0,0,1,0,},
- {0,0,1,1,1,1,0,1,1,1,0,0,},
- },
- {
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {1,2,1,1,1,0,0,0,0,0,0,0,},
- {1,1,1,1,1,0,0,0,0,0,0,0,},
- {0,0,1,1,1,0,0,0,0,0,0,0,},
- {0,1,1,1,0,0,0,0,0,0,0,0,},
- {0,1,1,1,1,1,1,1,1,0,1,1,},
- {0,0,1,1,1,1,1,0,1,1,0,0,},
- }
- }
-};
-
-const int sprite_snake_y[2][6][12][6] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X]
- {
- // Up
- {
- {0,1,1,1,1,0,},
- {1,1,1,1,1,1,},
- {1,1,1,1,1,1,},
- {0,1,1,1,1,0,},
- {0,0,1,1,0,0,},
- {0,1,1,1,0,0,},
- {0,1,1,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,0,0,0,0,},
- },
- {
- {0,1,1,1,1,0,},
- {1,1,1,1,1,1,},
- {1,1,1,1,1,1,},
- {0,1,1,1,1,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,0,0,},
- {0,1,1,0,0,0,},
- {0,1,1,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,0,1,1,0,},
- {0,0,0,0,1,0,},
- {0,0,1,1,0,0,},
- },
- {
- {0,1,1,1,1,0,},
- {1,1,1,1,1,1,},
- {1,1,1,1,1,1,},
- {0,1,1,1,1,0,},
- {0,0,1,1,0,0,},
- {0,0,0,1,1,0,},
- {0,0,1,1,0,0,},
- {0,1,1,0,0,0,},
- {0,1,1,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,0,0,1,0,},
- {0,0,0,1,0,0,},
- },
- {
- {0,1,1,1,1,0,},
- {1,1,1,1,1,1,},
- {1,1,1,1,1,1,},
- {0,1,1,1,1,0,},
- {0,0,1,1,0,0,},
- {0,0,1,1,1,0,},
- {0,0,0,1,1,0,},
- {0,0,1,1,0,0,},
- {0,1,1,0,0,0,},
- {0,1,1,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,0,0,1,0,},
- },
- {
- {0,1,1,1,1,0,},
- {1,1,1,1,1,1,},
- {1,1,1,1,1,1,},
- {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,0,1,1,0,},
- {0,0,1,1,0,0,},
- {0,1,1,0,0,0,},
- {0,1,0,0,0,0,},
- {0,0,1,1,0,0,},
- },
- {
- {0,1,1,1,1,0,},
- {1,1,1,1,1,1,},
- {1,1,1,1,1,1,},
- {0,1,1,1,1,0,},
- {0,0,1,1,0,0,},
- {0,1,1,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,0,0,0,0,},
- {0,0,1,0,0,0,},
- }
- },
- {
- // Down
- {
- {0,0,0,0,1,0,},
- {0,0,1,1,0,0,},
- {0,1,1,0,0,0,},
- {0,1,1,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,0,1,1,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,1,1,0,0,},
- {0,1,0,0,0,0,},
- {0,1,1,0,0,0,},
- {0,0,1,1,0,0,},
- {0,0,0,1,1,0,},
- {0,0,0,1,1,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,1,0,0,0,},
- {0,1,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,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,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,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,1,1,0,0,},
- {0,0,0,0,1,0,},
- {0,0,0,1,1,0,},
- {0,0,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,0,0,1,0,0,},
- {0,0,0,0,1,0,},
- {0,0,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,},
- }
- }
-};
-
-#endif
\ No newline at end of file
--- a/RoomEngine/Room/Room.cpp Sun May 05 18:37:23 2019 +0000
+++ b/RoomEngine/Room/Room.cpp Mon May 06 08:56:48 2019 +0000
@@ -109,4 +109,13 @@
if(_doorways[3]) { // W
lcd.drawSpriteTransparent(0, 15, 3, 11, (int *)wall_x[1]);
}
+}
+
+void Room::draw_enemies(N5110 &lcd)
+{
+ for (int i = 0; i < MAX_ENEMIES; i++) {
+ if (valid_enemies[i]) {
+ enemies[i]->draw(lcd);
+ }
+ }
}
\ No newline at end of file
--- a/RoomEngine/Room/Room.h Sun May 05 18:37:23 2019 +0000
+++ b/RoomEngine/Room/Room.h Mon May 06 08:56:48 2019 +0000
@@ -37,6 +37,7 @@
void unload();
void draw_room(N5110 &lcd);
void draw_room_overlay(N5110 &lcd);
+ void draw_enemies(N5110 &lcd);
// Variables
Entity *enemies[MAX_ENEMIES];
--- a/RoomEngine/RoomEngine.cpp Sun May 05 18:37:23 2019 +0000
+++ b/RoomEngine/RoomEngine.cpp Mon May 06 08:56:48 2019 +0000
@@ -1,5 +1,5 @@
#include "RoomEngine.h"
-
+// Constructor
RoomEngine::RoomEngine(float global_contrast)
{
_room_x = 5;
@@ -7,11 +7,13 @@
_global_contrast = global_contrast;
}
+// Destructor
RoomEngine::~RoomEngine()
{
delete player;
}
+// Public Functions
void RoomEngine::load(Player *current_player, Room *current_room)
{
player = current_player;
@@ -417,26 +419,13 @@
room->draw_room(lcd);
//lcd.drawSprite(0,0,screen_height,screen_width,(int *)level_map[1]);
player->draw(lcd);
- draw_enemies(lcd);
+ room->draw_enemies(lcd);
room->draw_room_overlay(lcd);
if (_L) {
draw_health(lcd);
}
}
-void RoomEngine::draw_enemies(N5110 &lcd)
-{
- for (int i = 0; i < MAX_ENEMIES; i++) {
- if (room->valid_enemies[i]) {
- lcd.drawSpriteTransparent(room->enemies[i]->get_pos_x()-room->enemies[i]->get_offset_x(),
- room->enemies[i]->get_pos_y()-room->enemies[i]->get_offset_y(),
- room->enemies[i]->get_sprite_height(),
- room->enemies[i]->get_sprite_width(),
- room->enemies[i]->get_frame());
- }
- }
-}
-
void RoomEngine::draw_health(N5110 &lcd)
{
for (int i = 0; i < player->get_hp(); i++){
--- a/RoomEngine/RoomEngine.h Sun May 05 18:37:23 2019 +0000
+++ b/RoomEngine/RoomEngine.h Mon May 06 08:56:48 2019 +0000
@@ -13,8 +13,12 @@
class RoomEngine
{
public:
+ // Constructor
RoomEngine(float global_contrast);
+ // Destructor
~RoomEngine();
+
+ // Functions
void load(Player *current_player, Room *current_room);
void entrance_scene(N5110 &lcd, Gamepad &gamepad);
void exit_scene(N5110 &lcd, Gamepad &gamepad);
@@ -23,6 +27,7 @@
void read_input(Gamepad &gamepad);
void update();
void render(N5110 &lcd, Gamepad &gamepad);
+
bool check_player_death();
int check_player_room_position();
@@ -71,7 +76,6 @@
void pause_detection(N5110 &lcd, Gamepad &gamepad);
void draw(N5110 &lcd);
- void draw_enemies(N5110 &lcd);
void draw_health(N5110 &lcd);
};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Title/Title.cpp Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,116 @@
+#include "Title.h"
+
+Title::Title()
+{
+ title_count = 0;
+ cursor_timer = 20;
+ title_option = 0;
+}
+
+int Title::get_seed()
+{
+ return title_count;
+}
+
+void Title::main(N5110 &lcd, Gamepad &gamepad, float &global_contrast)
+{
+ Player player(5, 36);
+ while(1){ // Title Screen Loop
+ title_option = 0;
+ while(!gamepad.check_event(Gamepad::A_PRESSED)){
+ lcd.clear();
+ draw_title_screen(lcd);
+ lcd.refresh();
+
+ title_options_joystick(gamepad);
+
+ title_count++;
+ wait_ms(1000/40); // 1s/framerate
+ }
+ while(gamepad.check_event(Gamepad::A_PRESSED)){}
+ if(title_option == 0) {
+ break;
+ } else if (title_option == 1) {
+ title_option_option(lcd, gamepad, player, global_contrast);
+ } else if (title_option == 2) {
+ title_option_credit(lcd, gamepad);
+ } else if (title_option == 3) {
+ title_option_hi_scores(lcd);
+ }
+ }
+}
+
+void Title::draw_title_screen(N5110 &lcd)
+{
+ lcd.drawSprite(11, 4, 15, 44, (int *)title_name_0);
+ lcd.drawSpriteTransparent(19, 14, 17, 53, (int *)title_name_1);
+ lcd.drawCircle(79, 7, 10, FILL_BLACK);
+ lcd.drawCircle(81, 5, 8, FILL_WHITE);
+ lcd.drawSprite(56, 6, 11, 5, (int *)star_sprite[abs(((title_count/20) % 7) - 3)]);
+ lcd.drawSprite(12, 34, 8, 8, (int *)button_A_sprite);
+ lcd.drawSprite(22, 37, 3, 2, (int *)arrow_left_sprite);
+ lcd.drawSprite(59, 37, 3, 2, (int *)arrow_right_sprite);
+ lcd.drawSprite(69, 31, 12, 6, (int *)sprite_player[(title_count/40) % 4][(title_count/10) % 4]);
+ lcd.drawSprite(26, 35, 9, 32, (int *)title_options_sprite[title_option]);
+}
+
+void Title::title_options_joystick(Gamepad &gamepad)
+{
+ if ((gamepad.get_direction() == 3) && (cursor_timer > 20)) { // Detect Joystick going right
+ cursor_timer = 0;
+ if (title_option >= 3) {
+ title_option = 0;
+ } else {
+ title_option++;
+ }
+ } else if ((gamepad.get_direction() == 7) && (cursor_timer > 20)) { // Detect Joystick going left
+ cursor_timer = 0;
+ if (title_option <= 0) {
+ title_option = 3;
+ } else {
+ title_option--;
+ }
+ }
+ cursor_timer++;
+}
+
+void Title::title_option_option(N5110 &lcd, Gamepad &gamepad, Player &player, float &global_contrast)
+{
+ while(!gamepad.check_event(Gamepad::A_PRESSED)) {
+ global_contrast = gamepad.read_pot();
+ lcd.setContrast(global_contrast);
+ lcd.clear();
+ lcd.printString("Set contrast", 0, 0);
+ lcd.printString("using the", 0, 1);
+ lcd.printString("potentiometer", 0, 2);
+ player.draw(lcd);
+ lcd.refresh();
+ player.move(1, 0, (int *)level_map[0][0], (bool *)sprite_transparent_player);
+ player.buttons(false, true, false, false);
+ player.update_bullets((int *)level_map[0][0], (bool *)sprite_transparent_player);
+ wait_ms(1000/40);
+ }
+ wait(0.05);
+ while(gamepad.check_event(Gamepad::A_PRESSED)) {
+ }
+}
+
+void Title::title_option_credit(N5110 &lcd, Gamepad &gamepad)
+{
+ lcd.clear();
+ lcd.printString("Made by:", 0, 0);
+ lcd.printString("Steven Mahasin", 0, 1);
+ lcd.printString("201192939", 0, 2);
+ lcd.refresh();
+ wait(0.05);
+ while(!gamepad.check_event(Gamepad::A_PRESSED)) {
+ }
+ wait(0.05);
+ while(gamepad.check_event(Gamepad::A_PRESSED)) {
+ }
+}
+
+void Title::title_option_hi_scores(N5110 &lcd)
+{
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Title/Title.h Mon May 06 08:56:48 2019 +0000
@@ -0,0 +1,35 @@
+#ifndef TITLE_H
+#define TITLE_H
+
+#include "Player.h"
+#include "N5110.h"
+#include "Gamepad.h"
+
+class Title
+{
+private:
+ // Member Variables
+ int title_count;
+ int cursor_timer;
+ int title_option;
+
+ // Functions
+ void draw_title_screen(N5110 &lcd);
+ void title_options_joystick(Gamepad &gamepad);
+
+ void title_option_option(N5110 &lcd, Gamepad &gamepad, Player &player, float &global_contrast);
+ void title_option_credit(N5110 &lcd, Gamepad &gamepad);
+ void title_option_hi_scores(N5110 &lcd);
+
+public:
+ // Constructor
+ Title();
+
+ // Accessor
+ int get_seed();
+
+ // Functions
+ void main(N5110 &lcd, Gamepad &gamepad, float &global_contrast);
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp Sun May 05 18:37:23 2019 +0000
+++ b/main.cpp Mon May 06 08:56:48 2019 +0000
@@ -19,37 +19,27 @@
#include "Headless.h"
#include "Snake.h"
#include "RoomEngine.h"
-#include <time.h>
+#include "Title.h"
#define INSIDE 4
#define MAX_ROOMS_MAP_X 11
#define MAX_ROOMS_MAP_Y 11
// Variables
-int title_count = 0;
-int cursor_timer = 20;
-int title_option = 0;
float global_contrast = 0.5;
+Player *player;
+Room *rooms[MAX_ROOMS_MAP_Y][MAX_ROOMS_MAP_X];
+RoomEngine *room_engine;
// Objects
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad gamepad;
+Title title;
// Prototypes
-void title_screen();
-void draw_title_screen(N5110 &lcd);
-void title_options_joystick(Gamepad &gamepad);
-
-void title_option_option();
-void title_option_credit();
-void title_option_hi_scores();
void game_loop();
void game_over();
-Player *player;
-Room *rooms[MAX_ROOMS_MAP_Y][MAX_ROOMS_MAP_X];
-RoomEngine *room_engine;
-// Functions
int main()
{
// Initialize
@@ -59,11 +49,10 @@
while(1) { // Gameloop
- player = new Player(5, 36);
- title_screen();
+ title.main(lcd, gamepad, global_contrast);
delete player;
- srand(title_count);
+ srand(title.get_seed());
player = new Player(39, 27);
room_engine = new RoomEngine(global_contrast);
@@ -74,108 +63,6 @@
}
}
-void draw_title_screen(N5110 &lcd)
-{
- lcd.drawSprite(11, 4, 15, 44, (int *)title_name_0);
- lcd.drawSpriteTransparent(19, 14, 17, 53, (int *)title_name_1);
- lcd.drawCircle(79, 7, 10, FILL_BLACK);
- lcd.drawCircle(81, 5, 8, FILL_WHITE);
- lcd.drawSprite(56, 6, 11, 5, (int *)star_sprite[abs(((title_count/20) % 7) - 3)]);
- lcd.drawSprite(12, 34, 8, 8, (int *)button_A_sprite);
- lcd.drawSprite(22, 37, 3, 2, (int *)arrow_left_sprite);
- lcd.drawSprite(59, 37, 3, 2, (int *)arrow_right_sprite);
- lcd.drawSprite(69, 31, 12, 6, (int *)sprite_player[(title_count/40) % 4][(title_count/10) % 4]);
- lcd.drawSprite(26, 35, 9, 32, (int *)title_options_sprite[title_option]);
-}
-
-void title_options_joystick(Gamepad &gamepad)
-{
- if ((gamepad.get_direction() == 3) && (cursor_timer > 20)) { // Detect Joystick going right
- cursor_timer = 0;
- if (title_option >= 3) {
- title_option = 0;
- } else {
- title_option++;
- }
- } else if ((gamepad.get_direction() == 7) && (cursor_timer > 20)) { // Detect Joystick going left
- cursor_timer = 0;
- if (title_option <= 0) {
- title_option = 3;
- } else {
- title_option--;
- }
- }
- cursor_timer++;
-}
-
-void title_screen()
-{
- while(1){ // Title Screen Loop
- title_option = 0;
- while(!gamepad.check_event(Gamepad::A_PRESSED)){
- lcd.clear();
- draw_title_screen(lcd);
- lcd.refresh();
-
- title_options_joystick(gamepad);
-
- title_count++;
- wait_ms(1000/40); // 1s/framerate
- }
- while(gamepad.check_event(Gamepad::A_PRESSED)){}
- if(title_option == 0) {
- break;
- } else if (title_option == 1) {
- while(!gamepad.check_event(Gamepad::A_PRESSED)) {
- title_option_option();
- }
- wait(0.05);
- while(gamepad.check_event(Gamepad::A_PRESSED)) {
- }
- } else if (title_option == 2) {
- title_option_credit();
- wait(0.05);
- while(!gamepad.check_event(Gamepad::A_PRESSED)) {
- }
- wait(0.05);
- while(gamepad.check_event(Gamepad::A_PRESSED)) {
- }
- } else if (title_option == 3) {
-
- }
- }
-}
-
-void title_option_option()
-{
- global_contrast = gamepad.read_pot();
- lcd.setContrast(global_contrast);
- lcd.clear();
- lcd.printString("Set contrast", 0, 0);
- lcd.printString("using the", 0, 1);
- lcd.printString("potentiometer", 0, 2);
- player->draw(lcd);
- lcd.refresh();
- player->move(1, 0, (int *)level_map[0][0], (bool *)sprite_transparent_player);
- player->buttons(false, true, false, false);
- player->update_bullets((int *)level_map[0][0], (bool *)sprite_transparent_player);
- wait_ms(1000/40);
-}
-
-void title_option_credit()
-{
- lcd.clear();
- lcd.setContrast(global_contrast);
- lcd.printString("Made by:", 0, 0);
- lcd.printString("Steven Mahasin", 0, 1);
- lcd.printString("201192939", 0, 2);
- lcd.refresh();
-}
-void title_option_hi_scores()
-{
-
-}
-
void game_loop()
{
while(1) { // Floor Loop