Beyond Hello World (Tutorial #2 Displaying tiles)

Topics on software tools like TileStudio, comments on documentation and tutorials (or the lack of) should go here.
Post Reply
User avatar
etamme
Posts: 11
Joined: Mon Dec 22, 2008 9:42 pm
Location: New York, NY USA
Contact:

Beyond Hello World (Tutorial #2 Displaying tiles)

Post by etamme »

Thanks much to David, Davey, and Uze for the pointers on where I'd gone all wrong in my previous post. I'm again moving at about a snails pace, since that's about as fast as my brain works, and come out with a completely not brand new update to my previous post.

This code introduces using tiles, and very superficial tweaking of sound effects. I give you Bouncy Ball V.2. Comments and pointing fingers are welcome!

Code: Select all

#include <stdbool.h>
#include <avr/io.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#include "kernel/uzebox.h"
#include "data/fonts.pic.inc"
// This next line is for sound effects
// full tutorial at http://uzebox.org/forums/viewtopic.php?f=6&t=161
#include "data/patches.inc"

// Store all our strings in program flash instead of the teeny tiny ram
const char strX[] PROGMEM = "X:";
const char strY[] PROGMEM = "Y:";

// This is a tile for a ball that is all white, with a black background.  
// It also has a black "reflection" in the ball.
// You can find the tile studio tutorial at http://uzebox.org/forums/viewtopic.php?f=6&t=109
const char tiles[] PROGMEM ={
  0x00,0x00,0x00,0x00,0x00,0x00,
  0x00,0xFF,0xFF,0xFF,0xFF,0x00,
  0xFF,0xFF,0xFF,0x00,0x00,0xFF,
  0xFF,0xFF,0xFF,0xFF,0x00,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  0x00,0xFF,0xFF,0xFF,0xFF,0x00,
  0x00,0x00,0x00,0x00,0x00,0x00,
};

/* NOTE:  I changed the patch (sound effect) to a single bounce noise instead of a bounce with echo.
    data/patches.inc should have the following for patch 2.  
    
    const char patch02[] PROGMEM ={
    0,
    0,PC_ENV_SPEED,-12,
    5,PC_NOTE_UP,12,
    5,PC_NOTE_DOWN,12,
    5,PC_NOTE_CUT,0,
    0,PATCH_END
    };
    
    If you dont want to do this, you can just
    change
    
    TriggerFx(02,0xff,true);
    
    to 
    
    TriggerFx(01,0xff,true);
    
    In this code.

*/

int main(){
  // Again ... required for sound effects
  InitMusicPlayer(patches);
  
  // Load the tiles array to use
  SetTileTable(tiles);

  // X and Y position of the "ball"
  unsigned int x=1;
  unsigned int y=1;

  // The incrementors for X and Y, leave them signed ;)
  int xp=1;
  int yp=1;

  // Load fonts
  SetFontTable(fonts);
  
  // Loop forever
  while(1){

  // Clear the screen
    ClearVram();

  // This fills the tile at x,y with tile zero from the array.
    Fill(x, y, 1, 1, 0);

  // Print the X location string
    Print(16,11,strX);
  // Print the actual X location
    PrintLong(23,11,x);
  
    Print(16,12,strY);
    PrintLong(23,12,y);
    
  // This slows things down for just a bit ( 1/60 of a second I think )
    WaitVsync(1);
    
  // Increment positions of the X and Y
    x=x+xp;
    y=y+yp;

    if(y==27){
      // Play sound effect when the "wall" is hit
      TriggerFx(02,0xff,true);
      // Reverse the direction of the incrementor
      yp=-1;
    }
  // same stuff as above - just checking bounds
    if(y==0){
      TriggerFx(02,0xff,true);
      yp=1;
    }

    if(x==39){
      TriggerFx(02,0xff,true);
      xp=-1;
    }

    if(x==0){
      TriggerFx(02,0xff,true);
      xp=1;
    }
  }

} 
Last edited by etamme on Sun Jan 04, 2009 8:31 pm, edited 1 time in total.
User avatar
DaveyPocket
Posts: 378
Joined: Sun Sep 14, 2008 8:33 pm
Contact:

Re: Beyond Hello World ( Tutorial #2 )

Post by DaveyPocket »

This line:

Code: Select all

Fill(x, y, 1, 1, 0);
Can be replaced with:

Code: Select all

SetTile(x, y, 0);
You don't have to do the SetTile though, but what you did with the Fill function works just fine. SetTile is recommended though, Fill should be used for something larger other than one tile.
User avatar
codecrank
Posts: 66
Joined: Sun Nov 16, 2008 10:13 pm
Location: Denver, Co

Re: Beyond Hello World (Tutorial #2 Displaying tiles)

Post by codecrank »

In deed, If you look look at the implementation of Fill(), it just calls SetTile(). Not sure how expensive function calls are, but every extra cycle will help when you start pushing the limits :mrgreen:
Post Reply