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.
Revision 3:31ff7b3e2005, committed 2020-05-15
- Comitter:
- Neowless
- Date:
- Fri May 15 20:32:27 2020 +0000
- Parent:
- 2:cc9d8ec2e1f4
- Child:
- 4:c7dc43515215
- Commit message:
- test;
Changed in this revision
--- a/Engine/engine.cpp Fri May 15 17:44:25 2020 +0000
+++ b/Engine/engine.cpp Fri May 15 20:32:27 2020 +0000
@@ -4,12 +4,10 @@
void engine::init(){
}
-events engine::evet_check(chara &p, obs &b, Gamepad &pad){
+events engine::event_check(chara &p, obs &b, Gamepad &pad){
xy pxy = p.getxy();
- int width = p.getwidth();
- int height = p.getheight();
if(b.x>-1){
- if(((pxy.x - b.width < b.x)&&(pxy.x+width>b.x)) &&((pxy.y-b.height<b.y)&&(pxy.y+height>b.y))){
+ if(((pxy.x - b.width < b.x)&&(pxy.x+7>b.x)) &&((pxy.y-b.height<b.y)&&(pxy.y+8>b.y))){
return DEAD;
}
}
--- a/Engine/engine.h Fri May 15 17:44:25 2020 +0000
+++ b/Engine/engine.h Fri May 15 20:32:27 2020 +0000
@@ -1,3 +1,8 @@
+/** My Life Class
+* @dudge the situation of the game
+* @author Huo Yuheng
+* @date May, 2020
+*/
#ifndef ENGINE_H
#define ENGINE_H
@@ -7,7 +12,7 @@
#include "N5110.h"
#include "Gamepad.h"
-
+/** details of obscale */
struct obs{
int x;
int y;
@@ -16,18 +21,17 @@
int *data;
};
-
+/** the situation of the player */
enum events{
DEAD,
- FIRE,
- ELMININATE,
NONE,
};
class engine{
public:
void init();
- events evet_check(chara &p, obs &b, Gamepad &pad);
- void fire(int x,int y);
+ /** check situation */
+ events event_check(chara &p, obs &b, Gamepad &pad);
+ /** making random obscale */
int randomobs();
};
#endif
--- a/chara.cpp Fri May 15 17:44:25 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#include "chara.h"
-
-void chara::init(){
- _width = 7;
- _height = 8;
- int d[56] = {
- 0,0,1,1,1,0,0,
- 0,0,1,0,1,0,0,
- 0,0,1,1,1,0,0,
- 1,1,0,1,0,0,0,
- 1,0,1,1,1,1,0,
- 1,0,1,1,0,0,0,
- 1,1,0,0,1,0,0,
- 0,0,0,0,1,0,0
- };
- for(int i = 0; i<56;i++){
- data[i] = d[i];
- }
- _xy.x = 0;
- _xy.y = 25;
-}
-
-void chara::update(Gamepad &pad, FXOS8700CQ &device){
- Data values = device.get_values();
-
- if(pad.get_direction() == N){
- _xy.y = _xy.y -4;
- }else{
- _xy.y = _xy.y + 2;
- }
-
- if(values.ay>=0){
- _xy.x = _xy.x - int(values.ay*10);
- }else if(values.ay<=0){
- _xy.x = _xy.x - int(values.ay*10);
- }
-
- if(_xy.x>=77){
- _xy.x = 77;
- }else if(_xy.x<=0){
- _xy.x=0;
- }
- if(_xy.y>=41){
- _xy.y = 41 ;
- }else if(_xy.y<=7){
- _xy.y=7;
- }
-}
-
-void chara::display(N5110 &lcd){
- unsigned int width = _width;
- unsigned int height = _height;
- Bitmap p(data, height, width);
- p.render(lcd, _xy.x, _xy.y);
-}
-
-xy chara::getxy(){return _xy;}
-
-int chara::getwidth(){return _width;}
-int chara::getheight(){return _height;}
-
--- a/chara.h Fri May 15 17:44:25 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#ifndef CHARA_H
-#define CHARA_H
-
-#include "Bitmap.h"
-#include "N5110.h"
-#include "Gamepad.h"
-#include "mbed.h"
-#include "FXOS8700CQ.h"
-
-
-struct xy{
- int x;
- int y;
-};
-
-class chara{
- public:
- void init();
- void update(Gamepad &pad, FXOS8700CQ &device);
- void display(N5110 &lcd);
- xy getxy();
- int getwidth();
- int getheight();
-
- private:
- int _height;
- int _width;
- int data[56];
- xy _xy;
-
-};
-#endif
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/chara/chara.cpp Fri May 15 20:32:27 2020 +0000
@@ -0,0 +1,55 @@
+#include "chara.h"
+
+void chara::init(){
+ int d[56] = {
+ 0,0,1,1,1,0,0,
+ 0,0,1,0,1,0,0,
+ 0,0,1,1,1,0,0,
+ 1,1,0,1,0,0,0,
+ 1,0,1,1,1,1,0,
+ 1,0,1,1,0,0,0,
+ 1,1,0,0,1,0,0,
+ 0,0,0,0,1,0,0
+ };
+ for(int i = 0; i<56;i++){
+ data[i] = d[i];
+ }
+ _xy.x = 0;
+ _xy.y = 25;
+}
+
+void chara::update(Gamepad &pad, FXOS8700CQ &device){
+ Data values = device.get_values();
+
+ if(pad.get_direction() == N){
+ _xy.y = _xy.y -4;
+ }else{
+ _xy.y = _xy.y + 2;
+ }
+
+ if(values.ay>=0){
+ _xy.x = _xy.x - int(values.ay*10);
+ }else if(values.ay<=0){
+ _xy.x = _xy.x - int(values.ay*10);
+ }
+
+ if(_xy.x>=77){
+ _xy.x = 77;
+ }else if(_xy.x<=0){
+ _xy.x=0;
+ }
+ if(_xy.y>=41){
+ _xy.y = 41 ;
+ }else if(_xy.y<=7){
+ _xy.y=7;
+ }
+}
+
+void chara::display(N5110 &lcd){
+ Bitmap c(data, 8, 7);
+ c.render(lcd, _xy.x, _xy.y);
+}
+
+xy chara::getxy(){return _xy;}
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/chara/chara.h Fri May 15 20:32:27 2020 +0000
@@ -0,0 +1,39 @@
+/** My Life Class
+* @describe the characteristic
+* @author Huo Yuheng
+* @date May, 2020
+*/
+#ifndef CHARA_H
+#define CHARA_H
+
+#include "Bitmap.h"
+#include "N5110.h"
+#include "Gamepad.h"
+#include "mbed.h"
+#include "FXOS8700CQ.h"
+
+
+struct xy{
+ int x;
+ int y;
+};
+
+class chara{
+ public:
+ /** initialize the function */
+ void init();
+ /** change the position */
+ void update(Gamepad &pad, FXOS8700CQ &device);
+ /** draw the charachteristic*/
+ void display(N5110 &lcd);
+ /** get the postion */
+ xy getxy();
+ private:
+ /** bitmap */
+ int data[56];
+ /** posotion */
+ xy _xy;
+
+};
+#endif
+
--- a/life.cpp Fri May 15 17:44:25 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-#include "life.h"
-
-void life::init(){
- _x = 0;
- _y = 0;
- _num = 3;
- _width = 8;
- _height = 7;
- int d[56] = {
- 0,1,1,0,0,1,1,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,
- 0,1,1,1,1,1,1,0,
- 0,0,1,1,1,1,0,0,
- 0,0,0,1,1,0,0,0
- };
- for(int i = 0; i < 56; i++){
- icon[i] = d[i];
- }
-}
-void life::update(){
- _num = _num - 1;
-}
-void life::display(N5110 &lcd){
- for(int i = 0; i < _num; i++){
- int x = _x + _width*i;
- unsigned int width = _width;
- unsigned int height = _height;
- Bitmap p(icon, height, width);
- p.render(lcd, x, _y);
- }
-}
-
-int life::liferest(){return _num;}
-
--- a/life.h Fri May 15 17:44:25 2020 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#ifndef LIFE_H
-#define LIFE_H
-
-
-#include "Bitmap.h"
-#include "N5110.h"
-#include "Gamepad.h"
-class life{
- public:
- void init();
- void update();
- void display(N5110 &lcd);
- int liferest();
-
- private:
- int _x;
- int _y;
- int _num;
- int _width;
- int _height;
- int icon[56];
-};
-#endif
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/life/life.cpp Fri May 15 20:32:27 2020 +0000
@@ -0,0 +1,28 @@
+#include "life.h"
+
+void life::init(){
+ lives = 3;
+ int d[56] = {
+ 0,1,1,0,0,1,1,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,
+ 0,1,1,1,1,1,1,0,
+ 0,0,1,1,1,1,0,0,
+ 0,0,0,1,1,0,0,0};
+ }
+}
+void life::update(){
+ lives=lives-1;
+
+}
+void life::display(N5110 &lcd){
+ for(int i = 0; i < _num; i++){
+ int x = 0 + 8*i;
+ Bitmap p(icon, 7, 8);
+ p.render(lcd, x, 0);
+ }
+}
+
+int life::liferest(){return _num;}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/life/life.h Fri May 15 20:32:27 2020 +0000
@@ -0,0 +1,32 @@
+
+/** My Life Class
+* @Note the number of lives and draw the lives icon
+* @author Huo Yuheng
+* @date May, 2020
+*/
+class
+#ifndef LIFE_H
+#define LIFE_H
+
+
+#include "Bitmap.h"
+#include "N5110.h"
+#include "Gamepad.h"
+class life{
+ public:
+
+ void init();
+ /** decrease the lives */
+ void update();
+ /** show the remail lives on the display */
+ void display(N5110 &lcd);
+ int liferest();
+
+ private:
+ /**number of lives*/
+ int lives;
+ /** bitmap of lives */
+ int icon[56];
+};
+#endif
+
--- a/main.cpp Fri May 15 17:44:25 2020 +0000
+++ b/main.cpp Fri May 15 20:32:27 2020 +0000
@@ -1,423 +0,0 @@
-#include "Bitmap.h"
-#include "N5110.h"
-#include "Gamepad.h"
-#include "mbed.h"
-#include "FXOS8700CQ.h"
-#include "chara.h"
-#include "life.h"
-#include "engine.h"
-#include "N5110.h"
-#include "Gamepad.h"
-#include<iostream>
-
-using namespace std;
-N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
-FXOS8700CQ device(I2C_SDA,I2C_SCL);
-Gamepad pad;
-chara p;
-life lf;
-engine eg;
-bool n = true;
-obs bo[20];
-int bonum = 0;
-int score = 0;
-int m = 0;
-float fps=15;
-
-void init();
-void welcome();
-void screen();
-void update();
-void gameover();
-void drawBitmap(int x, int y, int width, int height, int *data);
-void setting();
-void renderj(int x, int y);
-void rendere(int x, int y);
-void rendert(int x, int y);
-void renderp(int x, int y);
-void rendera(int x, int y);
-void renderc(int x, int y);
-void renderk(int x, int y);
-
-int main()
-{
- while(1){
- init();
- welcome();
- setting();
-
- while(n){
- if(m%19==0){
- bo[bonum%20].y = eg.randomobs();
- bo[bonum%20].x = 82;
- bonum = bonum + 1;
- }
-
- lcd.clear();
- screen();
- update();
- lcd.refresh();
- cout<<fps<<endl;
- wait(fps);
- m = m + 1;
-
- }
- wait(1);
- }
-}
-
-void init(){
- device.init();
- lcd.init();
- pad.init();
- p.init();
- lf.init();
- eg.init();
- lcd.setContrast(0.5);
- n = true;
-
- bonum = 0;
- score = 0;
- m = 0;
- for(int i = 0; i < 20; i++){
- bo[i].x = -1;
- bo[i].y = -1;
- bo[i].width = 9;
- bo[i].height = 5;
- int data[45]= {
- 0,1,0,1,0,1,0,1,0,
- 1,0,1,0,1,0,1,0,1,
- 1,1,1,1,1,1,1,1,1,
- 1,0,1,0,1,0,1,0,1,
- 0,1,0,1,0,1,0,1,0
-
-
- };
-
- bo[i].data = data;
- }
-}
-
-void renderj(int x,int y){
- int j[153]={
- 1,1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 0,0,0,0,0,0,0,1,1,
- 1,1,0,0,0,0,0,1,1,
- 1,1,0,0,0,0,0,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
- };
- Bitmap jj(j,17,9);
- jj.render(lcd, x, y);
-}
-
-void rendere(int x,int y){
- int e[136]={
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,0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0,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,0
- };
- Bitmap pp(p,17,9);
- pp.render(lcd, x, y);
-}
-
-void rendera(int x,int y){
- int a[136]={
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1
- };
- Bitmap aa(a,17,8);
- aa.render(lcd, x, y);
-}
-
-void renderc(int x,int y){
- int c[136]={
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,0,0,0,0,1,1,
- 1,1,1,1,1,1,1,1,
- 1,1,1,1,1,1,1,1
- };
- Bitmap cc(c,17,8);
- cc.render(lcd, x, y);
-}
-
-void renderk(int x,int y){
- int k[187]={
- 1,1,0,0,0,0,0,0,0,1,1,
- 1,1,0,0,0,0,0,0,1,1,1,
- 1,1,0,0,0,0,0,1,1,1,0,
- 1,1,0,0,0,0,1,1,1,0,0,
- 1,1,0,0,0,1,1,1,0,0,0,
- 1,1,0,0,1,1,1,0,0,0,0,
- 1,1,0,1,1,1,0,0,0,0,0,
- 1,1,1,1,1,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,0,0,0,
- 1,1,0,0,0,0,0,0,0,0,0,
- 1,1,1,1,0,0,0,0,0,0,0,
- 1,1,1,1,1,0,0,0,0,0,0,
- 1,1,0,1,1,1,0,0,0,0,0,
- 1,1,0,0,1,1,1,1,0,0,0,
- 1,1,0,0,0,1,1,1,0,0,0,
- 1,1,0,0,0,0,1,1,1,1,1,
- 1,1,0,0,0,0,0,1,1,1,1
- };
- Bitmap kk(k,17,11);
- kk.render(lcd, x, y);
-}
-
-
-void welcome(){
- lcd.clear();
- for(int i = 1;i<=60;i++){
- lcd.clear();
- int jy = 40-i;
- if (jy<=0){
- jy = 1;
- }
- int ey = 45-i;
- if (ey<=0){
- ey = 1;
- }
- int ty = 50-i;
- if (ty<=0){
- ty = 1;
- }
- int py = 50-i;
- if (py<=0){
- py = 1;
- }
- int ay = 52-i;
- if (ay<=0){
- ay = 1;
- }
- int cy = 54-i;
- if (cy<=0){
- cy = 1;
- }
- int ky = 56-i;
- if (ky<=0){
- ky = 1;
- }
-
- renderj(6,jy);
- rendere(17,ey);
- rendert(27,ty);
- renderp(39,py);
- rendera(50,ay);
- renderc(60,cy);
- renderk(70,ky);
- wait(0.05);
- lcd.refresh();
- }
- lcd.printString("PERSS START",6,5);
-
- lcd.refresh();
- while( pad.check_event(Gamepad::START_PRESSED) == false){
- pad.leds_on();
- wait(0.1);
- pad.leds_off();
- wait(0.1);
-
- }
-}
-
-void setting(){
- lcd.clear();
- lcd.printString("SET DIFFICULTY",0,0);
- lcd.printString("A EZ",0,2);
- lcd.printString("B Default",0,3);
- lcd.printString("X Difficult",0,4);
- lcd.printString("Y NIGHTMARE",0,5);
- lcd.refresh();
- while(1){
- if( pad.check_event(Gamepad::A_PRESSED) == true){
- fps = 0.2;
- break;
- }
- if( pad.check_event(Gamepad::B_PRESSED) == true){
- fps = 0.1;
- break;
- }
- if( pad.check_event(Gamepad::X_PRESSED) == true){
- fps = 0.05;
- break;
- }
- if( pad.check_event(Gamepad::Y_PRESSED) == true){
- fps = 0.01;
- break;
- }
- pad.leds_on();
- wait(0.1);
- pad.leds_off();
- wait(0.1);
-
- }
-}
-
-void screen(){
- lcd.clear();
- p.display(lcd);
- lf.display(lcd);
- for(int i = 0; i <20; i++){
- if(bo[i].x >=0){
- drawBitmap(bo[i].x, bo[i].y, bo[i].width, bo[i].height, bo[i].data);}
- }
- lcd.refresh();
-}
-
-void update(){
- p.update(pad, device);
- for(int i = 0; i<20; i++){
- for(int j = 0; j < 20; j++){
- events e = eg.evet_check(p, bo[i],pad);
- if(e == DEAD){
- lf.update();
- bo[i].x = -1;
- pad.tone(1000,0.2);
- if(lf.liferest()==0){
- gameover();
- i = 20;
- j = 20;
- pad.tone(1000,0.5);
- break;
- }
- }else if(e == ELMININATE){
- bo[i].x = -1;
- score = score + 5;
- cout <<score<<endl;
- }
- }
- }
- for(int i = 0; i<20; i++){
- if((bo[i].x >=0) && (bo[i].x<=84)){
- bo[i].x = bo[i].x - 1;
- }
- }
-
-}
-
-void gameover(){
- cout <<"game over"<< endl;
- lcd.clear();
- lcd.printString("GAMEOVER ",0,1);
- lcd.printString("SCORE ",0,2);
- char buffer1[14];
- sprintf(buffer1,"%2d",score);
- lcd.printString(buffer1,0,3);
- lcd.printString(" Press A ",0,4);
- lcd.refresh();
- while ( pad.check_event(Gamepad::A_PRESSED) == false) {
- pad.leds_on();
- wait(0.1);
- pad.leds_off();
- wait(0.1);
- }
- n = false;
-}
-
-void drawBitmap(int x, int y, int width, int height, int *data){
- Bitmap p(data, height, width);
- p.render(lcd, x, y);
-}
-