13 Star 72 Fork 26

tuxiaobei/mario

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mushroom.cpp 1.02 KB
一键复制 编辑 原始数据 按行查看 历史
tuxiaobei 提交于 2022-01-04 11:45 . 更新readme.md,添加注释
#include "mushroom.h"
#include "musicplayer.h"
#include "level.h"
Mushroom::Mushroom(char* s)
{
ct = Costume{ 11, 0, 0 };
sscanf(s, "%d%d%d", &ct.b, &ct.c, &direction);
fx = 0;
collider_layer = 4;
id = ++COLLIDER_ID;
freeze = false;
width = 1, height = 1;
maxwx = 75;
name = "mushroom";
show_layer = 2;
}
bool Mushroom::update()
{
if (!isrun) return false;
if (fabs(fx) < EPS && onfloor) fx = 100 * direction;
return false;
}
std::pair<double, double> Mushroom::getctpos()
{
return std::make_pair(sx, sy);
}
Costume Mushroom::getcostume()
{
if (!isshow) return Costume{-1, -1, -1};
return ct;
}
bool Mushroom::report_collision(int direction, Collider* target, int target_collider_layer)
{
if (!isrun) return false;
switch (target_collider_layer) {
case 0: //如果碰到马里奥
level.remove(this);
musicplayer.play("sound-powerup");
break;
case 1: //如果碰到墙
if ((direction == LEFT && fx < 0) || (direction == RIGHT && fx > 0))
fx = -fx, vx = -vx, this->direction = -this->direction;
break;
}
return true;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/tuxiaobei/mario.git
[email protected]:tuxiaobei/mario.git
tuxiaobei
mario
mario
master

搜索帮助