Tutorial 3: Gamepad Controls and Sprite Manipulation: Difference between revisions

From Uzebox Wiki
Jump to navigation Jump to search
m (Created page with "This tutorial will cover interpreting input from a gamepad and movement of graphics on the screen. This is where our game becomes more of a game than just a picture on the screen...")
 
mNo edit summary
Line 1: Line 1:
This tutorial will cover interpreting input from a gamepad and movement of graphics on the screen. This is where our game becomes more of a game than just a picture on the screen.
This tutorial will cover interpreting input from a gamepad and movement of graphics on the screen. This is where our game becomes more of a game than just a picture on the screen.
== Fix Your Map ==
You should have noticed the white border on the right and bottom of the screen. White is the first tile in your tilesheet and that is used as the default tile to draw when the screen is cleared. The white is there because the map is not large enough to completely fill in the screen. We will need to modify the image and convert it again. We will also need to modify the convert.xml (gconvert).
First, let's fix the convert.xml file. look for this line:
<source lang="c">
<map var-name="screen1" left="0" top="5" width="28" height="26"/>
</source>
It should look like this instead:
<source lang="c">
<map var-name="screen1" left="0" top="6" width="30" height="28"/>
</source>
We changed the dimensions of the map and changed the 'top' part because we will be adding a row.
Now we need to adjust the image. You will need to add another 16x16 row of black squares and add another 16x16 column of width. Here is how I do it:
#Open your image in MS Paint.
#Add another 16 pixels of height and width. Press CTRL+E and add 16 to both the width and height.
##Now you have extra white space.
#Now, directly below the sprite tiles move the stuff on the bottom down into the new white space.
#The new row created will be white. Make it black.
#Now, copy exactly 16 pixels of width and the full height of the map. Paste into the white space on the right.
#Your image should be 240x272 pixels. Save the image and close MS Paint.
#Open up The GIMP and drag the file in. It should open right away.
##You will need to apply the Uzebox color palette again.
##Click Image > Mode > Indexed.
##Choose "Use custom palette"
##Uncheck the checkbox for "Remove unused colors from colormap".
##and then click "Convert".
##Now click File>Overwrite untitled.png.
##Close the GIMP and choose "Discard Changes". Close the GIMP.


== Basic Character Movement ==
== Basic Character Movement ==
**How to read from the gamepad?  
**How to read from the gamepad?  
http://uzebox.org/wiki/index.php?title=Tips:Controller_Event_Handling
**Do something based on gamepad input.
**Do something based on gamepad input.
*** Adjust the graphics
*** Adjust the graphics

Revision as of 03:35, 13 January 2014

This tutorial will cover interpreting input from a gamepad and movement of graphics on the screen. This is where our game becomes more of a game than just a picture on the screen.

Fix Your Map

You should have noticed the white border on the right and bottom of the screen. White is the first tile in your tilesheet and that is used as the default tile to draw when the screen is cleared. The white is there because the map is not large enough to completely fill in the screen. We will need to modify the image and convert it again. We will also need to modify the convert.xml (gconvert).

First, let's fix the convert.xml file. look for this line:

<map var-name="screen1" left="0" top="5" width="28" height="26"/>

It should look like this instead:

<map var-name="screen1" left="0" top="6" width="30" height="28"/>

We changed the dimensions of the map and changed the 'top' part because we will be adding a row.

Now we need to adjust the image. You will need to add another 16x16 row of black squares and add another 16x16 column of width. Here is how I do it:

  1. Open your image in MS Paint.
  2. Add another 16 pixels of height and width. Press CTRL+E and add 16 to both the width and height.
    1. Now you have extra white space.
  3. Now, directly below the sprite tiles move the stuff on the bottom down into the new white space.
  4. The new row created will be white. Make it black.
  5. Now, copy exactly 16 pixels of width and the full height of the map. Paste into the white space on the right.
  6. Your image should be 240x272 pixels. Save the image and close MS Paint.
  7. Open up The GIMP and drag the file in. It should open right away.
    1. You will need to apply the Uzebox color palette again.
    2. Click Image > Mode > Indexed.
    3. Choose "Use custom palette"
    4. Uncheck the checkbox for "Remove unused colors from colormap".
    5. and then click "Convert".
    6. Now click File>Overwrite untitled.png.
    7. Close the GIMP and choose "Discard Changes". Close the GIMP.

Basic Character Movement

    • How to read from the gamepad?

http://uzebox.org/wiki/index.php?title=Tips:Controller_Event_Handling

    • Do something based on gamepad input.
      • Adjust the graphics
    • Make it so the Link image can move around.

Animated Character Movement

  • Walking frames
  • Changing direction

Collisions

  • Link can walk through walls. To the Uzebox, the walls are just graphics. You have to instruct the Uzebox to prevent Link from walking into the wall graphics.

References / Links: • Uzebox Wiki: http://uzebox.org/wiki/ o The Uzebox wiki is the official source of documentation. The section • Uzebox download: https://code.google.com/p/uzebox/downloads/list o The official location to find Uzebox sources and the emulator. Also can find the development download that also includes sourcecode to many games. • Uzebox Forums: http://uzebox.org/forums/ o Updated more often that the Wiki. Discussions of many Uzebox aspects can be found here. • Hello World: http://uzebox.org/wiki/index.php?title=Hello_World o The basics of a new user’s first program. • GIMP Palette for the Uzebox: http://uzebox.org/forums/viewtopic.php?f=6&t=396 o This forum post describes the Uzebox color palette. • Tile Studio Tutorial: o Part 1: http://www.uzebox.org/forums/viewtopic.php?f=6&t=109 o Part 2: http://www.uzebox.org/forums/viewtopic.php?f=6&t=110 • Fuzebox-Hello Tile: http://www.ladyada.net/make/fuzebox/hellotile.html o Explains what a tile is and why they are used. Most-Common APIs for Uzebox: • Function SetTileTable: http://uzebox.org/wiki/index.php?title=Function_SetTileTable o void SetTileTable(const char *data); o Defines the tile set to use for rendering the background. • Function SetSpritesTileTable: http://uzebox.org/wiki/index.php?title=Function_SetSpritesTileTable o void SetSpritesTileTable(const char *data); o Defines the tile set to use for rendering sprites. • Function InitMusicPlayer: http://uzebox.org/wiki/index.php?title=Function_InitMusicPlayer o void InitMusicPlayer(const struct PatchStruct *patchPointersParam); o Initializes the music engine and defines the patch set to use to play song and sound effects. This function must be called before playing songs or effects. • Function DrawMap2: http://uzebox.org/wiki/index.php?title=Function_DrawMap2 o void DrawMap2(unsigned char x,unsigned char y,const char *map); o Draws a rectangular map pointed to by *map at the specified coordinates. Maps are char arrays in which the two first bytes respectively specifies the width and height of the map. These function expects the data to be located in flash (PROGMEM). • Function SetTile: http://uzebox.org/wiki/index.php?title=Function_SetTile o void SetTile(char x,char y, unsigned int tileId); o Draws a tile in vram at the specified location. You need to first set the tile set to use with SetTileTable(). • Function Fill: http://uzebox.org/wiki/index.php?title=Function_Fill o void Fill(int x,int y,int width,int height,int tile); o Fill an arbitrary sized, rectangular region using the specified tile index. • Function MapSprite: http://uzebox.org/wiki/index.php?title=Function_MapSprite o void MapSprite(unsigned char startSprite, const char *map); o Convenience function that uses a map to draw big sprites (composed of multiple 8x8 sprites). It assigns map indexes to sprites indexes and re-positions the sprites to tile them using the width and height specified in the map. o NOTE: Drawing a 2x2 mega-sprite will take up 4 sprites. If this is sprite 0 then it would take up sprite 0, 1, 2, 3. • Function MoveSprite: http://uzebox.org/wiki/index.php?title=Function_MoveSprite o void MoveSprite(unsigned char startSprite,unsigned char x,unsigned char y,unsigned char width,unsigned char height); o Convenience function to move a group of aggregated sprites. The position of all sprites are updated relative to the x and y parameters and the specified width and height. o NOTE: MoveSprite has pixel precision and thus can position sprites with much finer granularity than SetTile positions tiles. • • ClearVram uses the first tile to fill the entire screen.