• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=bootv2;27242411]1 program written in java could be a lot cleaner and faster than in c++. it's just about how it's programmed[/QUOTE] If you mean that a poorly written C++ program can be slower than a well coded Java program, I agree.
[QUOTE=The Great Ghast;27242572]But why is it bad? The game is functional.[/QUOTE] [cpp]unsigned int add( unsigned int a, unsigned int b ) { for ( int i = 1; i <= b; i++ ) a++; return a; }[/cpp] What's bad about it? It's functional.
[QUOTE=bootv2;27242411]yeah, can't deny that's terrible. but that's the fault of notch. not of the language. I could use the best programming language and write the worst code for it. it's just a manner of how smart you'll use the language. so don't bother if someone badly programs something in a language you want to use. tl;dr 1 program written in java could be a lot cleaner and faster than in c++. it's just about how it's programmed.([b]except that java is slow because it's JITted[/b], but since it's just a step to c++ you shouldn't bother with that)[/QUOTE] Bullshit. JITed languages like Java and C# can be just as fast and even faster (CPU-specific optimizations) than AOTed languages. (Both can be AOTed anyway)
So I just started C++, and have finally removed all the errors from my first few programs. They run just fine, the problem is the console opens, then closes before I can see the results. I'm using dev C++. How do I stop this?
[QUOTE=Overv;27242644][cpp]unsigned int add( unsigned int a, unsigned int b ) { for ( int i = 1; i <= b; i++ ) a++; return a; }[/cpp] What's bad about it? It's functional.[/QUOTE] Is that not supposed to work or something?
[QUOTE=The Great Ghast;27243264]Is that not supposed to work or something?[/QUOTE] It is supposed to be an inefficient way of adding two integers together (it works).
[QUOTE=MakeR;27243313]It is supposed to be an inefficient way of adding two integers together (it works).[/QUOTE] Hmmm, I see what you mean. I can see how he could do that better. Where do you all get Minecrafts source code?
Simply put: How do I stop my C++ console programs from closing on me?
[QUOTE=Raneman;27243446]Simply put: How do I stop my C++ console programs from closing on me?[/QUOTE] I tend to do this: [cpp]int main() { // Do stuff std::cin.get(); }[/cpp]
[QUOTE=The Great Ghast;27243357]Hmmm, I see what you mean. I can see how he could do that better. Where do you all get Minecrafts source code?[/QUOTE] We generally base our opinion off of the code seen in Notch's programming livecasts.
Is it possible to send a string into a function and use it to get an enum value? So far I have this: [cpp] char Code::dest(char *m[]) //m is the destination mnemonic { const struct { int d1, d2, d3; } dBit[] = { {0,0,0}, //null {0,0,1}, //M {0,1,0}, //D {0,1,1}, //MD {1,0,0}, //A {1,0,1}, //AM {1,1,0}, //AD {1,1,1}, //AMD }; enum d { null, M, D, MD, A, AM, AD, AMD }; } [/cpp]
[QUOTE=Overv;27242644][cpp]unsigned int add( unsigned int a, unsigned int b ) { for ( int i = 1; i <= b; i++ ) a++; return a; }[/cpp] What's bad about it? It's functional.[/QUOTE] That's how multiplication works on the MOS 6502. It doesn't have a mul instruction, so you need to implement a mul subroutine yourself with a loop.
I need a library that will allow me to: Load a image, and access it's pixels Make a image pixel by pixel Display these images C++, any suggestions?
I have a small top-down shooter made in XNA, and I'm wanting to add some weapons. How would I go adding a weapon sprite, and it "follow" the player? The method I'm currently using, is just check where the player is on the screen and update the weapons position (along with it's offsets, so it's in the front of the player, or his "hands"). Is there a better way to accomplish this?
you could make the weaponPosition hold just the ofset and when it comes to drawing or using the weapon possition you do: weaponPossition + playerPossition
When I compile this code it says there is something wrong with my if statement, what am I doing wrong?: [code] import java.util.Scanner; import javax.swing.JOptionPane; import java.util.Random; public class HeadsOrTails { public static void main (String[] args) { String result; String input = JOptionPane.showInputDialog("Enter Heads or Tails"); input = input.trim().toLowerCase(); double random = Math.random(); if random >= .5 && input.equals("heads") { result = "win!"; } else { result = "lose..."; } JOptionPane.showMessageDialog(null, "You " +result, "Results", JOptionPane.PLAIN_MESSAGE); } } [/code]
you should have () around your if statement: [code]if (random >= .5 && input.equals("heads"))[/code]
[QUOTE=Raneman;27243446]Simply put: How do I stop my C++ console programs from closing on me?[/QUOTE] well they're console applications so they're meant to be run from the command line. but if you don't want to then just use what MakeR posted.
[QUOTE=Raneman;27243446]Simply put: How do I stop my C++ console programs from closing on me?[/QUOTE] if on windows, and dont care about cross-platformness, you could do system("pause") This is a horrible way of doing it though, but it is good for the lazy;
[QUOTE=robmaister12;27251396]you should have () around your if statement: [code]if (random >= .5 && input.equals("heads"))[/code][/QUOTE] Wow I'm so stupid, I was messing around with the parenthesis and I guess I took those out and forgot to put them back in. Thanks. I finished my heads or tails program even though it sucks.
[QUOTE=Niteshifter;27244548]Is it possible to send a string into a function and use it to get an enum value?[/QUOTE] What language? [QUOTE=mmavipc;27250118]I need a library that will allow me to: Load a image, and access it's pixels Make a image pixel by pixel Display these images C++, any suggestions?[/QUOTE] SDL or SFML.
-snip- I'm sorry, I'm an idiot. Continue on.
[QUOTE=vexx21322;27254667]Language is Python. Problem is, how can I open a text file with a different extension?[/QUOTE] like you normally would?
[QUOTE=vexx21322;27254667]Language is Python. Problem is, how can I open a text file with a different extension?[/QUOTE] Do you think it's checking for an extension?
-snip- I'm sorry, I'm an idiot. Continue on.
I have a basic weapons class but i waant the shoot function to be handled by lua atm i have [csharp]if (mouse.LeftButton == ButtonState.Pressed) { foreach(Weapon gun in myWeapons) if (gun.isActive) { gun.CallFunction("shoot"); //this is what should happen when you shoot //entity particle = new entity(Content.Load<Texture2D>("images\\particles\\explosion")); //particle.particleDetails(this.position, 750, time, this.priv_rotation); //particleList.Add(particle); } }[/csharp] this tels c# about the lua function [code]public LuaFunction FindFunc(string name) { try { LuaFunction retfunc = this.weaponLua.GetFunction(name); return retfunc; } catch (Exception e) { return null; } } public void CallFunction(string name) { if (FindFunc(name) == null) { sprite = null; return; } try { LuaFunction retfunc = this.weaponLua.GetFunction(name); retfunc.Call(); } catch (Exception e) { } } [/code] and this is the actual lua function [code]function shoot() entity particle = new entity(Content.Load<Texture2D>("images\\particles\\explosion")); particle.particleDetails(this.position, 750, time, this.priv_rotation); particleList.Add(particle); end[/code] but how do i let lua know about the entities, particle list... that is used in the function?
[QUOTE=Richy19;27257550]and this is the actual lua function [code]function shoot() entity particle = new entity(Content.Load<Texture2D>("images\\particles\\explosion")); particle.particleDetails(this.position, 750, time, this.priv_rotation); particleList.Add(particle); end[/code][/QUOTE] How about learning the language before trying to embed it? :raise: Which wrapper are you using for Lua?
[QUOTE=raBBish;27258025]How about learning the language before trying to embed it? :raise: Which wrapper are you using for Lua?[/QUOTE] LuaInterface btw i know thats what you would put in c# and not what you use in lua but i put that there to give the general idea of what i want to do
[QUOTE=Richy19;27258088]LuaInterface[/QUOTE] [url]http://www.gamedev.net/reference/articles/article2275.asp[/url] Haven't used LuaInterface myself, but that looks like a useful tutorial.
Hey guys, whats the maths behind rotating a sprite to face the mouse? For some reason I can't search or anything on google ( school servers suck or something ), and can't look it up myself.
Sorry, you need to Log In to post a reply to this thread.