玩家精灵在按住移动键时移动而无需输入
Posted
技术标签:
【中文标题】玩家精灵在按住移动键时移动而无需输入【英文标题】:Player Sprite Moving without input when movement key is held 【发布时间】:2019-09-13 03:07:21 【问题描述】:每当我按住 D 或右箭头,然后松开,我的玩家精灵就会在我没有输入动作的情况下移动。此外,每当我移动时,僵尸精灵就会闪烁。我还想帮助我弄清楚如何让我的地图加载到游戏中。它目前只有 2 个精灵,但我认为绘制时间不够快,无法在屏幕清除之前完全加载。
RANDOMIZE TIMER
SCREEN _NEWIMAGE(800, 600, 32), 2
load_map
x = 0
y = 0
u = INT(RND * 450) + 50
o = 100
i = 0
t = 55
b = 143
DIM SHARED x AS INTEGER 'player coords
DIM SHARED y AS INTEGER 'player coords
DIM SHARED u AS INTEGER 'enemy coords
DIM SHARED o AS INTEGER 'enemy coords
DIM SHARED i AS INTEGER 'true/false for taking damage
DIM SHARED t AS INTEGER 'health pack coords
DIM SHARED v AS INTEGER 'health pack coords
DIM SHARED Keypress AS STRING
DIM SHARED player AS LONG
DIM SHARED zombie AS LONG
DIM SHARED map_data(800, 600) AS INTEGER
DIM SHARED Heath AS LONG
DIM SHARED healthpack AS LONG
player = _LOADIMAGE("TopDown\Sprites\3.png")
house = _LOADIMAGE("TopDown\Sprites\2.png")
zombie = _LOADIMAGE("TopDown\Sprites\4.png")
healthpack = _LOADIMAGE("TopDown\Sprites\5.png")
health = 100
u = INT(RND * 450) + 50
o = 100
TIMER ON
ON TIMER(.2) enemyai
DO
DO
PRINT health
Take_damage
Heal
_PUTIMAGE (x, y), player
_PUTIMAGE (t, v), healthpack
load_map
DO
Keypress = UCASE$(INKEY$)
IF LEN(Keypress) > 1 THEN Keypress = RIGHT$(Keypress, 1)
LOOP UNTIL Keypress > ""
load_map
CLS
SELECT CASE Keypress
CASE "W", "H": y = y - 10 'Up
CASE "A", "K": x = x - 10 'Left
CASE "S", "P": y = y + 10 'Down
CASE "D", "M": x = x + 10 'Right
CASE "Q", CHR$(27): END 'Q or Esc Ends prog.
END SELECT
_PUTIMAGE (x, y), player
LOOP UNTIL Keypress = ""
LOOP
SUB enemyai
o = o + 1
_PUTIMAGE (o, u), zombie
END SUB
SUB load_map
OPEN "TopDown\map.dat" FOR INPUT AS #1
FOR a = 0 TO (780 \ 16)
FOR b = 0 TO (580 \ 10)
INPUT #1, map_data(a, b)
NEXT
NEXT
CLOSE #1
END SUB
SUB Take_damage
IF x AND y = o AND u THEN
health = health - 5
END IF
END SUB
SUB Heal
IF x AND y = t AND v THEN
health = health + 10
ELSEIF health > 100 THEN
health = 100
END IF
END SUB
我正在寻找的是玩家只有在我输入移动时才会移动。可能是要加载的地图,当我移动时僵尸精灵不会闪烁,
我会一直努力寻找帮助的人,如果我发现任何问题,我会更新
Sprites 文件、Map.dat 以及我用于游戏和地图创建者的所有代码。 https://drive.google.com/drive/folders/1f_c8_3cbJi6yB4WXpQT4JjjLrHJRJEZ-?usp=sharing
【问题讨论】:
【参考方案1】:我能够得到帮助来解决我的问题
DIM SHARED BackGround&
gob$ = STR$(h)
gb$ = RTRIM$(LTRIM$(gob$))
'in do loop
_PUTIMAGE , MIX&, _DISPLAY
_DELAY .05
ClearLayer MIX&
'in sub load
_PUTIMAGE , BackGround&, _DISPLAY
'new subroutine
SUB ClearLayer (L&) 'prevents overlaping of sprites
_DEST L&
CLS
_DEST _DISPLAY
END SUB
【讨论】:
以上是关于玩家精灵在按住移动键时移动而无需输入的主要内容,如果未能解决你的问题,请参考以下文章