• Content count

  • Joined

  • Last visited

Community Reputation

133 Neutral

About GameDev135

  • Rank
  1. Hey, I am relatively new to java and am struggling with loading an image (usually use C++) The image is called 1.gif and is saved in the same directory as the java file I am working on. So I declared a (member) variable Image suitPic; Then in the constructor, I say suitPic = Toolkit.getDefaultToolkit().getImage("1.gif"); Finally in the paint() method, I wrote (where g is a Graphics device) g.drawImage(suitPic, x + 25, y+25, this); No image loads properly. Any suggestions ? I have been struggling with this for a couple hours now ! EDIT:::: Okay, now I can get it to work in the class card. However, I can not get it to work in the class deck, which uses card as a subclass. That is, I want to load the image to be saved in a card and then have cards that are stored in a deck. The problem before had to do with the directory that the images were saved in. It was in the same folder as the .java file but not the class file. However, this problem is still occuring with the deck class. Thanks [Edited by - GameDev135 on May 30, 2005 7:24:22 PM]
  2. Pong concepts.

    My pong, was designed this way (very sloppily im sure as pong was my first game as well) So keep track of a point (x,y) = its position. Then also keep track of another point velocity(x,y) = its velocity. Unlike speed, velocity can be negative. Every frame/loop call a UpdatePosition() function which says point = point + velocity. (That is pseudocode as depending on your language, you may or may not be able to just add 2 points to each other in this form---that is you may have to add the x and y coordinates separately.) Then in terms of bouncing off walls....I made mine very simple. I would just say if it hits a wall, switch the sign of the velocity. So if it hits a left or right wall, switch velocity.x, if it hits a top or bottom wall, switch the sign of velocity.y. Actually getting it to know when it will hit the wall might be a little more difficult. You want it to display actually hitting the wall. My first thought would be for 1 frame to set the velocity of the ball equal to the distance between the ball and the wall (when it is close enough to the wall it will pass it) But this won't quite work, because then you are making the velocity a smaller number, and when you switch the sign, it will still be messed up. So maybe do something like have your UpdatePosition() function do something a little different. How about actually detect the collision in there? (weird way of coding, maybe someone has a better idea)--So in there say, if (ball_coordinates + ball_velocity pass a wall) ---> then make the ball_coorinates equal to a wall coordinate....otherwise add the velocity to the position The other thing you can do. In real pong, the ball's speed increases whenever it hits a wall. So you can also increase the magnitude of the velocity after changing its sign. How about say something like -- velocity.x = velocity.x *1.1 and velocity.y = velocity.y * 1.1 (i think in real pong both velocities change). Note that to use the 1.1 you need to have the velocity and coordinates stored as a double---so it might make more sense to just figure out what the correct initial velocity for the ball is and just add a good amount each time instead of *1.1 (note that then you do need a switch statement for whichever wall it hits--but its not a very big one) ---Dan
  3. C++ File management help

    You should be able to just load a file based on a string name..... For example.... #include <fstream> #include <iostream> int main(int argc, char* argv[]) { int x; char *p = "textfile.txt"; ifstream f;; f >> x; f.close(); cout << x << endl; // prints the first number in textfile.txt return 0; }
  4. what about something as simple as designing websites. maybe even adding some javascript and stuff? I know when I was 12 I thought it was the most amazing thing when I was able to post a website which simply had a heading "Welcome!" HTML is such an easy language to learn the basics of it, and one can gradually progress to learning some javascript. Sure, you'll never make the next Doom in that, but, it gives someone a feel for programming and at least a starting point before moving onto something more substantial like C++
  5. EDIT:: Okay, I managed to solve the problem regarding tile_src.left getting crazy numbers--turns out that my values for world_cameray were being computed incorrectly, so the value for world_cameray was more than it should possibly be leading to problems......Now my issue is with clipping. How can I stop the tiles from "bleeding" over to the other side of the screen? Do I need to expand my for loop for drawing the tiles to include an extra iteration? That is, if the screen is divided normally into say 20 tiles wide, when there is an offset, I have to draw 19 tiles completely, plus parts of 2. So how should my iteration account for this? One thing I am thinking is iterate from tile 2-20 then manually add tiles 1 and 21. Would that be a good thing to do ? [/edit] Hey, I am having a problem with my rendering...I have traced it down to my draw tiles function and it involves the fact that tile_src.left can equal absolutely crazy numbers..... Here is my function--i put some extra comments in to explain some odd things: void draw_tiles(void) { int tile; int x, y; int scroll_x, scroll_y; // (NEW) int offset_x, offset_y; // (NEW) RECT tile_src; POINT point; int numRows = g_level.GetRows(); int numCols = g_level.GetCols(); short int *temp = g_level.GetMap(); for (y = 0; y < SCREEN_SIZEY && y< numRows; y++) { for (x = 0; x < SCREEN_SIZEX && y < numCols; x++) { scroll_x = x + (world_camerax / g_level.GetTileSize().x); scroll_y = y + (world_cameray / g_level.GetTileSize().y); offset_x = world_camerax % (g_level.GetTileSize().x ); offset_y = world_cameray % (g_level.GetTileSize().y ); //someone suggested to me that i put the following 2 lines instead, but those don't work either. // offset_x = world_camerax & g_level.GetTileSize().x; // offset_y = world_cameray & g_level.GetTileSize().y; tile = * ( temp + (scroll_y * numCols) + scroll_x); /* tile is a pointer to a short int. The way I store the map is as a dynamically allocated array of short ints....i realize this makes little sense, but its a long story why I did this, and at this point its too late to change it anyway....but this calculation has always been proper previous to this */ tile_src.left = (tile - 1) * g_level.GetTileSize().x; = 0; tile_src.right = g_level.GetTileSize().x; tile_src.bottom = g_level.GetTileSize().y; point.x = x * g_level.GetTileSize().x - offset_x; point.y = y * g_level.GetTileSize().y - offset_y; CopySurfaceToSurface(&tile_src,g_tiles,&point ,g_pBackSurface,TRUE,D3DCOLOR_ARGB(255,255,0,255)); /* this function is from The Zen Direct 3d Book by Walsh--I have used it many times before and it doesn't cause issues */ } } } I should note that the reason I am all of a sudden running into issues with this is that previously you could only scroll in multiples of the tilesize. Now I would like more smooth scrolling.... Btw, if I get this to work, do you have any suggestions for what to do about some clipping problems with parts of the tile carrying over to the other half of the screen? Thanks for your help! [Edited by - GameDev135 on November 15, 2004 11:37:49 PM]
  6. Dev C++ Help

    Could you post what code you have at the moment? Thanks (use the source tags too-- [ ] with the word source in between to start and [/ ] with the word source in between to finish)
  7. Problem drawing my "Map"

    Hmm....well if it actually successfully Sleeps for 1000 milliseconds like you say, then odds are that the problem is not with DessinerCarte(), though it does occur to me that when you send the parameter carte.ScreenBuffer to the WriteConsoleOutput function that it is possible it has not been initialized--though the WriteConsoleOutput() function may take care of this anyway...... But normally when a program crashs abruptly like this it means that you have dereferenced a null pointer somewhere. Since you say you just started learning C++ I'll try to explain what happens. Any time you have a pointer (which you do in your struct), which is indicated by the * after the type. So lets say we have: int *p; The variable p stores a memory location, which in turn is where an integer is stored. If we just had : int i; Then i simply stores an integer. If you want to make p point to a specific item, you could say: p = &i; -- The & means "address of" --so in this case p = the address of integer i; If you wanted to change the value that p points to, then you have to DEREFERENCE p. In c++, you do this by putting a * before it. So if we have.... int i; int *p; //declare a pointer p p = &i; // set p = to the address of i (*p) = 5; // the parenthesis are for emphasis not needed here Now the integer i will equal 5..... Anyway, another thing p can point to is NULL. This basically meams it points to nothing....Any time that you dereference a NULL pointer, the program will crash. Think of it as p points to nothing. By dereferencing it, you are trying to modify the value of nothing. This is why a lot of times that people use pointers, they put in a safety check before using the star: if (p != NULL) { *p = whatever; } So somewhere in your program, there probably is a pointer which is being dereferenced despite pointing to NULL. I hope my explanation is correct and makes sense.....Someone with more c++ experience maybe can correct me if i made some mistake.
  8. Hey, I am using directx 8.0 direct sound. I have never programmed sound before and have been browsing some of the articles on this website. I have managed to load to sound files, which I can play simultaneously using the DMUS_SEGF_SECONDARY flag when I call PlaySegmentEx. My question is do I need to load a different segment for every single direct x sound file that I want to be able to play? What is a good way to store/organize in memory all these sound files. I'll put some sample code in here of the application I have at the moment. My thinking for the game is I need a background music that can just play straight through the level and loop, plus sound effects for many actions. Anyway, here is the relevent code that I have for this part. Also when I turn that flag on for the background music, the song goes REALLY slowly. Does this mean that the file is just too big to be a secondary sound file ? //in GameInit() CoInitialize(NULL); CoCreateInstance(CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader8, (void**)&g_pLoader); CoCreateInstance(CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, IID_IDirectMusicPerformance8, (void**)&g_pPerformance ); // end of COM and DMusic setup // init audio g_pPerformance->InitAudio( NULL, // IDirectMusic interface not needed. NULL, // IDirectSound interface not needed. g_hWndMain, // Window handle. DMUS_APATH_SHARED_STEREOPLUSREVERB, // Default audiopath type. 64, // Number of performance channels. DMUS_AUDIOF_ALL, // Features on synthesizer. NULL // Audio parameters; use defaults. ); // end init audio CoCreateInstance(CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC, IID_IDirectMusicSegment8, (void**) &g_pSegment); CoCreateInstance(CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC, IID_IDirectMusicSegment8, (void**) &g_pSegment2); // Set the search directory. g_pLoader->SetSearchDirectory( GUID_DirectMusicAllTypes, // Types of files sought. /*L"C:\\Program Files\\KaZaA\\My Shared Folder"*/ NULL, // Where to look. Null for default FALSE // Don't clear object data. ); // This function has a lot of stuff I did to it, explained below WCHAR wstrFileName[MAX_PATH] = L"backinussr.mid"; //The above line's filename should be changed to whatever you wish to load //It can either be mid or wav files. Maybe others, look it up. if (FAILED(g_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment, // Class identifier. IID_IDirectMusicSegment8, // ID of desired interface. wstrFileName, // Filename. (LPVOID*) &g_pSegment))) // Pointer that receives interface. { MessageBox( NULL, "Media not found, sample will now quit.", "DMusic Tutorial", MB_OK ); return 0; } WCHAR wstrFileName2[MAX_PATH] = L"start.wav"; g_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment, IID_IDirectMusicSegment8, wstrFileName2, (LPVOID*) &g_pSegment2); g_pSegment->Download( g_pPerformance ); g_pSegment2->Download(g_pPerformance); //In HandleInput if (KEYDOWN(VK_LEFT)) { g_pPerformance->StopEx(g_pSegment,0,0); } if (KEYDOWN(VK_RIGHT)) { g_pPerformance->PlaySegmentEx( g_pSegment, // Segment to play. NULL, // Used for songs; not implemented. NULL, // For transitions. NULL, // DMUS_SEGF_SECONDARY, // Flags. 0, // Start time; 0 is immediate. NULL, // Pointer that receives segment state. NULL, // Object to stop. NULL // Audiopath, if not default. ); } if (KEYDOWN(VK_UP)) { g_pPerformance->PlaySegmentEx( g_pSegment2, NULL, NULL, DMUS_SEGF_SECONDARY, 0, NULL,NULL,NULL); } Note that everything works as it is supposed to, just I want to make sure before I actually throw this code into my game that I use the best method or organizing many sounds. Thanks!! Daniel
  9. Hey guys I am writing a 2d shooting/combat game. A large amount of the base engine of the game is complete and right now I am trying to add a heads up display. The first thing I was thinking was I should display a health bar. (I know how to display the health bar as an integer, but I think it would look better as a bar) How can I do something like this? The answer can't be to just have a hundred different images which I display? Is it that I draw a tiny image to represent lets say 5 percent of the bar and then iteratively reprint this image again and again? What if I want to make the health a different color when he is almost dead? Do I just add a different if clause for which picture to show? What do you guys suggest? Thanks! --Daniel
  10. inheritance question (in c++)

    ahh... that is a clever way to do things, thanks!
  11. hey, quick syntax question.....Suppose I have 2 classes, FOO and BARR. BARR is derived from FOO. Both FOO and BARR have a function Fun() I then have a FOO *p which calls Fun(). Depending on whether p actually points to a FOO or a BARR it will go to the function Fun() inside either class. Is there anyway to ensure that the Fun() method in the parent class is called and then to have it check if the child class has this method as well and go to it in this event? Is this making sense? Or should I just copy everything from the parent class method into the child class method? Thanks --Dan
  12. Wow, guys these are fantastic ideas! I am so excited at the moment to start coding this stuff! One question though regarding one of the posts. Benjamin Heath, I am kind of confused as to what you mean by a "tag" system. Could you be more specific as well as what you mean regarding input? Thanks! Thanks guys for your suggestions! --Daniel
  13. rand() question

    actually, i believe if you sum ANY random variables--or enough of them anyway, it will be a gaussian (normal) distribution. I think this is the Weak Law of Large Numbers. Like if you flip a coin 100,000 times, the number of heads will follow a normal distribution (actually you don't need to flip it nearly that many times for it to be a normal distribution) edit: note that all the random variables have to be of an identical distribution for this to be true (assuming it is in the first place)--that is, you can't sum gaussian random variables with uniform and expect it to be normal (makes sense, but worth explicetly saying)
  14. Hey, I am currently in the process of making a 2d side-scrolling game. The main character is a ninja, and the majority of the basic work has been set up. The level includes powerups (right now, only one, which makes him move faster, but I plan to include many others such as extra jumping, extra life, maybe knives to throw, etc). I have allowed enemies to be loaded into the level and additionally have added death animations and stuff like that. However, my real question is this: What would you guys think is a fun mechanism for combat? My original thought was "head-stomping" (like Mario) simply because this would be the easiest. However, I think the game would be much more fun if I could have the combit be based on punching, kicking, etc. In a head stomping game, it is easy to say who kills whom. If the guy lands on the bad guys head, the bad guy dies, otherwise the main character dies. However, I am struggling to figure out what this one should be. Sure, I can give the enemies the same punch and kick functions that I give the main character--but what chance will the ninja have to actually avoid the enemies attacks? It probably would be difficult to make this involve a skill. Perhaps one thing I should do is simply find some other games with the same style as this one is and try to play them. I think back to Spiderman 2 (3d game, yes- but it was close combat in nature) and quite frankly while I found the game fun, I thought it got somewhat repetitive in the combats with the generic enemies. While the bosses were fun, fighting the generic enemies just didn't require very much skill and one could easily get by on simple button mashing. While I think each individual enemy SHOULD be easy to kill, since I plan on making many of them per level, I would like to give the enemies at least a CHANCE to fight, but without making the game a situation where no matter what, the main character will probably lose a certain amount of life per battle, and needs the power ups to stay alive. Anyway, any suggestions as to what could make this combat more fun? For the moment, let us not even worry about the feasibility of the actual implementation. (Though I will note that I am doing this project in C++ using DirectX) I am trying to just think in general principles at this point before wasting time coding things and then deciding something else could be better. Thanks! Dan