Weekly Qbasic and Qb64 Lesson Topics
July 18, 2018, 07:51:52 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Character Movement Help


Pages: [1]
  Print  
Author Topic: Character Movement Help  (Read 75 times)
rynsp8
Newbie
*
Posts: 1


« on: May 30, 2016, 12:20:38 pm »

I'm having difficulty with a concept I'm trying to learn: character movement.  I've gotten my 'character' to display on screen; it's just a green dot with a white perimeter, and I can make it move using the arrow keys, but for some reason, it moves the 'character' but leaves a copy in the previous location.  The code is below:

-----------------------------------------------------------
_TITLE "character movement"
DIM SHARED scrn&, character&
DIM SHARED white&, green&, black&
scrn& = _NEWIMAGE(800, 600, 32)

SCREEN scrn&
CALL MakeColors

CALL MakeCharacter
character_x = 20
character_y = 20
gameover$ = "false"

DO

    CALL MakeCharacter
    _PUTIMAGE (character_x, character_y), character&, scrn&
    _DISPLAY

    k$ = INKEY$
    IF k$ <> "" THEN
        code = ASC(k$)
        IF code = 0 THEN
            code = ASC(k$, 2)
            IF code = 72 THEN 'move up
                character_y = character_y - 5
            ELSEIF code = 80 THEN 'move down
                character_y = character_y + 5
            ELSEIF code = 75 THEN 'move left
                character_x = character_x - 5
            ELSEIF code = 77 THEN 'move right
                character_x = character_x + 5
            END IF
        ELSE
            IF k$ = CHR$(27) THEN gameover$ = "true"
        END IF
    END IF
LOOP UNTIL gameover$ = "true"
SYSTEM

SUB MakeCharacter ()
character& = _NEWIMAGE(30, 30)
_DEST character&
CIRCLE (20, 17), 6, white&
PAINT (20, 17), green&, white&
END SUB

SUB MakeColors ()
white& = _RGB(255, 255, 255)
green& = _RGB(0, 255, 0)
black& = _RGB(0, 0, 0)
END SUB
---------------------------------------------------------------------

I've been going over it for a few days but I'm not making any headway.
Report Spam   Logged

Social Buttons


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Buy traffic for your forum/website
traffic-masters
Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy