当前位置:网站首页>【plang 1.4.4】编写茶几玛丽脚本
【plang 1.4.4】编写茶几玛丽脚本
2022-08-02 03:29:00 【ChivenZhang】
本着测试plang语言工具健壮性的初衷,再次打起了写小游戏的念头。但是一想到是用命令行作为显示端,就觉得头皮发麻。
今天做的叫做茶几玛丽(四不像),还是硬着头皮上代码。
先设计玛丽类:
package mario;
import std::IO;
import std::Type;
import std::TIME;
public class Mario : GameObject
{
public Mario()
{
super();
}
public update()
{
gui.draw(x+offX, y+offY, 'm');
}
public update(x->int, y->int)->boolean
{
if(run)
{
time->long = TIME.clock();
t->float = (time-lastTime) * 0.001;
v0->float = -20;
offY = v0 * t + 20 * t * t;
offX += x==0 ? 0f : (x<0 ? -0.5f : 0.5f);
if(offY >0)
{
lastTime = TIME.clock();
run = false;
}
}
return run;
}
public reset()
{
lastTime = TIME.clock();
run = true;
}
public getX()->int
{
return x + offX;
}
public getY()->int
{
return y + offY;
}
x->int = 5;
y->int = 10;
offX->float = 0;
offY->float = 0;
run->boolean = false;
lastTime->long = TIME.clock();
}
再设计蘑菇类:
package mario;
public class MushRoom : GameObject
{
public MushRoom()
{
super();
}
public update()
{
gui.draw(x + offX, y,'#');
}
public update(x->int, y->int)->boolean
{
if(run)
{
offX += 1;
if(offX > 20) run = false;
}
else
{
offX -= 1;
if(offX < -20) run = true;
}
return false;
}
public getX()->int
{
return x + offX;
}
public getY()->int
{
return y;
}
x->int = 20;
y->int = 10;
run->boolean = true;
offX->float = 0;
}
万事俱备,只欠场景类。动起来。。
import std::IO;
import std::Type;
import mario::Mario;
import mario::MushRoom;
import std::IOEXT;
import std::OS;
public class Main
{
public static main()
{
m->Mario = new Mario();
n->MushRoom = new MushRoom();
L->int = 0;
R->int = 50;
T->int = 0;
B->int = 20;
offX->int = 1;
offY->int = 0;
while(true)
{
OS.system("cls");
a->int = IOEXT.key('A');
d->int = IOEXT.key('D');
w->int = IOEXT.key('W');
s->int = IOEXT.key('S');
q->int = IOEXT.key('Q');
if(q != 0)
{
break;
}
if(a != 0 && d != 0)
{
;
}
else if(a != 0)
{
offX = -1;
m.reset();
}
else if(d != 0)
{
offX = 1;
m.reset();
}
if(offX != 0)
{
if(m.update(offX, offY) == false)
{
offX = 0;
}
}
if(n.getX() == m.getX() && n.getY() == m.getY())
{
break;
}
n.update(0,0);
m.update();
n.update();
co_yield null;
}
IO.printf("game over!");
}
}
运行截图:
源代码远程仓库:https://github.com/ChivenZhang/plang-demo
自研产品介绍:Plang高级编程语言
边栏推荐
- How to quickly build your own IoT platform?
- VCA821可变增益放大器
- 关于IIC SDA毛刺的那些事
- 2020 - AAAI - Image Inpainting论文导读《Learning to Incorporate Structure Knowledge for Image Inpainting》
- 使用批处理脚本修改hosts文件
- Two-Stream Convolutional Networks for Action Recognition in Videos双流网络论文精读
- 2019 - ICCV - 图像修复 Image Inpainting 论文导读《StructureFlow: Image Inpainting via Structure-aware ~~》
- 【MQ-3 酒精检测器与 Arduino检测酒精】
- Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset I3D论文精读
- IoT solution
猜你喜欢
Transformer结构解析及常见问题
回溯法 & 分支限界 - 2
Arduino点亮数码管
工业边缘网关究竟强大在哪里?
[Arduino uses a rotary encoder module]
【科普贴】SD卡接口协议详解
[Spark]-协同过滤
与TI的lvds芯片兼容-GM8284DD,GM8285C,GM8913,GM8914,GM8905C,GM8906C,国腾振芯LVDS类芯片,
Arduino lights up nixie tubes
[Popular Science Post] I2C Communication Protocol Detailed Explanation - Partial Software Analysis and Logic Analyzer Example Analysis
随机推荐
Scala 中的集合(二):集合性能比较
【plang 1.4.5】编写坦克(双人)游戏脚本
Type c PD 电路设计
[Arduino connects the clock module to display the time on LCD1602]
使用Vercel托管自己的网站
【树莓派入门(2)树莓派的远程控制】
如何在 Scala 中科学地操作 collection(一):集合类型与操作
Comparative analysis of mobile cloud IoT pre-research and Alibaba Cloud development
【科普贴】UART接口通讯协议
TQP3M9009电路设计
AD PCB导出Gerber文件(非常详细的步骤)
无源域适应(SFDA)方向的领域探究和论文复现(第二部分)
[Spark]-LSH局部敏感哈希
Typora use
Quo Vadis, Action Recognition? A New Model and the Kinetics Dataset I3D论文精读
How to remotely debug PLC?
【plang1.4.3】编写水母动画脚本
USB HUB USB集线器电路设计
龙讯LT6911系列C/UXC/UXB/GXC/GXB芯片功能区别阐述
uniCloud通讯录实战