This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:comporg:spring2025:projects:mtb2 [2025/02/24 22:37] – [scoring] cgrant9 | notes:comporg:spring2025:projects:mtb2 [2025/02/28 05:03] (current) – [score storage] bdildine | ||
---|---|---|---|
Line 6: | Line 6: | ||
For our purposes, we can check if the ball's x position has exceeded 640 or subceeded 0 | For our purposes, we can check if the ball's x position has exceeded 640 or subceeded 0 | ||
====score storage==== | ====score storage==== | ||
+ | You can store the score and other variables you may use such as x and y positions to locations in memory by defining it, for example: | ||
+ | < | ||
+ | %define LScore | ||
+ | </ | ||
+ | You can then load each score into a register before use so you can use the same score tracking function for both the right and left players scores by loading different scores before calling the function. | ||
====score display==== | ====score display==== | ||
+ | Displaying the player' | ||
+ | First off, and debatably more complex portion, is creating an itoa function\\ | ||
+ | To do this we can break down what we need to get printable characters from any arbitrary number\\ | ||
+ | That process requires getting each digit from our number, ie to print 104, we need to have print a 1, a 0, and a 4, as they are all separate regions is the BIOS texture\\ | ||
+ | One possible way of doing this is to use math to pick apart a number from right to left, converting each digit to its ASCII value, and store them, in a process that may look like: | ||
+ | < | ||
+ | | ||
+ | | ||
+ | _itoa: | ||
+ | | ||
+ | IMOD R2, 10 ; Retrieve the last digit from the copy | ||
+ | IADD R2, 0x30 ; Convert the number to its ASCII value | ||
+ | PUSH R2 ; Store the digit onto the stack | ||
+ | IDIV R1, 10 ; Remove the last digit from the original | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Once we have each character we want to print, printing them is a simple matter\\ | ||
+ | The process may look like: | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | ... | ||
+ | |||
+ | | ||
+ | | ||
+ | PUSH R0 ; | ||
+ | CALL _itoa ; (assuming itoa has a RET instruction) | ||
+ | _innerloop: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | IADD RX, 10 ; Move xpos to next open space | ||
+ | | ||
+ | _return: | ||
+ | RET | ||
+ | </ | ||
====computer operated player==== | ====computer operated player==== | ||
====determining computer paddle movement==== | ====determining computer paddle movement==== | ||
+ | The simplest version of a computer operated player has the bot moving the paddle to the same vertical position as the ball. | ||
+ | |||
+ | First we need to get the difference in position between the paddle and the ball. | ||
+ | |||
+ | *NOTE* we want the center of the paddle to hit the center of the ball, so we must make sure to compensate for the distance between the hotpots and centers of the paddle | ||
+ | |||
+ | This will tell us the direction and magnitude the paddle should move, but we will want to cap the movement speed of the paddle so the bot isn't too good. | ||
+ | |||
+ | We can also add a small multiplier to further limit the movement of the bot. | ||
+ | |||
+ | < | ||
+ | _npcMovement: | ||
+ | ;RY is the register containing the ball's y pos | ||
+ | ;RP is the register containing the paddles y pos | ||
+ | ;RT is a temporary register | ||
+ | |||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | RET | ||
+ | </ | ||
====difficulty of computer player==== | ====difficulty of computer player==== | ||
+ | The difficulty of the computer can be tuned by changing the max speed and responsiveness during their movement step | ||
+ | |||
+ | Another way to increase difficulty is to have the ball move faster or have a smaller paddle. You could also give the computer player a larger paddle. |