Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;game made by Shaked Stein De Shalit School
- IDEAL
- MODEL small
- STACK 100h
- DATASEG
- p1y dw 75 ;player 1 top y position
- p2y dw 75 ;player 2 top y position
- x dw 160 ;ball x position
- y dw 100 ;ball y position
- vx dw 5 ;ball x velocity
- vy dw 0 ;ball y velocity
- score1 dw 0 ;player 1 score
- score2 dw 0 ;player 2 score
- idk dw 0 ;a variable only used to loop in deleteScore
- p1winmsg db " player 1 won$"
- p2winmsg db " player 2 won$"
- msg3 db " press any key to start again$"
- msg4 db " press esc to exit$"
- note dw 1C3Fh ;note for ball collision with right paddle
- note2 dw 2394h ;note for ball collision with left paddle
- count db 0 ;frame count used for the collision sound
- CODESEG
- proc ClearRight ;clear the area near the right paddle
- push ax
- push bx
- push cx
- push dx
- mov ax,0 ;black color
- mov bx,318 ;right paddle x position
- mov cx,200 ;number of loops - 200 lines of pixels
- Loop2:
- mov [es:bx],ax
- mov [es:bx-1],ax
- mov [es:bx-2],ax
- mov [es:bx-3],ax
- mov [es:bx-4],ax
- mov [es:bx-5],ax
- mov [es:bx-6],ax
- mov [es:bx-7],ax
- mov [es:bx-8],ax
- add bx,320 ;go down one line
- loop Loop2
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp ClearRight
- proc ClearLeft ;clear the area near the left paddle
- push ax
- push bx
- push cx
- push dx
- mov ax,0 ;black color
- mov bx,2 ;left paddle x position
- mov cx,200 ;number of loops
- Loop3:
- mov [es:bx],ax
- mov [es:bx+1],ax
- mov [es:bx+2],ax
- mov [es:bx+3],ax
- mov [es:bx+4],ax
- mov [es:bx+5],ax
- mov [es:bx+6],ax
- mov [es:bx+7],ax
- mov [es:bx+8],ax
- add bx,320 ;go down one line
- loop Loop3
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp ClearLeft
- proc Delay ;60 FPS - wait 1/60 of a sec
- push ax
- push bx
- push cx
- push dx
- mov dx,0411Ah ;low value of the milliseconds number - 1000000/60
- mov cx,0 ;high value of the milliseconds number
- mov ah,86h ;wait interrupt
- mov al,0
- int 15h
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Delay
- proc DrawP1 ;draw player 1 paddle
- push ax
- push bx
- push cx
- push dx
- mov bh,50 ;loop 50 times to draw the paddle
- mov al,3 ;paddle color
- mov bl,0
- mov cx,318 ;paddle x
- mov dx,[p1y] ;paddle top y
- DrawR:
- inc dx ;go down one line
- mov ah,0Ch ;draw interrupt
- int 10h
- dec bh
- cmp bh,0
- ja DrawR
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DrawP1
- proc DrawP2 ;draw player 2 paddle
- push ax
- push bx
- push cx
- push dx
- mov bh,50 ;loop 50 times to draw the paddle
- mov al,3 ;color
- mov bl,0
- mov cx,2 ;paddle x
- mov dx,[p2y] ;paddle top y
- DrawL:
- inc dx ;go down one line
- mov ah,0Ch ;draw interrupt
- int 10h
- dec bh
- cmp bh,0
- ja DrawL
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DrawP2
- proc DrawBall ;draw the 2x2 pixels ball
- push ax
- push bx
- push cx
- push dx
- mov al,4 ;color
- mov bl,0
- mov cx,[x] ;top left x pos
- mov dx,[y] ;top left y pos
- mov ah,0Ch ;print pixel
- int 10h
- inc cx ;move right
- mov ah,0Ch
- int 10h
- inc dx ;move down
- mov ah,0Ch
- int 10h
- dec cx ;move left
- mov ah,0Ch
- int 10h
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DrawBall
- proc Deleteball ;delete the ball from the last frame
- push ax
- push bx
- push cx
- push dx
- mov al,0
- mov bx,[x] ;calculate previous x pos
- sub bx,[vx]
- mov cx,bx
- mov bx,[y] ;calculate previous y pos
- sub bx,[vy]
- mov dx,bx
- mov bl,0
- mov ah,0Ch ;draw on the previous ball in black
- int 10h
- inc cx
- mov ah,0Ch
- int 10h
- inc dx
- mov ah,0Ch
- int 10h
- dec cx
- mov ah,0Ch
- int 10h
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Deleteball
- proc Deletecurrentball ;delete current ball
- push ax
- push bx
- push cx
- push dx
- mov al,0
- mov cx,[x]
- mov dx,[y]
- mov bl,0
- mov ah,0Ch ;draw on the ball in black
- int 10h
- inc cx
- mov ah,0Ch
- int 10h
- inc dx
- mov ah,0Ch
- int 10h
- dec cx
- mov ah,0Ch
- int 10h
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Deletecurrentball
- proc CollisionSound ;sound when ball collides with the right paddle
- push ax
- push bx
- push cx
- push dx
- ;
- in al,61h ;open speaker
- or al,00000011b
- out 61h,al
- mov al,0B6h ;get access to speaker
- out 43h,al
- mov ax,[note] ;put note in speaker
- out 42h,al
- mov al,ah
- out 42h,al
- mov [count],0 ;reset count of frames - used to close speaker later
- ;
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CollisionSound
- proc CollisionSound2 ;sound when ball collides with the left paddle
- push ax
- push bx
- push cx
- push dx
- ;
- in al,61h ;open speaker
- or al,00000011b
- out 61h,al
- mov al,0B6h ;get access to speaker
- out 43h,al
- mov ax,[note2] ;put note in speaker
- out 42h,al
- mov al,ah
- out 42h,al
- mov [count],0 ;reset count of frames - used to close speaker later
- ;
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CollisionSound2
- proc CheckCollision1 ;check ball collision with p1
- push ax
- push bx
- push cx
- push dx
- Check1: ;check if ball x is where the paddle is
- cmp [x],315
- jb Midjump2
- cmp [x],320
- jb Check2
- jmp Midjump2
- Check2:
- mov ax,[p1y] ;check if ball is in the 1st fifth
- cmp [y],ax
- jb Midjump2
- add ax,10
- cmp [y],ax
- jb Collide1
- jmp Check3
- Check3: ;2nd fifth
- cmp [y],ax
- jb Midjump2
- add ax,10
- cmp [y],ax
- jb Collide2
- jmp Check4
- Check4: ;middle
- cmp [y],ax
- jb Midjump2
- add ax,10
- cmp [y],ax
- jb Collide3
- jmp Check5
- Check5: ;4th fifth
- cmp [y],ax
- jb Midjump2
- add ax,10
- cmp [y],ax
- jb Col4midjump ;collide4
- jmp Check6
- Check6: ;5th fifth
- cmp [y],ax
- jb Midjump2
- add ax,10
- cmp [y],ax
- jb Col5midjump ;collide5
- jmp Midjump2
- Midjump2: ;to avoid jump out of range bug
- jmp ExitP
- Col4midjump:
- jmp Collide4
- Collide1:
- mov [vx],-3
- mov [vy],-3
- call ClearRight ;clear ball position which is in the right column
- call Deleteball
- call deletecurrentball
- call collisionSound
- jmp ExitP
- Collide2:
- mov [vx],-4
- mov [vy],-2
- call ClearRight ;clear ball position which is in the right column
- call Deleteball
- call deletecurrentball
- call collisionSound
- jmp ExitP
- Collide3:
- mov [vx],-5
- mov [vy],0
- call ClearRight ;clear ball position which is in the right column
- call Deleteball
- call deletecurrentball
- call collisionSound
- jmp ExitP
- Col5midjump:
- jmp Collide5
- Collide4:
- mov [vx],-4
- mov [vy],2
- call ClearRight ;clear ball position which is in the right column
- call Deleteball
- call deletecurrentball
- call collisionSound
- jmp ExitP
- Collide5:
- mov [vx],-3
- mov [vy],3
- call ClearRight ;clear ball position which is in the right column
- call Deleteball
- call deletecurrentball
- call collisionSound
- jmp ExitP
- ExitP:
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CheckCollision1
- proc CheckCollision2 ;check ball collision with p1
- push ax
- push bx
- push cx
- push dx
- Check7: ;check if ball x is where the paddle is
- cmp [x],5
- ja Midjump3
- cmp [x],0
- ja check8
- jmp Midjump3
- Check8:
- mov ax,[p2y] ;check if ball is in the 1st fifth
- cmp [y],ax
- jb Midjump3
- add ax,10
- cmp [y],ax
- jb Collide6
- jmp Check9
- Check9: ;2nd fifth
- cmp [y],ax
- jb Midjump3
- add ax,10
- cmp [y],ax
- jb Collide7
- jmp Check10
- Check10: ;middle
- cmp [y],ax
- jb Midjump3
- add ax,10
- cmp [y],ax
- jb Collide8
- jmp Check11
- Check11: ;4th fifth
- cmp [y],ax
- jb Midjump3
- add ax,10
- cmp [y],ax
- jb Col9midjump ;collide9
- jmp Check12
- Check12: ;5th fifth
- cmp [y],ax
- jb Midjump3
- add ax,10
- cmp [y],ax
- jb Col10midjump ;collide10
- jmp Midjump3
- Midjump3: ;to avoid jump out of range bug
- jmp ExitP2
- Col9midjump:
- jmp Collide9
- Collide6:
- mov [vx],3
- mov [vy],-3
- call ClearLeft ;clear ball position which is in the left column
- call Deleteball
- call deletecurrentball
- call collisionSound2
- jmp ExitP2
- Collide7:
- mov [vx],4
- mov [vy],-2
- call ClearLeft ;clear ball position which is in the left column
- call Deleteball
- call deletecurrentball
- call collisionSound2
- jmp ExitP2
- Collide8:
- mov [vx],5
- mov [vy],0
- call ClearLeft ;clear ball position which is in the left column
- call Deleteball
- call deletecurrentball
- call collisionSound2
- jmp ExitP2
- Col10midjump:
- jmp Collide10
- Collide9:
- mov [vx],4
- mov [vy],2
- call ClearLeft ;clear ball position which is in the left column
- call Deleteball
- call deletecurrentball
- call collisionSound2
- jmp ExitP2
- Collide10:
- mov [vx],3
- mov [vy],3
- call ClearLeft ;clear ball position which is in the left column
- call Deleteball
- call deletecurrentball
- call collisionSound2
- jmp ExitP2
- ExitP2:
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CheckCollision2
- proc CheckCollisionY
- push ax
- push bx
- push cx
- push dx
- CheckRoof: ;check collision with the top
- cmp [y],5
- ja CheckFloor
- cmp [y],0
- ja CollideY
- jmp CheckFloor
- CheckFloor: ;check collision with the bottom
- cmp [y],195
- jb ExitP3
- cmp [y],200
- jb CollideY
- jmp ExitP3
- CollideY: ;change y velocity
- call Deleteball
- mov ax,-1
- imul [vy]
- mov [vy],ax
- jmp ExitP3
- ExitP3:
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CheckCollisionY
- proc CheckWin2
- push ax
- push bx
- push cx
- push dx
- CheckwinR: ;check if ball is in the right and above paddle
- cmp [x],315
- jb Midjump4
- cmp [x],320
- ja Midjump4
- mov ax,[p1y]
- cmp [y],ax
- jb Point2
- CheckwinR2: ;check if ball is below paddle
- add ax,50
- cmp [y],ax
- ja Point2
- jmp ExitwinP2
- Point2: ;reset the positions, increase the player's score
- mov [x],160
- mov [y],100
- mov [vx],5
- mov [vy],0
- inc [score2]
- mov [p1y],75
- mov [p2y],75
- call ClearRight ;delete the ball
- call ClearLeft
- call Deleteball
- call deletecurrentball
- cmp [score2],6 ;if player reaches 6 points - he wins the game
- jae Win2
- call DeleteScore2
- jmp ExitwinP2
- Midjump4:
- jmp ExitwinP2
- Win2:
- mov [vx],0
- mov ah, 0 ;change to text mode
- mov al, 2
- int 10h
- mov dx,04240h ;wait 1 second to prevent game reset from key spamming
- mov cx,0Fh
- mov ah,86h ;wait interrupt
- mov al,0
- int 15h
- mov cx,12
- LoopLine2:
- mov dl, 0ah
- mov ah, 2h
- int 21h
- loop LoopLine2
- mov dx,offset p2winmsg ;print player 2 won
- mov ah,9h
- int 21h
- mov dl, 0ah
- mov ah, 2h
- int 21h
- mov dx,offset msg3 ;print press any key to start again
- mov ah,9h
- int 21h
- mov dl, 0ah ;line down
- mov ah, 2h
- int 21h
- mov dx,offset msg4 ;print press esc to exit
- mov ah,9h
- int 21h
- WaitForKey2:
- mov ah, 1
- int 16h
- jz WaitForKey2 ;wait for player input
- cmp ah,1h ;if key is escape
- je ExitGame2
- pop dx
- pop cx
- pop bx
- pop ax
- jmp Resetgame ;restart the game
- ExitGame2:
- mov al,0h ;exit game interrupt
- mov ah,4Ch
- int 21h
- ExitwinP2:
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CheckWin2
- proc CheckWin1
- push ax
- push bx
- push cx
- push dx
- CheckwinR3: ;check if ball is in the left and above the paddle
- cmp [x],5
- ja Midjump5
- cmp [x],0
- jb Midjump5
- mov ax,[p2y]
- cmp [y],ax
- jb Point1
- CheckwinR4: ;check if ball is below paddle
- add ax,50
- cmp [y],ax
- ja Point1
- jmp ExitwinP1
- Point1: ;increase points and reset the positions
- mov [x],160
- mov [y],100
- mov [vx],5
- mov [vy],0
- inc [score1]
- mov [p1y],75
- mov [p2y],75
- call ClearRight ;delete the ball
- call ClearLeft
- call Deleteball
- call deletecurrentball
- cmp [score1],6
- jae Win1
- call DeleteScore1
- jae ExitwinP1
- Midjump5:
- jmp ExitwinP1
- Win1:
- mov [vx],0
- mov ah, 0 ;change to text mode
- mov al, 2
- int 10h
- mov dx,4240h ;wait 1 second
- mov cx,0Fh
- mov ah,86h ;wait interrupt
- mov al,0
- int 15h
- mov cx,12
- LoopLine1:
- mov dl, 0ah
- mov ah, 2h
- int 21h
- loop LoopLine1
- mov dx,offset p1winmsg ;print player 1 won
- mov ah,9h
- int 21h
- mov dl, 0ah
- mov ah, 2h
- int 21h
- mov dx,offset msg3 ;print press any key to start again
- mov ah,9h
- int 21h
- mov dl, 0ah ;line down
- mov ah, 2h
- int 21h
- mov dx,offset msg4 ;print press esc to exit
- mov ah,9h
- int 21h
- WaitForKey1:
- mov ah, 1
- int 16h
- jz WaitForKey1
- cmp ah,1h ;if key = escape
- je ExitGame1
- pop dx
- pop cx
- pop bx
- pop ax
- jmp Resetgame
- ExitGame1:
- mov al,0h
- mov ah,4Ch
- int 21h
- ExitwinP1:
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp CheckWin1
- proc DrawRoofandFloor ;draw the top and bottom lines
- push ax
- push bx
- push cx
- push dx
- mov bx,0 ;start at top left
- mov cx,320*2 ;number of loops - 2 lines
- LoopRoof:
- mov ax,15 ;white ecolor
- mov [es:bx],ax ;color the pixel
- inc bx
- loop LoopRoof
- mov bx,320*198 ;start near the bottom, on the left
- mov cx,320*2 ;number of loops - 2 lines
- LoopFloor:
- mov ax,15
- mov [es:bx],ax ;color the pixel
- inc bx
- loop LoopFloor
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DrawRoofandFloor
- proc Draw0 ;draw the number 0 for score
- push ax
- push bx
- push cx
- push dx
- mov al,10
- mov bl,0
- mov dx,10
- mov ah,0Ch
- mov bh,5
- Right0:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja Right0
- mov bh,10
- Down0:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down0
- mov bh,5
- Left0:
- int 10h
- dec cx
- dec bh
- cmp bh,0
- ja Left0
- mov bh,10
- Up0:
- int 10h
- dec dx
- dec bh
- cmp bh,0
- ja Up0
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Draw0
- proc Draw1 ;draw the number 1 for score
- push ax
- push bx
- push cx
- push dx
- mov al,10
- mov bl,0
- mov dx,10
- mov ah,0Ch
- mov bh,11
- Down1:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down1
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Draw1
- proc Draw2 ;draw the number 2 for score
- push ax
- push bx
- push cx
- push dx
- mov al,10
- mov bl,0
- mov dx,10
- mov ah,0Ch
- mov bh,5
- Right2:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja Right2
- mov bh,5
- Down2:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down2
- mov bh,5
- Left2:
- int 10h
- dec cx
- dec bh
- cmp bh,0
- ja Left2
- mov bh,5
- Down21:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down21
- mov bh,6
- Right22:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja Right22
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Draw2
- proc Draw3 ;draw the number 3 for score
- push ax
- push bx
- push cx
- push dx
- mov al,10
- mov bl,0
- mov dx,10
- mov ah,0Ch
- mov bh,5
- Right3:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja Right3
- mov bh,5
- Down3:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down3
- mov bh,5
- Left3:
- int 10h
- dec cx
- dec bh
- cmp bh,0
- ja Left3
- mov bh,5
- R3:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja R3
- mov bh,5
- D3:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja D3
- mov bh,6
- L3:
- int 10h
- dec cx
- dec bh
- cmp bh,0
- ja L3
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Draw3
- proc Draw4 ;draw the number 4 for score
- push ax
- push bx
- push cx
- push dx
- mov al,10
- mov bl,0
- mov dx,10
- mov ah,0Ch
- mov bh,5
- Down4:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down4
- mov bh,5
- Right4:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja Right4
- mov bh,5
- Up4:
- int 10h
- dec dx
- dec bh
- cmp bh,0
- ja Up4
- mov bh,10
- D4:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja D4
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Draw4
- proc Draw5 ;draw the number 5 for score
- push ax
- push bx
- push cx
- push dx
- mov al,10
- mov bl,0
- add cx,5
- mov dx,10
- mov ah,0Ch
- mov bh,5
- Left5:
- int 10h
- dec cx
- dec bh
- cmp bh,0
- ja Left5
- mov bh,5
- Down5:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja Down5
- mov bh,5
- Right5:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja Right5
- mov bh,5
- D5:
- int 10h
- inc dx
- dec bh
- cmp bh,0
- ja D5
- mov bh,6
- L5:
- int 10h
- dec cx
- dec bh
- cmp bh,0
- ja L5
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp Draw5
- proc DrawScore ;draw the score for both players
- push ax
- push bx
- push cx
- push dx
- mov cx,80 ;x position for top left of the number
- cmp [score2],0 ;find what score he has, jump to the right score to draw
- je JDraw0
- cmp [score2],1
- je JDraw1
- cmp [score2],2
- je JDraw2
- cmp [score2],3
- je JDraw3
- cmp [score2],4
- je JDraw4
- cmp [score2],5
- je JDraw5
- JDraw0:
- call Draw0
- jmp ScoreP1
- JDraw1:
- call Draw1
- jmp ScoreP1
- JDraw2:
- call Draw2
- jmp ScoreP1
- JDraw3:
- call Draw3
- jmp ScoreP1
- JDraw4:
- call Draw4
- jmp ScoreP1
- JDraw5:
- call Draw5
- jmp ScoreP1
- ScoreP1:
- mov cx,240 ;x position for top left of the number, the other player
- cmp [score1],0
- je JDraw01
- cmp [score1],1
- je JDraw11
- cmp [score1],2
- je JDraw21
- cmp [score1],3
- je JDraw31
- cmp [score1],4
- je JDraw41
- cmp [score1],5
- je JDraw51
- JDraw01:
- call Draw0
- jmp ExitP4
- JDraw11:
- call Draw1
- jmp ExitP4
- JDraw21:
- call Draw2
- jmp ExitP4
- JDraw31:
- call Draw3
- jmp ExitP4
- JDraw41:
- call Draw4
- jmp ExitP4
- JDraw51:
- call Draw5
- jmp ExitP4
- ExitP4:
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DrawScore
- proc DeleteScore2 ;delete the score of player 2
- push ax
- push bx
- push cx
- push dx
- mov al,0
- mov bl,0
- mov cx,80
- mov dx,10
- mov ah,0Ch
- mov [idk],11
- LoopIDK2:
- mov bh,7
- R2:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja R2
- inc dx
- mov cx,80
- dec [idk]
- cmp [idk],0
- ja LoopIDK2
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DeleteScore2
- proc DeleteScore1 ;delete the score of player 2
- push ax
- push bx
- push cx
- push dx
- mov al,0
- mov bl,0
- mov cx,240
- mov dx,10
- mov ah,0Ch
- mov [idk],11
- LoopIDK:
- mov bh,7
- R:
- int 10h
- inc cx
- dec bh
- cmp bh,0
- ja R
- inc dx
- mov cx,240
- dec [idk]
- cmp [idk],0
- ja LoopIDK
- pop dx
- pop cx
- pop bx
- pop ax
- ret
- endp DeleteScore1
- start:
- mov ax, @data
- mov ds, ax
- mov ax,0A000h ;use es for some graphics. A000 is the graphics memory
- mov es,ax
- Resetgame:
- mov ax,13h ;graphics mode
- int 10h
- mov [p1y],75
- mov [p2y],75
- mov [score1],0
- mov [score2],0
- mov [vx],5
- mov [count],0
- GameLoop: ;the infinitely running GameLoop
- call DrawRoofandFloor
- call Delay
- call DrawP1
- call DrawP2
- call Deleteball ;delete ball of previous frame
- mov ax,[vx] ;move ball
- add [x],ax
- mov ax,[vy]
- add [y],ax
- call DrawBall
- call DrawScore
- call CheckCollision1
- call CheckCollision2
- call CheckCollisionY
- call CheckWin1
- call CheckWin2
- inc [count]
- cmp [count],10d
- je CloseSpeaker
- Key: ;check for keypresses for paddle movement
- mov ah,1
- int 16h
- jz GameLoop
- mov ah,0
- int 16h
- cmp ah,11h ;w
- je Moveup2
- cmp ah,1Fh ;s
- je Movedown2
- cmp ah,48h
- je Moveup1 ;up arrow
- cmp ah,50h
- je Movedown1 ;down arrow
- jmp GameLoop
- midjump: ;jump because the next jumps are too far from GameLoop
- jmp GameLoop
- Moveup1: ;move p1 up
- cmp [p1y],5
- jbe GameLoop
- sub [p1y],10
- call ClearRight
- call DrawP1
- jmp GameLoop
- Movedown1: ;move p1 down
- cmp [p1y],145
- jae GameLoop
- add [p1y],10
- call ClearRight
- call DrawP1
- jmp GameLoop
- Moveup2: ;move p2 up
- cmp [p2y],5
- jbe Midjump
- sub [p2y],10
- call ClearLeft
- call DrawP2
- jmp GameLoop
- Movedown2: ;move p2 down
- cmp [p2y],145
- jae Midjump
- add [p2y],10
- call ClearLeft
- call DrawP2
- jmp Midjump
- CloseSpeaker:
- in al,61h
- and al,11111100b
- out 61h,al
- mov [count],0
- jmp GameLoop
- exit:
- mov ax, 4c00h
- int 21h
- END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement