• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=Z_guy;33089173]You need to store the sf::SoundBuffer, just like you need to store sf::Texture.[/QUOTE] Thanks, it was sort of working just now but they kept going out of scope and being disposed before I heard anything :v [editline]2nd November 2011[/editline] Alright, now I'm keeping a sf::Sound and sf::SoundBuffer pair for every different sound, but when I load more than about 26 sounds I get this: [IMG]http://i.imgur.com/5j3jV.png[/IMG]
[QUOTE=subenji99;33089102]if contFlag is controlling the gamestate in the way I think it is, (the game should continue when it's true, the game is over when it's false) then your error is setting it false when input == "Twist" If it's supposed to be the decider for a player's turn though, judging by your comments you don't actually add a new card in on a "Twist" - there's not enough code here to really find the problem.[/QUOTE] Ah, sorry, I didn't want to flood everyone with my code, i'll add the rest of that part, I'll just omit the part which runs independently of the rest [CODE] //-----------------------------------------------Player turn---------------------------------- // Create variable for player use boolean pBustFlag = false, contFlag = false; int playerScore = 0, turnCount = 0; String playerCards = "", inputString = ""; while (stickFlag == false) { // Deal the first two cards regardless of player control turnCount ++; // Pick a random card of a random suit Random r = new Random(); cardRand = r.nextInt(12) + 1; suitRand = r.nextInt(3) + 1; // Name the suit depending on the random value chosen switch (suitRand) { case 1: suitName = "Hearts"; break; case 2: suitName = "Diamonds"; break; case 3: suitName = "Clubs"; break; case 4: suitName = "Spades"; break; } // The list of cards the player has is added too with the cards value and suit switch (cardRand) { case 1: playerCards = playerCards + " Ace of " + suitName; break; case 11: playerCards = playerCards + " Jack of " + suitName; break; case 12: playerCards = playerCards + " Queen of " + suitName; break; case 13: playerCards = playerCards + " King of " + suitName; break; default : playerCards = playerCards + " " + Integer.toString(cardRand) + " of " + suitName; break; } // Add to the players score dependant on the type of card and its value switch (cardRand) { case 11: playerScore += 10; break; case 12: playerScore += 10; break; case 13: playerScore += 10; break; default: playerScore += cardRand; break; } while (contFlag == false){ //Decide if the player is bust if (playerScore <= 21){ // Display players cards System.out.println("Your hand contains: " + playerCards); System.out.println("You currently have a score of: " + playerScore); Scanner in = new Scanner(System.in); // If it's after the first turn the ask the player to choose stick or twist System.out.print("Stick or Twist? : "); inputString = in.nextLine(); if (inputString.equals("Stick")) { stickFlag = true; contFlag = true; } else if (inputString.equals("Twist")) { stickFlag = false; contFlag = false; } else { contFlag = false; System.out.println("Unrecognised input"); } } else { contFlag = false; pBustFlag = true; } } cardRand = 0; suitRand = 0; suitName = ""; } [/CODE] I hope that there is enough to help now, cheers And thanks for just rating dumb with no reasoning, sure does help
(yeah, the other code wasn't relevant, I thought maybe there was more code within the 'while(contFlag == false)' loop) From that, all I can see is the code should be looping back to the printlines and input request again on a "Twist" input, so maybe there's some quirk with those functions. I'd suspect the input scanner. Sorry I can't help further.
[QUOTE=NovembrDobby;33089786]-sfml sound problems-[/QUOTE] Fixed it, I made a channel system where there are only 6 sf::Sound objects. Normally each sound gets auto-assigned to channel 1-5 but I can specify which channel I want a sound to use, if two would overlap (each channel can only play one at a time). [code] channels[sound->channel]->SetBuffer(*sound->buffer); channels[sound->channel]->SetPitch(pitch + 1); //def xna pitch = 0, def SFML pitch = 1 if (type == snd_fx) channels[sound->channel]->SetVolume(100.0f * mult_vol * Core::opt_flt_cur("snd_volume") * Core::opt_flt_cur("snd_volume_fx")); else if(type == snd_ui) channels[sound->channel]->SetVolume(100.0f * mult_vol * Core::opt_flt_cur("snd_volume") * Core::opt_flt_cur("snd_volume_ui")); channels[sound->channel]->Play(); [/code] I should probably make it automatic so it can play any 6 sounds in combination by checking which channels are taken, but meh
I need help with how to populate a combobox with a text file (4 items in the text file) on loadup. [CODE]Private Sub frmSkis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim Equipcbo As String cboEquip.Items.Clear() Dim EquipCostR As New IO.StreamReader("F:\Computing\VB Projects\SarasSkis\equipment.txt", True) Equipcbo = EquipCostR.ReadLine() Do While EquipCostR.Peek() >= 0 Console.WriteLine(EquipCostR.ReadLine()) cboEquip.Items.Add(Equipcbo) Loop EquipCostR.Close() [/code] And this is how far as I got, I'm a newbie only started computing a month ago. Any help would be appreciated (This is in VB2008) Edit - Worked it out and I can see where I went wrong with the help of a friend
[QUOTE=subenji99;33092481](yeah, the other code wasn't relevant, I thought maybe there was more code within the 'while(contFlag == false)' loop) From that, all I can see is the code should be looping back to the printlines and input request again on a "Twist" input, so maybe there's some quirk with those functions. I'd suspect the input scanner. Sorry I can't help further.[/QUOTE] Didn't think it would be :P I'll take a further look in the morning, thanks anyway
This is C. I am learning it. I want this to return a floating-point number, instead of an integer, but it only returns 0. Help? [code]#include <stdio.h> float div(int a, int b); int main() { int a; int b; printf("Enter any number: "); scanf("%d", &a); printf("What do you want to divide that number by?\n"); scanf("%d", &b); printf("The quotient of your two numbers is %d\n", div(a, b) ); getchar(); } float div(int a, int b) { return a/b; } [/code]
[QUOTE=Meatpuppet;33094055]This is C. I am learning it. I want this to return a floating-point number, instead of an integer, but it only returns 0. Help? [code]#include <stdio.h> float div(int a, int b); int main() { int a; int b; printf("Enter any number: "); scanf("%d", &a); printf("What do you want to divide that number by?\n"); scanf("%d", &b); printf("The quotient of your two numbers is %d\n", div(a, b) ); getchar(); } float div(int a, int b) { return a/b; } [/code][/QUOTE] int/int returns int. You need to convert one or both parameters to a float using static_cast. And use %f to print floats.
[QUOTE=ZeekyHBomb;33094177]int/int returns int. You need to convert one or both parameters to a float using static_cast. And use %f to print floats.[/QUOTE]Got everything except static_cast. What does that mean? [editline]2nd November 2011[/editline] Tried just converting the ints and the %fs, now 5/2 gives me 2.00000000
[QUOTE=ZeekyHBomb;33094177]int/int returns int. You need to convert one or both parameters to a float using static_cast. And use %f to print floats.[/QUOTE] That is C, not C++. What works here is obviously then a C cast. Read on casting somewhere to know how it works, but the basic idea is that it transforms values between types. One of the values of a calculation has to be a float for the other one to be promoted as well. Try (float)a/b;
Got it, I just converted all instances of 'int a' and 'int b' to 'float a' and 'float b' Now it works. Thanks, I don't care about all those extra 0s; I'll get to casting when I need it, if it's not in the tutorial I am taking.
I'm a little stuck with a problem with calculating movable tiles. The way I have it set up, it uses my old FOV recursive algorithm from my Rougelike: it searches one tile above and below the original tile, and for every time it goes up/down, it checks every possible side combination. The problem arises when an object (i.e., an enemy) is in the way, it stops. In some cases, it should be able to go behind the enemy by moving around them, but how should I calculate that? Example: [img]http://img35.imageshack.us/img35/7316/awscreenshot06b.png[/img]
Does anyone have ideas for how to randomly generate a polygon that is guaranteed to be convex? What I'm doing now is creating a regular polygon and randomly moving the vertices radially outward from the center, but sometimes that results in concave shapes and Box2D shits itself with assertion failures. I've looked into ways of testing whether a polygon is convex but I'm looking for something more efficient than "while the shape is not convex generate another one" Relevant code: [cpp] for(double ang = 0.0; ang < 2*PI; ang += interval) { int length = maxW/2 + rand() % maxH; points.push_back(Vector2(length*cos(ang), length*sin(ang))); n++; } [/cpp]
I'd just finished making 2D layers in OpenGL to find out objects aren't drawn in accordance to when the render functions are called. Is there any way to fix this? (I've googled and supposedly disabling the Z buffer should make it work how I initially thought, but it does nothing for me)
Okay so I've got a question that I thought would be a lot easier than it's turning out to be (maybe I'm just not looking in the right places). I have a 3D box. I have a 3D direction vector. I want to rotate this box so that it is "facing" that direction. Specifically, I'm trying to calculate a rotation matrix. [cpp]D3DXMATRIX Plane::getWorldMatrix() const { D3DXMATRIX scale, rotate, translate; D3DXMatrixScaling(&scale, .1f, 10, 10); /* need to calculate rotation here, all attempts have failed */ D3DXMatrixTranslation(&translate, point.x, point.y, point.z); return scale * rotate * translate; }[/cpp] Looking for tutorials, explanations, demos, whatever I can get my hands on. This shouldn't be a three hour endeavor.
[QUOTE=sim642;33086021]atan2(y1 - y0, x1 - x0) will be in radians. [/quote] When I try this it only outputs an angle between 0.054 and -0.054. The quad barely moves as I move the pointer around it.
I've having a real problem finding the exact regular expression to do what I need. I need a regular expression to give me just the domain name of whatever url I input. for example: [url]http://google.com/search?blahblahblah[/url] = google.com [url]http://www.something.more.com/blah[/url] = more.com
I'm starting Python, what IDE would you recommend? I do some web development, and I use Sublime Text for that so I'd love to stay with that, but would it be more helpful to have debugging and code completion etc. when learning Python? Thanks
New C++ programmer here, I am working on a simple text based game to help me understand C++ better, I recently I found out how to do stuff when a key is pressed rather than when you type something in. I am currently re-doing my navigation system to be arrow-key selection based rather than typing-based. It works great except for a huge problem, in some places I have a getline cin for stuff like choosing a name, and after I select something in the menu by pressing enter, the cin that comes ~10 seconds after that picks up the enter and attempts to select a blank name, I use GetAsyncKeyState to pick up keyboard presses, I assume the problem is because the cin picks up stuff that's been written before it appears, is there some way to empty what has been typed in before the cin appears?
[QUOTE=Alcapwne;33105047]I'm starting Python, what IDE would you recommend? I do some web development, and I use Sublime Text for that so I'd love to stay with that, but would it be more helpful to have debugging and code completion etc. when learning Python? Thanks[/QUOTE] PyDev It's a plugin for the Eclipse IDE.
[QUOTE=vexx21322;33105505]PyDev It's a plugin for the Eclipse IDE.[/QUOTE] alright, thanks :)
I'm starting to learn C, with a view to moving on to doing 2D graphical simulations at some point, but I'm no where near experienced enough with programming to attempt that yet. What sort of projects would be good to help me bridge the gap from what I'm doing now with simple loops and the like to more complicated stuff?
This is in actionscript 3 I need to store the players name, which they will have typed into a dynamic text box on an earlier frame. i then need to be able to use this name in later frames easily.
how do I check whether a number is an integer in Python?
[QUOTE=farmatyr;33104955]When I try this it only outputs an angle between 0.054 and -0.054. The quad barely moves as I move the pointer around it.[/QUOTE] Eh? It should be in the range [-pi/2, pi/2]. Are you sure you haven't missed something? [editline]3rd November 2011[/editline] [QUOTE=Alcapwne;33108188]how do I check whether a number is an integer in Python?[/QUOTE] [code] try: x = int(x) except: #do whatever if it cannot be converted to an int else: #do whatever if x has been converted to an int [/code] This isn't a direct check (mainly it tries to force x to be an integer, and hits an exception if it isn't), but I think it's the most Pythonic way of handling this problem. Fits in well with the whole duck typing paradigm. If you really [i]need[/i] to check whether a number is an integer for some kind of mathematical reason, I'm sure there's some way to do that too.
Im trying to draw stuff to an openGL ready renderwindow but it wont draw anything. Found out its this: [b]glEnable(GL_CULL_FACE);[/b] Not sure why that would make it not draw. Had to do this, bit anoying: [cpp]App.SaveGLStates(); glDisable(GL_CULL_FACE); App.Draw(backGroundSprite); App.RestoreGLStates(); glEnable(GL_CULL_FACE);[/cpp]
ffs I can't get this to work. I need to create an array of unique characters from an array of repeating characters, all I've figured out is that this new array will end up being partial and that it is no longer than 26 spaces. [cpp]for (int i = 0; i < listInput.length; i++){ if (listInput[i] == ' ') continue; for (int c = 0; c < 26; c++){ if(newList[c] == listInput[i]) continue; newList[i] = listInput[i]; } }[/cpp]
[QUOTE=Sh33p;33107147]I'm starting to learn C, with a view to moving on to doing 2D graphical simulations at some point, but I'm no where near experienced enough with programming to attempt that yet. What sort of projects would be good to help me bridge the gap from what I'm doing now with simple loops and the like to more complicated stuff?[/QUOTE] Personally I would recommend C++ over C as taking an object oriented aproach to graphical simulations (such as games) makes things much easier in the long run. A good idea for a simple(ish) project is some kind of text based adventure game. You can implement file input / output (game saving / loading), practise handling user input (parsing strings) and lots of other stuff like that. [editline]4th November 2011[/editline] [QUOTE=POLOPOZOZO;33113711]ffs I can't get this to work. I need to create an array of unique characters from an array of repeating characters, all I've figured out is that this new array will end up being partial and that it is no longer than 26 spaces. [cpp]for (int i = 0; i < listInput.length; i++){ if (listInput[i] == ' ') continue; for (int c = 0; c < 26; c++){ if(newList[c] == listInput[i]) continue; else newList[i] = listInput[i]; } }[/cpp][/QUOTE] Could you clarify your problem a little bit? Are you trying to create a new array which only contains characters once? For example, aabbcd -> abcd?
Yes so "p r o g r a m m i n g" becomes "p r o g r a m i n" the spaces are just in there to signify each space of the array.
[QUOTE=jalb;33074205]Whenever you go to check if the player is "grounded," you could do his current position +(0, 1). So check "if he was one pixel down," would he be in the ground? If so, there's no point in applying gravity. You have to be careful with this, though. If your player's position could contain a decimal point (5.2 y) then you could check 5.2 + 1 = 6.2, he would be in the ground, but the ground is at 6y. When the sprite goes to draw, the player would be at 5.2 but the ground would be at 6.0. The player might appear to be floating up one pixel. This could be solved by "ceiling" the y when drawing the sprite. You have to play around with it. It depends how your gravity code is written.[/QUOTE] I don't think that would be very good if the player is floating 1 pixel above the moving tile. I think it's pretty distracting.
Sorry, you need to Log In to post a reply to this thread.