diff --git a/BaseObject.cpp b/BaseObject.cpp index 968bc39..8bcead1 100644 --- a/BaseObject.cpp +++ b/BaseObject.cpp @@ -119,7 +119,7 @@ void BaseObject::update(double time) { //position += velocity * time; velocity += acceleration * time; } -void BaseObject::show(Vector offset) { +void BaseObject::show(Vector& offset) { figure.update(static_cast(round(position.x()) + offset.x()), static_cast(round(position.y()) + offset.y())); } bool BaseObject::block_crash(BaseObject& t) { diff --git a/BaseObject.h b/BaseObject.h index ba5e727..2144b5d 100644 --- a/BaseObject.h +++ b/BaseObject.h @@ -93,7 +93,7 @@ class BaseObject void width(int w); void height(int h); void update(double time); - void show(Vector offset); + void show(Vector& offset); bool block_crash(BaseObject& t); bool pxiel_crash(); }; diff --git a/Global.h b/Global.h index 0d1d5fc..e9616fe 100644 --- a/Global.h +++ b/Global.h @@ -2,8 +2,8 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -#define WINDOWS_WIDTH 640 -#define WINDOWS_HEIGHT 480 +#define WINDOWS_WIDTH 680 +#define WINDOWS_HEIGHT 490 #define DEBUG #ifdef DEBUG diff --git a/Map.cpp b/Map.cpp index 18d4dee..445ee78 100644 --- a/Map.cpp +++ b/Map.cpp @@ -6,13 +6,27 @@ void Map::init(BaseObject* h) loadimage(&background, _T("assets\\images\\map1.png")); _width = background.getwidth(); _height = background.getheight(); + int unit_length = 35; + //单元格为35*35的方格,全地图横向228个单元,纵向14个单元 //注意坐标是从0开始的 - rocket.push_back(Rocket(-1, 0, 1, WINDOWS_HEIGHT)); - rocket.push_back(Rocket(7818, 0, 1, WINDOWS_HEIGHT)); - rocket.push_back(Rocket(0, 411, 2366, 69)); - rocket.push_back(Rocket(2434, 411, 515, 69)); - rocket.push_back(Rocket(3051, 411, 2195, 69)); - rocket.push_back(Rocket(5314, 411, 2503, 69)); + rocket.push_back(Rocket(-1 * unit_length, 0 * unit_length, 1 * unit_length, 14 * unit_length)); + rocket.push_back(Rocket(228 * unit_length, 0 * unit_length, 1 * unit_length, 14 * unit_length)); + rocket.push_back(Rocket(0 * unit_length, 12 * unit_length, 69 * unit_length, 2 * unit_length)); + rocket.push_back(Rocket(71 * unit_length, 12 * unit_length, 15 * unit_length, 2 * unit_length)); + rocket.push_back(Rocket(89 * unit_length, 12 * unit_length, 64 * unit_length, 2 * unit_length)); + rocket.push_back(Rocket(155 * unit_length, 12 * unit_length, 73 * unit_length, 2 * unit_length)); + rocket.push_back(Rocket(0 * unit_length, 14 * unit_length, 227 * unit_length, 1 * unit_length)); + for(int i=0;i<4;i++) + rocket.push_back(Rocket((134+i) * unit_length, (11-i) * unit_length, 1 * unit_length, (i+1) * unit_length)); + for(int i = 0; i < 4; i++) + rocket.push_back(Rocket((140 + i) * unit_length, (8 + i) * unit_length, 1 * unit_length, (4 - i) * unit_length)); + for(int i = 0; i < 4; i++) + rocket.push_back(Rocket((148 + i) * unit_length, (11 - i) * unit_length, (5-i) * unit_length, 1 * unit_length)); + for(int i = 0; i < 4; i++) + rocket.push_back(Rocket((155 + i) * unit_length, (8 + i) * unit_length, 1 * unit_length, (4 - i) * unit_length)); + for(int i = 0; i < 8; i++) + rocket.push_back(Rocket((181 + i) * unit_length, (11 - i) * unit_length, (9 - i) * unit_length, 1 * unit_length)); + rocket.push_back(Rocket(212 * unit_length, 11 * unit_length, 1 * unit_length, 1 * unit_length)); hero = h; } diff --git a/Map.h b/Map.h index f1f7369..9634b5f 100644 --- a/Map.h +++ b/Map.h @@ -3,6 +3,7 @@ #define _MAP_H_ + #include #include "Global.h" #include "Rocket.h" diff --git a/Mario.cpp b/Mario.cpp index 34c5620..52e99b1 100644 --- a/Mario.cpp +++ b/Mario.cpp @@ -1,16 +1,16 @@ #include "Mario.h" -void Mario::run() { +void Mario::run(double speed) { if(direction == RIGHT) - velocity.x(0.3); + velocity.x(speed); else - velocity.x(-0.3); + velocity.x(-speed); } -void Mario::jump() { +void Mario::jump(double speed) { if(figure.status() == "jumpping" || figure.status() == "falling") return; position.y(position.y()); - velocity.y(-1); + velocity.y(speed); } void Mario::still() { diff --git a/Mario.h b/Mario.h index 7626687..b79e2ab 100644 --- a/Mario.h +++ b/Mario.h @@ -2,6 +2,8 @@ #ifndef _MARIO_H_ #define _MARIO_H_ +#define NORMAL_RUN_SPEED 0.3 +#define NORMAL_JUMP_SPEED -1.2 #include #include "BaseObject.h" @@ -16,10 +18,10 @@ class Mario: public BaseObject int direction; public: Mario():BaseObject(),direction(RIGHT){} - void run(); - void jump(); + void run(double speed = NORMAL_RUN_SPEED); + void jump(double speed = NORMAL_JUMP_SPEED); void still(); - void turn(int d); + void turn(int d = RIGHT); void init(); }; diff --git a/assets/images/map1.bmp b/assets/images/map1.bmp deleted file mode 100644 index 028e6c9..0000000 Binary files a/assets/images/map1.bmp and /dev/null differ diff --git a/assets/images/map1.png b/assets/images/map1.png index 491aa9f..252bc77 100644 Binary files a/assets/images/map1.png and b/assets/images/map1.png differ diff --git "a/\350\266\205\347\272\247\351\251\254\351\207\214\345\245\245.exe" "b/\350\266\205\347\272\247\351\251\254\351\207\214\345\245\245.exe" new file mode 100644 index 0000000..ef73f17 Binary files /dev/null and "b/\350\266\205\347\272\247\351\251\254\351\207\214\345\245\245.exe" differ