Question

First of all, I'm using MASM in windows os. I'm trying to make an animation character 'O' that can be moved by the user and I chose A, W, S, and D to move it. The code works fine, however, the borders are blinking + the O can penetrates them.

Any idea how to fix this? I need the O to be moved ONLY in certain margins, which means it shouldn't go beyond my boarders.

        INCLUDE Irvine32.inc

        Displayshape Macro
                  mov edx, offset shape
                  call writestring
    endm

          setcur macro dl, dh
    local bottom, quit, xcor, ycor, row, col, shape


    .data
    xcor byte "Xcor is out of range",0
    ycor byte "Ycor is out of range",0

    .code
    bottom:
    .IF ( DL <0) || (DL > 79)
    lea edx, xcor
              call writestring
              jmp quit
    .ENDIF
    .IF( DH<0) || ( DH> 24)

    lea edx, ycor
            call writestring
              jmp quit
    .ENDIF
              call gotoxy
    repeat 80
    add dl, 1
              mov eax, '*'
              call writechar
    endm
    quit:
    endm

    .DATA
    row db ?
    col db ?
    shape db 'O',0
    .code
    main PROC


    second:
      mov eax, white + (Blue*16)
      call setTextcolor
      call clrscr
      mov eax, white + (blue * 16)
      call setTextColor
      mov dh, 15
      mov dl, 30
      call gotoxy
      mov row, dh
      mov col, dl
    displayshape
      call           moveit
      call crlf

    exit ; exit to operating system
    main ENDP




      moveit proc
      mov eax, white + ( blue * 16 )
      call setTextcolor
    Get_key:
      call readchar

      cmp al, 'w'
    je moveup
      cmp al, 's'
    je  movedown
      cmp al, 'a'
    je  moveleft
      cmp al, 'd'
    je  moveright
      jmp exit1

      moveup:
      call clrscr
           mov dl, 0
      mov dh, 20
      setcur dl, dh
      mov dl, 0
      mov dh, 0
      mov dh, 2
      setcur dl, dh
      mov dh, row
    sub dh, 1
      mov dl, col
      call gotoxy
      mov row, dh 
      mov col, dl
    Displayshape
      jmp get_key

      movedown:
      call clrscr
           mov dl, 0
      mov dh, 20
      setcur dl, dh
      mov dl, 0
      mov dh, 0
      mov dh, 2
      setcur dl, dh
      mov dh, row
    add dh, 1 ;           move down needs incrementation
      mov dl, col
      call gotoxy
      mov row, dh 
      mov col, dl
    Displayshape
      jmp get_key

      moveright:
      call clrscr
           mov dl, 0
      mov dh, 20
      setcur dl, dh
      mov dl, 0
      mov dh, 0
      mov dh, 2
      setcur dl, dh
      mov dl, col
    add dl, 2
      mov dh, row
      call gotoxy
      mov row, dh 
      mov col, dl
    Displayshape
      jmp get_key

      moveleft:
      call clrscr
           mov dl, 0
      mov dh, 20
      setcur dl, dh
      mov dl, 0
      mov dh, 0
      mov dh, 2
      setcur dl, dh
      mov dl, col
    sub dl, 2
      mov dh, row
      call gotoxy
      mov row, dh 
      mov col, dl
    Displayshape
      jmp get_key
    exit1:
    ret
      moveit endp


    END main
Was it helpful?

Solution

I used an if statement in the method to the margins

such as : .if(dl > 77)

and it worked !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top