User Tools

Site Tools


notes:spring2025:projects:mtb0

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:spring2025:projects:mtb0 [2025/02/05 15:47] – [Specifying Texture in XML] cgrant9notes: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 32: Line 36:
 </code> </code>
 ====Selecting Texture==== ====Selecting Texture====
-Just like in C, selecting texture is simple +Vircon32 has built in functionality for working with any textures specified in the xml\\ 
- +To draw anything to the screen you need few things: 
-In C to select a texture we can use:+  * Texture 
 +  * Region  
 +  * Location 
 +The easiest portion to set up is the texture, as you only need the command
 <code> <code>
-select_texture( int texture_id );+select_texture(texture_id);
 </code> </code>
 +where texture_id is the id of the texture you are using, which is determined by its position in the xml file
 +====Defining Region====
 +The next step to drawing a sprite to the screen is selecting the region of the texture you want to use.\\
 + 
 +Because regions are specified portions of a texture, you can use many commands to define them in different ways, however, all of the commands will follow a similar structure\\
  
-In Assembly the process is similaras the command is simply:+The simplest command you can use is define_region_center()which follows the structure:
 <code> <code>
-out GPU_SelectedTexture #+define_region_center(min_x, min_y, max_x, max_y );
 </code> </code>
-Where the # is either the immediate value of the texture idor register containing the texture id+Where each argument corresponds to a coordinate on the .png filethat together draw box containing your region.\\
  
-====Defining Region==== +As stated abovethis command is not the only one, so you should also try experimenting with some of the otherswhich can be found in the C API reference on the Vircon32 website\\
-Defining a region is where assembly becomes much less simpleas in C one can use a variety of built in functions that handle everythingwhereas in assembly we have to send the GPU every value ourselves+
  
-This looks like: +Specifically this section:https://www.vircon32.com/api/video.html#Definition%20of%20texture%20regions\\
-<code> +
-out GPU_SelectedRegion # +
-out GPU_RegionMinX # +
-out GPU_RegionMinY # +
-out GPU_RegionMaxX # +
-out GPU_RegionMaxY # +
-out GPU_RegionHotspotX # +
-out GPU_RegionHotspotY # +
-</code> +
-Once again with corresponding to an immediate value or register containing the values we want to input+
 ====Selecting Region==== ====Selecting Region====
 +It is simple to select a region. Use the command select_region() and pass the identifier of that region, ie. select_region(0);
  
 +
 +====Region Software====
 +If you need more help visualizing the region process, the software provided by the creator of vircon32, linked below, can help. It visualizes the Region selection within an image that is provided to the software, and can even generate a header file for automation given the different parameters one would provide it.
 +https://github.com/vircon32/ComputerSoftware/releases/tag/regioneditor-v25.1.6
 =====Check for keypresses===== =====Check for keypresses=====
  
 ====Selecting joystick==== ====Selecting joystick====
 +
 +In VirCon32 you can select a gamepad with <code>select_gamepad(int gamepad_id);</code> So for example: <code>select_gamepad(0);</code>
 +
  
 ====Reading joystick value==== ====Reading joystick value====
  
 +You can get the X and Y values using:
 +<code>
 +int DirectionX, DirectionY;
 +gamepad_direction(&DirectionX, &DirectionY);
 +</code>
 ====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(), gamepad_right(), gamepad_up(), and gamepad_down().\\ 
 +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, and screen_width. These are the borders of the screen.
  
 +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 as you move from bottom to top. X goes positive as you move to the right, and negative to the left.
 ====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====
  
  
notes/spring2025/projects/mtb0.1738770421.txt.gz · Last modified: 2025/02/05 15:47 by cgrant9