C/C++ Programming Help Thread
This is a discussion on C/C++ Programming Help Thread within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Zitat von cruisx How can i make it so that the cliffs have collision detection too? I know how to ...
-
03-25-2008, 02:10 AM #8281QJ Gamer Silver
- Registriert seit
- Feb 2007
- Ort
- Melbourne, Australia
- Beiträge
- 1.773
- Points
- 8.717
- Level
- 62
- My Mood
-
- Downloads
- 0
- Uploads
- 0
Zitat von cruisx
Someone said that earlier, sorry forgot who :oLook for Box-Line collision on Google.
WHA!?
-
03-25-2008, 08:16 AM #8282
- Registriert seit
- Jan 2006
- Beiträge
- 9
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
I have got a error when i try to compile.
-
03-25-2008, 08:20 AM #8283It's good to be free...

- Registriert seit
- Feb 2007
- Beiträge
- 2.440
- Points
- 10.420
- Level
- 67
- Downloads
- 0
- Uploads
- 0
:facepalm:
You spelled debug wrong.pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
-
03-25-2008, 08:20 AM #8284I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
*Sigh* have you even tried seeing what the error is?
pspdebub does not exist, is exactly true, its pspdebug.
-Aura
EDIT: Archaemic beat me to it :Argh:
-
03-25-2008, 08:21 AM #8285QJ Gamer Platinum
- Registriert seit
- Feb 2006
- Ort
- National Front Disco
- Beiträge
- 13.057
- Points
- 66.627
- Level
- 100
- Downloads
- 0
- Uploads
- 0
I think you spelt pspdebug.h wrong in the include, you wrote:
When it should be:Code:#include <pspdebub.h>
EDIT: Beaten...Code:#include <pspdebug.h>
-
03-25-2008, 08:41 AM #8286
- Registriert seit
- Jan 2006
- Beiträge
- 9
- Points
- 4.209
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von Moose Island
Sorry for this stupid action of me i am just a starter but thanks.
-
03-25-2008, 11:31 AM #8287I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I have the address of a function of mine which is not working, and I want to link a new function in its place. I think I found a post a while ago showing the same basic idea, where it replaced the address of the function in memory,and I've been searching for close to an hour to find it again with no luck. Can anyone give me some example code or link me to the post again if you somehow know the post? The post, IIRC, was about getting sceKernelExitGame to link to the devs shell, and to not exit to the XMB instead, incase thats of any help.
Thanks.
-Aura
-
03-25-2008, 12:17 PM #8288
I don't know how, but I remember that thread also.
Zitat von Auraomega
I've got a couple questions
I think that's it.[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
03-25-2008, 12:20 PM #8289QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von BigSanFrey
ok thanks, ill see if box-line collision helps me and if i understand it =)
also someone else told me to use his, just wondering what you guys think..
Code:typedef enum { TILE_PLAYER=1, TILE_GRASS=2...ETC } inline int getCurrentTileType(const int& x,const int& y,const map& themap) { return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x])); } inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap) { px=-1,py=-1; int x=0,y=0; for (y=0;y<themap.height();y++) { for (x=0;x<themap.width();x++) { if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue; px = x; py = y; return; } } } int main() { map themap; while(running) { int player_x,player_y,current_tile; getTilePos(TILE_PLAYER,player_x,player_y,themap); current_tile = getCurrentTileType(player_x,player_y,themap); if(current_tile == TILE_GRASS) { //COLLISON! do whatever.. } if(timer.diff() >= 10)..cleanup render etc.. } }
-
03-25-2008, 12:37 PM #8290
In my Lua tile engine, that's how I did collision detection. And IMO, it's a very fast and easy way.
Zitat von cruisx
[IMG]http://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Zoso.svg/744px-Zoso.svg.png[/IMG]
Looking for some good C programming tutorials for the PSP? Look no further! [URL="http://psp-coding.com/"]PSP-Coding.com[/URL] is your source for all your PSP coding needs.
-
03-25-2008, 01:01 PM #8291I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yep, in one, thanks for that :)
Zitat von Judas
@cruisx:
Thats, in my opinion, the easiest and quickest method of 2D collision, I only use Box-Line collision for 3D and the method you posted for 2D collisions.
-Aura
-
03-25-2008, 01:07 PM #8292QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
Zitat von Auraomega
ok sweet =p.this might sound noobish but can i use that in Oslib or do i have to convert it for it to work?
-
03-25-2008, 01:10 PM #8293I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
That method should work just fine in OSLib I believe, I use the method with graphics.c and OSLib is similar in the way it acts.
-Aura
-= Double Post =-
My code, in another module to my existing faulty code:
The above code works if its directly done into the main Project4 code, but when its done from an external module it crashes the PSP. My assumption is that the address not correct.Code:int load_MUSIC(char bpath[], int clockA, int clockB); int load_MUSIC_patched(char bpath[], int clockA, int clockB) { // Corrected code } int module_start() { *((unsigned int *)load_MUSIC) = J(load_MUSIC_patched); return 0; } int module_stop(void) { return 0; }
I have used a stub file:
is the underlined pointer the address in memory which the function will be loaded (I doubt because isn't the memory dynamic?), or is it the NID? If its the NID, is there a function to find the memory location using the NID?Code:.set noreorder #include "pspstub.s" STUB_START "Project4Stub",0x40090000,0x00010005 STUB_FUNC 0x7DD2EC2C,load_MUSIC STUB_END
-AuraGeändert von Auraomega (03-25-2008 um 02:47 PM Uhr) Grund: Automerged Doublepost
-
03-25-2008, 03:49 PM #8294QJ Gamer Blue
- Registriert seit
- Jul 2006
- Beiträge
- 132
- Points
- 4.296
- Level
- 41
- Downloads
- 0
- Uploads
- 0
can someone help me out with the collision detection? I made it so that it works for the walls but i am a bit confused on how to use this code for various parts of the map, sorry for all the questions, it is my first time and i don't understand some of the stuff.

like for example the wood fence.
Code:typedef enum { TILE_PLAYER=1, TILE_GRASS=2...ETC } inline int getCurrentTileType(const int& x,const int& y,const map& themap) { return (((x>=themap.width() ||y>=themap.height() ||y<0||x<0)?-1 :themap.tiles[y][x])); } inline void getTilePos(const int& wanted_tile,int& px,int& py,const map& themap) { px=-1,py=-1; int x=0,y=0; for (y=0;y<themap.height();y++) { for (x=0;x<themap.width();x++) { if ( getCurrentTileType(px,py,themap) != wanted_tile ) continue; px = x; py = y; return; } } } int main() { map themap; while(running) { int player_x,player_y,current_tile; getTilePos(TILE_PLAYER,player_x,player_y,themap); current_tile = getCurrentTileType(player_x,player_y,themap); if(current_tile == TILE_GRASS) { //COLLISON! do whatever.. } if(timer.diff() >= 10)..cleanup render etc.. } }
heres my code
Code://OSlib header file #include <oslib/oslib.h> //Include the Data part of the map #include "Ocean.h" //Necessary to create eboot PSP_MODULE_INFO("OSLib Sample", 0, 1, 1); PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU); //declaration of the pointers of our images OSL_IMAGE *sprite, *Ocean_tileset; //declaration of the pointers of our Map OSL_MAP *Ocean; //definitions #define DOWN 0 #define UP 35 #define RIGHT 70 #define LEFT 105 //variables int sprite_position; int sprite_march; int i; //function declarations void Buttons(); void SpriteAnimate(); int main() { //Initialization of the Oslib library oslInit(0); //Initialization of the graphics mode oslInitGfx(OSL_PF_8888, 1); //Shows the psp-hacks hombrew competition splash screen oslShowPSPHacksLogo(); //Sets the transparency color (pink) oslSetTransparentColor(RGB(255,0,255)); //loads our images into memory Ocean_tileset = oslLoadImageFile("tileset.png", OSL_IN_RAM, OSL_PF_5551); sprite = oslLoadImageFile("sprite.png", OSL_IN_RAM, OSL_PF_5551); //Disables the transpaent color (pink) oslDisableTransparentColor(); //verification that all files are present if (!sprite || !Ocean_tileset) oslDebug("It is impossible to load one or more of the images that are required in this program. Please make sure you have all the files required in the eboot folder"); //configuration of the Map Ocean = oslCreateMap( Ocean_tileset, //Tileset Ocean_map, //Map 16,16, //Size of the tiles 64,65, //Size of the Map OSL_MF_U16); //Format of the Map //Sets the sprite's original position on the screen sprite->x = 155; sprite->y = 95; sprite_position = DOWN; //main while loop while (!osl_quit) { //To be able to draw on the screen oslStartDrawing(); //calls the Buttons() function Buttons(); //Draws the Map on the screen oslDrawMapSimple(Ocean); //Draw the images to the screen oslDrawImage(sprite); //Ends drawing mode oslEndDrawing(); //Synchronizes the screen oslSyncFrame(); } //Terminate the program oslEndGfx(); oslQuit(); return 0; } void Buttons() { //initiate the PSP's buttons oslReadKeys(); //Takes a screenshot of the PSP's screen if (osl_keys->pressed.select) oslWriteImageFilePNG(OSL_SECONDARY_BUFFER, "screenshot.png", 0); //Basic border collision if (sprite->x <= 0) sprite->x = 0; if (sprite->y <= 0) sprite->y = 0; if (sprite->x >= 460) sprite->x = 460; if (sprite->y >= 239) sprite->y = 239; if (osl_keys->held.down) { Ocean->scrollY += 8; sprite->y += 1; sprite_position = DOWN; SpriteAnimate(); } if (osl_keys->held.up) { Ocean->scrollY -= 8; sprite->y -= 1; sprite_position = UP; SpriteAnimate(); } if (osl_keys->held.right) { Ocean->scrollX += 8; sprite->x += 1; sprite_position = RIGHT; SpriteAnimate(); } if (osl_keys->held.left) { Ocean->scrollX -= 8; sprite->x -= 1; sprite_position = LEFT; SpriteAnimate(); } //If a button is not pressed if (!osl_keys->held.value) { //Start the variable over for when a button is pressed again sprite_march = 0; //Sets the sprite's direction oslSetImageTileSize(sprite,0,sprite_position,22,35); } } void SpriteAnimate() { //Moves the sprite in the row that it is in sprite_march++; //Moves the sprite constantly with no static position oslSetImageTileSize(sprite,(sprite_march * 22),sprite_position,22,35); //resets the sprite movement in that row if (sprite_march == 6) sprite_march = 0; }
-
03-26-2008, 07:45 PM #8295
hey if i wanted to splash an image, what kind of could would i use. this is for the computer. im having a real hard time finding it on google.
thanks
-
03-27-2008, 07:39 AM #8296Banned for LIFE
- Registriert seit
- Oct 2006
- Ort
- East London, England
- Beiträge
- 2
- Points
- 18.744
- Level
- 86
- Downloads
- 0
- Uploads
- 0
what lib are you using?
-
03-27-2008, 05:17 PM #8297I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
How can I set the formatting on a float? I have the presision set as high as I need it, but I was wondering if there was any way to remove the trailing zeros when they are not needed?
is the underlined pointer the address in memory which the function will be loaded (I doubt because isn't the memory dynamic?), or is it the NID? If its the NID, is there a function to find the memory location using the NID?Code:.set noreorder #include "pspstub.s" STUB_START "Project4Stub",0x40090000,0x00010005 STUB_FUNC 0x7DD2EC2C,load_MUSIC STUB_END
-Aura
-
03-27-2008, 08:13 PM #8298QJ Gamer Bronze

- Registriert seit
- Aug 2007
- Ort
- Australia
- Beiträge
- 659
- Points
- 8.045
- Level
- 60
- Downloads
- 0
- Uploads
- 0
Hey,
Zitat von Auraomega
Im not sure i quite understand you but if you do 0.%f it will get rid of the 0's so the number is displayed like an integer. For example:
will display 10 instead of 10.000...Code:float a; a = 10.0; pspDebugScreenPrintf("0.%f", a);
Just a quick question, iv written a small function to remove a given colour from an image using graphics.h. Problem is that putPixelImage() doesnt support alpha colours so how else could i go about changing the pixel colour to transparent?
-
03-28-2008, 02:18 AM #8299QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
From memory:
Code:float a = 10.3425465577; printf("0.%f", a); // 10 printf("0.2%f", a); // 10.34 printf("5.2%f", a); // 00010.34[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
03-28-2008, 04:02 AM #8300I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Yeah, but doesn't that way remove them completely? I have presision set to what value I need, but when not all digits after the decimal point are being used I want to remove the trailing zeros, not completely remove them altogether. If theres no way to do this with formatting, would there be any way to check the significant figures, and make the length equal to this value? (I know you can change the length with a variable, I'm just not sure how to check the length).
-Aura
-
03-28-2008, 12:51 PM #8301QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
No, why would it if it isn't writing to the variable?
Zitat von Auraomega
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
03-28-2008, 02:11 PM #8302I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Hmm, let me put it another way now I have more time to explain:
The first output gives trailing zeros, the second output is what I am actually aiming for (without the trailing zeros), I can't set the presision to what is needed, as the value used will actually be dynamic.Code:float e = 2.71; printf("%5.5f", e) // 2.71000 printf("%5.2f", e) // 2.71
(Oh, and 5.2%f is incorrect, the presision should go between the % and the f, not before, else you get 5.2[value], and the %5.2 doesn't appear to give zeros in front of the number).
-Aura
-
03-28-2008, 02:33 PM #8303QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Honestly, I don't think you can due the IEEE format. In addition, 2.71 might actually be 2.710000000000000001 due to the nature of floating points.
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
03-28-2008, 02:59 PM #8304Developer

- Registriert seit
- Mar 2006
- Beiträge
- 1.026
- Points
- 7.577
- Level
- 58
- Downloads
- 0
- Uploads
- 0
First of all I have to ask why you need to do this, perhaps there is a better method to achieve your goal.
Also, I generally use fabs() for things like this.
Check out my homebrew & C tutorials at http://insomniac.0x89.org/
Coder formerly known as Insomniac197
tshirtz: what is irshell ??
Atarian_: it's where people who work for the IRS go when they die
-
03-28-2008, 03:07 PM #8305I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm trying to throw together a basica calculator, and to keep it to some level of presision, I'm needing to use floats, when the answer has been found it becomes the next value, thus meaning the first and last value at least have to have presision. Theres probably a better way, but for the 10 odd minutes I've spent overall making it, I've not thought of one, and since creating it I've been working on other things.
Also, isn't fabs just modulus?
-Aura
-
03-28-2008, 03:20 PM #8306QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
C or C++?
Edit: Actually, don't iostream and printf output float values up to the first trailing 0 by default?[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
03-28-2008, 03:21 PM #8307I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
I'm currently using C, and its a small tool in a big project, so I can't really turn it into C++ even if theres an easy solution.
-Aura
-
03-28-2008, 03:27 PM #8308QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
One REALLY roundabout method I can think of is to convert the float to a char string and transverse from the end of the string to the front looking for '0's until it hits a non '0' character and place a null terminator there.
I see if I can whip up an example.[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]
-
03-28-2008, 03:30 PM #8309I'm back!

- Registriert seit
- Feb 2007
- Ort
- England
- Beiträge
- 902
- Points
- 8.236
- Level
- 61
- Downloads
- 0
- Uploads
- 0
Hmm, that definatly seems a good idea, and I can't believe I hadn't thought of it myself, it wouldn't even be that hard to make, I'll get onto that right away.
Thanks.
-Aura
-
03-28-2008, 03:40 PM #8310QJ Gamer Silver

- Registriert seit
- Jun 2006
- Ort
- UK
- Beiträge
- 2.326
- Points
- 10.263
- Level
- 67
- Downloads
- 0
- Uploads
- 0
Remember what I said about floats and precision? Well it is highlighted by what we are trying to do:
Output:Code:#include <stdio.h> #include <string.h> int main() { const int BUFFER_SIZE = 128; char buffer[BUFFER_SIZE] = ""; float aFloat = 3.65000f; snprintf( buffer, BUFFER_SIZE-1, "%.128f", aFloat ); buffer[BUFFER_SIZE-1] = '\0'; printf( buffer ); printf( "\n" ); for( int i = strlen(buffer) - 1; i >= 0 && buffer[i] == '0'; --i ) { buffer[i] = '\0'; } printf( buffer ); return 0; }
Code:3.6500000953674316406250000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 3.650000095367431640625
[Blog] [Portfolio]
[Homebrew Illuminati - Serious Homebrew Development Forums]
[I want to make Homebrew FAQ] [How I broke into the Games Industry]
[Programming Book List] [Programming Article List]


LinkBack URL
About LinkBacks
Mit Zitat antworten


Hello everyone I am new here and I am glad to be part of this amazing community and I think there...
New to forum