Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Commit

Permalink
完善地图障碍物
Browse files Browse the repository at this point in the history
  • Loading branch information
Wider committed Apr 11, 2020
1 parent 6d41096 commit 81288db
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion BaseObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(round(position.x()) + offset.x()), static_cast<int>(round(position.y()) + offset.y()));
}
bool BaseObject::block_crash(BaseObject& t) {
Expand Down
2 changes: 1 addition & 1 deletion BaseObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down
4 changes: 2 additions & 2 deletions Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 20 additions & 6 deletions Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define _MAP_H_



#include <graphics.h>
#include "Global.h"
#include "Rocket.h"
Expand Down
10 changes: 5 additions & 5 deletions Mario.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
8 changes: 5 additions & 3 deletions Mario.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#ifndef _MARIO_H_
#define _MARIO_H_

#define NORMAL_RUN_SPEED 0.3
#define NORMAL_JUMP_SPEED -1.2

#include<graphics.h>
#include "BaseObject.h"
Expand All @@ -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();
};

Expand Down
Binary file removed assets/images/map1.bmp
Binary file not shown.
Binary file modified assets/images/map1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 超级马里奥.exe
Binary file not shown.

0 comments on commit 81288db

Please sign in to comment.