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 Gamepad N5110
main.cpp
- Committer:
- 1012754868
- Date:
- 2019-04-26
- Revision:
- 0:5fcd72a90b20
- Child:
- 1:db2a69ca4929
File content as of revision 0:5fcd72a90b20:
//屏幕开始有蛇的图标
//主页过了之后选择菜单菜单包含速度历史记录
//音乐
/*
做选项的步骤
把选项打印出来
移动光标
移动到某一个点击确定跳转到一个界面,点击返回返回到设置
*/
#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Snake.h"
/************************Structs************************/
struct UserInput {
Direction d;
};
/************************Objects************************/
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);//set LCD pins
Gamepad pad;
Snake snake;
Direction d;
int SNAKY[11][48] = {
{0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,1,1,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,0,0,0},
{0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,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,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};
char _Buffer[200];
/************************Prototypes************************/
void start_game();
void game_setting();
/************************Variables************************/
//int heroChar[4]=(1,1,0,1);
//int bomb[4]=(0,1,0,1);
//int boulderLocation[4][8]={}// set the coordinate for boulder, if 00, boulder does not exist
/************************Main code************************/
int main()
{
lcd.init();//initializing display
pad.init();
//pc.printf("initalized");
snake.init(25,25,5,3);
start_game();
game_setting();
while (1) {
//printf("updated");
snake.drawsnake(lcd);
snake.snakemov(pad);
}
}
/************************Functions************************/
void start_game(){
lcd.printString(" LI Saiwen",0,3);
lcd.printString(" Press A",0,5);
lcd.refresh();
lcd.drawSprite(60,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(60,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(55,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(55,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(50,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(50,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(45,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(45,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(40,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(40,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(35,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(35,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(30,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(30,5,11,48,(int *)_SNAKY);
lcd.refresh();
lcd.drawSprite(25,5,11,48,(int *)SNAKY);
lcd.refresh();
wait(0.2);
lcd.drawSprite(25,5,11,48,(int *)_SNAKY);
lcd.drawSprite(20,5,11,48,(int *)SNAKY);
lcd.refresh();
while ( pad.check_event(Gamepad::A_PRESSED) == false) {
pad.leds_on();
wait(0.1);
pad.leds_off();
wait(0.1);
}
lcd.clear();
}
void game_setting() {
lcd.printString(" Menu",0,0);
lcd.printString(" A to set",0,1);
lcd.printString("set speed <",0,2);
lcd.printString("history ",0,3);
lcd.printString(" press start",0,5);
lcd.refresh();
int q = 1;
while ( pad.check_event(Gamepad::START_PRESSED) == false) {
d = pad.get_direction();
if(d == N || q == 1){
lcd.clear();
lcd.printString(" Menu",0,0);
lcd.printString(" A to set",0,1);
lcd.printString("set speed <",0,2);
lcd.printString("history ",0,3);
lcd.printString(" press start",0,5);
lcd.refresh();
if(pad.check_event(Gamepad::A_PRESSED) == true) {
bool IsCheck = false;
int c = 1;
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal <",0,2);
lcd.printString(" Difficult",0,3);
lcd.printString(" Hell",0,4);
lcd.refresh();
while(IsCheck == false){
d = pad.get_direction();
if(d == N && c == 1){
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal <",0,2);
lcd.printString(" Difficult",0,3);
lcd.printString(" Hell",0,4);
c = 1;
lcd.refresh();
}
else if(d == S && c == 1 ){
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal",0,2);
lcd.printString(" Difficult <",0,3);
lcd.printString(" Hell",0,4);
c = 2;
lcd.refresh();
}
else if(d == N && c == 2){
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal",0,2);
lcd.printString(" Difficult <",0,3);
lcd.printString(" Hell",0,4);
c = 1;
lcd.refresh();
}
else if(d == S && c == 2){
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal",0,2);
lcd.printString(" Difficult",0,3);
lcd.printString(" Hell <",0,4);
c = 3;
lcd.refresh();
}
else if(d == S && c == 3){
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal",0,2);
lcd.printString(" Difficult",0,3);
lcd.printString(" Hell <",0,4);
c = 3;
lcd.refresh();
}
else if(d == N && c == 3){
lcd.clear();
lcd.printString(" Speed set",0,0);
lcd.printString(" B to set",0,1);
lcd.printString(" Normal",0,2);
lcd.printString(" Difficult <",0,3);
lcd.printString(" Hell",0,4);
c = 2;
lcd.refresh();
}
wait(0.3);
if(c == 1 && pad.check_event(Gamepad::B_PRESSED) == true) {
snake._speed = 0;
lcd.clear();
lcd.printString(" set success!",0,2);
lcd.printString(" Press Back!",0,4);
lcd.refresh();
}
else if(c == 2 && pad.check_event(Gamepad::B_PRESSED) == true) {
snake._speed = 10;
lcd.clear();
lcd.printString(" set success!",0,2);
lcd.printString(" Press Back!",0,4);
lcd.refresh();
}
else if(c == 3 && pad.check_event(Gamepad::B_PRESSED) == true) {
snake._speed = 50;
lcd.clear();
lcd.printString(" set success",0,2);
lcd.printString(" Press Back!",0,4);
lcd.refresh();
}
if(pad.check_event(Gamepad::BACK_PRESSED) == true){
IsCheck = true;
}
}
if(pad.check_event(Gamepad::BACK_PRESSED) == true){
break;
}
}
}
if(d == S && q == 1){
lcd.clear();
lcd.printString(" Menu",0,0);
lcd.printString(" A to set",0,1);
lcd.printString("set speed",0,2);
lcd.printString("history <",0,3);
lcd.printString(" press start",0,5);
lcd.refresh();
q = 2;
}
if(d == S && q == 2){
lcd.clear();
lcd.printString(" Menu",0,0);
lcd.printString(" A to set",0,1);
lcd.printString("set speed",0,2);
lcd.printString("history <",0,3);
lcd.printString(" press start",0,5);
lcd.refresh();
q = 2;
}
if(d == N && q == 2) {
lcd.clear();
lcd.printString(" Menu",0,0);
lcd.printString(" A to set",0,1);
lcd.printString("set speed <",0,2);
lcd.printString("history ",0,3);
lcd.printString(" press start",0,5);
lcd.refresh();
q = 1;
}
if(q == 2 && pad.check_event(Gamepad::A_PRESSED) == true) {
lcd.clear();
sprintf(_Buffer,"%2d",snake.Highest_score);
lcd.printString(_Buffer,24,3);
lcd.printString("Highest score",0,1);
lcd.printString(" Press Back",0,4);
lcd.refresh();
while(pad.check_event(Gamepad::BACK_PRESSED) == false){
}
lcd.clear();
lcd.printString("MOVE joystick",0,1);
lcd.refresh();
}
pad.leds_on();
wait(0.1);
pad.leds_off();
wait(0.1);
}
lcd.clear();
lcd.printString(" start!!!",0,1);
lcd.printString("Enjoy yourself",0,3);
lcd.refresh();
wait(2);
}