I’ve been thinking of releasing a lot of my source code… but I think quality is better than quantity… and I have a lot of CRAPPY code (mostly hacked up junk just to quickly throw something together). I’d rather release just good code so people can learn from it, or if someone’s trying to do something specific, send them my code and explain it to them in a post/email, rather than just posting ugly code.
DogP
You need to fix your ()’s, like:
if ((getBGMapChar(1, (xpos/8)+1, (ypos/8)+1)==512)||(getBGMapChar(1, (xpos/8)+2, (ypos/8)+1)==512)||(getBGMapChar(1, (xpos/8)+1, (ypos/8)+2)==512)||(getBGMapChar(1, (xpos/8)+2, (ypos/8)+2)==512)) level=level-1, xpos=10, ypos=160, horz=0, vert=0;
DogP
That’s just a placeholder for whatever you want to do when they crash into a wall.
DogP
I don’t think it’s very efficient to use to write a framebuffer… it’s really not that efficient speed-wise for anything. I think it’s biggest benefit is that it’s convenient to do operations on data as if it was strings of bits, rather than having to worry about alignment, masking, shifting, etc. If you’re processing a screen, you know where everything should be, and can easily draw vertical lines using standard instructions. Of course it may be more efficient if you do a bitstring function in asm than a vertical line function in c (since gcc doesn’t do bitstrings), but you should be able to do an asm vertical line function without bitstrings much more efficiently than bitstrings.
If you make a raycaster, I’d just use a standard vertical line drawing function written in c, and when you get to a point that you want to optimize, just rewrite the line functions in asm, and drop it right into your existing code without having to make any other changes (and I’d be glad to help out w/ that if you need it).
DogP
Yeah, you need the function declared above the main function… like this:
HWORD getBGMapChar(int bgmap, int x, int y)
{
return (BGMM[(0x1000 * bgmap) + (y * 64) + x]&0x7FF);
}
int main()
{
...existing code...
if ((getBGMapChar(bgmap, x, y)==40) || (getBGMapChar(bgmap, (x+1), y)==40) || (getBGMapChar(bgmap, x, (y+1))==40) || (getBGMapChar(bgmap, (x+1), (y+1))==40))
crash=1;
...rest of code...
}
The argument names in the first line are different than what I used in the main program below… the ones for the main program are just placeholders that you should change… in your program it should actually be getBGMapChar(1, (xpos/8)+1, (ypos/8)+1)==512. The first function (getBGMapChar) shouldn’t be changed.
DogP
Good to see you’re getting the hang of it. For walls, the easiest way I can think of is to check the BGMap at the position of the sub to determine which character is there, and if it’s your wall character (coral or whatever you want it to be), then crash.
Couple comments:
1) The wall character should be 8×8.
2) The wall character should be on 8 pixel boundaries (so it uses the same character rather than two new character for the top half and bottom half).
3) If you understand BGMaps, you can just create the wall character and create the BGMap by hand (pretty easy), which will take care of alignment for you, since BGMaps are created by an 8×8 character on 8 pixel boundaries. Otherwise you can make it in paint and use VIDE to convert it… just make sure in the charset that there’s only one copy of the wall character.
4) If you want your walls to be at different offsets, it’s doable, you’ll just need to check for multiple characters, but since only part of the character would actually be the wall, you’d have to check for partial collision as well, because people would get really annoyed if they die because they came within 7 pixels of a wall.
Now… how to do it. Like I said, create the BGMap as usual. Then figure out which offset in the charseg that the wall character is at (you can just count the chars in VIDE, and remember the first char is offset 0, not 1). Then do something like:
HWORD getBGMapChar(int bgmap, int x, int y)
{
return (BGMM[(0x1000 * bgmap) + (y * 64) + x]&0x7FF);
}
if ((getBGMapChar(bgmap, x, y)==40) || (getBGMapChar(bgmap, (x+1), y)==40) || (getBGMapChar(bgmap, x, (y+1))==40) || (getBGMapChar(bgmap, (x+1), (y+1))==40))
crash=1;
For the example, I’m assuming the wall char is at location 40 in charseg0. If it was in charseg1, it’d be at 512+40, and so on. I’m also assuming that your sub is 16×16, which is why it’s checking x, y, x+1, and y+1. I would suggest that you make your sub a multiple of 8 if it isn’t already, to make this easy. Note that it doesn’t need to be a rectangle… it could be rectangle plus periscope at the top by doing something like only checking the 8×8 squares that are used like: x, (y+1); x, (y+2); (x+1), y; (x+1), (y+1); (x+1), (y+2); (x+2), (y+1); (x+2), (y+2);. Notice that it’s a rectangle with a periscope at x+1, y.
I’d also try to make the graphics as close to filling the chars as possible to keep people from being annoyed that they crashed because of the rectangular collision detection. Of course you could also add more specific checking around the sub, but once again, that’s more complexity.
Note that x,y is referring to coordinates in 8×8 chars, so 1,1 would actually be pixels 8,8. And you’ll need to divide your movement x,y by 8 to determine the char.
I see you referred to VUE Snake… one thing you should notice is that it moves in large steps, which makes collision detection easy, since it always either completely occupies a block or not at all… but I’m assuming you’re wanting your sub to move in the small smooth steps like you’ve shown so far.
I haven’t tested this code, and I just threw it together from the concept that I use for collision detection on Mario Kart, but it should work. I’d expect that it’ll need some tweaking, or that I left something somewhat important out. Hopefully it’ll get you started though.
DogP
I’d say it’s unlikely to see Reality Boy ported to it, since it’s not very efficient and barely runs full speed on a fast PC… although the ARM9 in the iphone has some similarities to the v810, so the CPU core could probably be rewritten in ASM to gain some speed. I don’t know if Allegro has been ported to the iphone or not… if not, it’d take a lot of work to get Reality Boy working for it (the only open source emu… well, and Red Dragon, but that’s based on RB).
The best chance would probably be Richard Bannister porting ViBE, since that’s already for the Apple, although I don’t know how many of the Apple libraries he used, and how many have been ported to the iphone. Of course that’s not open source, so it’d really have to be him making it (or he’d have to give the source to someone else to do it).
DogP
LOL! Akumie, are you KR155E’s official spokesman? 😉
DogP
I believe those plugins have to be in the plugins directory inside the VIDE directory, not just in the root of the VIDE directory (make it if it doesn’t already exist). This is what you should see when you get it correctly: http://home.comcast.net/~virtual.boy/VB/export.jpg . This only pops up when you export the charmap, not the charset.
DogP
I see this topic is still a sticky, but pretty old… any word on the progress of the new VIDE? I don’t have any new suggestions, but reading through this post again makes me excited about how cool it will (hopefully) be.
DogP
I see you’re copying the chars to Charseg 2… when you exported the map, did you select that the chars will be in Charseg 2? You need to make sure you install DanB’s VIDE export plugin that was mentioned earlier in the thread if you haven’t already.
This will make a popup window come up when you click export to .h on the charmap. In that window, you want to select charseg 2. You could also put the treasure graphics in the same image as the rest of your game graphics, and just select it with vbSetWorld(29, WRLD_ON|2, xpos, 0, ypos, X_POS_IN_GFX, 0, Y_POS_IN_GFX, WIDTH, HEIGHT);, which cuts out a chunk WIDTH wide and HEIGHT high starting at X_POS_IN_GFX, Y_POS_IN_GFX in your graphics, and places it at xpos and ypos.
If nobody answers your question about creating the level, I’ll try to answer tomorrow night, but I’m pretty busy tonight and don’t have time for a lengthy post.
DogP
Oh… you should clear your BGMap(1)… similar to the copymem((void*)BGMap(0)… that you used for creating your graphics, you need to set the other BGMap to be all blank. You can do that with setmem((void*)BGMap(1), 255, 1024*16); . I put 255 in there assuming that char 255 in your charseg is an all blank character. If not, go into VIDE and find the index of a blank character and put that number in.
DogP
I haven’t tried compiling any of this code, but I think this is probably what you want to do. For the first problem, you want to have the text output to a different BGMap. You do that by ORing the BGMap number in the second argument of vbSetWorld(), then change the vbTextOut to output to BGMap 1 like:
vbSetWorld(30, WRLD_ON|1, 0, 0, 0, 0, 0, 0, 384, 224); vbTextOut(1, 1, 7,"IMPORTANT:");
For the second question, do you have a itoa() function in your libgccvb.h? If so, that’s what you want to use. If not, I’d suggest getting it (should be able to find one in some sample code around here), but realize it’s not perfect. A simple way to do it would also be:
char level_str[3]; char lives_str[3]; //null terminate string level_str[2]=0; lives_str[2]=0; level_str[0]=(level/10)+'0'; level_str[1]=(level%10)+'0'; lives_str[0]=(lives/10)+'0'; lives_str[1]=(lives%10)+'0'; vbTextOut(1, 4, 7,level_str); vbTextOut(1, 5, 7,lives_str);
Don’t forget all variables need to be declared before any code, so the char lines need to be up by your int vert=…. and the other code can be done in your main loop, but should only need to be done whenever the player loses a life or goes to the next level. This code would assume that the level and lives are never higher than 99 (and always display 2 digits).
Also, any reason you only want to play with the left eye? 😉 You should change the WRLD_LON to WRLD_ON (or WRLD_LON|WRLD_RON). That will make it display to both eyes.
DogP
Very cool! About the start press problem, you can fix that by doing while(vbReadPad()&K_STA); after the while(!(vbReadPad()&K_STA)){}. That will cause it to wait until the button is released.
The other suggestion (doesn’t matter too much in this case, but good programming practice) is to change the while(!(vbReadPad()&K_ANY)){} and K_STA loops to do the vbTextOut and other things outside the loop, then just wait with while(!(vbReadPad()&K_ANY)); . The way you’re doing it now, you’re redrawing the same text over and over, when you just need to draw it once and wait. I see you also have multiple vbDisplayShow()s… that’s unnecessary, and definitely doesn’t need to be done in the loop.
For it to keep moving instead of changing the sub’s position directly with the keypad, increment/decrement it’s position with a variable that you change with the keypad. Something like this:
while(1)
{
if(vbReadPad()&(K_LD)) vert=1;
if(vbReadPad()&(K_LU)) vert=-1;
if(vbReadPad()&(K_LL)) horz=-1;
if(vbReadPad()&(K_LR)) horz=1;
xpos+=horz;
ypos+=vert;
vbSetWorld(31, WRLD_LON, 0, 0, 0, 0, 0, 0, 0, 0);
vbSetWorld(30, WRLD_LON, xpos, 0, ypos, 0, 0, 0, 384, 224);
vbSetWorld(29, WRLD_END, 0, 0, 0, 0, 0, 0, 0, 0);
vbWaitFrame(1);
}
Of course this will cause it to always move… to make it to press right to start moving right, then left to stop, then left again to start going left, do something like:
if(vbReadPad()&(K_LD)) vert++; if (vert>1) vert=1; if(vbReadPad()&(K_LD)) vert--; if (vert<-1) vert=-1;
Then you could modify that to have acceleration and deceleration based on how long they hold the button by making it clip at +/- 2 or 3, etc with if (vert>3) vert=3; Of course you'll also need to make sure it doesn't go off the screen, but that can be part of the collision detection that I'm sure you're planning on doing.
Nice work so far... keep it up!
DogP
Instead of using if(vbReadPad()&K_ANY), use while(!(vbReadPad()&K_ANY)). If you just want it to wait, just do: while(!(vbReadPad()&K_ANY));, or if you want it to do something while it waits for a keypress, you can do while(!(vbReadPad()&K_ANY))
{
//do stuff
}
DogP
Well if you already know how to program, I’d just download some sample code and go from there. There’s a few basic things you need to know about C, but for the most part, you’ll recognize them immediately by looking at some code. I’ve never really found books to help much… just try compiling someone’s working code, change some things until it does what you want it to do (or breaks), then go from there.
DogP
I don’t remember the actual model of the printer off hand, but I know it supports at least a couple types of plastic (I’ve seen black and white things printed by it).
DogP
You really just need to know C… but I wouldn’t say C is the best language to learn programming with. You should have at least an understanding of how programming works, which a simpler language on a PC might help you understand (BASIC, Visual Basic, even some web stuff like Javascript). Once you learn the loose languages, then you can jump into some of the stricter languages like C. But until you understand programming, there’s really no need to get your computer set up (unless you just want to play around). If so, check out: http://www.vr32.de/modules/tech/index.php?sec=utils … basically you need gccvb, VIDE, and Reality Boy.
You could also pick a niche that you are good at, like creating graphics, sounds/music, or even game/level design… which, if you restrict yourself to limitations that the VB has, would be very useful for those that do program (basically don’t make fully 3D rendered scenes with 16.7 million colors… we have 4 shades of red, counting black).
DogP
Video works fine for me on my XP laptop w/ WMP9. I’m gonna try to get this center piece printed out on a 3D printer (in whatever material they think would be most suitable… probably something somewhat flexible, but strong)… hopefully they’ll be able to do it for me.
DogP