This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:comporg:spring2025:projects:mtb1 [2025/02/17 18:47] – [Selecting Texture] cgrant9 | notes:comporg:spring2025:projects:mtb1 [2025/02/20 03:33] (current) – [How to check if our sprite has reached a bound] tkastne1 | ||
---|---|---|---|
Line 48: | Line 48: | ||
</ | </ | ||
**NOTE: if you are trying to print text, the region_id for each character is the ASCII value associated with it.\\ | **NOTE: if you are trying to print text, the region_id for each character is the ASCII value associated with it.\\ | ||
- | For example, to print the character ' | + | For example, to print the character ' |
=====Check for keypresses===== | =====Check for keypresses===== | ||
====Selecting joystick==== | ====Selecting joystick==== | ||
+ | Selecting a joystick is very similar to the C process and only takes one command. | ||
+ | In C, we use: | ||
+ | < | ||
+ | select_gamepad( gamepadID ); | ||
+ | </ | ||
+ | Where gamepadID is the value of the gamepad you wish to select. | ||
+ | |||
+ | In assembly we use: | ||
+ | < | ||
+ | out INP_SelectedGamepad, | ||
+ | </ | ||
+ | Where again, gamepadID is the gamepad we wish the use. | ||
+ | |||
====Reading joystick value==== | ====Reading joystick value==== | ||
+ | Reading the joystick values is also similar to the C version, the C version is the following: | ||
+ | < | ||
+ | variableName = gamepad_left(); | ||
+ | </ | ||
+ | Where variableName is a integer variable | ||
+ | In assembly we use registers instead of variables to store the returned value | ||
+ | < | ||
+ | in R0, INP_GamepadLeft | ||
+ | </ | ||
+ | Reading the other directions can be done by using up/ | ||
====translating read joystick value into X and Y==== | ====translating read joystick value into X and Y==== | ||
+ | The value returned by the gamepad is the number of frames it has been in that state | ||
+ | |||
+ | This value can be converted into a boolean with ige: | ||
+ | < | ||
+ | ige R0, 0 | ||
+ | </ | ||
+ | Where R0 is a joystick direction value | ||
+ | After you have the boolean version, you can either use a conditional jump to a label that does whatever you want when a certain direction is pressed, or directly add/ | ||
+ | < | ||
+ | jt R0 _label | ||
+ | </ | ||
+ | or | ||
+ | < | ||
+ | iadd R1, R0 | ||
+ | </ | ||
+ | Where R1 is a x/y position | ||
=====Playfield bounds checking===== | =====Playfield bounds checking===== | ||
Line 62: | Line 101: | ||
====How to check if our sprite has reached a bound==== | ====How to check if our sprite has reached a bound==== | ||
+ | Checking the bounds of the screen can be done using greater than/less than instructions | ||
+ | Remember that instructions overwrite the register | ||
+ | < | ||
+ | mov R0, R1 | ||
+ | ilt R0, YMIN | ||
+ | jt R0, _upper_bound | ||
+ | </ | ||
+ | and | ||
+ | < | ||
+ | mov R0, R1 | ||
+ | igt R0, YMAX | ||
+ | jt R0, _lower_bound | ||
+ | </ | ||
+ | Where R1 is a the y position and YMIN/YMAX are the min and max bounds | ||
====How to limit our sprite from leaving the playfield==== | ====How to limit our sprite from leaving the playfield==== | ||
====How to cause our sprite to wrap-around on the playfield==== | ====How to cause our sprite to wrap-around on the playfield==== | ||