Jump to content
  • Advertisement

N8dunn

Member
  • Content Count

    154
  • Joined

  • Last visited

Community Reputation

236 Neutral

About N8dunn

  • Rank
    Member
  1. an array and a pointer are essentially the same thing. when you declare an array (ie. int array[NUM_OBJECTS];) it is like saying "ok, give me a pointer to some memory address, and reserve NUM_OBJECTS * sizeof(int) memory for me to use." later, when you say "array[INDEX];" you are basically saying "hey, remember that memory i reserved earlier? well, i want to take a look at the address you gave me plus INDEX * sizeof(int)." so, some interesting things you can do: *array + (INDEX * sizeof(int)) == array[INDEX]; *array == array[0]; array == &(array[0]); anyway, so when you have an array, you have a pointer, and can treat it as such. there are some limitations that the complier imposes on you because it's a set size and all that, but for the most part, it's the same thing. hope that helps you. oh, sidenote: if you pass a pointer to a function, and expect to treat it as an array, make sure you have some way of knowing how big that array should be. if you are always going to pass the same size array, pass in an array[SIZE] instead.
  2. N8dunn

    Platform SDK

    not trying to be a dick, but... why are you using a 7 year old os? you may want to look into upgrading. just an idea.
  3. N8dunn

    Little Space scene (Movie)

    Quote:Original post by Radioactivebloke Cool. I hope you don't mind me dissing, but I think the sound was a bit out of sync. The loudest part of the woosh should be when the ships are about 1/3 in from the left and fade out a bit faster. [smile] if you wanna get technical, there shouldnt be ANY sound :-P
  4. Quote:Original post by Martee SetConsoleDisplayMode() is even easier ... ...or would be if i could figure out how to get it to be defined. according to my local msdn (that was installed with VS) it doesnt exist, but the online one lists it. possibly a .net framework 2 beta thing? or is there an updated windows sdk?
  5. This code will do it, though it does use some win32 stuff. If you have any questions, ask away! // Auto-fullscreen routine for console windows by Nathan Dunn, 2005 // Include stuff for manipulating windows #include <windows.h> // The length of our buffer to hold the window title #define CONSOLE_TITLE_LENGTH 200 // Entry point int main() { // Buffer to hold the original title char szOldConsoleTitle[CONSOLE_TITLE_LENGTH] = {0}; // The new title of the window. I used random // numbers/letters to make it as unique as I can char szNewConsoleTitle[CONSOLE_TITLE_LENGTH] = "fd3739j531kse43p"; // First, we get the title of the console window. // We store it in the old title string so that we can put it // back later on. Right now, we want a totally unique title. GetConsoleTitle(szOldConsoleTitle, CONSOLE_TITLE_LENGTH); // This sets the window to the unique title. SetConsoleTitle(szNewConsoleTitle); // Chill for a moment to make sure the title is updated. Sleep(40); // Now we can grab the handle to the window by trying to // find it using the unique name we have assigned it. HWND hConsoleWnd = FindWindow(NULL, szNewConsoleTitle); // Make sure we have the handle to the window. If we don't, // back away slowly. if (!hConsoleWnd) { MessageBox(NULL, "Window Handle Not Found!", "Error", MB_OK); return -1; } // Return the title of the window to its original title. SetConsoleTitle(szOldConsoleTitle); // Now we send the ALT+ENTER message to the window. We // send SendMessage the handle to the window, the message // that we are pressing the ALT key and another key, that // that other key is the ENTER key, and verification that // the ALT key is indeed down. The window receives this and // says "Oh, hey! I need to go fullscreen! Well, let's do it // then." All that is handled by the console window itself, // and you don't have to worry about it. SendMessage(hConsoleWnd, WM_SYSKEYDOWN, VK_RETURN, 1<<29); // Now we say things are cool, and return normally. return 0; } [Edited by - N8dunn on April 25, 2005 7:07:21 PM]
  6. N8dunn

    Help saving information.

    The way I would go about it (simplified a bit): // include files we will need #include <stdio.h> #include <string.h> // define some constants for later #define NUMSCORES 10 #define NAMELENGTH 20 // define what a high score consists of: // a string called name (the player's name) // an int called score (the player's score) struct hiscore { char name[NAMELENGTH]; int score; }; // our list of scores hiscore HiscoreList[NUMSCORES] = { 0 }; // game function prototypes void GameInit(); bool GameRun(); void GameShutdown(); int main() { GameInit(); // init the game while(GameRun()) { } // run the game GameShutdown(); // kill the game return 0; } void GameInit() { // First we need a file to open. We acheive this // by declaring a FILE pointer. We use fopen to // actually get access to the file. It takes in // the name of the file, and opening conditions. // In this case, I used "rb" for read binary. For // a full list, see the MSDN, or google fopen FILE *pFile = fopen("hiscorelist.bin", "rb"); // Now make sure the file actually opened. if (pFile) { // Good, we have a file, now get info from it. // Start looping so we can fill the whole list //* for(int i = 0; i < NUMSCORES; i++) { // Here we use fread to grab the name and score from // the file. fread takes in a pointer to the // variable that we want to fill, the size of that // variable, how many times we should read it, and // the file to read from. fread(HiscoreList.name, NAMELENGTH, 1, pFile); fread(&HiscoreList.score, sizeof(int), 1, pFile); } //*/ // Alternatively, we could do this: /* fread(HiscoreList, sizeof(hiscore), NUMSCORES, pFile); //*/ // What this does is start filling HiscoreList, reading // in the size of a hiscore, NUMSCORES number of times. // Try switching between the two and compare what happens. // Now we need to close up the file. Use fclose // to do this. All it takes in is the pointer to // the file. fclose(pFile); } ////////////////////////////////////////////////////////// // Here I just did some default case handling, creating a // default list of names and scores to show the user if // this is the first time it's played. else { char DefaultNameList[NUMSCORES][NAMELENGTH] = { "NAME1", "NAME2", "NAME3", "NAME4", "NAME5", "NAME6", "NAME7", "NAME8", "NAME9", "NAME10" }; int DefaultScoreList[NUMSCORES] = { 100, 90, 80, 70, 60, 50, 40, 30, 20, 10 }; for (int i = 0; i < NUMSCORES; i++) { strcpy(HiscoreList.name, DefaultNameList); HiscoreList.score = DefaultScoreList; } } // End default case handling ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // Here i just print out the list printf("HiscoreList loaded/created:\n"); for (int i = 0; i < NUMSCORES; i++) { printf(HiscoreList.name); printf("\n"); printf("%i\n", HiscoreList.score); } // End printing stuff ////////////////////////////////////////////////////////// } bool GameRun() { ////////////////////////////////////////////////////////// // This is just the main game function, mostly empty // for this example static int nCount = 0; if (!nCount) printf("Game Running"); else printf("."); if (nCount++ < 1000) return true; return false; // and that's that ////////////////////////////////////////////////////////// } void GameShutdown() { // Ok, writing to the file is pretty simple. // We open the file like before, except that // this time we use "wb" for write binary. FILE *pFile = fopen("hiscorelist.bin", "wb"); // Again, check to see if the file is open if (pFile) { // This is the same deal as before, loop through // all the names in the list, but this time fwrite // the name and score. fwrite works the same // as fread. //* for (int i = 0; i < NUMSCORES; i++) { fwrite(HiscoreList.name, NAMELENGTH, 1, pFile); fwrite(&HiscoreList.score, sizeof(int), 1, pFile); } //*/ // Like before, we can just write everything as one // big chunk if we want. In this case, interchanging // the two methods (ie: read piece by piece but write as // one item) will still work perfectly fine. /* fwrite(HiscoreList, sizeof(hiscore), NUMSCORES, pFile); //*/ // Now we just close up the file fclose(pFile); } } any questions, feel free to ask.
  7. N8dunn

    How much do you pay for gas per gallon?

    Quote:Original post by Saruman I eat about 70USD / week in fuel right now... SUVs are horrible.:( fixed. :-P
  8. N8dunn

    How much do you pay for gas per gallon?

    "I can't understand why the price of gas suddenly rises when oil goes up, but takes months to go down long after oil falls! I can't get behind ... that!" -William Shatner -"I Can't Get Behind That" -Has Been
  9. N8dunn

    Black Jack Program, C++

    Quote:Original post by DLT_Chief im making a similar program except im using a class. I dont mean to steal the spotlight but im having trouble with some what would seem, very simple do while loops. Heres the problem: char Continue; do { cout << "Do you want to play again (Y or N)??" << endl; cin >> Continue; }while(Continue!='Y'||Continue!='y'||Continue!='N'||Continue!='n'); the program is supposed to loop until either Y, y, N or n is enetered but no matter waht i enter(even Y, y, N or n) the program continues to loop, ie. never-ending. Please help. ok, the simple answer is: change your || to &&. the long answer: basically, in these instances, what you want to do is analyze what is really going on. so lets take that loop, and run through it. first, Continue is declared. you really should initialize it to something (0), but in this case it's probably all right the way it is. next we enter the loop, and print out the prompt. now we get our input, and store it in Continue. let's say that the user enters 'a'. now we do our checks. is Continue not 'Y'? yes. is Continue not 'y'? yes. is Continue not 'N'? yes. is Continue not 'n'? yes. so, true OR true OR true OR true results in true. so we loop again. prompt for input, get input, and do our checks. let's say that this time the user entered Y. awesome, now we want to break out of our loop, right? well, we still have to check, because the program doesnt know that Y means break yet. so we go to the check. is Continue not 'Y'? no. is Continue not 'y'? yes. is Continue not 'N'? yes. is Continue not 'n'? yes. so false OR true OR true OR true result in true. so we loop again. uh-oh, that's not right. well, what went wrong? we checked to see if at least one of the cases was true. since they can't all be false at once (ie: Continue can't be Y, y, N, and n all at once [Continue != 'Y' is false if Continue IS Y. same with y, N, and n.]) so the statement will never be false, and we will never NOT loop. ok, so, if we change to &&, and Continue is Y, we get 'Y' != 'Y' (false) && 'Y' != 'y' (true) && 'Y' != 'N' (true) && 'Y' != 'n' (true). false AND ... we can stop here, the whole statement is false. break the loop, and move on with the project. hope that helped you. if you need clarification, let me know. -nate
  10. N8dunn

    Need one minute speech / play / song / whatever

    no emotion? i recommend an excerpt from some professor's c++ 101 class. or from an online tutorial. here's one. bore them to tears while helping them become giant nerds. alternatively, you could pick some random poem, start reading it, burst into tears about 10 seconds into it, and start blubbering about how your nana used to read it to you and she just died and this was supposed to be a tribute but now its ruined and youre soooo upset. good luck.
  11. I'm sorry, I must be missing something, because why can't you just use strlen(str) + 1? that will give you the length of the string without the null terminator, and then add one for the null terminator. as far as i know, that's not a windows thing, its a c thing. Am I wrong? [EDIT] yes, i know this will only work with character arrays (as versus arrays of other types), but that's what he's using, so it should work here. [EDIT2] oh, someone already is using strlen... that'll teach me to not read every detail :-D
  12. This is what I came up with: #include <iostream> using namespace std; // Our structure struct SpecialInt { int nInt; // The integer member bool bBool; // The boolean member char cChar; // The character member // These allow our structure to act // like a normal identifier. If // an integer is needed, nInt is used. // If a boolean, bBool, and if a character, // cChar. operator int() {return nInt;} /*operator bool() {return bBool;} operator char() {return cChar;}*/ }; // testapp int main() { SpecialInt siSpecialInt; siSpecialInt.bBool = true; siSpecialInt.cChar = 'A'; siSpecialInt.nInt = 10; int nInt = siSpecialInt; int nInt2 = siSpecialInt + 50; /*bool bBool = siSpecialInt; bool bBool2 = !(bool)siSpecialInt; char cChar = siSpecialInt; char cChar2 = (char)siSpecialInt + ('N' - 'A');*/ cout << "nInt = " << nInt << '\n'; cout << "nInt2 = " << nInt2 << '\n'; /*cout << "bBool = " << bBool << '\n'; cout << "bBool2 = " << bBool2 << '\n'; cout << "cChar = " << cChar << '\n'; cout << "cChar2 = " << cChar2 << '\n';*/ return 0; } The part that's commented out works just fine when commented in, except that you have to explicitly typecast if you are going to use operators, since things like +, -, !, etc can be used on more than one type, and become ambigous. naturally, if you say int nInt = siSpecialInt; nInt++; that will work just fine, but siSpecialInt++; won't. With only one typecast operator, no need for typecasting. SpecialInt siSpecialInt2 = siSpecialInt; still works just fine. also, cout << siSpecialInt; will display the value of siSpecialInt.nInt. Hope this helps you. Play around with it and see what you can do.
  13. N8dunn

    See through walls

    Quote:Original post by Wildfire That's his grizzly suit... the 'URSUS MARK VII'. Try looking on google: "troy hurtubise". http://www.museumofhoaxes.com/hoax/weblog/comments/2296/ oh... OOOHHH... i think i saw him on ripley's believe it or not getting hit by a car or something. it was mildy amusing.
  14. N8dunn

    See through walls

    why is it that when things like this come up, there are no photos of it in use? i mean, it's not hard to doctor photos, but still, it'd be nice to see it actually working. Quote: Troy dreamed the Angel Light would be able to see through walls with window-like efficiency, and then built it with no blueprints, drawings or schematics. “I turned it on—that was well over a year ago—and it worked and it was really awesome.” Quote: Hurtubise purchase a remote-control plane for $1,800 and took it and the Angel Light to a flying field on the way to Powassan. He directed the Angel Light beam toward the sky and started the plane flying. "On the first loop it came around, passed through the beam of light and fell right to the ground,” Hurtubise said. Quote: The Hurtubise put his hand in the light beam. “I could see my blood vessels, muscles, everything, like I’d taken an Exacto knife, cut into my skin and peeled it back,” Hurtubise said. These quotes make me doubt the validity of the claim. He built it from scratch, without a design, and when he turned it on, it just worked? How often does that happen. How often do you write a complex program with no design, compile once at the very end, and when you do finally compile it everything works perfectly, with no problems? If the plane stopped working, it wouldn't just drop to the ground, unless it was pointed straight down at the time. Even if it was pointed straight up, it should have flipped and glided a bit. So it can see through walls, but only a couple layers of skin? I think I'm going to have to call shenanigans on this one. [EDIT] Quote: btw, what's that on the right? Godly armor of 1337ness lvl 348? ... yes.
  15. N8dunn

    Mensa Workout

    27, and left 3 blank... is that good? :-P on a related note: when i was in college i had a mensa page-a-day calander, and became disillusioned with it when i figured out one of those "only one other word can be made from the letters in foo." puzzles, only to find out that the answer they gave was different from mine. when i looked up both words in a dictionary, the word i came up with was there, but the one they gave as an answer was not. and no, i don't remember what the word was. [EDIT] also, has no one ever heard of a 3,4,5 right triangle? its a pythagorean triplet. those come in handy every now and then.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!