1

我正在编写一个游戏,你是一只蜘蛛,你试图避免火灾。我正在对火进行编码,当它击中右边缘时,它会返回左边缘并无限地上下移动。我使用学校免费软件的代码作为基础,并进行了一些修改“弹跳球动画”

test1.xdest并且test1.ydest没有在其他任何地方被调用,而是在sub bouncemain 中do loop。我不确定它为什么这样做。

SCREEN _NEWIMAGE(640, 480, 32)
RANDOMIZE TIMER
TYPE test 'player info
    x AS INTEGER
    y AS INTEGER
END TYPE

TYPE test1 'fire info
    x AS INTEGER
    y AS INTEGER
    xdest AS INTEGER
    ydest AS INTEGER
    number AS INTEGER
    fire AS LONG
END TYPE

DIM SHARED spider AS test
DIM SHARED test1 AS test1
test1.x = 0 'fire x chord
test1.y = 0 'fire y chord

test1.xdest = 1 '1 if fire is moving right 0 left
test1.ydest = 0 '1 up 0 down
test1.fire = _LOADIMAGE("./fire.png")

DO
    PCOPY 1, _DISPLAY
    CLS
    IF _KEYDOWN(18432) THEN spider.y = spider.y - 5
    IF _KEYDOWN(20480) THEN spider.y = spider.y + 5

    IF _KEYDOWN(19200) THEN spider.x = spider.x - 5
    IF _KEYDOWN(19712) THEN spider.x = spider.x + 5
    CIRCLE (spider.x, spider.y), 5, _RGB(177, 83, 127)
    _PUTIMAGE (test1.x, test1.y), test1.fire
    IF test1.xdest = 1 THEN test1.x = test1.x + 5
    IF test1.xdest = 0 THEN test1.x = text1.x - 5

    IF test1.ydest = 1 THEN test1.y = test1.y - 5
    IF test1.ydest = 0 THEN test1.y = test1.y + 5

    bounce
    border

    WAIT &H3DA, &H3DA
    WAIT &H3DA, &H3DA, 8
    _DISPLAY
    PCOPY _DISPLAY, 1
LOOP

SUB bounce 'makes the fire bounce
    IF test1.x >= 628 THEN
        test1.xdest = 0
    END IF
    IF test1.x <= 0 THEN
        text1.xdest = 1
    END IF
    IF test1.y >= 468 THEN
        test1.ydest = 1
    END IF
    IF test1.y <= 0 THEN
        test1.ydest = 0
    END IF
END SUB
SUB border 'prevents palyer from going OOB
    IF spider.x > 630 THEN spider.x = spider.x - 5
    IF spider.x < 0 THEN spider.x = spider.x + 5
    IF spider.y > 470 THEN spider.y = spider.y - 5
    IF spider.y < 0 THEN spider.y = spider.y + 5
END SUB
4

2 回答 2

0

这个程序的问题是有几个错别字

  • 在第 37 行,您错误地写成了te x t1.x。应该是te s t1.x
  • 在第 56 行,您错误地写了te x t1.xdest。应该是te s t1.xdest

如果你想使用,你可以使代码更有效率ELSE IF

IF test1.x >= 628 THEN
    test1.xdest = 0
ELSE IF test1.x <= 0 THEN
    test1.xdest = 1
END IF
IF test1.y >= 468 THEN
    test1.ydest = 1
ELSE IF test1.y <= 0 THEN
    test1.ydest = 0
END IF
于 2020-08-24T16:46:13.203 回答
0

我想通了,在第 37 行,我拼错了我的一个变量,我把text1.x而不是test1.x

于 2020-06-01T21:11:09.300 回答