Chat with us, powered by LiveChat hello this is my code i have small problem my code is a game of bouncing ball when i run the code im not seeing the ball. CAN SOMEONE FIX IT PLEASE. - Tutorie

hello this is my code i have small problem my code is a game of bouncing ball when i run the code im not seeing the ball. CAN SOMEONE FIX IT PLEASE.

hello this is my code i have small problem my code is a game of bouncing ball when i run the code im not seeing the ball. CAN SOMEONE FIX IT PLEASE.

.data screen: .space 65536 # 2-D array representing the screen (256×256 pixels) ball_size: .word 8 # size of the ball (in pixels) ball_color: .word 0xFF0000 # color of the ball (in RGB format) ball_x: .word 20 # initial x position of the ball ball_y: .word 20 # initial y position of the ball ball_dx: .word 2 # initial x velocity of the ball ball_dy: .word 3 # initial y velocity of the ball screen_width: .word 256 # width of the screen screen_height: .word 256 # height of the screen ball_xx: .word 50 ball_yy: .word 50 ball_sizez: .word 10 ball_x_speed: .word 1 ball_y_speed: .word 1 ball_x_max: .word 256 ball_y_max: .word 256 beep6: .word 89 duration6: .word 500 instrument6: .word 58 volume6: .word 100 .text main: jal initialize_screen jal draw_ball loop: jal move_ball jal draw_ball j loop initialize_screen: # set up screen colors and positions li $t0, 0x00000000 # set background color to black li $t1, 0 li $t2, 0 li $t3, 0 sw $t0, screen($t1) sw $t0, screen($t2) sw $t0, screen($t3) addi $t1, $t1, 4 addi $t2, $t2, 4 addi $t3, $t3, 4 sw $t0, screen($t1) sw $t0, screen($t2) sw $t0, screen($t3) # set ball position and velocity lw $t4, ball_x lw $t5, ball_y sw $t4, ball_x sw $t5, ball_y lw $t4, ball_dx lw $t5, ball_dy sw $t4, ball_dx sw $t5, ball_dy jr $ra draw_ball: # draw the ball on the screen # get ball position lw $t0, ball_x lw $t1, ball_y # get ball color lw $t2, ball_color # get ball size lw $t3, ball_size # calculate screen offset mul $t4, $t1, 256 add $t4, $t4, $t0 # draw ball li $t5, 0 loop2: sw $t2, screen($t4) addi $t5, $t5, 1 beq $t5, $t3, done_drawing addi $t4, $t4, 4 j loop2 done_drawing: jr $ra move_ball: # update the ball’s position and velocity lw $t0, ball_x lw $t1, ball_dx add $t0, $t0, $t1 sw $t0, ball_x lw $t0, ball_y lw $t1, ball_dy add $t0, $t0, $t1 sw $t0, ball_y # check for collisions with the edges of the screen lw $t0, ball_x lw $t1, ball_y lw $t2, ball_size lw $t3, screen_width sub $t4, $t3, $t2 # maximum x position slt $t5, $t0, $t2 # check left edge beq $t5, $zero, check_right addi $t0, $t2, 1 # set x position to left edge lw $t6, ball_x_speed sub $t6, $zero, $t6 # reverse x direction sw $t6, ball_x_speed # update ball_x_speed j check_bottom check_right: slt $t5, $t4, $t0 # check right edge beq $t5, $zero, check_top addi $t0, $t4, -1 # set x position to right edge lw $t6, ball_x_speed sub $t6, $zero, $t6 # reverse x direction sw $t6, ball_x_speed # update ball_x_speed j check_bottom check_top: lw $t3, screen_height sub $t7, $t3, $t2 # maximum y position slt $t5, $t1, $t2 # check top edge beq $t5, $zero, check_bottom addi $t1, $t2, 1 # set y position to top edge lw $t6, ball_y_speed sub $t6, $zero, $t6 # reverse y direction sw $t6, ball_y_speed # update ball_y_speed j end_move check_bottom: slt $t5, $t7, $t1 # check bottom edge beq $t5, $zero, end_move addi $t1, $t7, -1 # set y position to bottom edge lw $t6, ball_y_speed sub $t6, $zero, $t6 # reverse y direction sw $t6, ball_y_speed # save new y speed in memory j move_ball # jump to the move_ball label end_move: # code for when the ball has reached its final position # End the program li $v0, 10 syscall # check for collisions with the edges of the screen lw $t0, ball_x lw $t1, ball_y lw $t2, ball_size sub $t3, $t3, $t2 # maximum x position li $t6, 256 sub $t3, $t6, $t2 # maximum x position slt $t4, $t0, $t2 # check left edge beq $t4, $zero, check_right # if not at left edge, check right edge addi $t0, $t2, -1 # set x position to right edge lw $t5, ball_x_speed sub $t5, $zero, $t5 # reverse x direction sw $t5, ball_x_speed # update ball_x_speed j check_bottom slt $t4, $t0, $t3 # check right edge beq $t4, $zero, check_top # if not at right edge, check top edge addi $t0, $t3, -1 # set x position to right edge lw $t5, ball_x_speed sub $t5, $zero, $t5 # reverse x direction sw $t5, ball_x_speed # update ball_x_speed j check_bottom slt $t4, $t1, $t2 # check top edge beq $t4, $zero, check_bottom # if not at top edge, check bottom edge addi $t1, $t2, -1 # set y position to top edge lw $t5, ball_y_speed sub $t5, $zero, $t5 # reverse y direction sw $t5, ball_y_speed # update ball_y_speed lw $t6, ball_y_max # maximum y position slt $t4, $t1, $t6 # check bottom edge beq $t4, $zero, end_check # if not at bottom edge, exit check addi $t1, $t6, -1 # set y position to bottom edge lw $t5, ball_y_speed sub $t5, $zero, $t5 # reverse y direction sw $t5, ball_y_speed # update ball_y_speed end_check: sw $t0, ball_x # update ball_x sw $t1, ball_y # update ball_y # check for collisions with edges of screen lw $t0, ball_xx lw $t1, ball_yy lw $t2, ball_sizez sub $t3, $t3, $t2 # maximum x position li $t6, 256 sub $t3, $t6, $t2 # maximum x position slt $t4, $t0, $zero # check left edge beq $t4, $zero, right_edge addi $t0, $t0, 1 # reverse direction and move ball j continue right_edge: add $t0, $zero, $t3 # reverse direction and move ball j continue continue: # update ball position sw $t0, ball_x sw $t1, ball_y # pause for a short amount of time li $v0, 32 li $a0, 50000 syscall

Are you struggling with this assignment?

Our team of qualified writers will write an original paper for you. Good grades guaranteed! Complete paper delivered straight to your email.

Place Order Now