Use Object Orientated Bounding Box (OOBB) Collision or Line Box collision tests.Zitat:
Zitat von ZereoX
Printable View
Use Object Orientated Bounding Box (OOBB) Collision or Line Box collision tests.Zitat:
Zitat von ZereoX
edit: see what yaustar said.
Like a said I'm still a newbie. So could you show me an example?
Say i had something like:
how would i go about copying "score 2" into another string? strcpy doesnt let you set the params for where to copy to and fromCode:char str[32];
sprintf(str, "score 1 = 10, score 2 = 13");
http://www.gamasutra.com/features/19991018/Gomez_5.htmZitat:
Zitat von ZereoX
can someone please help? =)Zitat:
Zitat von cruisx
ughZitat:
Zitat von Xsjado7
Look it over, it's pretty self explanatory. Store the scores in variables, then get them from there.Code:char str[64]; // I would go a little higher just incase of bigger variables
int score1 = 10, score2 = 13;
sprintf(str, "Score 1 = %i, Score 2 = %i", score1, score2);
I think he was asking about splitting an existing string.Zitat:
Zitat von Slasher
lol, yeah. For eample; i wanna cut "score = 2" and chuck it another string or something to that extent
Why not use std::string instead of messing around with char[] sprintf and the likes? it's so easier.Zitat:
Zitat von Xsjado7
http://www.cplusplus.com/reference/string/string/
my apps in C, not C++ :(
you can still use std::strings I think, you'll just have to modify some things (.cpp instead of .c for your files, -lstdc++ added in your makefile). this won't stop you writing everything in C if you like, but you'll be able to use std::strings at the same time (you'll also benefit from iostreams & lists/vectors/maps, this will make your life a lot easier).Zitat:
Zitat von Xsjado7
Oh, ok. Thanks for the help :D
-= Double Post =-
Just renamed my stuff and added the etra lib but i get errors thrown at me. Im going to try something else. Im gonna write the string to a temporary file on the memory stick. from there i can use sceIo functions like sceIoRead which allows me to tell it how far to read and such. Thanks again for the help though
:down: really really bad solution. you better show us the errors and your code so we can help, or continue investigate proper C code with memcopy and all that crap.Zitat:
Zitat von Xsjado7
My errors, and thats just from my main.cpp. I have more than 8 more source filesCode:source/../settings/stats.h(26) : error: expected unqualified-id before 'throw'
source/main.cpp: In function 'void newGame()':
source/main.cpp(33) : error: 'mainGame' was not declared in this scope
source/main.cpp: In function 'void mainGame()':
source/main.cpp(89) : warning: passing 'double' for argument 4 to 'void fillScre
enRect(Color, int, int, int, int)'
source/main.cpp(90) : warning: passing 'double' for argument 4 to 'void fillScre
enRect(Color, int, int, int, int)'
source/main.cpp(115) : error: expected unqualified-id before 'throw'
source/main.cpp(115) : error: expected `)' before 'throw'
source/main.cpp(117) : error: expected unqualified-id before 'throw'
source/main.cpp(117) : error: expected `;' before 'throw'
source/main.cpp(118) : error: expected unqualified-id before 'throw'
source/main.cpp(118) : error: expected `;' before 'throw'
source/main.cpp: In function 'int main()':
source/main.cpp(277) : error: cannot convert 'const char*' to 'short unsigned in
t*' for argument '2' to 'int OSK(char*, short unsigned int*, short unsigned int*
)'
source/main.cpp(364) : error: cannot convert 'const char*' to 'short unsigned in
t*' for argument '2' to 'int OSK(char*, short unsigned int*, short unsigned int*
)'
source/main.cpp(373) : error: 'dispCredits' was not declared in this scope
I'll need your main.cpp to see what's wrong.
Oh, forgot to mention, "throw" is actually a variable in my "player" struct. I take it its a command in C++ due to it being highlighted in Notepad++ when i type it
yup, it's a reserved key word of the c++ language. hope this solves everything, if not post here.Zitat:
Zitat von Xsjado7
Ok, i think iv got it sorted out. Do i have to code any different to use those new functions?
only when using strings, remember that it's a c++ class, so to allocate memory for it (if you want to use pointers, which in most cases is not needed) istead of malloc use new, and instead of free use delete. apart from that, you can continue working completely in C.Zitat:
Zitat von Xsjado7
small example to get you started:
PHP-Code:#include <string>
using namespace std;
string str ("this is a string");
//now use the power of the string class: str.substr(), str.find()..
//nothing else to do!
Hey, iv been messing with the stuff on the computer, setting up a my function. Just a quick question, is it possible to do something like:
Obviously it doesnt work but is there anything like this?Code:char str[32]="Im a string";
string str2;
strcpy(str2, str);
I think this will do it:Zitat:
Zitat von Xsjado7
even this works (only to show you that you can do things like that, example above is better for this exact case you have)Code:char str[32]="Im a string";
string str2(str);
of course if you just want to declare a string that is initialized, do it simply like this:Code:char str[32]="Im a string";
string str2=str; //or string str2="Im a string"
http://www.cplusplus.com/reference/s...ng/string.htmlCode:string str2("Im a string");
Code:char str[32]="Im a string";
string str2( str );
string str3 = str;
Sweet, thanks guys
-= Double Post =-
okay, iv got m function working perfectly on computer but i just put it into my game and i get:
Iv added -lstdc++ in my makefile so what am i missing?Code:scores.cpp(34) : error: 'string' was not declared in this scope
-= Double Post =-
iv got past that error now, i just had to include <string>. Now im getting a few errors:
those lines consist of:Code:source/scores.cpp(57) : error: incompatible types in assignment of 'std::basic_s
tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]'
source/scores.cpp(73) : error: incompatible types in assignment of 'std::basic_s
tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]'
source/scores.cpp(83) : error: incompatible types in assignment of 'std::basic_s
tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]'
source/scores.cpp(93) : error: incompatible types in assignment of 'std::basic_s
tring<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]'
source/scores.cpp(103) : error: incompatible types in assignment of 'std::basic_
string<char, std::char_traits<char>, std::allocator<char> >' to 'char [128]'
just with a different variable name e.g score.hs2name...Code:score.hs1name = loadbuff3.substr(1, seperator-1);
Note: Everything worked fine on the computer
What datatype is score.hs2name?
can anyone help me out, i've been trying to shutdown the psp with the square button and including psppower.h but i dont know what is needed to power off in 3.90 as this call is old afaik :D
i've been tryingCode:else if (pad.Buttons & PSP_CTRL_SQUARE)
{
sceSysconPowerStandby();
}
Does this work on PSP? Can I use a file descriptor?Code:int write(int fd, char *Buff, int NumBytes);
Considering your function name is so vague and not in the SDK or STL no *rolls eyes*
Yeah... It's for dos;Zitat:
Zitat von SG57
Now-a-days i'm intermixing multiple platforms (3 to be exact) :p
actually it should work fine. its posix (unistd.h) fwrite works, which just wraps write. just ignore sg57. you can use it.
ok guys iv been trying to get this right for a few days but have had no luck.
so i have a code for collision right, but i dont know how to correctly modify it so it works for one more sprite on the screen.
this is the code for 1 sprite collision:
now when i try to modify it for another sprite on the screen, the second sprite still has no collision =\ but the first sprite still does.Code:if ((img1posX + img1width > img2posX) &&
(img1posX < img2posX + img2width) &&
(img1posY + img1height > img2posY) &&
(img1posY < img2posY + img2height) )
my code:
Code:if ((img1posX + img1width > img2posX) &&
(img1posX < img2posX + img2width) &&
(img1posX + img1width > img3posX) &&
(img1posX < img2posX + img3width) &&
(img1posY + img1height > img2posY) &&
(img1posY < img2posY + img2height) )
Spoiler for Post:
I guess it's a char[128].Zitat:
Zitat von yaustar
the = operator works only in one way:
string = char[] is ok
char[] = string doesn't work
but you can get a const char* from a string with mystring.c_str() if that helps.
-= Double Post =-
xsjado, maybe I can help you with this function:
it splits a string given a delimiter, and returns it as a vector.Code:vector<string> split(string str, string delim)
{
vector<string> results;
unsigned int cutAt;
while((cutAt = str.find_first_of(delim)) != str.npos)
{
if(cutAt > 0)
{
results.push_back(str.substr(0,cutAt));
}
str = str.substr(cutAt+1);
}
if(str.length() > 0)
{
results.push_back(str);
}
return results;
}
for example, split("032.5=Me|034.9=You |105.0=Someone|096.6=Some oneelse|025.2=Santa", "|") will give you a vector containing this:
"032.5=Me"
"034.9=You"
"105.0=Someone"
etc...
and with the same technique you can get what you want from the string.
-= Double Post =-
cruisx, if you have a working function for collision between 2 sprites, just call it for all your sprites on screen, change the parameters that's all...
I spend two hours learning C++ functions and writing out my function then i log on today to find this :rolleyes:
spending time learning is a good thing ;)Zitat:
Zitat von Xsjado7
Do you know why my code isnt working though? It just gets to:
and nothing happens, doesnt do itCode:name1 = loadbuff3.substr(1, seperator-1);
I'll need the whole function or code block.Zitat:
Zitat von Xsjado7
Code:pspDebugScreenInit();
//This is for the seperator between scores
int seperator;
//This is for the "=" sign between the time and name in a highscore
int equals;
//The buffer for use with atof
char* loadbuff2;
//The buffer for use with string:: functions
string loadbuff3;
//For storing the highscore names
string name1, name2, name3, name4, name5;
//Conversions
//Convert global.loadbuff for use with string:: functions
loadbuff3 = global.loadbuff;
loadbuff2 = new char [loadbuff3.size()+1];
strcpy(loadbuff2, loadbuff3.c_str());
pspDebugScreenPrintf("loadbuff3 copied to loadbuff2\n");
//Get first highscore data
//Get score.hs1
score.hs1 = atof(loadbuff2);
pspDebugScreenPrintf("Got time from first highscore\n");
//Remove score.hs1 from loadbuff3
loadbuff3.erase(0, 5);
pspDebugScreenPrintf("Erased furst highscore from loadbuff3\n");
//Get the seperator from between the data of the first and second highscores
seperator = loadbuff3.find("|");
pspDebugScreenPrintf("Found seperator from between highscore 1 and 2\n");
//Read from six bytes in to the seperator AKA get the name for the first highscore
name1 = loadbuff3.substr(1, seperator-1);
pspDebugScreenPrintf("Got first highscore name\n");
it's because:
- strings indices start at 0
- substr is like this: string.substr(size_t pos = 0, size_t n = npos) with pos = where to start, n = length of the substring, and not where to stop.
your code (I suppose loadbuff=="Me|"):
name1 = loadbuff3.substr(1, seperator-1);
does this:
name1 = loadbuff3.substr(1, 1);
so name="e".
I haven't tested but maybe try to write name1 = loadbuff3.substr(0, seperator); to see if I'm right.
http://www.cplusplus.com/reference/s...ng/substr.html
Forgot to mention, each float is stored as 5 characters, 3 digits for the seconds, a full stop and one digit for the miliseconds if that helps for anything.
Also its:
because i havent removed the "=" sign so its going to be "=Me|".Code:name1 = loadbuff3.substr(1, seperator-1);
-= Double Post =-
So does anyone have any ideas as to why the PSP gets caught at using .substr? Doesnt make any sense