Page 1 of 2

Newbie wanting help

Posted: December 20th, 2014, 1:54 pm
by Chris
OK, so I've been making my game, slowly, and it works OK, but I do have a few questions.
#1. How would I make it so I can have more than one place to draw graphics from? I'm using TIM tool and am having success in adding new images to it, but I figure sometime soon, the CLUT will be all filled up. Is there a way to switch or add a CLUT so I can have more images? How would I do so in the code?
#2. How do I display text? Any font will do. I tried printf and no text showed up.
If you want to look at my code, you can find it here:
http://www.atari2600land.com/jackandthebeanstalk/

Re: Newbie wanting help

Posted: December 25th, 2014, 11:14 pm
by Shendo
You can place CLUT anywhere in the VRAM. I'm not sure I understand when you say that it will all be filled up...

As for displaying text you can use FntPrint() function. printf is for debug only and is usually used on serial port..
However I encurage you to write your own text displaying routine because FntPrint is pretty limited.

Re: Newbie wanting help

Posted: December 26th, 2014, 8:00 pm
by Chris
OK, so suppose I have an image starting at 0,0. So how would I make it read a different image at 0,0? Or would you just have different CLUTs? I will try FntPrint() first and see how that works.

Re: Newbie wanting help

Posted: December 27th, 2014, 11:16 am
by Shendo
First I would suggest to just go with 16 bit images to avoid using CLUTs.
Once you manage that then start using palletized images.

You should upload image to VRAM outside of your display buffer (usually 320,0 should suffice) and then make a sprite out of it. After that set up a game loop and draw that sprite each frame.

Re: Newbie wanting help

Posted: December 27th, 2014, 5:35 pm
by Chris
OK, so when I go into TimTool to make a new image, I select 16 bit colors. So does that mean I haven't been using CLUTs at all and so I could put the sprite at any position?

Re: Newbie wanting help

Posted: December 27th, 2014, 5:39 pm
by Shadow
16-bit TIM's don't use CLUT's. You don't need to worry about it if they are 16-bits (just like Shendo said).

Re: Newbie wanting help

Posted: January 7th, 2015, 3:28 pm
by Chris
I have a tree sprite. I want multiple copies of the tree sprite scattered various places, like a pattern. How would I do this? The pattern of the trees would change once you clear the screen.

Re: Newbie wanting help

Posted: January 7th, 2015, 3:56 pm
by Shadow
If you want them in a pattern, then you should use a predefined array for the TIM's X and Y position on the screen.

I'm confused by your second line " The pattern of the trees would change once you clear the screen.". It contradicts your first argument stating it's not random. If it's not random, then an array will work. Otherwise, you will need to use the random function within Psy-Q. Additional logic will be required to ensure that you do not get trees overlapping and being placed too close to one another.

Code: Select all

int Random(int max) { return (rand()%max); }

Re: Newbie wanting help

Posted: January 7th, 2015, 4:06 pm
by Chris
Well, I would want the trees in specific various places, not randomly, like to create a maze of trees that the player must navigate through.

Re: Newbie wanting help

Posted: January 7th, 2015, 4:54 pm
by Shadow
Ah, well a hardcoded array will suffice nicely then :)

Re: Newbie wanting help

Posted: January 8th, 2015, 1:08 pm
by Chris
But before I attempt to do that, a new problem popped up. It seems that moving Jack left or up glitches up all the sprites until he gets to near the top. I don't know what's causing this.

Re: Newbie wanting help

Posted: January 8th, 2015, 6:05 pm
by Shadow
Looks like you're overwriting something.

Re: Newbie wanting help

Posted: January 8th, 2015, 10:17 pm
by nocash
Or you got something wrong when you tried to scroll-down the screen when moving-up?

Using a VRAM Viewer that can display the whole 1024x512 pixel video memory (=not just the display area) might help you to figure out what's going on.

Re: Newbie wanting help

Posted: January 9th, 2015, 6:50 am
by Chris
I fixed that problem I was having. Seems like I was calling something when I wasn't supposed to be.
About arrays, then, I have been using the sample code for displaying a picture. Would I be able to shorten the code a lot when I put it in one? Here's the code I am using to display one tree:

Code: Select all

 RECT            rect;                                    // RECT structure
 GsIMAGE         tim_data;                                // holds tim graphic info
   
   // put data from the raw binary header file into rect         
   GsGetTimInfo((u_long *)(treetoruninto+4),&tim_data);

   // load the image into the frame buffer
   rect.x = tim_data.px;                                    // tim start X coord
   rect.y = tim_data.py;                                    // tim start Y coord
   rect.w = tim_data.pw;                                    // data width
   rect.h = tim_data.ph;                                    // data height
   // load the tim data into the frame buffer
   LoadImage(&rect, tim_data.pixel);       

   // load the CLUT into the frame buffer
   rect.x = tim_data.cx;                                    // x pos in frame buffer
   rect.y = tim_data.cy;                                    // y pos in frame buffer
   rect.w = tim_data.cw;                                    // width of CLUT
   rect.h = tim_data.ch;                                    // height of CLUT
   // load data into frame buffer (DMA from DRAM to VRAM)
   LoadImage(&rect, tim_data.clut);



   // initialise sprite
   treea.attribute=0x2000000;                           	// 16 bit CLUT, all options off (0x1 = 8-bit, 0x2 = 16-bit)
   treea.x = treeax;                                        // draw at x coord 0
   treea.y = treeay;                                        // draw at y coord 0
   treea.w = 15;                                        	// width of sprite
   treea.h = 42;                               		    	// height of sprite
   // texture mode (0 4-bit, 1 8-bit, 2 16-bit), semi-transparency rate, texture x, texture y in the framebuffer
   treea.tpage=GetTPage(2, 1, 896, 0);
   treea.r = 128;                                       	// RGB Data
   treea.g = 128;
   treea.b = 128;
   treea.u=0;                                           	// position within timfile for sprite
   treea.v=0;                                           
   treea.cx = tim_data.cx;                             	 	// CLUT location x coord
   treea.cy = tim_data.cy;                              	// CLUT location y coord
   treea.r=treea.g=treea.b=128;                   			// normal luminosity
   treea.mx = 0;                                        	// rotation x coord
   treea.my = 0;                                        	// rotation y coord
   treea.scalex = ONE;                                  	// scale x coord (ONE = 100%)
   treea.scaley = ONE;                                  	// scale y coord (ONE = 100%)
   treea.rotate = 0;                                    	// degrees to rotate

Re: Newbie wanting help

Posted: January 18th, 2015, 4:37 pm
by Chris
I learned about arrays, I think I learned how to understand them, but what I don't understand is how to make multiple copies(in this case, trees), out of the same image. As a test, I did an array from 0-4 and I only got one tree to display at the last array point. What do I do?

int treesxscreen1 [5] = { 30, 70, 140, 170, 230 };

Re: Newbie wanting help

Posted: January 18th, 2015, 5:10 pm
by Shadow
You need to tell the function to use treesxscreen1 but increment through the array of 1 to 5.
At the moment, you have, but it's using the last integer in the array (230) which would be 5.

Re: Newbie wanting help

Posted: January 18th, 2015, 5:19 pm
by Chris
Well, even if I do this, it still displays one tree:

Code: Select all

    treea.x = treesxscreen1[0];                                   // draw at x coord 0
    treea.y = treesxscreen1[0];                                   // draw at y coord 0
    treea.x = treesxscreen1[1];                                   // draw at x coord 0
    treea.y = treesxscreen1[1];  
    treea.x = treesxscreen1[2];                                   // draw at x coord 0
    treea.y = treesxscreen1[2];                                   // draw at y coord 0
    treea.x = treesxscreen1[3];                                   // draw at x coord 0
    treea.y = treesxscreen1[3];  
    treea.x = treesxscreen1[4];                                   // draw at x coord 0
    treea.y = treesxscreen1[4];                                   // draw at y coord 0

Re: Newbie wanting help

Posted: January 18th, 2015, 5:47 pm
by Shadow
Of course it will :P
It's setting them, yes, but it's doing them in order so the variable is being overwritten.
So, the last one will be the one set (treea.x = treesxscreen1[4]; treea.y = treesxscreen1[4];)

You need to do looping/routine logic. Something like this (note, this is just a crude example!):

Code: Select all

for(;;)
{
     // if the tree is off the screen, update the position
     if (treea.x < 0) { treea.x = treesxscreen1[0]; treea.y = treesxscreen1[0]; }
     if (treea.x == 100) { treea.x = treesxscreen1[1]; treea.y = treesxscreen1[1]; }
     // and so on...
}

Re: Newbie wanting help

Posted: January 18th, 2015, 6:02 pm
by Chris
If I try to do any for statement beginning with for(;;) the game freezes.

Re: Newbie wanting help

Posted: January 18th, 2015, 6:13 pm
by Chris
OK, I understand why now.