27

Dependencies:   N5110

Committer:
cbs27
Date:
Sat Apr 24 03:01:47 2021 +0000
Revision:
2:9a31febe6d2f
Parent:
1:48a028c4089e
,,

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cbs27 0:ef959ad27a16 1 /* mbed Microcontroller Library
cbs27 0:ef959ad27a16 2 * Copyright (c) 2019 ARM Limited
cbs27 0:ef959ad27a16 3 * SPDX-License-Identifier: Apache-2.0
cbs27 0:ef959ad27a16 4 */
cbs27 0:ef959ad27a16 5
cbs27 0:ef959ad27a16 6 #include "mbed.h"
cbs27 0:ef959ad27a16 7 #include "platform/mbed_thread.h"
cbs27 0:ef959ad27a16 8 #include "N5110.h"
cbs27 0:ef959ad27a16 9
cbs27 0:ef959ad27a16 10 #include "shapes.h"
cbs27 0:ef959ad27a16 11 #include "main.h"
cbs27 0:ef959ad27a16 12 #include "monster.h"
cbs27 0:ef959ad27a16 13
cbs27 0:ef959ad27a16 14 N5110 lcd(p8,p9,p10,p11,p13,p21);
cbs27 0:ef959ad27a16 15 DigitalIn button_A(p29);
cbs27 0:ef959ad27a16 16 DigitalIn button_B(p28);
cbs27 0:ef959ad27a16 17 DigitalIn button_C(p27);
cbs27 0:ef959ad27a16 18 DigitalIn button_D(p26);
cbs27 1:48a028c4089e 19 DigitalOut led1(LED1);
cbs27 1:48a028c4089e 20 DigitalOut led2(LED2);
cbs27 1:48a028c4089e 21 DigitalOut led3(LED3);
cbs27 0:ef959ad27a16 22
cbs27 0:ef959ad27a16 23 Monster monster;
cbs27 0:ef959ad27a16 24
cbs27 0:ef959ad27a16 25 int lifes;
cbs27 0:ef959ad27a16 26 int score, best_score;
cbs27 2:9a31febe6d2f 27 bool auto_attack;
cbs27 0:ef959ad27a16 28
cbs27 0:ef959ad27a16 29 void init();
cbs27 0:ef959ad27a16 30 void welcome();
cbs27 0:ef959ad27a16 31
cbs27 0:ef959ad27a16 32 void choice();
cbs27 0:ef959ad27a16 33
cbs27 0:ef959ad27a16 34 void game_begin();
cbs27 0:ef959ad27a16 35 void show_score();
cbs27 0:ef959ad27a16 36 void instruction();
cbs27 0:ef959ad27a16 37
cbs27 0:ef959ad27a16 38 int main()
cbs27 0:ef959ad27a16 39 {
cbs27 0:ef959ad27a16 40 init();
cbs27 0:ef959ad27a16 41 welcome();
cbs27 0:ef959ad27a16 42
cbs27 0:ef959ad27a16 43 while(1) {
cbs27 0:ef959ad27a16 44
cbs27 0:ef959ad27a16 45 if (button_A.read() == 1 ) {
cbs27 0:ef959ad27a16 46
cbs27 0:ef959ad27a16 47 choice();
cbs27 0:ef959ad27a16 48
cbs27 0:ef959ad27a16 49 }
cbs27 0:ef959ad27a16 50 }
cbs27 0:ef959ad27a16 51
cbs27 0:ef959ad27a16 52 }
cbs27 0:ef959ad27a16 53
cbs27 0:ef959ad27a16 54 //**********************//
cbs27 0:ef959ad27a16 55
cbs27 0:ef959ad27a16 56 void init() {
cbs27 0:ef959ad27a16 57
cbs27 0:ef959ad27a16 58 lcd.init();
cbs27 0:ef959ad27a16 59 lifes = 3;
cbs27 0:ef959ad27a16 60 score = 0;
cbs27 0:ef959ad27a16 61
cbs27 0:ef959ad27a16 62 }
cbs27 0:ef959ad27a16 63
cbs27 0:ef959ad27a16 64 void welcome() {
cbs27 0:ef959ad27a16 65
cbs27 0:ef959ad27a16 66 lcd.clear();
cbs27 0:ef959ad27a16 67
cbs27 0:ef959ad27a16 68 lcd.drawSprite(60,12,12,14,(int *)bigMonster);
cbs27 0:ef959ad27a16 69 lcd.printString("Monster",0,0);
cbs27 0:ef959ad27a16 70 lcd.printString("Game",0,2);
cbs27 0:ef959ad27a16 71
cbs27 0:ef959ad27a16 72 lcd.printString("Press A NEXT",0,5);
cbs27 0:ef959ad27a16 73
cbs27 0:ef959ad27a16 74 lcd.refresh();
cbs27 1:48a028c4089e 75 thread_sleep_for(50);
cbs27 0:ef959ad27a16 76
cbs27 0:ef959ad27a16 77 }
cbs27 0:ef959ad27a16 78
cbs27 0:ef959ad27a16 79 void choice() {
cbs27 0:ef959ad27a16 80
cbs27 0:ef959ad27a16 81 lcd.clear();
cbs27 0:ef959ad27a16 82
cbs27 0:ef959ad27a16 83 lcd.printString("A. BEGIN",0,0);
cbs27 0:ef959ad27a16 84 lcd.printString("B. SCORE",0,2);
cbs27 0:ef959ad27a16 85 lcd.printString("C. INFO",0,4);
cbs27 0:ef959ad27a16 86
cbs27 0:ef959ad27a16 87 lcd.refresh();
cbs27 0:ef959ad27a16 88
cbs27 0:ef959ad27a16 89 thread_sleep_for(50);
cbs27 0:ef959ad27a16 90
cbs27 0:ef959ad27a16 91 while(1) {
cbs27 0:ef959ad27a16 92
cbs27 0:ef959ad27a16 93 if(button_A.read() == 1) {
cbs27 0:ef959ad27a16 94 game_begin();
cbs27 0:ef959ad27a16 95 }
cbs27 0:ef959ad27a16 96 if(button_B.read() == 1) {
cbs27 0:ef959ad27a16 97 show_score();
cbs27 0:ef959ad27a16 98 }
cbs27 0:ef959ad27a16 99 if(button_C.read() == 1) {
cbs27 0:ef959ad27a16 100 instruction();
cbs27 0:ef959ad27a16 101 }
cbs27 2:9a31febe6d2f 102 if(button_D.read() == 1) {
cbs27 2:9a31febe6d2f 103
cbs27 2:9a31febe6d2f 104 lcd.clear();
cbs27 2:9a31febe6d2f 105
cbs27 2:9a31febe6d2f 106 lcd.printString("THE LAST",18,2);
cbs27 2:9a31febe6d2f 107 lcd.printString("DEFENCE",21,4);
cbs27 2:9a31febe6d2f 108
cbs27 2:9a31febe6d2f 109 lcd.refresh();
cbs27 2:9a31febe6d2f 110
cbs27 2:9a31febe6d2f 111 thread_sleep_for(200);
cbs27 2:9a31febe6d2f 112
cbs27 2:9a31febe6d2f 113 monster.monster_main3(lcd, button_A, button_B, button_C, button_D, led1, led2, led3);
cbs27 2:9a31febe6d2f 114 }
cbs27 0:ef959ad27a16 115
cbs27 0:ef959ad27a16 116 }
cbs27 0:ef959ad27a16 117
cbs27 0:ef959ad27a16 118 }
cbs27 0:ef959ad27a16 119
cbs27 0:ef959ad27a16 120 //***********************//
cbs27 0:ef959ad27a16 121
cbs27 0:ef959ad27a16 122 void game_begin() {
cbs27 0:ef959ad27a16 123
cbs27 1:48a028c4089e 124 monster.monster_main(lcd, button_A, button_B, button_C, button_D, led1, led2, led3);
cbs27 0:ef959ad27a16 125
cbs27 0:ef959ad27a16 126 }
cbs27 0:ef959ad27a16 127
cbs27 0:ef959ad27a16 128 void show_score() {
cbs27 0:ef959ad27a16 129
cbs27 0:ef959ad27a16 130 lcd.clear();
cbs27 0:ef959ad27a16 131
cbs27 0:ef959ad27a16 132 lcd.printString("BEST SCORE",12,1);
cbs27 0:ef959ad27a16 133
cbs27 0:ef959ad27a16 134 char buffer[14];
cbs27 0:ef959ad27a16 135 sprintf(buffer,"%d",best_score);
cbs27 0:ef959ad27a16 136 lcd.printString(buffer,12,3);
cbs27 0:ef959ad27a16 137
cbs27 0:ef959ad27a16 138 lcd.printString("Press A BACK",0,5);
cbs27 0:ef959ad27a16 139
cbs27 0:ef959ad27a16 140 lcd.refresh();
cbs27 0:ef959ad27a16 141
cbs27 0:ef959ad27a16 142 while(1) {
cbs27 0:ef959ad27a16 143
cbs27 0:ef959ad27a16 144 if(button_A.read() == 1) {
cbs27 0:ef959ad27a16 145 choice();
cbs27 0:ef959ad27a16 146 }
cbs27 0:ef959ad27a16 147 }
cbs27 0:ef959ad27a16 148
cbs27 0:ef959ad27a16 149 }
cbs27 0:ef959ad27a16 150
cbs27 0:ef959ad27a16 151
cbs27 0:ef959ad27a16 152 void instruction() {
cbs27 0:ef959ad27a16 153
cbs27 0:ef959ad27a16 154 lcd.clear();
cbs27 0:ef959ad27a16 155
cbs27 0:ef959ad27a16 156 lcd.drawSprite(0,0,6,7,(int *)whiteMonster);
cbs27 0:ef959ad27a16 157 lcd.drawSprite(0,9,7,7,(int *)blackMonster);
cbs27 0:ef959ad27a16 158 lcd.drawSprite(2,19,3,3,(int *)shapStar);
cbs27 0:ef959ad27a16 159 lcd.drawSprite(1,26,4,5,(int *)shapHeart);
cbs27 0:ef959ad27a16 160
cbs27 0:ef959ad27a16 161 lcd.printString("Your monster",12,0);
cbs27 0:ef959ad27a16 162 lcd.printString("Enemy",12,1);
cbs27 0:ef959ad27a16 163 lcd.printString("Jewel",12,2);
cbs27 0:ef959ad27a16 164 lcd.printString("Lives",12,3);
cbs27 0:ef959ad27a16 165
cbs27 0:ef959ad27a16 166 lcd.printString("Press A BACK",0,5);
cbs27 0:ef959ad27a16 167
cbs27 0:ef959ad27a16 168 // thread_sleep_for(200);
cbs27 0:ef959ad27a16 169 lcd.refresh();
cbs27 0:ef959ad27a16 170
cbs27 0:ef959ad27a16 171 while(1) {
cbs27 0:ef959ad27a16 172
cbs27 0:ef959ad27a16 173 if(button_A.read() == 1) {
cbs27 0:ef959ad27a16 174 choice();
cbs27 0:ef959ad27a16 175 }
cbs27 0:ef959ad27a16 176 }
cbs27 0:ef959ad27a16 177
cbs27 0:ef959ad27a16 178 }