Player Sprite Moving without input when movement key is held

70 Views Asked by At

whenever I hold down either D or Right Arrow,then let go, my player sprite moves without me inputting movement. Also, whenever I do move, the zombie sprite flickers. i also would like help on figuring out how to get my map to load into the game. it currently only has 2 sprites, but I think the Draw time isn't fast enough for it to load fully before the screen clears.

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


what i'm looking for is the player only moving when I input movement. possably the map to load, and the zombie sprite to not flicker when I move,

I will work on this along the way to someone to help, ill update if I figure anything out

Files for Sprites, Map.dat,and all my code for both the game, and the map creator. https://drive.google.com/drive/folders/1f_c8_3cbJi6yB4WXpQT4JjjLrHJRJEZ-?usp=sharing

1

There are 1 best solutions below

0
On

i was able to get help to fix my problem

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