27

Dependencies:   N5110

Committer:
cbs27
Date:
Fri Apr 09 06:34:43 2021 +0000
Revision:
1:48a028c4089e
Parent:
0:ef959ad27a16
Child:
2:9a31febe6d2f
..;

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 0:ef959ad27a16 27
cbs27 0:ef959ad27a16 28 void init();
cbs27 0:ef959ad27a16 29 void welcome();
cbs27 0:ef959ad27a16 30
cbs27 0:ef959ad27a16 31 void choice();
cbs27 0:ef959ad27a16 32
cbs27 0:ef959ad27a16 33 void game_begin();
cbs27 0:ef959ad27a16 34 void show_score();
cbs27 0:ef959ad27a16 35 void instruction();
cbs27 0:ef959ad27a16 36
cbs27 0:ef959ad27a16 37 int main()
cbs27 0:ef959ad27a16 38 {
cbs27 0:ef959ad27a16 39 init();
cbs27 0:ef959ad27a16 40 welcome();
cbs27 0:ef959ad27a16 41
cbs27 0:ef959ad27a16 42 while(1) {
cbs27 0:ef959ad27a16 43
cbs27 0:ef959ad27a16 44 if (button_A.read() == 1 ) {
cbs27 0:ef959ad27a16 45
cbs27 0:ef959ad27a16 46 choice();
cbs27 0:ef959ad27a16 47
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 void init() {
cbs27 0:ef959ad27a16 56
cbs27 0:ef959ad27a16 57 lcd.init();
cbs27 0:ef959ad27a16 58
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 0:ef959ad27a16 102
cbs27 0:ef959ad27a16 103 }
cbs27 0:ef959ad27a16 104
cbs27 0:ef959ad27a16 105 }
cbs27 0:ef959ad27a16 106
cbs27 0:ef959ad27a16 107 //***********************//
cbs27 0:ef959ad27a16 108
cbs27 0:ef959ad27a16 109 void game_begin() {
cbs27 0:ef959ad27a16 110
cbs27 1:48a028c4089e 111 monster.monster_main(lcd, button_A, button_B, button_C, button_D, led1, led2, led3);
cbs27 0:ef959ad27a16 112
cbs27 0:ef959ad27a16 113 }
cbs27 0:ef959ad27a16 114
cbs27 0:ef959ad27a16 115 void show_score() {
cbs27 0:ef959ad27a16 116
cbs27 0:ef959ad27a16 117 lcd.clear();
cbs27 0:ef959ad27a16 118
cbs27 0:ef959ad27a16 119 lcd.printString("BEST SCORE",12,1);
cbs27 0:ef959ad27a16 120
cbs27 0:ef959ad27a16 121 char buffer[14];
cbs27 0:ef959ad27a16 122 sprintf(buffer,"%d",best_score);
cbs27 0:ef959ad27a16 123 lcd.printString(buffer,12,3);
cbs27 0:ef959ad27a16 124
cbs27 0:ef959ad27a16 125 lcd.printString("Press A BACK",0,5);
cbs27 0:ef959ad27a16 126
cbs27 0:ef959ad27a16 127 lcd.refresh();
cbs27 0:ef959ad27a16 128
cbs27 0:ef959ad27a16 129 while(1) {
cbs27 0:ef959ad27a16 130
cbs27 0:ef959ad27a16 131 if(button_A.read() == 1) {
cbs27 0:ef959ad27a16 132 choice();
cbs27 0:ef959ad27a16 133 }
cbs27 0:ef959ad27a16 134 }
cbs27 0:ef959ad27a16 135
cbs27 0:ef959ad27a16 136 }
cbs27 0:ef959ad27a16 137
cbs27 0:ef959ad27a16 138
cbs27 0:ef959ad27a16 139 void instruction() {
cbs27 0:ef959ad27a16 140
cbs27 0:ef959ad27a16 141 lcd.clear();
cbs27 0:ef959ad27a16 142
cbs27 0:ef959ad27a16 143 lcd.drawSprite(0,0,6,7,(int *)whiteMonster);
cbs27 0:ef959ad27a16 144 lcd.drawSprite(0,9,7,7,(int *)blackMonster);
cbs27 0:ef959ad27a16 145 lcd.drawSprite(2,19,3,3,(int *)shapStar);
cbs27 0:ef959ad27a16 146 lcd.drawSprite(1,26,4,5,(int *)shapHeart);
cbs27 0:ef959ad27a16 147
cbs27 0:ef959ad27a16 148 lcd.printString("Your monster",12,0);
cbs27 0:ef959ad27a16 149 lcd.printString("Enemy",12,1);
cbs27 0:ef959ad27a16 150 lcd.printString("Jewel",12,2);
cbs27 0:ef959ad27a16 151 lcd.printString("Lives",12,3);
cbs27 0:ef959ad27a16 152
cbs27 0:ef959ad27a16 153 lcd.printString("Press A BACK",0,5);
cbs27 0:ef959ad27a16 154
cbs27 0:ef959ad27a16 155 // thread_sleep_for(200);
cbs27 0:ef959ad27a16 156 lcd.refresh();
cbs27 0:ef959ad27a16 157
cbs27 0:ef959ad27a16 158 while(1) {
cbs27 0:ef959ad27a16 159
cbs27 0:ef959ad27a16 160 if(button_A.read() == 1) {
cbs27 0:ef959ad27a16 161 choice();
cbs27 0:ef959ad27a16 162 }
cbs27 0:ef959ad27a16 163 }
cbs27 0:ef959ad27a16 164
cbs27 0:ef959ad27a16 165 }