当前位置:网站首页>【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高级编程语言
边栏推荐
- 2019 - ICCV - 图像修复 Image Inpainting 论文导读《StructureFlow: Image Inpainting via Structure-aware ~~》
- 最第k大的数的一般性问题
- 单火线开关设计详解
- SyntaxError: unexpected character after line continuation character
- GM7150 CVBS转BT656视频解码芯片详细内容及设计要求
- 简单的RC滤波电路
- 同时求最大值与最小值(看似简单却值得思考~)
- 远程调试PLC,到底如何操作?
- 使用Vercel托管自己的网站
- 龙讯LT6911系列C/UXC/UXB/GXC/GXB芯片功能区别阐述
猜你喜欢
随机推荐
[Arduino connected to GP2Y1014AU0F dust sensor]
完全背包问题(动态规划)
USB2.0一致性测试方法_高速示波器
联阳IT66121FN提供SDI转HDMI方案分享
引擎开发日志:集成Bullet3物理引擎
[Spark]-RDD详解之变量&操作
PCB Design Ideas
【Arduino 连接GP2Y1014AU0F 灰尘传感器】
兼容C51与STM32的Keil5安装方法
博达工业云与阿里云对比
PCB设计思路
MIPI解决方案 ICN6202:MIPI DSI转LVDS转换芯片
基于树莓派的智能箱包开发环境搭建
[Arduino connected to GPS module (NEO-6M) to read positioning data]
【Arduino连接GPS 模块 (NEO-6M)读取定位数据】
单火线开关设计详解
【Popular Science Post】Detailed explanation of MDIO interface
如何快速搭建属于自己的物联网平台?
【Arduino 连接DHT11 湿度和温度传感器】
OneNET Studio与IoT Studio对比分析







![[Arduino connects the clock module to display the time on LCD1602]](/img/88/5baac76a24924d1cfd675ff5da830e.png)

