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.
MinerEngine/MinerEngine.cpp
- Committer:
- ZhongYufan
- Date:
- 2020-04-27
- Revision:
- 11:9da147cd7c18
- Parent:
- 10:51870f8e2e1a
- Child:
- 12:07a9f2140d9b
File content as of revision 11:9da147cd7c18:
#include "MinerEngine.h"
MinerEngine::MinerEngine()
{
}
MinerEngine::~MinerEngine()
{
}
int sprite[48][84] = {
// *10 *20 *30 *40 *50 *60 *70 *80
/*1 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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 },
/*2 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1,1 },
/*3 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1 },
/*4 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,1,1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1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
/*46 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
/*47 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
/*48 */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};
int arrow[8][8] = {
{0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,1,0,0,0,0,0},
{0,1,1,1,1,1,0,0},
{0,0,1,0,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,0,0,0,0,0},
};
void MinerEngine::init(int winch_width,int winch_height,int gold_num,int monster_speed)
{
// initialise the game parameters
_winch_width = winch_width;
_winch_height = winch_height;
_gold_num = gold_num;
_monster_speed = monster_speed;
_winch.init(_winch_height,_winch_width);
_monster.init(_monster_speed);
_claw.init(_winch_width);
_gold.init(_gold_num);
_s = 1;
_state = 0;
_catching = 0;//是否正在抓取,x轴锁定
_claw_get = 0;//是否已经碰到金子
_monster_collision=0;//是否撞到怪物
_now_score = 0;
_highest_score = 0;
for (int i=0;i<9;i++) {
_gold_reached_num[i] = 0;
}
}
///////////////
void MinerEngine::state_switch(Gamepad &pad, N5110 &lcd)
{
while(1){
switch(_state) {
case 0:
menu(pad,lcd) ;
break;
case 1:
instruction(pad,lcd);
break;
case 2:
options(pad,lcd);
break;
case 3:
game_run(pad,lcd);
break;
case 4:
game_over(pad,lcd);
break;
}
}
}
int MinerEngine::get_select(Gamepad &pad) {
if ( pad.check_event(Gamepad::Y_PRESSED) == true && _s >0) {
_s--;
}else if ( pad.check_event(Gamepad::A_PRESSED) == true && _s < 2) {
_s++;
}
return _s;
}
void MinerEngine::instruction(Gamepad &pad, N5110 &lcd) {
lcd.clear();
lcd.printString(" Instructions",4,2);//testing
lcd.refresh();
}
void MinerEngine::menu(Gamepad &pad, N5110 &lcd) {
while ( pad.check_event(Gamepad::START_PRESSED) == false && pad.check_event(Gamepad::JOY_PRESSED) == false) {
lcd.clear();
_s = get_select(pad); // get the selection
lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
lcd.drawRect(1,1,WIDTH-2,HEIGHT-2,FILL_TRANSPARENT);
lcd.printString(" Press Y or A",2,1); // print the instruction
lcd.printString(" Instructions",4,2);
lcd.printString(" Start Game",4,3);
lcd.printString(" Options",4,4);
if ( _s == 1 ) {
lcd.drawSprite(65,24,8,8,(int *)arrow);
}else if ( _s == 2) {
lcd.drawSprite(65,32,8,8,(int *)arrow);
}else if( _s == 0) {
lcd.drawSprite(65,16,8,8,(int *)arrow);
}
lcd.refresh();
}
if ( _s == 0) { // select the game
//select(pad,lcd);
_state = 1;
}
else if ( _s == 1){
_state = 3;
}
else if (_s == 2){
_state = 2;
}
}
void MinerEngine::options(Gamepad &pad, N5110 &lcd) {
while ( pad.check_event(Gamepad::START_PRESSED) == false && pad.check_event(Gamepad::JOY_PRESSED) == false) {
lcd.clear();
int _s = get_select(pad);
lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
lcd.drawRect(1,1,WIDTH-2,HEIGHT-2,FILL_TRANSPARENT);
lcd.printString(" Press Y or A",2,1);
lcd.printString(" Easy",4,2);
lcd.printString(" Normal",4,3);
lcd.printString(" Hard",4,4);
if ( _s == 0) {
lcd.drawSprite(63,15,8,8,(int *)arrow);
_monster_speed = 1; // change the speed_winch
}else if ( _s == 1 ) {
lcd.drawSprite(63,24,8,8,(int *)arrow);
_monster_speed = 2;
}else if ( _s == 2) {
lcd.drawSprite(63,32,8,8,(int *)arrow);
_monster_speed = 3;
}
lcd.refresh();
}
_state = 0;
}
void MinerEngine::game_run(Gamepad &pad, N5110 &lcd) {
_monster_collision=0;
while(_monster_collision==0) {
lcd.clear();
read_input(pad);
update(pad);
draw(lcd);
lcd.refresh();
}
}
/////////////
/////////////
void MinerEngine::check_gold_collision(Gamepad &pad)//只检查金子Y<=13
{
for (int i=0;i<9;i++) {
if (_gold_reached_num[i]==0) {
Vector2D gold_pos = _gold.get_pos(i);
if (gold_pos.y <= 14) {
_claw_get=0;
_now_score++;
_claw.add_now_score();
_gold_reached_num[i] = 1;
//pad.tone(1500.0,0.5);
pad.leds_on();
wait(0.5);
pad.leds_off();
}
}
}
}
void MinerEngine::print_scores(N5110 &lcd) {
// get scores from winchs
int highest_score = _winch.get_highest_score();
// print to LCD
char buffer1[14];
sprintf(buffer1,"%2d",_now_score);
lcd.printString(buffer1,1,0); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
if (_now_score>_highest_score) {
_highest_score = _now_score;
}
char buffer2[14];
sprintf(buffer2,"%2d",_highest_score);
lcd.printString(buffer2,WIDTH-13,0);
}
void MinerEngine::read_input(Gamepad &pad)
{
_d = pad.get_direction();
_mag = pad.get_mag();
if (pad.check_event(Gamepad::A_PRESSED) == true){
_catching=1;
_claw.set_velocity(1.0);
}
}
void MinerEngine::draw(N5110 &lcd)
{
// draw the elements in the LCD buffer
// pitch
lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
//horizontal line
lcd.drawLine(0,13,WIDTH,13,1);
lcd.drawLine(0,0,WIDTH,0,0);
print_scores(lcd);
_winch.draw(lcd);
_claw.draw(lcd);
_gold.draw(lcd);
_monster.draw(lcd);
}
void MinerEngine::update(Gamepad &pad)
{
if (_catching==0) {
_winch.update(_d,_mag);
}
Vector2D winch_pos = _winch.get_pos();
_claw.update(_d,_mag,winch_pos);
wait(0.05);
_monster.update();
wait(0.05);
_gold.update();
check_monster_collision(pad);
check_claw_collision(pad);
check_gold_collision(pad);
check_gold_reload();
}
void MinerEngine::check_monster_collision(Gamepad &pad)
{
// read current claw attributes
Vector2D claw_pos = _claw.get_pos();
int monster_x = _monster.get_pos();
if (monster_x==claw_pos.x && claw_pos.y>=22) {
_monster_collision=1;
_state=4;
pad.tone(750.0,0.1);// audio feedback
}
}
void MinerEngine::check_claw_collision(Gamepad &pad)
{
Vector2D claw_pos = _claw.get_pos();// read current claw attributes
for (int i=0;i<9;i++) {
if (_gold_reached_num[i]==0) {
Vector2D gold_pos = _gold.get_pos(i);
if (claw_pos.x-gold_pos.x<5&&
claw_pos.x-gold_pos.x>-5&&
(claw_pos.y+3)-gold_pos.y>-2) {
_claw_get=1;
_gold.gold_caught(i);
pad.tone(1000.0,0.1); }// audio feedback
}
}
if (claw_pos.y>HEIGHT-4||_claw_get==1) {
//_claw_get=0;
_claw.set_velocity(-1.0);
pad.tone(1500.0,0.1);
pad.leds_on();
wait(0.2);
pad.leds_off();
}
if (claw_pos.y<=14) {
_claw.set_velocity(0.0);
_catching = 0;
}
}
//void MinerEngine::claw_down(Gamepad &pad){
//}
/////////////////////////////////////////////////////
void MinerEngine::welcome(Gamepad &pad, N5110 &lcd) {
lcd.drawSprite(0,0,48,84,(int *)sprite);
lcd.drawRect(4,31,25,9, FILL_WHITE);
lcd.drawRect(4,39,31,10, FILL_WHITE);
lcd.printString("GOLD",5,4);
lcd.printString("MINER",5,5);
lcd.drawLine(0,47,84,47,1);
lcd.refresh();
// while ( pad.check_event(Gamepad::START_PRESSED) == false) {
// play_music(pad);
//}
// screen_rollup(pad,lcd);
// loading(pad,lcd);
}
void MinerEngine::game_over(Gamepad &pad, N5110 &lcd) {
lcd.clear();
while ( pad.check_event(Gamepad::START_PRESSED) == false
&& pad.check_event(Gamepad::JOY_PRESSED) == false
&& pad.check_event(Gamepad::BACK_PRESSED) == false)
{
lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
lcd.drawRect(1,1,WIDTH-2,HEIGHT-2,FILL_TRANSPARENT);
lcd.printString(" !! Game Over !! ",2,2);
lcd.printString(" Press [back] to menu",4,3);
lcd.printString(" press [start] to restart",4,4);
lcd.refresh();
}
if (pad.check_event(Gamepad::START_PRESSED) == true
||pad.check_event(Gamepad::JOY_PRESSED) == true) {
_state=3;
}
if (pad.check_event(Gamepad::BACK_PRESSED) == true) {
_state=0;
}
}
void MinerEngine::play_music(Gamepad &pad) {
pad.tone(370,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(554,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(493,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(554,0.15);
wait(0.2);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(659,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(554,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(493,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(554,0.15);
wait(0.35);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
pad.tone(554,0.15);
wait(0.2);
pad.leds_on();
wait(0.02);
pad.leds_off();
wait(0.02);
}
void MinerEngine::screen_rollup(Gamepad &pad, N5110 &lcd) {
lcd.clear();
for (int i=0;i<47;i++) {
for(int m=0;m<47;m++) {
for (int n=0;n<84;n++) {
sprite[m][n]= sprite[m+1][n];
sprite[47][n]= 0;
}
}
lcd.drawSprite(0,0,48,84,(int *)sprite);
lcd.refresh();
wait(0.1);
}
}
void MinerEngine::loading(Gamepad &pad, N5110 &lcd) {
lcd.printString("Loading....",12,0);
lcd.drawRect(20,12,50,10,FILL_TRANSPARENT);
for (int i=0;i<50;i++) {
lcd.drawRect(20,12,i,10,FILL_BLACK);
lcd.refresh();
wait(0.05);
}
lcd.printString("Complete!",20,4);
lcd.refresh();
wait(0.8);
lcd.clear();
}
void MinerEngine::check_gold_reload() {
int gold_left = _gold.get_left_num();
if (gold_left<1) {
_gold.init(9);
for (int i=0;i<9;i++) {
_gold_reached_num[i] = 0;
}
}
}