当前位置:网站首页>【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高级编程语言
边栏推荐
猜你喜欢
【Arduino connects SD card module to realize data reading and writing】
从Attention到Self-Attention和Multi-Head Attention
目标检测(一):R-CNN系列
【科普贴】SD卡接口协议详解
联阳(ITE)IT66021FN:HDMI转RGB芯片 3D 资料
Industry where edge gateway strong?
Personal image bed construction based on Alibaba Cloud OSS+PicGo
Type c PD 电路设计
《scala 编程(第3版)》学习笔记3
2020 - AAAI - 图像修复 Image Inpainting论文导读 -《Region Normalization for Image Inpainting》
随机推荐
Scala 中的集合(二):集合性能比较
倍福ET2000侦听器使用
字符串匹配(蛮力法+KMP)
Arduino点亮数码管
引擎开发日志:场景编辑器开发难点
Cadence allegro导出Gerber文件(制板文件)图文操作
《scala 编程(第3版)》学习笔记2
联阳(ITE)IT66021FN:HDMI转RGB芯片 3D 资料
【DS3231 RTC实时时钟模块与Arduino接口构建数字时钟】
兼容C51与STM32的Keil5安装方法
【科普贴】MDIO接口详解
GM7150,振芯科技,视频解码器,CVBS转BT656/601,QFN32,替换TVP5150/CJC5150
树莓派入门(1)系统镜像烧录
【Arduino 连接GP2Y1014AU0F 灰尘传感器】
【opencv】error: (-215:Assertion failed) ssize.empty() in function ‘cv::resize‘报错原因
案例|工业物联网解决方案·智慧钢厂高性能安全数采
MOS管开关原理及应用详解
基于树莓派的智能箱包开发环境搭建
MPU6050 加速度计和陀螺仪传感器与 Arduino 连接
【科普贴】SPI接口详解