• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Funley;32780494]How would i do "reloading" in XNA? I know its as simple as to just wait when 5 seconds when the ammo reaches zero and then set the ammo to the max ammo, buuuuuuuuut its not that simple anyway. [editline]haah[/editline] Why the optimistic? [editline]haah2[/editline] Nuu, why you be giving meh odd ratings![/QUOTE] Things like reloading should not be dependent on a graphics library. Generally, though, you would at some point check to see if it's 0, optionally fire an animation, accumulate some interval of time from frametime (or some other way of keeping track of time), then once your accumulation has passed the interval, set it back to max.
[QUOTE=aerochug;32718804]So I've just started to get back into C++, and I've run into this problem with trimming strings: [cpp] // all this code should be fine #include <string> using namespace std; const string whiteSpaces = " \f\n\r\t\v"; void trimRight( string& str, const string& trimChars = whiteSpaces ) { string::size_type pos = str.find_last_not_of( trimChars ); str.erase( pos + 1 ); } void trimLeft( string& str, const string& trimChars = whiteSpaces ) { string::size_type pos = str.find_first_not_of( trimChars ); str.erase( 0, pos ); } void trim( string& str, const string& trimChars = whiteSpaces ) { trimRight( str, trimChars ); trimLeft( str, trimChars ); } [/cpp] so I pulled that code off somewhere to trim strings, and when I try to use it like this, [cpp]string str = " test "; trim(str);[/cpp] ... I get: [code]error C2660: 'trim' : function does not take 1 arguments[/code] even though the 'trimChars' argument is already a default argument.[/QUOTE] Any ideas?
[QUOTE=aerochug;32785160]Any ideas?[/QUOTE] Works fine for me... Are you sure you don't have another "trim" function in your code somewhere and you might be including that one instead? That's all I can think of.
[QUOTE=JimJam707;32781963]I'm trying to make a script/program with makes the user enter a number (x), and tests it for being a prime number. What I want it to do is see if when x is divided by all the numbers from 2 to the number just before x, if there is any remainders. If there are always remainders, the number will be prime, no remainders, and it's not. I know I need to use % :S[/QUOTE] You're right about needing to use modulus, but what you're missing is a loop. Just loop over the potential factors, compute [i]n[/i] mod each of them, and if the result is zero (meaning it's evenly divisible), you found a factor. Your loop only needs to go up to the square root of [i]n[/i], since every factor above the square root has a corresponding factor below the square root, such that the two of them together make [i]n[/i]. But if you don't want to bother with that, you can just loop up to [i]n[/i]; it's less efficient but still correct.
-snip-
[QUOTE=jalb;32785741]Works fine for me... Are you sure you don't have another "trim" function in your code somewhere and you might be including that one instead? That's all I can think of.[/QUOTE] Hmm, I'll check it out. Thanks.
I'm trying to make a small maze game. So far I've managed to get the player to move through it. What I can't seem to manage to do is collision detection. The file "dungeon.txt" is read line by line into a string array (so line[1][3] = first line,third character etc.) and printed out to the screen. The user move the "X" by using the wasd and arrow keys (through the gotoxy function which sets the coordinates for the cursor). I've already set the limits so the player can't go beyond the maze but I don't know how I can stop the player from going through walls and also telling him if he won. Here's the code. [cpp]#include <iostream> #include <fstream> #include <Windows.h> #include <string> #include <conio.h> using namespace std; //====== FUNCTION DECLARATIONS ======// void DrawTable(); int MainGame(); void gotoxy(short x,short y); //========== MAIN FUNCTION ==========// int main () { DrawTable(); MainGame(); } //============== GOTOXY =============// void gotoxy(int x,int y) { COORD coord = {x,y}; SetConsoleCursorPosition (GetStdHandle (STD_OUTPUT_HANDLE), coord); } //=========== DRAW TABLE ===========// void DrawTable() { int i = 0; string line[10]; ifstream myfile ("dungeon.txt"); gotoxy(0,1); if (myfile.is_open()) { while ( !myfile.eof() ) { getline (myfile,line[i]); cout << " " << line[i] << endl; i++; } myfile.close(); } } //============= MAIN GAME ==========// int MainGame() { bool gameover = 0; char player = 'X'; int move; int xy [2] = {3,2}; gotoxy(xy[0],xy[1]); cout << player; do { gotoxy(68,23); cout << "x= " << xy[0] << " y= " << xy[1]; move = _getch(); switch (move){ case('w'): xy[1]--; break; case('d'): xy[0]++; break; case('s'): xy[1]++; break; case('a'): xy[0]--; break; //ARROW KEYS DETECTION case(224): move = _getch(); if (move == 72) xy[1]--; else if (move == 75) xy[0]--; else if (move == 77) xy[0]++; else if (move == 80) xy[1]++; break; default: cout << "Press a valid key!"; } system ("cls"); DrawTable(); //============ LIMITS ==============// if (xy[0] < 1) xy[0]++; if (xy[0] > 20) xy[0]--; if (xy[1] < 1) xy[1] ++; if (xy[1] > 7) xy[1] --; //==================================// gotoxy(xy[0], xy[1]); cout << player; }while (gameover != 1); return 0; } [/cpp] dungeon.txt: [code] ##################### ## ############ ## ## ## ### ## ## ## ### ## ## #F# ### ## # # ### # ### ### # # ### ### ### ## # ### ### # ########## ##################### [/code]
in the movement cases, check if the block you are moving into is solid( in this case it has the value '#' ) and if it is, reverse the move otherwise don't, so [code] case('w'): xy[1]--; if(line[xy[0]][xy[1]]=='#') { xy[1]++; } break; [/code] for each of the movement cases should work. the xy[1]++ is the opposite of the xy[1]--, so change that for each one or it WON'T work and you'll be spending ages finding the bug if you're as bad as I am at times :v:
Hey guys, what command/line would I use or what can I use to make a program read/write a html file? In my case, I am learning HTML, and I made website, I want to write java program that I could basically launch, it asks for: Date, Entry, Title, and picture perhaps and based on that it adds entry into that HTML file and saves it. Thanks.
Thanks. Didn't work until I realized that xy[0] is the column and xy[1] is the line and not the other way.
In C++ , when i use rand() to generate a random number, it generates the same number every time i run the program. How do i make it generate a unique number for each instance?
You need to give it a seed. Try srand() to set it. Try giving it the time.
[QUOTE=Jookia;32798848]You need to give it a seed. Try srand() to set it. Try giving it the time.[/QUOTE] Thanks, that makes sense.
How can i detect when any key is pushed and get the pushed key in XNA? Its for a simple console thing im making.
[csharp] using Microsoft.Xna.Framework.Input; [...] KeyboardState state = Keyboard.GetState(); Keys[] pressedKeys = state.GetPressedKeys(); foreach(Key k in pressedKeys) { doStuff(); }[/csharp] Should work.
[b]XNA[/b] I'm not really sure how to word this.. I have a class, Tile, that I'm trying to keep small so I'm splitting it up into several classes. E.g. I have a Tile_Template class (to be later copypastad for other classes), and I want Tile to be able to use its functions, but also the functions of any other Tile_ class (Tile_Air, Tile_Wall etc). I want it to be so that when I make a new Tile, you set a variable to whatever kind of Tile_ class you define (e.g. new Tile(Tile_Template, ...)) and that Tile would use all of the functions from Tile_Template. Sorry if this is explained badly/I repeated anything, fucking family is throwing a drunk music-blasting party behind me and I can't think straight [editline]16 October 2011[/editline] Thanks, Ltp0wer. [img]http://www.facepunch.com/fp/ratings/heart.png[/img]
[QUOTE=benji2015;32806262][b]XNA[/b] I'm not really sure how to word this.. I have a class, Tile, that I'm trying to keep small so I'm splitting it up into several classes. E.g. I have a Tile_Template class (to be later copypastad for other classes), and I want Tile to be able to use its functions, but also the functions of any other Tile_ class (Tile_Air, Tile_Wall etc). I want it to be so that when I make a new Tile, you set a variable to whatever kind of Tile_ class you define (e.g. new Tile(Tile_Template, ...)) and that Tile would use all of the functions from Tile_Template. Sorry if this is explained badly/I repeated anything, fucking family is throwing a drunk music-blasting party behind me and I can't think straight[/QUOTE] You should look into "class inheritance"
Is there a way, in VC++, to change the color of a single character?
Anybody know of a good reading material, preferably free, on networking and networking algorithms/optimisation?
[QUOTE=WhatTheEf;32809057]Is there a way, in VC++, to change the color of a single character?[/QUOTE] Why would you ever need this?
[QUOTE=T3hGamerDK;32809597]Why would you ever need this?[/QUOTE] Let's say I have a 'X' among tons of '#''s and it's hard to see it. I want to change it's color so that it's easier to see it.
[QUOTE=WhatTheEf;32809686]Let's say I have a 'X' among tons of '#''s and it's hard to see it. I want to change it's color so that it's easier to see it.[/QUOTE] I'm not 100% sure on this but I [I]think[/I] VS will highlight things you've #defined so you might be able to do #define X X Completely untested, and of course it'll do ALL the X characters in that file and any including files... If it doesn't highlight it, I'm sure there's an extension you could do it with. That's the only way I can think of doing it, anyway.
Ah, my bad. I meant different color in the app i'm running, not in the IDE's text editor. :v:
[QUOTE=WhatTheEf;32810121]Ah, my bad. I meant different color in the app i'm running, not in the IDE's text editor. :v:[/QUOTE] I'm pretty sure you're going to need to use an external library for that. Look into PDCurses.
not sure if this should be in webdev, but I'm trying to get a mode for emacs that'll do php/css/html in one mode. I came across [URL="http://www.emacswiki.org/emacs/HtmlModeDeluxe"]HtmlModeDeluxe[/URL] which seems to be what I'm looking for. Only problem is that this file is missing: [URL]http://www-users.rwth-aachen.de/g.ohrner/Download/mmm-mode-older_post0.4.7_cvs.tar.bz2[/URL] Anyone know how to set up this mode?
Wrong forum.
[QUOTE=aero1444;32814985]not sure if this should be in webdev, but I'm trying to get a mode for emacs that'll do php/css/html in one mode. I came across [URL="http://www.emacswiki.org/emacs/HtmlModeDeluxe"]HtmlModeDeluxe[/URL] which seems to be what I'm looking for. Only problem is that this file is missing: [URL]http://www-users.rwth-aachen.de/g.ohrner/Download/mmm-mode-older_post0.4.7_cvs.tar.bz2[/URL] Anyone know how to set up this mode?[/QUOTE] I think you'd be better off asking in the Linux forum, actually. You'd think people there might use emacs.
How do you wait until a signal with boost? I want to have a thread wait until a value is set and then have the thread process it.
[QUOTE=high;32816945]How do you wait until a signal with boost? I want to have a thread wait until a value is set and then have the thread process it.[/QUOTE] Can't you sleep with zero time and check if the value is set every time the thread regains control?
I need help with making a cell shader for a future mod for HL2. How would I set about doing this?
Sorry, you need to Log In to post a reply to this thread.