This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:spring2025:projects:mtb0 [2025/02/10 21:35] – [How to check if our sprite has reached a bound] tstrickl | notes:spring2025:projects:mtb0 [2025/02/12 22:38] (current) – [translating read joystick value into X and Y] cgrant9 | ||
---|---|---|---|
Line 13: | Line 13: | ||
=====Design your sprites / custom texture===== | =====Design your sprites / custom texture===== | ||
+ | Designing your own sprites is how you can really make your project yours.\\ | ||
+ | There are many tools you can use to create custom sprites\\ | ||
+ | If you are willing to buy it or build it from source Aesprite is a great option\\ | ||
+ | Another great option for those with Steam is Pixel Studio, which is free, although it does have some quirks to work around. (This is what i personally use and it works great)\\ | ||
====Specifying Texture in XML==== | ====Specifying Texture in XML==== | ||
Line 66: | Line 70: | ||
====Selecting joystick==== | ====Selecting joystick==== | ||
+ | |||
+ | In VirCon32 you can select a gamepad with < | ||
+ | |||
====Reading joystick value==== | ====Reading joystick value==== | ||
+ | You can get the X and Y values using: | ||
+ | < | ||
+ | int DirectionX, DirectionY; | ||
+ | gamepad_direction(& | ||
+ | </ | ||
====translating read joystick value into X and Y==== | ====translating read joystick value into X and Y==== | ||
+ | You can also check explicitly for certain button presses instead of using gamepad_direction() with the gamepad functions, most pertinent to this project would be gamepad_left(), | ||
+ | These functions return a value based on how long the button is being pressed/how long it has been unpressed, decreasing starting from -1 every frame it is unpressed, and increasing starting from 1 every frame it is pressed; The value returned is never zero | ||
=====Playfield bounds checking===== | =====Playfield bounds checking===== | ||
====Vircon32 screen resolution==== | ====Vircon32 screen resolution==== | ||
+ | Vircon32 has a screen resolution of 640x360, that is, 640 pixels across and 360 pixels vertically | ||
====How to check if our sprite has reached a bound==== | ====How to check if our sprite has reached a bound==== | ||
First, it is required to figure out what the bounds of the screen are. Within the video.h header, there are 2 provided definitions. screen_height, | First, it is required to figure out what the bounds of the screen are. Within the video.h header, there are 2 provided definitions. screen_height, | ||
- | Next, one needs to figure out how the coordinate plane is organized. The coordinate plane viewed within Vircon32 is within the confines of the first quadrant of the Cartesian plane, but there is a catch. 0,0 is at the top left, and the y-axis is flipped from what you would expect. Y increases as you move from top to bottom, and negative | + | Next, one needs to figure out how the coordinate plane is organized. The coordinate plane viewed within Vircon32 is within the confines of the first quadrant of the Cartesian plane, but there is a catch. 0,0 is at the top left, and the y-axis is flipped from what you would expect. Y increases as you move from top to bottom, and decreases |
====How to limit our sprite from leaving the playfield==== | ====How to limit our sprite from leaving the playfield==== | ||
+ | We can create minimum and maximum values that our box position can have (e. g. BoxMinX, BoxMaxY, etc...) and check to see if the box has reached these values or not in our main function. By creating another function and calling it after the Box's X and Y position have been calculated but BEFORE the box has been drawn we can update the box's position to ensure it does not leave our bounds. This separate function would compare the calculated X and Y values to the min and max values and update accordingly if the box has exceeded these values. Keep in mind if you want the sprite fully visible on screen you must account for that and slightly adjust your bounds from the standard screen_width and screen_height. | ||
====How to cause our sprite to wrap-around on the playfield==== | ====How to cause our sprite to wrap-around on the playfield==== | ||