x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of threads: 4563
Number of posts: 16029

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
trouble with paddle movement, in breakout Posted by kkhan on 6 Apr 2004 at 4:42 PM
This message was edited by kkhan at 2004-4-6 18:24:25

Hi,

I have figured out how to get the paddle moving etc. Just need some pointers on how to move the ball etc., like how to reverse direction etc.

http://www.cs.uh.edu/~automata/files/constants.inc

comment ~ *****************
	Name:		<NAME>
	SSN:		<SSN>
	Section:	<SECTION>
	Date:		<DUE DATE>
	Assignment:	<ASSIGNMENT NUMBER>
	Description:
	Input:
	Output:
	~ *****************

.model small
.586
.stack 100h
.nolist
	;*************************************************
	;Includes
	;*************************************************
	include bios.inc
	include constants.inc
.list
.data
     ballpositionx word STARTX
     ballpositiony word STARTY
     paddlepositionx word PADDLEY
     paddlepositiony word PADDLEX
     ballvelocityy word STARTVELY
     ballvelocityx word STARTVELX
     brickarray db (ENDBRICKX-STARTBRICKX)*2 dup("*")
     brickarray2 db (ENDBRICKX-STARTBRICKX)*2 dup ("*")
     repeater word REPEATTIMES*300

.code

	main proc
	    .startup
	    @Cls
	    @Setcsrpos,0,0

	    ;initialize everything
	    mov ax,00DBh
	    mov di,0


        InitLoop:	    
            mov [brickarray+di],al
	    mov [brickarray2+di],al
	    inc di
	    cmp di,(ENDBRICKX-STARTBRICKX)*2
	    jne InitLoop

	 GameLoop:
	    @Cls
	    mov cx,((ENDBRICKX-STARTBRICKX)-1)*2
	    xor ax,ax
	    mov ax,VIDSEG

	    mov es,ax
	    lea si,brickarray
	    mov di,(160*STARTBRICKY)+STARTBRICKX*2
	    rep movsb

	    mov cx,(ENDBRICKX-STARTBRICKX-1)*2
	    xor si,si
	    lea si,brickarray2
	    mov di,(160*(STARTBRICKY+1))+STARTBRICKX*2
	    rep movsb

	    mov ax,160

	    mul paddlepositionx
	    push ax
	    mov ax,2
	    mul paddlepositiony
	    pop bx
	    add ax,bx
	    mov di,ax
	    mov ax,00DFH
	    mov cx,PADDLELEN
	  PaddleLoop:
	    mov es:[di],al
	    add di,2
	    dec cx
	    cmp cx,0
	    jne PaddleLoop

	    mov ax,160
	    mul ballpositiony
	    push ax
	    mov ax,2
	    mul ballpositionx
	    pop bx
	    add ax,bx
	    mov di,ax
	    mov ax,0C07h
	    mov es:[di],ax


            MoveBall:
	    inc ballpositionx
	    inc ballpositiony

	    xor ax,ax
	    mov ah, 00h
	    int 16h


	    cmp ah,01h
	    je done
	    cmp ah,48h
            je PaddleUp
	    cmp ah,50h
	    je PaddleDown
	    cmp ah,4Dh
            je PaddleLeft
	    cmp ah,4Bh
            je PaddleRight
            jmp GoBack

            PaddleUp:
	    cmp paddlepositionx,0
	    jle GoBack
	    dec paddlepositionx
	    jmp GoBack

	    PaddleDown:
	    cmp paddlepositionx,24
	    jge GoBack
	    inc paddlepositionx
	    jmp GoBack

	    PaddleLeft:
	    cmp paddlepositiony,74
	    jge GoBack
	    inc paddlepositiony
	    jmp GoBack

	    PaddleRight:
	    cmp paddlepositiony,0
	    jle GoBack
	    dec paddlepositiony
            
            GoBack:
  	    dec repeater
	    cmp repeater,0
	    jne GameLoop






		done:

	    @Cls
	    @Setcsrpos,0,0
		.exit
	main endp

end




Report
Re: trouble with paddle movement, in breakout Posted by ASHLEY4 on 6 Apr 2004 at 9:55 PM
The ball has a x and y ,if the x is the same and y is inc then the ball move in the y direction (eg down the screen) ,to make the ball go across the screen at a angle you inc the x and y by the same (eg:1) you also check that you have not hit the edge,if you do hit the edge you inc the x and dec the y. this gives the bounc.

To make shore you inc or dec at the right time you have a var ,that is a 1 or a 2,when the ball hits the bottom you change from a 1 to a 2 and dec y, when the ball hits the top you change form a 2 to a 1 and inc y etc.
this is it in the code.
;------------------------------------------------------------------------------------------------
; Bounces ball off the walls
;------------------------------------------------------------------------------------------------

BounceBall              PROC

                        CMP     BallXstate,1
                        JE      A10
                        sub     BallX,2                    ;dec
                        JMP     B10
A10:                     add    BallX,2                    ;inc

B10:                    CMP     BallYstate,1
                        JE      A20
                        sub     BALLY,2                     ;dec
                        JMP     B20
A20:                    add     BALLY,2                     ;inc

B20:                    CMP     BallX,4
                        JNE     C10
                        MOV     AX,BallY
                        MOV     BX,PadLY
                        SUB     BX,3
                        CMP     BX,AX
                        JLE     Z1
                        INC     Score2
                        CALL    DeLay
                        JMP     Againz
Z1:                     MOV     CL,18
Z12:                    CMP     BX,AX
                        JE      Z2
                        INC     BX
                        LOOP    Z12
                        INC     Score2
                        CALL    DeLay
                        JMP     Againz
Z2:                     MOV     BallXstate,1
                        CALL    Beep1
C10:
                        CMP     BallX,312
                        JNE     C20
                        MOV     AX,BallY
                        MOV     BX,PadRY
                        SUB     BX,3
                        CMP     BX,AX
                        JLE     Q1
                        INC     Score1
                        CALL    DeLAY
                        JMP     Againz 
Q1:                     MOV     CL,18
Q12:                    CMP     BX,AX
                        JE      Q2
                        INC     BX
                        LOOP    Q12
                        INC     Score1
                        CALL    DeLAY
                        JMP     Againz

Q2:                     MOV     BallXstate,2
                        CALL    Beep1
C20:
                        CMP     BALLY,0
                        JNE     D10
                        MOV     BALLYSTATE,1
                        CALL    BEEP2
D10:
                        CMP     BallY,198
                        JNE     D20
                        MOV     BallYstate,2
                        CALL    Beep2
D20:    
                        RET

BounceBall              ENDP



ASHLEY4.
Report
Re: trouble with paddle movement, in breakout Posted by kkhan on 7 Apr 2004 at 3:06 PM
thanks for that, any reason why my code to check wheter the ball hit the paddle or not isnt working ??/

comment ~ *****************
	Name:		<NAME>	
	SSN:		<SSN>	
	Section:	<SECTION>	
	Date:		<DUE DATE>	
	Assignment:	<ASSIGNMENT NUMBER>	
	Description:	Input:	Output:
	~ *****************
.model small
.586
.stack 100h
.nolist	
;*************************************************
	;Includes	
;*************************************************
	include bios.inc	
	include constants.inc
.list
.data     
	ballpositionx word STARTX     
	ballpositiony word STARTY     
	paddlepositionx word PADDLEY     
	paddlepositiony word PADDLEX     
	ballvelocityy word STARTVELY     
	ballvelocityx word STARTVELX     
	brickarray db (ENDBRICKX-STARTBRICKX)*2 dup("*")     
	brickarray2 db (ENDBRICKX-STARTBRICKX)*2 dup ("*")     
	repeater word REPEATTIMES*300
.code	
	main proc	    
	.startup	    
	@Cls	    
	@Setcsrpos,0,0	    
	;initialize everything	    
	mov ax,00DBh	    
	mov di,0            
	neg ballvelocityx        
	InitLoop:	                
	mov [brickarray+di],al	    
	mov [brickarray2+di],al	    
	inc di	    
	cmp di,(ENDBRICKX-STARTBRICKX)*2	    
	jne InitLoop	 

	GameLoop:	    
	@Cls	    
	mov cx,((ENDBRICKX-STARTBRICKX)-1)*2
	xor ax,ax	    
	mov ax,VIDSEG	    
	mov es,ax	    
	lea si,brickarray	    
	mov di,(160*STARTBRICKY)+STARTBRICKX*2	    
	rep movsb	    

	mov cx,(ENDBRICKX-STARTBRICKX-1)*2	    
	xor si,si	    
	lea si,brickarray2	    
	mov di,(160*(STARTBRICKY+1))+STARTBRICKX*2	    
	rep movsb	    

	mov ax,160	    
	mul paddlepositionx	    
	push ax	    
	mov ax,2	    
	mul paddlepositiony	    
	pop bx	    
	add ax,bx	    
	mov di,ax	    
	mov ax,00DFH	    
	mov cx,PADDLELEN	  

	PaddleLoop:	    
	mov es:[di],al	    
	add di,2	    
	dec cx	    
	cmp cx,0	    
	jne PaddleLoop	    

	mov ax,160	    
	mul ballpositiony	    
	push ax	    
	mov ax,2	    
	mul ballpositionx	    
	pop bx	    
	add ax,bx	    
	mov di,ax	    
	mov ax,0C07h	    
	mov es:[di],ax            

	BallMove:            
	cmp ballpositionx,0            
	jle NegXVel            
	cmp ballpositionx,79            
	jge NegXVel            
	cmp ballpositiony,0            
	jle NegYVel             
	cmp ballpositiony,24            
	jge NegYVel            
	jmp RegularBallMove            

	NegXVel:            
	neg ballvelocityx            
	jmp RegularBallMove            

	NegYVel:            
	neg ballvelocityy            
	jmp RegularBallMove            

	RegularBallMove:            
	mov ax,ballvelocityx            
	add ballpositionx,ax            
	mov ax,ballvelocityy            
	add ballpositiony,ax                        

	GoOn:            
	xor ax,ax	    
	mov ah, 00h	    
	int 16h                                     	    
	
	cmp ah,01h	    
	je done	    
	cmp ah,48h            
	je PaddleUp	    
	cmp ah,50h	    
	je PaddleDown	    
	cmp ah,4Dh            
	je PaddleLeft	    
	cmp ah,4Bh            
	je PaddleRight            
	jmp GoBack            

	PaddleUp:	    
	cmp paddlepositionx,13	    
	jle CheckBall	    
	dec paddlepositionx	    
	jmp CheckBall	    

	PaddleDown:	    
	cmp paddlepositionx,23	    
	jge CheckBall
	inc paddlepositionx	    
	jmp CheckBall

	PaddleLeft:	    
	cmp paddlepositiony,74	    
	jge CheckBall
	inc paddlepositiony	    
	jmp CheckBall

	PaddleRight:	    
	cmp paddlepositiony,0	    
	jle CheckBall
	dec paddlepositiony

        CheckBall:
        mov ax,paddlepositiony
        sub ax,ballpositiony
        cmp ax,-1
        je Negate
        jmp GoBack

        Negate:
        neg ballvelocityy
        mov ax,ballvelocityy            
	add ballpositiony,ax
                            

	GoBack:  	    
	dec repeater	    
	cmp repeater,0	    
	jne GameLoop            

	done:	    
	@Cls	    
	@Setcsrpos,0,0		
	.exit	
main endp
end


Report
Re: trouble with paddle movement, in breakout Posted by ASHLEY4 on 7 Apr 2004 at 6:54 PM
Hi
1)First could you put some comments,it will make it easyer to read.
2) Y do you use 79 for ballpos X ,and 24 for ballpos Y thats text mode.
3) You should first test the X of the paddle + the width to see if they are the same as the ball X ,IF not the same IT not going to hit the paddle this loop.if it the same check Y of paddle + the SIZE of paddle,If its below the Y of the paddle or above the Y + the paddle SIZE ,then its mist the paddle.

0 ;ball Y below Y of paddle (= mist )
#
#
#
#
0 ;ball Y above paddle Y + paddle size (= mist )


####### = paddle
0 = ball

ASHLEY4.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.