ECE 2035 final project
Dependencies: mbed wave_player 4DGL-uLCD-SE MMA8452
Revision 2:22d36e7740f1, committed 2019-04-15
- Comitter:
- npatel387
- Date:
- Mon Apr 15 12:25:08 2019 +0000
- Parent:
- 1:399033d39feb
- Commit message:
- final;
Changed in this revision
diff -r 399033d39feb -r 22d36e7740f1 globals.h --- a/globals.h Wed Apr 04 21:11:07 2018 +0000 +++ b/globals.h Mon Apr 15 12:25:08 2019 +0000 @@ -5,6 +5,9 @@ #ifndef GLOBAL_H #define GLOBAL_H +#define NUM_BUCKETS1 40 +#define NUM_BUCKETS2 20 +#define NUM_MAPS 2 // Include all the hardware libraries #include "mbed.h" #include "wave_player.h"
diff -r 399033d39feb -r 22d36e7740f1 graphics.cpp --- a/graphics.cpp Wed Apr 04 21:11:07 2018 +0000 +++ b/graphics.cpp Mon Apr 15 12:25:08 2019 +0000 @@ -1,12 +1,213 @@ #include "graphics.h" - +#include "hardware.h" #include "globals.h" +static int player[121] = {0x00000000, 0xff5a0c45, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xff5a0c45, 0xff5a0c45, 0xff3e2113, 0xff434345, 0xff434345, 0xff434345, 0xff434345, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0xff5a0c45, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff434345, 0xff434345, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0xff3e2113, 0xff3e2113, 0xff277a28, 0xff277a28, 0xff3e2113, 0xff3e2113, 0xff277a28, 0xff277a28, 0xff3e2113, 0xff3e2113, 0x00000000, +0x00ffe0bd, 0x00000000, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0x00000000, 0x00ffe0bd, 0x00000000, +0x00000000, 0x00000000, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000 +}; + +static int player_shield[121] = {0x00000000, 0xff5a0c45, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xff5a0c45, 0xff5a0c45, 0xff3e2113, 0xff434345, 0xff434345, 0xff434345, 0xff434345, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0xff5a0c45, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff434345, 0xff434345, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0x00c66a00, 0x00ff8d09, 0x00c66a00, 0xff277a28, 0xff3e2113, 0xff3e2113, 0xff277a28, 0xff277a28, 0xff3e2113, 0xff3e2113, 0x00000000, +0x00ff8d09, 0x00ff8d09, 0x00ff8d09, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0x00000000, 0xffbde0ff, 0x00000000, +0x00c66a00, 0x00ff8d09, 0x00c66a00, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000}; + +static int player_sword[121] = {0x00000000, 0xff5a0c45, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xff5a0c45, 0xff5a0c45, 0xff3e2113, 0xff434345, 0xff434345, 0xff434345, 0xff434345, 0xff3e2113, 0x00000000, 0x00ffd700, 0x00000000, +0xff5a0c45, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00ffd700, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00ffd700, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00ffd700, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff434345, 0xff434345, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00ffd700, 0x00000000, +0x00c66a00, 0x00ff8d09, 0x00c66a00, 0xff277a28, 0xff3e2113, 0xff3e2113, 0xff277a28, 0xff277a28, 0x00ffd700, 0x00ffd700, 0x00ffd700, +0x00ff8d09, 0x00ff8d09, 0x00ff8d09, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0x00000000, 0x00ffd700, 0x00000000, +0x00c66a00, 0x00ff8d09, 0x00c66a00, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000}; + +static int player_plate[121] = {0x00000000, 0xff5a0c45, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xff5a0c45, 0xff5a0c45, 0xff3e2113, 0xff434345, 0xff434345, 0xff434345, 0xff434345, 0xff3e2113, 0x00000000, 0x00ffd700, 0x00000000, +0xff5a0c45, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00ffd700, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00ffd700, 0x00000000, +0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, 0x00ffd700, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff434345, 0xff434345, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00ffd700, 0x00000000, +0x00c66a00, 0x00ff8d09, 0x00c66a00, 0x000ba1d9, 0xff3e2113, 0xff3e2113, 0x000ba1d9, 0x000ba1d9, 0x00ffd700, 0x00ffd700, 0x00ffd700, +0x00ff8d09, 0x00ff8d09, 0x00ff8d09, 0x000ba1d9, 0x000ba1d9, 0x000ba1d9, 0x000ba1d9, 0x000ba1d9, 0x00000000, 0x00ffd700, 0x00000000, +0x00c66a00, 0x00ff8d09, 0x00c66a00, 0x000ba1d9, 0x000ba1d9, 0x000ba1d9, 0x000ba1d9, 0x000ba1d9, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000}; + +static int player_running[121] = {0x00000000, 0x00000000, 0x00000000, 0xff5a0c45, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff5a0c45, 0xff5a0c45, 0xff3e2113, 0xff434345, 0xff434345, 0xff434345, 0xff434345, 0xff3e2113, 0x00000000, +0x00000000, 0x00000000, 0xff5a0c45, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, +0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, +0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff434345, 0xff000000, 0xff3e2113, +0xffb4b4b4, 0xffb4b4b4, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff434345, 0xff434345, 0xff3e2113, 0xff3e2113, 0x00000000, +0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0xff277a28, 0xff277a28, 0xff3e2113, 0xff3e2113, 0xff277a28, 0xff3e2113, 0xff3e2113, +0xffb4b4b4, 0xffb4b4b4, 0xffbde0ff, 0x00000000, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xffbde0ff, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0xff277a28, 0xff497a4a, 0x00000000, +0xffb4b4b4, 0xffb4b4b4, 0x00000000, 0x00000000, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113, 0x00000000, 0x00000000, 0x00000000, 0xff3e2113, 0xff3e2113}; + +static int walls[121] = {0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, +0xff202020, 0xff6d6d6e, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff202020, +0xff202020, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff6d6d6e, 0xff202020, +0xff202020, 0xff6d6d6e, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff202020, +0xff202020, 0xff6d6d6e, 0xff08320a, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff6d6d6e, 0xff08320a, 0xff202020, +0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, +0xff202020, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff08320a, 0xff474747, 0xff474747, 0xff202020, +0xff202020, 0xff474747, 0xff474747, 0xff474747, 0xff08320a, 0xff474747, 0xff08320a, 0xff474747, 0xff474747, 0xff474747, 0xff202020, +0xff202020, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff08320a, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff202020, +0xff202020, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff474747, 0xff08320a, 0xff474747, 0xff474747, 0xff474747, 0xff202020, +0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020, 0xff202020}; + +static int plant[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff999999, 0xff999999, 0xff747474, 0xff747474, 0xff999999, 0xff999999, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xff999999, 0xff999999, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff999999, 0xff999999, 0x00000000, 0x00000000, +0x00000000, 0xff999999, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff999999, 0x00000000, +0x00000000, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0x00000000}; + +static int startNPC[121] = {0x00000000, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00ff2525, 0x00000000, 0x00000000, 0x00000000, +0x00ff2525, 0x00ff2525, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, +0xffffffff, 0x00000000, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00ffc58f, 0xffddd058, 0xffffffff, 0x00ffc58f, 0xffddd058, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00ffc58f, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xffff8fe1, 0x00ffc58f, 0x00d44b4b, 0x00d44b4b, 0x00ffc58f, 0xffff8fe1, 0x00000000, 0x00000000, 0x00000000, +0xffff8fe1, 0xffff8fe1, 0xffff8fe1, 0xffff8fe1, 0x00ffc58f, 0x00ffc58f, 0xffff8fe1, 0xffff8fe1, 0xffff8fe1, 0xffff8fe1, 0x00000000, +0x00ffc58f, 0x00000000, 0xffff8fe1, 0xffff6dd8, 0xffff8fe1, 0xffff8fe1, 0xffff6dd8, 0xffff8fe1, 0x00000000, 0x00ffc58f, 0x00000000, +0x00000000, 0x00000000, 0xffff8fe1, 0xffff8fe1, 0xffff6dd8, 0xffff6dd8, 0xffff8fe1, 0xffff8fe1, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xffff8fe1, 0xffff8fe1, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffff8fe1, 0xffff8fe1, 0x00000000, 0x00000000}; + +static int cave[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff838383, 0xff838383, 0xff838383, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0xff838383, 0xff252525, 0xff252525, 0xff252525, 0xff838383, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff838383, 0xff838383, 0xff252525, 0xff252525, 0xff252525, 0xff838383, 0xff838383, 0x00000000, 0x00000000, +0x00000000, 0xff838383, 0xff838383, 0xff252525, 0xff252525, 0xff252525, 0xff252525, 0xff252525, 0xff838383, 0xff838383, 0x00000000, +0x00000000, 0xff838383, 0xff323232, 0xff252525, 0xff252525, 0xff252525, 0xff252525, 0xff252525, 0xff323232, 0xff838383, 0x00000000, +0xff838383, 0xff838383, 0xff323232, 0xff323232, 0xff323232, 0xff323232, 0xff323232, 0xff323232, 0xff323232, 0xff838383, 0xff838383, +0xff838383, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff838383, +0xff838383, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff585858, 0xff838383, +0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383, 0xff838383}; + +static int swordInStone[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00ffd700, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00ffd700, 0x00ffd700, 0x00ffd700, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00ffd700, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00ffd700, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0xff999999, 0xff999999, 0x00ffd700, 0xff999999, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff999999, 0xff999999, 0xff747474, 0x00ffd700, 0xff999999, 0xff999999, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xff999999, 0xff999999, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff999999, 0xff999999, 0x00000000, 0x00000000, +0x00000000, 0xff999999, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff747474, 0xff999999, 0x00000000, +0x00000000, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0xff999999, 0x00000000}; + +static int elvarg[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00fff6f6, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00808000, 0x00808000, 0x00000000, 0x00fff6f6, 0x00000000, 0x00000000, 0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, +0x00808000, 0x00d20303, 0x00808000, 0x00fff6f6, 0x00000000, 0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, +0x00808000, 0x00808000, 0x00808000, 0x00000000, 0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, 0x00000000, +0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00000000, 0x00000000, +0x00000000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, 0x00808000, +0x00000000, 0x00000000, 0x00808000, 0x005a5a00, 0x00000000, 0x00000000, 0x005a5a00, 0x00808000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00fff6f6, 0x00808000, 0x005a5a00, 0x00000000, 0x00fff6f6, 0x005a5a00, 0x00808000, 0x00000000, 0x00000000, 0x00000000}; + +static int gate[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, +0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, +0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, +0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, 0x00e5ea00, +0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, 0x00959826, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}; + +static int treasure[121] = {0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, +0x004d3402, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x004d3402, +0x004d3402, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x004d3402, +0x004d3402, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x002d1e01, 0x004d3402, +0x004d3402, 0x00d93b3b, 0x0050c878, 0x00ffd700, 0x00ffd700, 0x00ffd700, 0x00d93b3b, 0x00ffd700, 0x00ffd700, 0x0050c878, 0x004d3402, +0x004d3402, 0x00ffd700, 0x00ffd700, 0x00d93b3b, 0x0050c878, 0x00ffd700, 0x00d93b3b, 0x00ffd700, 0x00d93b3b, 0x00ffd700, 0x004d3402, +0x00d1d50b, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x00d1d50b, +0x00d1d50b, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x00d1d50b, +0x00d1d50b, 0x004d3402, 0x00d1d50b, 0x00d1d50b, 0x00d1d50b, 0x00d1d50b, 0x00d1d50b, 0x00d1d50b, 0x00d1d50b, 0x004d3402, 0x00d1d50b, +0x00d1d50b, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x00d1d50b, +0x00d1d50b, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x004d3402, 0x00d1d50b}; + +static int boulder[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0x00000000, 0x00000000, +0x00000000, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0x00000000, +0x00000000, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0x00000000, +0x00000000, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0x00000000, +0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0x00000000, +0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, +0xff656565, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0xff898989, 0xff898989, +0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff656565, 0xff898989, +0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, +0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff656565, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989, 0xff898989}; + +static int phat[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, +0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, 0xffa3111a, 0x00000000, +0x00000000, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0x00000000, +0x00000000, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0x00000000, +0x00000000, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0x00000000, +0x00000000, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0xffa3111a, 0x00000000}; + +static int rolling[121] = {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xffc5c5c5, 0xffc5c5c5, 0xffc5c5c5, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000}; void draw_player(int u, int v, int key) { - uLCD.filled_rectangle(u, v, u+11, v+11, RED); + if(key == 0) + uLCD.BLIT(u, v, 11, 11, player); + else if(key == 1) + uLCD.BLIT(u, v, 11, 11, player_shield); + else if(key == 2) + uLCD.BLIT(u, v, 11, 11, player_sword); + else if(key == 3) + uLCD.BLIT(u, v, 11, 11, player_plate); + else if(key == 4) + uLCD.BLIT(u, v, 11, 11, player_running); } #define YELLOW 0xFFFF00 @@ -37,30 +238,113 @@ void draw_wall(int u, int v) { - uLCD.filled_rectangle(u, v, u+10, v+10, BROWN); + uLCD.BLIT(u, v, 11, 11, walls); } void draw_plant(int u, int v) { - uLCD.filled_rectangle(u, v, u+10, v+10, GREEN); + uLCD.BLIT(u, v, 11, 11, plant); +} + +void draw_startNPC(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, startNPC); +} + +void draw_cave(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, cave); +} + +void draw_swordInStone(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, swordInStone); +} + +void draw_elvarg(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, elvarg); } -void draw_upper_status() +void draw_gate(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, gate); +} + +void draw_treasure(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, treasure); +} + +void draw_boulder(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, boulder); +} + +void draw_phat(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, phat); +} + +void draw_rolling(int u, int v) +{ + uLCD.BLIT(u, v, 11, 11, rolling); +} + +void draw_upper_status(int x_pos, int y_pos) { // Draw bottom border of status bar uLCD.line(0, 9, 127, 9, GREEN); - // Add other status info drawing code here + uLCD.locate(0,0); + uLCD.printf("X:%-3iY:%-2i", x_pos, y_pos); } -void draw_lower_status() + +void draw_lower_status(int health, int phats) { // Draw top border of status bar uLCD.line(0, 118, 127, 118, GREEN); - // Add other status info drawing code here + uLCD.locate(0,15); + uLCD.printf("HP:%-3iPHats:%-2i/5", health, phats); } +void draw_menu(int omnipotent, int sword, int shield, int platebody, int key) +{ + uLCD.filled_rectangle(0, 10, 127, 117, 0xD3D3D3); + uLCD.textbackground_color(0xD3D3D3); + uLCD.color(0x000000); + uLCD.locate(0,2); + uLCD.printf("Menu: Exit w/ B3\n"); + uLCD.printf("----------------\n"); + uLCD.printf("Omnipotent:%i\n", omnipotent); + if(shield) + uLCD.printf("Goal:Defeat Elvarg"); + else if(platebody) + uLCD.printf("Goal:Return to NPC"); + uLCD.printf("Shield: %i\n", shield); + if(shield == 0) + uLCD.printf(" Talk to NPC\n"); + uLCD.printf("Sword: %i\n", sword); + if(sword == 0) + uLCD.printf(" Find Excalibur\n"); + uLCD.printf("Key: %i\n", key); + if(key == 0) + uLCD.printf(" Defeat Elvarg\n"); + uLCD.printf("Platebody: %i\n", platebody); + if(platebody == 0) + uLCD.printf(" Unlock Treasure\n"); + uLCD.textbackground_color(0x000000); + uLCD.color(GREEN); + GameInputs inputs = read_inputs(); + while(inputs.b3) + { + wait_ms(200); + inputs = read_inputs(); + } +} + void draw_border() { uLCD.filled_rectangle(0, 9, 127, 14, WHITE); // Top @@ -69,4 +353,52 @@ uLCD.filled_rectangle(124, 14, 127, 117, WHITE); // Right } +void draw_bad() +{ + uLCD.filled_rectangle(0, 0, 127, 127, 0xBB0A1E); + uLCD.textbackground_color(0xBB0A1E); + uLCD.color(0xFFFFFF); + uLCD.text_width(2); + uLCD.text_height(2); + uLCD.locate(0,2); + uLCD.printf("YOU DIED!"); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(2,10); + uLCD.printf("Reset Mbed"); +} +void draw_good() +{ + uLCD.filled_rectangle(0, 0, 127, 127, 0x40E0D0); + uLCD.textbackground_color(0x40E0D0); + uLCD.color(0xFFFFFF); + uLCD.text_width(2); + uLCD.text_height(2); + uLCD.locate(0,2); + uLCD.printf("Quest\nCompleted\n!!!!!!!!!!!"); +} + +void draw_start() +{ + uLCD.filled_rectangle(0, 0, 127, 127, 0x808000); + uLCD.textbackground_color(0x808000); + uLCD.color(0xBB0A1E); + uLCD.text_width(3); + uLCD.text_height(3); + uLCD.locate(0,0); + uLCD.printf("Dragon\nSlayer"); + uLCD.text_width(1); + uLCD.text_height(1); + uLCD.locate(1,14); + uLCD.printf("Press any button"); + uLCD.textbackground_color(0x000000); + uLCD.color(GREEN); + GameInputs inputs = read_inputs(); + while(inputs.b1 && inputs.b2 && inputs.b3) + { + wait_ms(200); + inputs = read_inputs(); + } +} +
diff -r 399033d39feb -r 22d36e7740f1 graphics.h --- a/graphics.h Wed Apr 04 21:11:07 2018 +0000 +++ b/graphics.h Mon Apr 15 12:25:08 2019 +0000 @@ -29,17 +29,29 @@ void draw_nothing(int u, int v); void draw_wall(int u, int v); void draw_plant(int u, int v); - +void draw_startNPC(int u, int v); +void draw_cave(int u, int v); +void draw_swordInStone(int u, int v); +void draw_elvarg(int u, int v); +void draw_gate(int u, int v); +void draw_treasure(int u, int v); +void draw_boulder(int u, int v); +void draw_phat(int u, int v); +void draw_rolling(int u, int v); /** * Draw the upper status bar. */ -void draw_upper_status(); +void draw_upper_status(int x_pos, int y_pos); /** * Draw the lower status bar. */ -void draw_lower_status(); +void draw_lower_status(int health, int phats); +void draw_bad(); +void draw_good(); +void draw_start(); +void draw_menu(int omnipotent, int sword, int shield, int platebody, int key); /** * Draw the border for the map. */
diff -r 399033d39feb -r 22d36e7740f1 hardware.cpp --- a/hardware.cpp Wed Apr 04 21:11:07 2018 +0000 +++ b/hardware.cpp Mon Apr 15 12:25:08 2019 +0000 @@ -10,7 +10,7 @@ // Hardware initialization: Instantiate all the things! uLCD_4DGL uLCD(p9,p10,p11); // LCD Screen (tx, rx, reset) -//SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) +SDFileSystem sd(p5, p6, p7, p8, "sd"); // SD Card(mosi, miso, sck, cs) Serial pc(USBTX,USBRX); // USB Console (tx, rx) MMA8452 acc(p28, p27, 100000); // Accelerometer (sda, sdc, rate) DigitalIn button1(p21); // Pushbuttons (pin) @@ -39,5 +39,13 @@ GameInputs read_inputs() { GameInputs in; + in.b1 = button1; + in.b2 = button2; + in.b3 = button3; + if(!acc.isXYZReady()) + { + wait(0.01); + } + acc.readXYZGravity(&in.ax, &in.ay, &in.az); return in; }
diff -r 399033d39feb -r 22d36e7740f1 hash_table.cpp --- a/hash_table.cpp Wed Apr 04 21:11:07 2018 +0000 +++ b/hash_table.cpp Mon Apr 15 12:25:08 2019 +0000 @@ -1,6 +1,6 @@ /* - Student Name: - Date: + Student Name: Nikhil Patel + Date: 11-8-18 ======================= ECE 2035 Project 2-1: @@ -30,7 +30,7 @@ - "HashTableEntry myNewHashTableEntry;" The preceding underscore "_" simply provides a distinction between the names - of the actual struct defition and the "nicknames" that we use to initialize + of the actual struct definition and the "nicknames" that we use to initialize new structs. [See Hidden Definitions section for more information.] @@ -126,7 +126,11 @@ * @return The pointer to the hash table entry */ static HashTableEntry* createHashTableEntry(unsigned int key, void* value) { - + HashTableEntry* node = (HashTableEntry*)malloc(sizeof(HashTableEntry)); + node->value = value; + node->key = key; + node->next = NULL; + return node; } /** @@ -140,7 +144,15 @@ * @return The pointer to the hash table entry, or NULL if key does not exist */ static HashTableEntry* findItem(HashTable* hashTable, unsigned int key) { - + int bucketNum = hashTable->hash(key); + HashTableEntry* this_entry = hashTable->buckets[bucketNum]; + while(this_entry) { + if(this_entry->key == key) { + return this_entry; + } + this_entry = this_entry->next; + } + return NULL; } /**************************************************************************** @@ -167,7 +179,7 @@ newTable->num_buckets = numBuckets; newTable->buckets = (HashTableEntry**)malloc(numBuckets*sizeof(HashTableEntry*)); - // As the new buckets are empty, init each bucket as NULL. + // As the new buckets contain indeterminant values, init each bucket as NULL. unsigned int i; for (i=0; i<numBuckets; ++i) { newTable->buckets[i] = NULL; @@ -178,21 +190,109 @@ } void destroyHashTable(HashTable* hashTable) { - + unsigned int i = 0; //init counter + for(i=0; i<hashTable->num_buckets; ++i){ //loop through each bucket + HashTableEntry* iterator = hashTable->buckets[i]; //start at head of bucket + while(iterator){ //until reach end of linked list at bucket + HashTableEntry* tmp = iterator->next; //store the next node + free(iterator->value); //free the node's value + free(iterator); //free the node itself + iterator = tmp; //restore the next node + } + } + free(hashTable->buckets); //free the buckets + free(hashTable); //free the hash table itself } void* insertItem(HashTable* hashTable, unsigned int key, void* value) { - + HashTableEntry* this_entry = findItem(hashTable,key); //will return a non-NULL value if the key exists + if(this_entry){ //if key already exists + void* replacedVal = this_entry->value; //get the value being replaces + this_entry->value = value; //replace the original value + return replacedVal; //return the value that was replaced + } + else{ //if key doesn't already exist + HashTableEntry* newNode = createHashTableEntry(key,value); //create a new node + int bucketNum = hashTable->hash(key); //get the bucket num where it will be added + if(hashTable->buckets[bucketNum] == NULL){ //if the bucket is empty + hashTable->buckets[bucketNum] = newNode; //the head of the bucket is the new node + return NULL; //return NULL to show nothing was replaced + } + else{ //if the bucket already has a linked list started + HashTableEntry* iterator = hashTable->buckets[bucketNum]; //first node + while(iterator){ //until the end of the linked list + if(iterator->next == NULL){ //reached tail of list + iterator->next = newNode; //place new node at tail + return NULL; //return NULL to show nothing was replaced + } + iterator = iterator->next; //go on to the next node + } + } + } + return NULL; } void* getItem(HashTable* hashTable, unsigned int key) { - + int bucketNum = hashTable->hash(key); //get the bucket number of the item + HashTableEntry* this_entry = hashTable->buckets[bucketNum]; //get the head of the bucket + while(this_entry) { //loop through the bucket's linked list + if(this_entry->key == key) { //if the node's key matches to input + return this_entry->value; //return the matching value + } + this_entry = this_entry->next; //go on to next node + } + return NULL; //No node with such a key } void* removeItem(HashTable* hashTable, unsigned int key) { - + int bucketNum = hashTable->hash(key); //bucket number where item is + HashTableEntry* iterator = hashTable->buckets[bucketNum]; //head of bucket + HashTableEntry* this_entry = findItem(hashTable,key); //get address/NULL of item + if(this_entry == NULL) //key doesnt exist + return NULL; + else{ //key exists + void* val = this_entry->value; //store key's value address + if(iterator == this_entry) { //item is first in linked list + hashTable->buckets[bucketNum] = this_entry->next; //unlink first node from list + free(this_entry); //free the first node + return val; //return the value of node removed + } + else{ //item isn't the first in the linked list + while(iterator){ //iterate through the linked list + if(iterator->next->key == key){ //if next node has key + iterator->next = this_entry->next; //unlink it from the list + free(this_entry); //free it + return val; //return the value of node removed + } + iterator = iterator->next; //go on to next node + } + } + } + return NULL; } void deleteItem(HashTable* hashTable, unsigned int key) { - -} \ No newline at end of file + int bucketNum = hashTable->hash(key); //bucket where item is + HashTableEntry* iterator = hashTable->buckets[bucketNum]; //head of bucket + HashTableEntry* this_entry = findItem(hashTable,key); //get address/NULL of item + if(this_entry == NULL) //key doesnt exist + return; //do nothing + else{ //key exists + if(iterator == this_entry) { // item is first node of linked list + hashTable->buckets[bucketNum] = this_entry->next; //unlink first node from list + free(this_entry->value); //free the node's value + free(this_entry); //free the node + } + else{ //item isn't first node in list + while(iterator){ //iterate through list + if(iterator->next->key == key){ //if next node has key + iterator->next = this_entry->next; //unlink node from list + free(this_entry->value); //free node's value + free(this_entry); //free node + return; + } + iterator = iterator->next; //go to next node + } + } + } +}
diff -r 399033d39feb -r 22d36e7740f1 hash_table.h --- a/hash_table.h Wed Apr 04 21:11:07 2018 +0000 +++ b/hash_table.h Mon Apr 15 12:25:08 2019 +0000 @@ -124,4 +124,4 @@ */ void deleteItem(HashTable* myHashTable, unsigned int key); -#endif \ No newline at end of file +#endif
diff -r 399033d39feb -r 22d36e7740f1 main.cpp --- a/main.cpp Wed Apr 04 21:11:07 2018 +0000 +++ b/main.cpp Mon Apr 15 12:25:08 2019 +0000 @@ -5,11 +5,23 @@ #include "graphics.h" #include "speech.h" +int omnipotent = 0; +int mapToggle = 0; +int finished = 0; +int walk = 0; + // Functions in this file int get_action (GameInputs inputs); int update_game (int action); void draw_game (int init); void init_main_map (); +void init_second_map(); +int go_up(int x, int y, int i); +int go_down(int x, int y, int i); +int go_right(int x, int y, int i); +int go_left(int x, int y, int i); +int interact(int x, int y); +int NPC_move(int x, int y); int main (); /** @@ -20,6 +32,12 @@ int x,y; // Current locations int px, py; // Previous locations int has_key; + int omnipotent; + int has_sword; + int has_shield; + int has_platebody; + int health; + int num_phats; } Player; /** @@ -29,13 +47,124 @@ #define NO_ACTION 0 #define ACTION_BUTTON 1 #define MENU_BUTTON 2 +#define OMNIPOTENT 7 #define GO_LEFT 3 +#define GO_LEFT2 10 #define GO_RIGHT 4 +#define GO_RIGHT2 11 #define GO_UP 5 +#define GO_UP2 12 #define GO_DOWN 6 +#define GO_DOWN2 13 +#define BAD_END 8 +#define GOOD_END 9 + +char *questStartLine1 = "Wow a knight!what"; +char *questStartLine2 = "perfect timing!"; +char *questStartLine3 = "I beg you,please"; +char *questStartLine4 = "defeat the evil"; +char *questStartLine5 = "dragon Elvarg!"; +char *questStartLine6 = "He resides in a"; +char *questStartLine7 = "cave to the NEast"; +char *questStartLine8 = "You'll need an"; +char *questStartLine9 = "antifire shield"; +char *questStartLine10 = "and Excalibur!"; +char *questStartLine11 = "I hear Excalibur"; +char *questStartLine12 = "can be found in"; +char *questStartLine13 = "the same cave."; +char *questStartLine14 = "It'll be embedded"; +char *questStartLine15 = "in a stone there."; +char *questStartLine16 = "Take my antifire"; +char *questStartLine17 = "shield, man."; +char *questStartLine18 = "If you do defeat"; +char *questStartLine19 = "Elvarg, take"; +char *questStartLine20 = "the key he drops."; +char *questStartLine21 = "It unlocks his"; +char *questStartLine22 = "treasure room"; +char *questStartLine23 = "to the south."; +char *questStartLine24 = "Good luck!"; +char *questStartLine25 = "Come back when"; +char *questStartLine26 = "you're done!"; + +char *questHasShield1 = "Go to the cave,"; +char *questHasShield2 = "find Excalibur,"; +char *questHasShield3 = "and defeat Elvarg"; + +char *questHasSword1 = "Go fight Evlarg!"; + +char *questHasPlatebody1 = "Thank you!!!!"; +char *questHasPlatebody2 = "You have helped"; +char *questHasPlatebody3 = "me out.I am"; +char *questHasPlatebody4 = "very grateful!"; + +char *findSword1 = "You pull and"; +char *findSword2 = "wield Excalibur."; + +char *elvarg1 = "You approach"; +char *elvarg2 = "Elvarg attacks..."; +char *elvarg3a1 = "With no shield,"; +char *elvarg3a2 = "you are burnt to"; +char *elvarg3a3 = "a crisp.(-10 HP)"; +char *elvarg3b1 = "You have no sword"; +char *elvarg3b2 = "Your punches have"; +char *elvarg3b3 = "no effect so you"; +char *elvarg3b4 = "are badly wounded"; +char *elvarg3b5 = "(-9 HP)"; +char *elvarg3c1 = "Using Excalibur &"; +char *elvarg3c2 = "the shield you"; +char *elvarg3c3 = "defeat Elvarg w/"; +char *elvarg3c4 = "only minor wounds"; +char *elvarg3c5 = "(-3 HP).He drops"; +char *elvarg3c6 = "the key to his"; +char *elvarg3c7 = "treasure room!"; + + int get_action(GameInputs inputs) { - return NO_ACTION; + if(Player.health <= 0) + { + return BAD_END; + } + else if(finished) + { + return GOOD_END; + } + else if(!inputs.b1){ + return ACTION_BUTTON; + } + else if(!inputs.b2){ + return OMNIPOTENT; + } + else if(!inputs.b3){ + return MENU_BUTTON; + } + else if(inputs.ax >= .2){ + if(inputs.ax >= .4) + return GO_LEFT2; + else + return GO_LEFT; + } + else if(inputs.ax <= -.3){ + if(inputs.ax <= -.5) + return GO_RIGHT2; + else + return GO_RIGHT; + } + else if(inputs.ay >= .3){ + if(inputs.ay >= .5) + return GO_DOWN2; + else + return GO_DOWN; + } + else if(inputs.ay <= -.2){ + if(inputs.ay <= -.4) + return GO_UP2; + else + return GO_UP; + } + else{ + return NO_ACTION; + } } /** @@ -50,6 +179,7 @@ #define NO_RESULT 0 #define GAME_OVER 1 #define FULL_DRAW 2 +#define RUN 3 int update_game(int action) { // Save player previous location before updating @@ -60,17 +190,356 @@ // You can define functions like "go_up()" that get called for each case. switch(action) { - case GO_UP: break; - case GO_LEFT: break; - case GO_DOWN: break; - case GO_RIGHT: break; - case ACTION_BUTTON: break; - case MENU_BUTTON: break; - default: break; + case GO_UP: + if(go_up(Player.x, Player.y, 0)) + return FULL_DRAW; + break; + case GO_UP2: + if(go_up(Player.x, Player.y,1)) + return RUN; + break; + case GO_LEFT: + if(go_left(Player.x, Player.y, 0)) + return FULL_DRAW; + break; + case GO_LEFT2: + if(go_left(Player.x, Player.y, 1)) + return RUN; + break; + case GO_DOWN: + if(go_down(Player.x, Player.y, 0)) + return FULL_DRAW; + break; + case GO_DOWN2: + if(go_down(Player.x, Player.y, 1)) + return RUN; + break; + case GO_RIGHT: + if(go_right(Player.x, Player.y, 0)) + return FULL_DRAW; + break; + case GO_RIGHT2: + if(go_right(Player.x, Player.y, 1)) + return RUN; + break; + case ACTION_BUTTON: + if(interact(Player.x, Player.y)) + return FULL_DRAW; + break; + case OMNIPOTENT: //toggle omnipotent mode + Player.omnipotent = !omnipotent; + omnipotent = !omnipotent; + break; + case MENU_BUTTON: //open menu + draw_menu(Player.omnipotent, Player.has_sword, Player.has_shield, Player.has_platebody, Player.has_key); + return FULL_DRAW; + case BAD_END: + return BAD_END; + case GOOD_END: + return GOOD_END; + default: + return NPC_move(Player.x, Player.y); } return NO_RESULT; } +//Functions to move player +int go_up(int x, int y, int i) +{ + MapItem *item = get_north(x, y); + MapItem *item2 = get_north(x,y-1); + if((item->walkable && item->type != PLANT2) || Player.omnipotent) + { + if((i && item2->walkable && item2->type != PLANT2) || Player.omnipotent) + { + Player.y = Player.y - 2; + return RUN; + } + Player.y--; + return 1; + } + else if(item->type == PLANT2) + { + Player.health--; + speaker.period(1.0/150.0); // 500hz period + speaker =0.25; //25% duty cycle - mid range volume + wait(.02); + speaker=0.0; // turn off audio + wait(0.5); + return 1; + } + else if(item->type == ROLLING && item2 == NULL) + { + map_erase(x,y-1); + add_rolling(x,y-2); + Player.y--; + return 1; + } + return 0; +} + +int go_down(int x, int y, int i) +{ + MapItem *item = get_south(x, y); + MapItem *item2 = get_south(x, y+1); + if((item->walkable && item->type != PLANT2) || Player.omnipotent) + { + if((i && item2->walkable && item2->type != PLANT2) || Player.omnipotent) + { + Player.y = Player.y + 2; + return RUN; + } + Player.y++; + return 1; + } + else if(item->type == PLANT2) + { + Player.health--; + speaker.period(1.0/150.0); // 500hz period + speaker =0.25; //25% duty cycle - mid range volume + wait(.02); + speaker=0.0; // turn off audio + wait(0.5); + return 1; + } + else if(item->type == ROLLING && item2 == NULL) + { + map_erase(x,y+1); + add_rolling(x,y+2); + Player.y++; + return 1; + } + return 0; +} + +int go_left(int x, int y, int i) +{ + MapItem *item = get_west(x, y); + MapItem *item2 = get_west(x-1,y); + if((item->walkable && item->type != PLANT2) || Player.omnipotent) + { + if((i && item2->walkable && item2->type != PLANT2) || Player.omnipotent) + { + Player.x = Player.x - 2; + return RUN; + } + Player.x--; + return 1; + } + else if(item->type == PLANT2) + { + Player.health--; + speaker.period(1.0/150.0); // 500hz period + speaker =0.25; //25% duty cycle - mid range volume + wait(.02); + speaker=0.0; // turn off audio + wait(0.5); + return 1; + } + else if(item->type == ROLLING && item2 == NULL) + { + map_erase(x-1,y); + add_rolling(x-2,y); + Player.x--; + return 1; + } + return 0; +} + +int go_right(int x, int y, int i) +{ + MapItem *item = get_east(x, y); + MapItem *item2 = get_east(x+1, y); + if((item->walkable && item->type != PLANT2) || Player.omnipotent) + { + if((i && item2->walkable && item2->type != PLANT2) || Player.omnipotent) + { + Player.x = Player.x + 2; + return RUN; + } + Player.x++; + return 1; + } + else if(item->type == PLANT2) + { + Player.health--; + speaker.period(1.0/150.0); // 500hz period + speaker =0.25; //25% duty cycle - mid range volume + wait(.02); + speaker=0.0; // turn off audio + wait(0.5); + return 1; + } + else if(item->type == ROLLING && item2 == NULL) + { + map_erase(x+1,y); + add_rolling(x+2,y); + Player.x++; + return 1; + } + return 0; +} + +int interact(int x, int y) +{ + MapItem *north = get_north(x,y); + MapItem *south = get_south(x,y); + MapItem *east = get_east(x,y); + MapItem *west = get_west(x,y); + if(north->type == STARTNPC || south->type == STARTNPC || east->type == STARTNPC || west->type == STARTNPC) + { + if(Player.has_platebody) + { + speech(questHasPlatebody1, questHasPlatebody2, questHasPlatebody3, questHasPlatebody4); + finished = 1; + return 1; + } + else if(!Player.has_platebody && Player.has_key) + { + speech("Search the", "treasure room", "first! Then", "come talk"); + return 1; + } + else if(Player.has_sword) + { + speech(questHasSword1, "", "", ""); + return 1; + } + else if(Player.has_shield ) + { + speech(questHasShield1, questHasShield2, questHasShield3, ""); + return 1; + } + else + { + speech(questStartLine1, questStartLine2, questStartLine3, questStartLine4); + speech(questStartLine5, questStartLine6, questStartLine7, questStartLine8); + speech(questStartLine9, questStartLine10, questStartLine11, questStartLine12); + speech(questStartLine13, questStartLine14, questStartLine15, questStartLine16); + speech(questStartLine17, questStartLine18, questStartLine19, questStartLine20); + speech(questStartLine21, questStartLine22, questStartLine23, questStartLine24); + speech(questStartLine25, questStartLine26,"",""); + Player.has_shield = 1; + return 1; + } + } + else if(north->type == CAVE || south->type == CAVE || east->type == CAVE || west->type == CAVE) + { + if(mapToggle == 0) + { + mapToggle = !mapToggle; + set_active_map(1); + Player.x = 5; + Player.y = 5; + } + else + { + mapToggle = !mapToggle; + set_active_map(0); + Player.x = 39; + Player.y = 4; + } + return 1; + } + else if(north->type == SWORDINSTONE || south->type == SWORDINSTONE || east->type == SWORDINSTONE || west->type == SWORDINSTONE) + { + if(Player.has_shield) + { + Player.has_sword = 1; + speech(findSword1, findSword2, "", ""); + map_erase(15,15); + draw_plant(15,15); + } + else + { + speech("You should", "talk to the man", "where you started", "first"); + } + return 1; + } + else if(north->type == ELVARG || south->type == ELVARG || east->type == ELVARG || west->type == ELVARG) + { + speech(elvarg1, elvarg2, "", ""); + if(!Player.has_shield) + { + speech(elvarg3a1, elvarg3a2, elvarg3a3, ""); + Player.health = Player.health - 10; + return 1; + } + else if(!Player.has_sword) + { + speech(elvarg3b1, elvarg3b2, elvarg3b3, elvarg3b4); + speech(elvarg3b5, "", "", ""); + Player.health = Player.health - 9; + return 1; + } + else + { + Player.has_key = 1; + speech(elvarg3c1, elvarg3c2, elvarg3c3, elvarg3c4); + speech(elvarg3c5, elvarg3c6, elvarg3c7, ""); + map_erase(10,10); + Player.health = Player.health - 3; + return 1; + } + } + else if(north->type == GATE || south->type == GATE || east->type == GATE || west->type == GATE) + { + if(Player.has_key) + { + speech("You unlock the", "gate with the key", "", ""); + map_erase(10,45); + return 1; + } + else + { + speech("Requires Elvarg's", "key to open", "", ""); + return 1; + } + } + else if(north->type == TREASURE || south->type == TREASURE || east->type == TREASURE || west->type == TREASURE) + { + Player.has_platebody = 1; + speech("You are amazed", "to find a", "legendary rune", "platebody."); + speech("you equip the", "legendary armor.", "Time to return", "to that weird"); + speech("guy. His request", "has been", "fulfilled.", ""); + return 1; + } + else if(north->type == PHAT || south->type == PHAT || east->type == PHAT || west->type == PHAT) + { + if(Player.num_phats == 0) + speech("find all 5", "hidden party", "hats!", ""); + Player.num_phats++; + if(Player.num_phats == 5) + { + speech("you found all", "5 party hats!", "You are very", "special!"); + } + if(north->type == PHAT) + map_erase(x, y-1); + if(south->type == PHAT) + map_erase(x, y+1); + if(east->type == PHAT) + map_erase(x+1, y); + if(west->type == PHAT) + map_erase(x-1, y); + return 1; + } + + return 0; +} + +int NPC_move(int x, int y) +{ + if(!((Player.x == (7+!walk)) && (Player.y == 7)) && (map_width() == 50)) + { + wait_ms(200); + map_erase(7+walk, 7); + walk = !walk; + add_startNPC(7+walk,7); + wait_ms(200); + return FULL_DRAW; + } + return 0; +} + /** * Entry point for frame drawing. This should be called once per iteration of * the game loop. This draws all tiles on the screen, followed by the status @@ -78,7 +547,24 @@ * drawing tiles that have changed from the previous frame. */ void draw_game(int init) -{ +{ + if(init == BAD_END) + { + speaker.period(1.0/150.0); // 500hz period + speaker =0.25; //25% duty cycle - mid range volume + wait(.5); + speaker=0.0; // turn off audio + wait(0.5); + draw_bad(); + wait(10000); + } + if(init == GOOD_END) + { + draw_good(); + wait(10000); + } + + // Draw game border first if(init) draw_border(); @@ -103,9 +589,21 @@ // Figure out what to draw DrawFunc draw = NULL; - if (init && i == 0 && j == 0) // Only draw the player on init + if (init && i == 0 && j == 0 && get_here(Player.x, Player.y)->walkable != 2) // Only draw the player on init { - draw_player(u, v, Player.has_key); + if(init == RUN) + { + draw_player(u,v,4); + wait_ms(100); + } + if(Player.has_platebody) + draw_player(u, v, 3); + else if(Player.has_sword) + draw_player(u, v, 2); + else if(Player.has_shield) + draw_player(u ,v, 1); + else + draw_player(u ,v, 0); continue; } else if (x >= 0 && y >= 0 && x < map_width() && y < map_height()) // Current (i,j) in the map @@ -135,8 +633,8 @@ } // Draw status bars - draw_upper_status(); - draw_lower_status(); + draw_upper_status(Player.x,Player.y); + draw_lower_status(Player.health, Player.num_phats); } @@ -161,6 +659,59 @@ add_wall(map_width()-1, 0, VERTICAL, map_height()); pc.printf("Walls done!\r\n"); + //draw in treasure room + add_wall(6, 45, VERTICAL, 4); + add_wall(7, 45, HORIZONTAL, 3); + add_gate(10,45); + add_wall(11, 45, HORIZONTAL, 3); + add_wall(14, 45, VERTICAL, 4); + + + add_startNPC(7,7); + pc.printf("NPCs!\r\n"); + + add_boulder(3,3); + + add_cave(40,4); + pc.printf("Cave!\r\n"); + add_rolling(39,4); + add_rolling(41,4); + add_rolling(40,5); + add_rolling(40,3); + + add_treasure(10,47); + pc.printf("Treasure!\r\n"); + + add_phat(45,45); + add_phat(25,25); + add_phat(10,48); + + print_map(); +} + +void init_second_map() +{ + // "Random" plants + Map* map = set_active_map(1); + for(int i = map_width() + 3; i < map_area(); i += 39) + { + add_plant2(i % map_width(), i / map_width()); + } + pc.printf("plants\r\n"); + + pc.printf("Adding walls!\r\n"); + add_wall(0, 0, HORIZONTAL, map_width()); + add_wall(0, map_height()-1, HORIZONTAL, map_width()); + add_wall(0, 0, VERTICAL, map_height()); + add_wall(map_width()-1, 0, VERTICAL, map_height()); + pc.printf("Walls done!\r\n"); + + //add sprites + add_cave(4,5); + add_elvarg(10,10); + add_swordInStone(15,15); + add_phat(3,10); + add_phat(10,17); print_map(); } @@ -175,17 +726,31 @@ // First things first: initialize hardware ASSERT_P(hardware_init() == ERROR_NONE, "Hardware init failed!"); + draw_start(); + // Initialize the maps maps_init(); + init_second_map(); init_main_map(); // Initialize game state set_active_map(0); Player.x = Player.y = 5; + Player.has_key = 0; + Player.has_sword = 0; + Player.has_shield = 0; + Player.has_platebody = 0; + Player.health = 10; // Initial drawing + uLCD.filled_rectangle(0, 0, 127, 8, BLACK); + uLCD.filled_rectangle(0, 119, 127, 127, BLACK); draw_game(true); - + + // Variables + GameInputs in; + int action; + int draw; // Main game loop while(1) { @@ -193,11 +758,15 @@ Timer t; t.start(); // Actuall do the game update: - // 1. Read inputs - // 2. Determine action (get_action) + // 1. Read inputs + in = read_inputs(); + // 2. Determine action (get_action) + action = get_action(in); // 3. Update game (update_game) + draw = update_game(action); // 3b. Check for game over // 4. Draw frame (draw_game) + draw_game(draw); // 5. Frame delay t.stop();
diff -r 399033d39feb -r 22d36e7740f1 map.cpp --- a/map.cpp Wed Apr 04 21:11:07 2018 +0000 +++ b/map.cpp Mon Apr 15 12:25:08 2019 +0000 @@ -17,7 +17,7 @@ * This is a global variable, but can only be access from this file because it * is static. */ -static Map map; +static Map map[NUM_MAPS]; static int active_map; /** @@ -25,8 +25,8 @@ * key information (x, y) into a one-dimensional unsigned integer. * This function should uniquely map (x,y) onto the space of unsigned integers. */ -static unsigned XY_KEY(int X, int Y) { - // TODO: Fix me! +static unsigned XY_KEY(int X, int Y, int size) { + return (X+size*Y); //linearize a 2d index } /** @@ -34,34 +34,43 @@ * unsigned key (the output of XY_KEY) and turns it into a hash value (some * small non-negative integer). */ -unsigned map_hash(unsigned key) +unsigned map_hash1(unsigned key) { - // TODO: Fix me! + return key%NUM_BUCKETS1; +} + +unsigned map_hash2(unsigned key) +{ + return key%NUM_BUCKETS2; } void maps_init() { - // TODO: Implement! - // Initialize hash table - // Set width & height + map[0].items = createHashTable(map_hash1, NUM_BUCKETS1); + map[0].h = 50; + map[0].w = 50; + map[1].items = createHashTable(map_hash2, NUM_BUCKETS2); + map[1].h = 20; + map[1].w = 20; } Map* get_active_map() { // There's only one map - return ↦ + return &map[active_map]; } Map* set_active_map(int m) { active_map = m; - return ↦ + return &map[active_map]; } + void print_map() { // As you add more types, you'll need to add more items to this array. - char lookup[] = {'W', 'P'}; + char lookup[] = {'W', 'P', 'N'}; for(int y = 0; y < map_height(); y++) { for (int x = 0; x < map_width(); x++) @@ -76,39 +85,48 @@ int map_width() { + return map[active_map].w; } int map_height() { + return map[active_map].h; } int map_area() { + return map[active_map].h * map[active_map].w; } MapItem* get_north(int x, int y) { + return (MapItem*)getItem(map[active_map].items, XY_KEY(x,y-1,map_height())); } MapItem* get_south(int x, int y) { + return (MapItem*)getItem(map[active_map].items, XY_KEY(x,y+1,map_height())); } MapItem* get_east(int x, int y) { + return (MapItem*)getItem(map[active_map].items, XY_KEY(x+1,y,map_height())); } MapItem* get_west(int x, int y) { + return (MapItem*)getItem(map[active_map].items, XY_KEY(x-1,y,map_height())); } MapItem* get_here(int x, int y) { + return (MapItem*)getItem(map[active_map].items, XY_KEY(x,y, map_height())); } void map_erase(int x, int y) { + deleteItem(map[active_map].items, XY_KEY(x,y,map_height())); } void add_wall(int x, int y, int dir, int len) @@ -120,7 +138,7 @@ w1->draw = draw_wall; w1->walkable = false; w1->data = NULL; - unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y) : XY_KEY(x, y+i); + unsigned key = (dir == HORIZONTAL) ? XY_KEY(x+i, y, map_height()) : XY_KEY(x, y+i, map_height()); void* val = insertItem(get_active_map()->items, key, w1); if (val) free(val); // If something is already there, free it } @@ -133,6 +151,116 @@ w1->draw = draw_plant; w1->walkable = true; w1->data = NULL; - void* val = insertItem(get_active_map()->items, XY_KEY(x, y), w1); + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_plant2(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = PLANT2; + w1->draw = draw_plant; + w1->walkable = true; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_startNPC(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = STARTNPC; + w1->draw = draw_startNPC; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y,map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_swordInStone(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = SWORDINSTONE; + w1->draw = draw_swordInStone; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_elvarg(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = ELVARG; + w1->draw = draw_elvarg; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_cave(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = CAVE; + w1->draw = draw_cave; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_gate(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = GATE; + w1->draw = draw_gate; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_treasure(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = TREASURE; + w1->draw = draw_treasure; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_boulder(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = BOULDER; + w1->draw = draw_boulder; + w1->walkable = 2; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_phat(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = PHAT; + w1->draw = draw_phat; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); + if (val) free(val); // If something is already there, free it +} + +void add_rolling(int x, int y) +{ + MapItem* w1 = (MapItem*) malloc(sizeof(MapItem)); + w1->type = ROLLING; + w1->draw = draw_rolling; + w1->walkable = false; + w1->data = NULL; + void* val = insertItem(get_active_map()->items, XY_KEY(x, y, map_height()), w1); if (val) free(val); // If something is already there, free it } \ No newline at end of file
diff -r 399033d39feb -r 22d36e7740f1 map.h --- a/map.h Wed Apr 04 21:11:07 2018 +0000 +++ b/map.h Mon Apr 15 12:25:08 2019 +0000 @@ -53,8 +53,18 @@ // MapItem types // Define more of these! -#define WALL 0 -#define PLANT 1 +#define WALL 0 +#define PLANT 1 +#define STARTNPC 2 +#define SWORDINSTONE 3 +#define ELVARG 4 +#define CAVE 5 +#define PLANT2 6 +#define GATE 7 +#define TREASURE 8 +#define BOULDER 9 +#define PHAT 10 +#define ROLLING 11 /** * Initializes the internal structures for all maps. This does not populate @@ -150,5 +160,15 @@ * before adding the plant. */ void add_plant(int x, int y); +void add_plant2(int x, int y); //trap plant +void add_startNPC(int x, int y); +void add_swordInStone(int x, int y); +void add_elvarg(int x, int y); +void add_cave(int x, int y); +void add_gate(int x, int y); +void add_treasure(int x, int y); +void add_boulder(int x, int y); +void add_phat(int x, int y); +void add_rolling(int x, int y); #endif //MAP_H \ No newline at end of file
diff -r 399033d39feb -r 22d36e7740f1 speech.cpp --- a/speech.cpp Wed Apr 04 21:11:07 2018 +0000 +++ b/speech.cpp Mon Apr 15 12:25:08 2019 +0000 @@ -29,25 +29,78 @@ void draw_speech_bubble() { + //draw speech bubble borders + uLCD.line(0, 114, 127, 114, GREEN); // Bottom + uLCD.line(0, 70, 127, 70, GREEN); // Top + uLCD.line(0, 71, 0, 113, GREEN); // Left + uLCD.line(127, 71, 127, 113, GREEN); // Right + + //fill speech bubble borders + uLCD.filled_rectangle(1, 71, 126, 113, 5); } void erase_speech_bubble() { + //restore original color at speech bubble borders + uLCD.line(0, 114, 127, 114, WHITE); // Bottom + uLCD.line(0, 94, 127, 94, BLACK); // Top + uLCD.line(0, 95, 0, 113, WHITE); // Left + uLCD.line(127, 95, 127, 113, WHITE); // Right + + uLCD.filled_rectangle(1, 95, 126, 113, BLACK); + } void draw_speech_line(const char* line, int which) { + if(which == TOP) + { + uLCD.locate(1,9); + uLCD.printf(line); + } + else if(which == BOTTOM) + { + uLCD.locate(1,10); + uLCD.printf(line); + } + else if(which == 3) + { + uLCD.locate(1,11); + uLCD.printf(line); + } + else + { + uLCD.locate(1,12); + uLCD.printf(line); + } + } void speech_bubble_wait() { + GameInputs inputs; + inputs = read_inputs(); + int blink = 1; + while(inputs.b1) + { + blink = !blink; + wait_ms(200); + if(blink) + uLCD.filled_circle(123, 114, 3, GREEN); + else + uLCD.filled_circle(123, 114, 3, BLACK); + inputs = read_inputs(); + + } } -void speech(const char* line1, const char* line2) +void speech(const char* line1, const char* line2, const char* line3, const char* line4) { draw_speech_bubble(); draw_speech_line(line1, TOP); draw_speech_line(line2, BOTTOM); + draw_speech_line(line3, 3); + draw_speech_line(line4, 4); speech_bubble_wait(); erase_speech_bubble(); }
diff -r 399033d39feb -r 22d36e7740f1 speech.h --- a/speech.h Wed Apr 04 21:11:07 2018 +0000 +++ b/speech.h Mon Apr 15 12:25:08 2019 +0000 @@ -4,7 +4,7 @@ /** * Display a speech bubble. */ -void speech(const char* line1, const char* line2); +void speech(const char* line1, const char* line2, const char* line3, const char* line4); /** * Display a long speech bubble (more than 2 lines).