hello, I’m programming a new game based on characters from old Spanish game called “Captain Sevilla ‘”, I know nothing of programming in C and I need your help.(what little I know is thanks to your comments and demos)
when include in the code new documents. h , the screen appears black. Why?
I leave the code works. I want to include the character and move it for the background (for the moment,jejeje)
thank you very much for your time!!
my english is very bad, sorry!!
Rubengar, I took a look at the code you posted (capitan.c) and I tried to make it easier to read and give you some tips in the comments. Other than some minor readability issues, it looks pretty good. If you want an example of moving a character around on the screen, check out demo 2 in that folder of 6 demos I posted. Also, I would recommend switching from the single file libgccvb to the more complete version that’s spread over multiple files (that’s also in the folder with my demos.)
Tambien, no te sientas mal de su ingles… Deseo que hable espanol como te hablar ingles!
Fwirt wrote:
Also, I would recommend switching from the single file libgccvb to the more complete version that’s spread over multiple files (that’s also in the folder with my demos.)
Maybe his libgccvb.h #includes them, so he doesn’t need to bother with it. That’s what mine does.
Also, why do you use for(;;) instead of while(1)? Is there any advantage, or is it just a stylistic choice? I believe that the compiler will recognize 1 as being always true and will not generate code to test the condition.
Tanks for your time!!
what is the error?? the screen goes black when I include more documents. h!!!
HorvatM wrote:
Maybe his libgccvb.h #includes them, so he doesn’t need to bother with it. That’s what mine does.
That’s what mine does too, actually. I guess I wasn’t thinking… :-P. I assumed that he had the single file one because when I started programming that version was all that I could find.
HorvatM wrote:
Also, why do you use for(;;) instead of while(1)? Is there any advantage, or is it just a stylistic choice? I believe that the compiler will recognize 1 as being always true and will not generate code to test the condition.
RunnerPack suggested that to me. I always used to use while(1) because I thought that was correct (and I still think it’s more readable) but RunnerPack suggested that for(;;) was a tiny bit faster. Now that you bring it up and I did some research, I’m not sure if that’s actually true (maybe someone knowledgeable can tell me either way?)
rubengar wrote:
what is the error?? the screen goes black when I include more documents. h!!!
I’m sorry rubengar, I don’t understand… Do you mean that when you include a file called “documents.h” your screen won’t display anything, or do you mean that if you try to include any more files in your program, your screen blacks out? Either way, unless you’re changing something in your main function, it shouldn’t be affecting your display… (Unless you’re running out of memory somehow?)
EDIT: I just made a quick C program:
int main() { while(1); //for(;;); return 0; }
…to test the while vs. for thing and compiled it twice (once with the for commented out, once with the while commented out) with gcc -S to generate an assembly listing. It came out the same both times. So they are functionally equivalent then. There’s really only going to be one infinite loop in your program anyway, but I guess you can choose which way you want to do it without speed concerns…
- This reply was modified 14 years ago by Fwirt.
HorvatM wrote:
why do you use for(;;) instead of while(1)? Is there any advantage, or is it just a stylistic choice? I believe that the compiler will recognize 1 as being always true and will not generate code to test the condition.
You are right, no speed advantage with modern compilers. Plus, even if it was a dumb compiler and did use a few extra clocks, who cares?
But the real reason is because it is bad programming practice to check an expression that can only equate one way (for example, while(1) can only be true in this case). So if you check your code using something like a lint checker or misra rule checker, this would be flagged as an error.
mbuchman wrote:
You are right, no speed advantage with modern compilers. Plus, even if it was a dumb compiler and did use a few extra clocks, who cares?
A few extra clock cycles can make a big difference in timing critical situations! What if it was the difference between finishing your polygon drawing routine and having to wait another frame? Of course if it was that critical you would probably be writing assembly, but still…
Fwirt wrote:
I’m sorry rubengar, I don’t understand… Do you mean that when you include a file called “documents.h” your screen won’t display anything, or do you mean that if you try to include any more files in your program, your screen blacks out? Either way, unless you’re changing something in your main function, it shouldn’t be affecting your display… (Unless you’re running out of memory somehow?)
if I try to include any more files in my program, my screen blacks out.
Thanks for your time!!
It’s hard to say without knowing exactly what files you are trying to include. Maybe they are too large and contain too much data? The VB only has 64 KB of ram you know…
I solved the problem !! I change the part in the BAT file that refers to padding the ROM!! thanks friends!!!!
the character movement is OK! One question! when the caracter stop, how to stop always in the first frame of the animation?? and other cuestion because the caracter looks bad to go through the background!!
very very thanks!!!
Attachments:
rubengar wrote:
One question! when the caracter stop, how to stop always in the first frame of the animation??
Why not just set ‘frame’ to 0? It controls what frame is displayed, right?
and other cuestion because the caracter looks bad to go through the background!!
I might be wrong, but I believe it’s because it has black pixels.
“Why not just set ‘frame’ to 0? It controls what frame is displayed, right?”
set frame to 0 but don´t work for this function
“I might be wrong, but I believe it’s because it has black pixels.”
other colors are wrong too. In other games the black color can be used as solid colour.
thanks!!
HorvatM wrote:
rubengar wrote:
and other cuestion because the caracter looks bad to go through the background!!I might be wrong, but I believe it’s because it has black pixels.
Actually, the Virtual Boy is perfectly capable of displaying solid black, but you have to be careful, because there are two different “blacks.” If you set one of the pixels in your char to binary 00, that’s actually the code for a transparent pixel (but it will look black on a black background.) In order to get true black, you will have to change one of your palettes to include solid black, then set the bgmap to reference that color. For example:
VIP_REGS[GPLT0] = 0xE0; // 0b11100000
will change any cells in your BGMap using palette zero (the default) so that “dark red” (0b01) is now black. Make sure to put that statement after vbDisplayOn() if you want to try it, as vbDisplayOn() resets all palettes to 0xE4 (0b11100100).
Fwirt wrote:
HorvatM wrote:
rubengar wrote:
and other cuestion because the caracter looks bad to go through the background!!I might be wrong, but I believe it’s because it has black pixels.
Actually, the Virtual Boy is perfectly capable of displaying solid black, but you have to be careful, because there are two different “blacks.” If you set one of the pixels in your char to binary 00, that’s actually the code for a transparent pixel (but it will look black on a black background.) In order to get true black, you will have to change one of your palettes to include solid black, then set the bgmap to reference that color. For example:
VIP_REGS[GPLT0] = 0xE0; // 0b11100000will change any cells in your BGMap using palette zero (the default) so that “dark red” (0b01) is now black. Make sure to put that statement after vbDisplayOn() if you want to try it, as vbDisplayOn() resets all palettes to 0xE4 (0b11100100).
succes!!! thanks you very much!!
when the caracter stop, how to stop always in the first frame of the animation??
sorry for my questions!!
I´m a graphic designer in reality and your information is of great help to me!!
thanks friends!! 🙂
Attachments:
rubengar wrote:
when the caracter stop, how to stop always in the first frame of the animation??
That really depends on your code. The basic idea is that if the character is not moving, you set the sprite to the first frame. That means you have to keep track of whether the character should be moving, which could be as simple as checking if the player isn’t pressing anything. Some pseudocode for that would be:
if (left is pressed) move left update animation else if (right is pressed) move right update animation .... // More ifs else if (nothing is pressed) change the frame to the first one
…And then update the images onscreen. To be more efficient, you could even put the nothing pressed case at the top, and then your code wouldn’t have to check for any of the other cases. There are more complicated ways of doing this, but this simple way might work for you.
Fwirt wrote:
rubengar wrote:
when the caracter stop, how to stop always in the first frame of the animation??That really depends on your code. The basic idea is that if the character is not moving, you set the sprite to the first frame. That means you have to keep track of whether the character should be moving, which could be as simple as checking if the player isn’t pressing anything. Some pseudocode for that would be:
if (left is pressed) move left update animation else if (right is pressed) move right update animation .... // More ifs else if (nothing is pressed) change the frame to the first one…And then update the images onscreen. To be more efficient, you could even put the nothing pressed case at the top, and then your code wouldn’t have to check for any of the other cases. There are more complicated ways of doing this, but this simple way might work for you.
Succes!!! thanks friend!!! You are a big help for my!! I will send a “Jamón de pata negra” jejeje
Attachments:
Hi friends my character´s jump is very ugly!! I need your help to improve. Please you see my code and help me to improve jumping, I don´t mind the animation, only improve movement. I used 3 days and not improving jump, I leave my code! thanks for your time!!:-)
Attachments:
rubengar wrote:
Hi friends my character´s jump is very ugly!! I need your help to improve. Please you see my code and help me to improve jumping, I don´t mind the animation, only improve movement. I used 3 days and not improving jump, I leave my code! thanks for your time!!:-)
Hi, rubengar,
I haven’t looked at your code (or played your demo, actually…) but I’ve explained a system for jumping using simulated gravity in some detail in this post. Then I wrote an (untested) implementation and posted it here (BTW, the search function is your friend ;-)).
I hope this helps; this seems like it could end up being a very fun game!
EDIT: I just played it and looked at the code. I can see one major problem with your jumping (he immediately “teleports” to the top of the jump) and a small graphical glitch in the walk-cycle (some pixels from the next frame show up in one of the right-facing images) but it definitely looks good so far. Just try implementing the code I posted above. It can probably be copied/pasted, for the most part.
RunnerPack wrote:
rubengar wrote:
Hi friends my character´s jump is very ugly!! I need your help to improve. Please you see my code and help me to improve jumping, I don´t mind the animation, only improve movement. I used 3 days and not improving jump, I leave my code! thanks for your time!!:-)Hi, rubengar,
I haven’t looked at your code (or played your demo, actually…) but I’ve explained a system for jumping using simulated gravity in some detail in this post. Then I wrote an (untested) implementation and posted it here (BTW, the search function is your friend ;-)).
I hope this helps; this seems like it could end up being a very fun game!
EDIT: I just played it and looked at the code. I can see one major problem with your jumping (he immediately “teleports” to the top of the jump) and a small graphical glitch in the walk-cycle (some pixels from the next frame show up in one of the right-facing images) but it definitely looks good so far. Just try implementing the code I posted above. It can probably be copied/pasted, for the most part.
hello, your code I had seen him days ago, but I did not work.
I hope you can help me. you could include in my code your jump code??, maybe something I did wrong
🙁
the glitch I’ll fix it when the char animation ends!!
thank you very much!!!!
rubengar wrote:
hello, your code I had seen him days ago, but I did not work.
Can you post what you did? Maybe I can see your error (or, more likely, my error ;-)).
I hope you can help me. you could include in my code your jump code??, maybe something I did wrong
🙁
Well, I really don’t have time right now, and without the graphics I can’t recompile to test. Also, I think it would be a good learning experience for you to get it working yourself. You’re doing very well so far for a “non-programmer” 😀
Maybe you should just forget my code, and try to understand and then implement the algorithm yourself. Maybe a physics text-book would help?
the glitch I’ll fix it when the char animation ends!!
thank you very much!!!!
You’re very welcome.