PCEngineFans.com - The PC Engine and TurboGrafx-16 Community Forum
Tech and Homebrew => Turbo/PCE Game/Tool Development => Topic started by: soop on June 13, 2012, 12:44:59 AM
-
Ok, I'd like to have some text appearing at the bottom of the screen, under graphics.
I figure the easiest way to do this would just be to decrease the x value and start from the right side of the screen to produce a ticker-style feed, like they have on news shows.
However, I'd also like to try a typewriter-style approach, where the text appears left-to-right one character at a time.
The only way I can think of to create the second approach (typewriter) is to create a large array with each character as a a variable, and display all the characters below [ul][li]. Not sure if that will even work, and it would be a fairly large array (4000 chars?)[/li][/ul]
And I'm not sure the first (ticker) approach would work either, because it would end up at x -988974894
-
Are you talking similar to like a sports ticker on the bottom of like sports games? That's actually a great idea. You could always make a string and call a function that you create.
Something like this:
void scroll (char *s, int x)
{
// loops and leaves some space at the top/bottom border
for (int i = 19; i >= 5; i--)
{
gotoxy (x,i); // move up one line
cout << s; // output the string
wait(1); // wait one second
clrscr (); // clear the screen
}
}
-
For a scroll from the right side of the screen you are increasing the scroll value as well as the address to write the next character to. Actually, a ticker and typewriter display both use the same concept: write a single character, increase the writing address and reading address by 1, wait a constant number of vblanks, and write the next character. Thus you'll need 2 separate functions for setting up all these pointers, and for writing a single character.
For a ticker, you scroll the screen by a constant value, then write the next character after it's scrolled 8 pixels. The screen writing address will need to be reset after the screen has scrolled the full width of the defined BAM (tilemap).
For a typewriter, there's no scrolling, but the writing address will need to be reset (plus a vertical offset) everytime you reach the end of the screen.
-
Close - but it's for my game idea TMNT - Trevor McDonalds Newsreading Tournament. It's a simple game; you have a certain time limit to read a news bulletin, which you do by bashing I and II as fast as you can, ala shooting watch.
So I was thinking either any time a button is pressed, x is decremented by 1 (ticker) or the arry is incremented by 1 (typewriter).
So it's basically your code, but instead of the wait, we'd have to increment by button presses.
Am I thinking cout is some equivilent to put_string?
-
For a scroll from the right side of the screen you are increasing the scroll value as well as the address to write the next character to. Actually, a ticker and typewriter display both use the same concept: write a single character, increase the writing address and reading address by 1, wait a constant number of vblanks, and write the next character. Thus you'll need 2 separate functions for setting up all these pointers, and for writing a single character.
For a ticker, you scroll the screen by a constant value, then write the next character after it's scrolled 8 pixels. The screen writing address will need to be reset after the screen has scrolled the full width of the defined BAM (tilemap).
For a typewriter, there's no scrolling, but the writing address will need to be reset (plus a vertical offset) everytime you reach the end of the screen.
Oh sorry Chris, I didn't see that when I typed mine. Ok, that makes sense. So if I want to do the typewriter, do I put the text in an array of characters?
then I'll be like:
for $vertical_lines < x do {
cout @line_$linenumber [1..$wordnumber];
++verticallines;
if $verticallines=x then {
verticallines=0;
++$linenumber;
}
}
And then somewhere in there an interrupt to increase wordnumber if a buttonpress is detected every certasin number of vblanks
Sorry, I know that's not C, I don't know it well enough yet, but it should hopefully be clear enough?
-
This is all done very easily with HuC! put_string() takes in an X and Y that is the tile offset you want to write at...
3,2 for example would put a letter at 24,16 (each letter is 8x8, so 3 cells from the left is 24, 2 cells down is 16).
You can just write across the screen and increment the X by 1 until you reach screen capacity, and then just bump the Y down and start the whole process over.
The trickiest part in all honesty, will be getting it to happen with a nice frame delay between each letter that you write, so that it looks smooth.
Too fast = why even bother
Too slow = kill me now, this is taking forever to read!
You can store the entire chunk of text in question in an array, like you mentioned, and just step through it one character at a time and write them to screen. Put some sort of line break delimiter in there (* or @ for example). Any time you encounter that character in the array, kick the line down and continue onward. It's really simple if you do it this way.
If you have Insanity, put it in your system with a System Card 2 instead of 3. Watch the CD Error screen. (You can grab the demo from aetherbyte.com and do it in an emulator instead if you want).
Is this what you want to happen? If so, it's pretty easy to set up. If you have trouble with it, I can help out.
I fiddled around and have it doing it in the Protocade light cycle game too. That one plays sound too. So it's all blerpy.
-
This is all done very easily with HuC! put_string() takes in an X and Y that is the tile offset you want to write at...
3,2 for example would put a letter at 24,16 (each letter is 8x8, so 3 cells from the left is 24, 2 cells down is 16).
You can just write across the screen and increment the X by 1 until you reach screen capacity, and then just bump the Y down and start the whole process over.
The trickiest part in all honesty, will be getting it to happen with a nice frame delay between each letter that you write, so that it looks smooth.
Too fast = why even bother
Too slow = kill me now, this is taking forever to read!
You can store the entire chunk of text in question in an array, like you mentioned, and just step through it one character at a time and write them to screen. Put some sort of line break delimiter in there (* or @ for example). Any time you encounter that character in the array, kick the line down and continue onward. It's really simple if you do it this way.
If you have Insanity, put it in your system with a System Card 2 instead of 3. Watch the CD Error screen. (You can grab the demo from aetherbyte.com and do it in an emulator instead if you want).
Is this what you want to happen? If so, it's pretty easy to set up. If you have trouble with it, I can help out.
I fiddled around and have it doing it in the Protocade light cycle game too. That one plays sound too. So it's all blerpy.
Ok, will do - I'll have a mess about with it on the bus home too. The lack of internet is actually a tad annoying, I was trying to find an unsecured hotspot whenever we hit traffic yesterday just to download a PC Engine emulator, and as soon as I'[d connect, we'd speed away from it. So Yeah I'll download insanity and a few other bits when I get home.
-
I hope you won't download Insanity. It's Arkhan's game that he sells.
-
Yeah. All you need to do is set it to use system card 2 and try to play the game. The error screen has typewriter text.
-
Don't worry, if I end up playing it loads I'll donate some money :B or give him a free copy of this game when I make it :D
Umm, this is my first crack, without a bunch of stuff (everyone's left work early to go and watch football, so I'm getting in some coding), but I've cobbled this together from a bunch of sources, so there's probably a load wrong with it;
#include "huc.h"
str ronaldo[203] = {R,o,n,a,l,d,o, ,h,a,s,n,',t, ,r,e,a,l,l,y, ,f,o,u,n,d, ,h,i,s,*,R,e,a,l, ,M,a,d,r,i,d, ,f,o,r,m, ,i,n, ,a, ,b,i,g, t,o,u,r,n,*,a,m,e,n,t, ,f,o,r, ,P,o,r,t,u,g,a,l, ,y,e,t, ,-, ,b,u,t, ,h,e,*,',s, ,o,n,l,y, ,o,n,e, ,g,o,a,l, ,a,w,a,y, ,f,r,o,m, ,m,o,v,i,*,n,g, ,a,h,e,a,d, ,o,f, ,L,u,i,s, ,F,i,g,o, ,i,n, ,t,h,e, ,a,l,*,l,-,t,i,m,e, P,o,r,t,u,g,u,e,s,e, ,l,e,a,d,i,n,g, ,g,o,a,l,s,*,c,o,r,e,r,s, ,l,i,s,t,};
int chars =0;
int x = 1;
int y = 19;
j2 = joytrg(0);
for (int i < 203)
{
if ( ronaldo[chars]=="*") { y++}
put_string (ronaldo[1..chars]; \\don't know if put_string will work?
if(j2 & JOY_B) {chars++} // if button II is pressed, add a character
clrscr ();
{
I think though that that one will keep going up forever, whereas I need to limit the text to about 2 lines at the bottom of the screen.
-
I hope you won't download Insanity. It's Arkhan's game that he sells.
Sometimes I wonder if you fully read everything in threads, dude.
If you have Insanity, put it in your system with a System Card 2 instead of 3. Watch the CD Error screen. (You can grab the demo from aetherbyte.com and do it in an emulator instead if you want).
Anyway, soop,
you've got the right idea, but it's got some issues.
You need to use a while loop, not a for loop. For loops require an initial value, an exit condition, and an increment condition:
for(i = 0; i < 203; i++)
Also, the way you have this setup, it will loop 203 times and stop. If button 2 is never pressed, it will never show anything and it will exit. Also,you clear the screen, so you're going to wipe out everything anyways... so you really won't ever see anything, lol.
You want a while loop:
while(i < 203)
{
if(button 2 is pressed)
{
do the character printy stuff, including updating the current character pointer and all of that. Be sure to update i, or you will never exit this loop!
}
}
This is sloppy and needs done properly, but I think it gives you an idea of what I meant.
-
Gotcha. This is gonna take me a while to get used to.
-
yeah you may want to work through some C programming tutorials first before you graduate to dealing with HuC and all of its quirks.
-
*edited*
Not an appropriate line of conversation for this particular topic. Not interested in trolling the topic at hand.
-
No, I don't read every word. I read quickly, sometimes skimming, unless there appears to be some compelling reason for me to read fully. It's a forum, not a novel.
How will you know if there is a compelling reason to read fully, if you are skimming everything?
This is the internet equivalent of half-assedly listening to someone speak aloud. It's kind of a bad idea.
-
*edited*
Not an appropriate line of conversation for this particular topic. Not interested in trolling the topic at hand.
-
Reading quickly is practically the same as skimming, dude.
Bottom line, you aren't reading what people say carefully.
If you are going to respond/post, it's your job to make sure you read what people say.
I mean, you can keep flying through posts if you want. It just means you'll probably keep posting things that you wouldn't have, had you read everything.
-
*edited*
Not an appropriate line of conversation for this particular topic. Not interested in trolling the topic at hand.
-
Anyway, back to on-topic:
http://www.cprogramming.com/tutorial.html
Check this out Soop, to give you the right frame of reference for programming in C.
There are differences between this tutorial and HuC, but they are very minor and have to do with function declarations and loop initializers. We can get to that later.
-
Anyway, back to on-topic:
http://www.cprogramming.com/tutorial.html
Check this out Soop, to give you the right frame of reference for programming in C.
There are differences between this tutorial and HuC, but they are very minor and have to do with function declarations and loop initializers. We can get to that later.
Ah! thanks Arkhan, I actually stumbled across one of those already. I'll have a read through. The compiler hated that last one, something wrong with the array.
Phew, slogging through them. Not sure how much is going in, they're not as good as the HuC ones. On number 7, just about to move to arrays
-
No good. Are there any other tutorials? I feel like this guy is basically introducing me to concepts, giving me one example usage, and then moving on to other things. I know how to do what I'm thinking in AWK, but I need something a little more in-depth about arrays and strings here.
I'll have a look, but if anyone knows anything...
*edit* don't worry, I remembered we have access to a load of online programming books. O'Reilly to the rescue!
-
This is one of those cases where code-sharing might be nice (your latest code, I mean, not what you already posted above). We could all look at your code and those with know-how can offer advice and those without can learn from the sharing experience.
-
Thanks Spenoza - here's what I have so far;
#include <iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main ()
{
int length(8);
while (length < 203)
{
char ronaldo[203] = "Germany are favourites to win the tournament following another impressive performance and their manager Joachim Loew believes victory over Denmark is important in their final match of the group.";
printf ("%.*s\n", length, ronaldo);
length++;
clrscr();
}
}
Clrscr doesn't seem to work in the C compiler I downloaded, but everything else does. I'll have to try it on my netbook when I .. well, actually I'm gonna go out and get drunk tonight, so maybe Friday.
-
im on my vita so pardon my typos.
first you shouldnt declare a variable in the while. next you need to allocate memory for the string and use something like strcpy to copy it in. look up tutorials on c-strings check cplusplus.com!!!!
-
Just in terms of syntax, in addition to what Arkhan said you've got an interesting mix of C++ and C going on there. First, I'm pretty sure your string needs to be terminated with a '\0'. conio.h should include clrscr(), what's the error message you are receiving? You don't need to use the std namespace nor include iostream if you are using C style IO.
-
im on my vita so pardon my typos.
first you shouldnt declare a variable in the while. next you need to allocate memory for the string and use something like strcpy to copy it in. look up tutorials on c-strings check cplusplus.com!!!!
Shit, yeah I see the mistake with declaring the string in while. In fact, what I need to do is declare a load of strings, and actually have a pointer in the while loop, so I can switch in different strings.
But allocating memory and using strcpy? Arrgh, C, why must you make everything so difficult? I know it's more tailored to it, but I could have done thin is seconds with AWK or Perl...
Sadler, I'm getting "error: 'clrscr' was not declared in this scope"
Sorry for the mix of C and C++, I only really want to learn HuC, but I'm going by C++ tutorials. I just want to get the basics right now really, so hopefully it won't matter too much.
*edit* it looks like the terminating /0 is added automatically in the format I used. The string length was slightly over, so I edited it to
while (ronaldo[length] != '\0')
Which now ends bang on the end of the string, without me manually adding the /0 to the string.
*edit 2* now I'm having trouble with pointers...
#include <iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int main ()
{
int length(0);
char (*currentstring)[500];
char sadler[500] = "Just in terms of syntax, in addition to what Arkhan said you've got an interesting mix of C++ and C going on there. First, I'm pretty sure your string needs to be terminated with a '\0'. conio.h should include clrscr(), what's the error message you are receiving? You don't need to use the std namespace nor include iostream if you are using C style IO.";
char ronaldo[203] = "Germany are favourites to win the tournament following another impressive performance and their manager Joachim Loew believes victory over Denmark is important in their final match of the group.";
currentstring = &sadler;
while (*currentstring[length] != '\0')
{
printf ("%.*s\n", length, *currentstring, 8, 13);
length++;
}
}
I've added a second string, and called to one of them with a pointer within the loop. When I use th asterisk in front of the pointer (to call to the memory address of the string) it just prints the first character, J. If I remove the asterisks, which should call the actual data, it loops endlessly.
*edit 3* fixed, just needed to put brackets around the currentstring pointer. I must say, I'm enjoying this :)
*edit 4* Thinking about making a 2 dimensional array for each block of text, comprised of 32 character blocks, as a way to keep the text to 2 lines on screen. It might be more elegant than asterisks every 32 characters.
-
Well, I've done some looking, and it appears clrscr() is non-standard, and conio.h should be avoided.
Is this ... disdain of clrscr() inapplicable to HuC? I'd imagine a games console is different to a system console with regard to system calls and how they're used.
Still, it's a bit annoying I can't get it to work in this compiler, but it's not the end of the world.
Dammit, it looks like HuC doesn't like the syntax of this other compiler. I just tried slotting some stuff in, and it doesn't like the arrays (I focused on that rather than the pointers) and every time I try
char myarray[10];
or
char mayarray[10] "1234567890";
it says the variable isn't declared. Any ideas?
according to the wiki on obeybrew, I can do this, which isn't very different;
const int paldata[] = { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0};
const int sprdata[] = { 1001, 2002, 3003, 4004, 5005, 6006, 7007, 8008, 9009, 10010, 11011, 12012, 13013, 14014, 15015, 16016 };
maybe it's const, maybe it's just the curleys.
-
still on my vita. remember huc is just a compiler. it uses small c style syntax.
when i get home i got code for you. maybe you can come on irc. live help is easier
-
Fanks Ark, time difference is a bit of a bastard, it's like 1:30 am here, and I gotta sleep :D I got next week off though so it might be better to do it then?
Besides, it's train of thought, so I can probably solve it given time, but I def. appreciate the backup.
-
I wrote a little demo for you soop. It shows a picture at the top and prints some text at the bottom of the screen one character at a time, kind of like an RPG might. It's definitely not an example of good programming, but I put a lot of comments to hopefully help you out with HuC. I know it confused the hell out of me as I first began using it...
Anyway, here's the .rar with everything: http://pce.lifeabroad.org/files/soop1.rar
I got a little carried away so the code is rather long to paste here, but I uploaded it as a text file here (http://pce.lifeabroad.org/foo/soop1.txt) for quick reference...
hope it helps at least a bit
-
^^^ Yeah, go with that for now. I'm glad someone beat me to it, because I am tired. Weddings are long and boring.
-
wow! This is awesome, and much appreciated guys! Cabbage, I'm gonna look into this after my cup of tea :)
*edit* Cabbage, that's superb! I'm gonna re-edit my code now,, but what you've done is amazing :)
-
I should point out, functions do have types in HuC, and you can return values from them, even though you never actually say their types. The default is int.
-
Weddings are long and boring.
Wait 'till you try marriage itself! ;-D
-
My wedding wasn't long and boring, but if you're not the one getting married they sure can seem that way, especially the more traditional ones.
-
This was my sisters wedding, so I was involved with more than just the whole "sit down and watch the nonsense". I was part of the "show up early and help with all the pre nonsense nonsense"
Plus it was like 3 hours away, and outside.
These are things I don't like.
-
Weddings suck.
-
Weddings suck.
But honeymoon is the coolest part(mainly the night),after you spend your time solving problems in two, what you never had alone . :mrgreen:
-
You are right, honeymoons are great. Too bad some people get married when their lives are already busy and don't get honeymoons *grumble*