• What do you need help with? V. 3.0
    4,884 replies, posted
xveolcity = cosine(radians) * velocity yvelocity = sine(radians) * velocity
[QUOTE=PieClock;33064655]-snip, got it, finally. -[/QUOTE] Thanks for the solution, it's nice that you help others.
Yeah, I learned that lesson too. General rule of thumb is leave your answers, makes the search function a hell of a lot more useful.
[QUOTE=Jookia;33065090]Thanks for the solution, it's nice that you help others.[/QUOTE] No need to be a dick over it, I'm new to this stuff so I figured that most people wouldn't have a use for it, because to me it felt like standard stuff, and I don't really know what the problem was to begin with. Anyway, I wrote out a new cleaned up file with it as an example for myself, I'll edit it into my post in a minute.
[QUOTE=PieClock;33065601]No need to be a dick over it, I'm new to this stuff so I figured that most people wouldn't have a use for it, because to me it felt like standard stuff, and I don't really know what the problem was to begin with. Anyway, I wrote out a new cleaned up file with it as an example for myself, I'll edit it into my post in a minute.[/QUOTE] You'd be surprised how many times I go to look up some problem and the only person who's having the exact same issue as me mysteriously ended a thread with "fixed it, thanks" without explaining the solution.
quick rant I've been turning in all my C++ homework the day after it's assigned (we have a week to write the program) And basically... Last assignment I basically got graded down FORTY PERCENT for approaching the problem in a different way. The code wasn't complex, it did the job exactly the same way, it just wasn't to my teacher's liking. What's up with that? :suicide: i thought my way of handling things was creative because it followed his style guidelines of using base variables so you don't have to change a lot of stuff, four spaces for an indent, plus it allowed for any future expansion LIKE A GOOD CODER DOES... Yikes :/
I'd demand an explanation from the teacher if I were you. If the program does what it's supposed to (and isn't a horrendous mess of spaghetti code), it shouldn't receive a failing grade. Unless you had specific requirements for how you were supposed to implement it, and you ignored them?
[quote]Write a program that will populate an array of random numbers between 0 and 1410, print the array contents and memory locations, and include function that will return a pointer to the smallest number in an array. All iteration must be done using pointer arithmetic The program must implement the functions as defined in the pa6-skeleton.cpp file: int* find_smallest_number(int*, int); void fill_with_random_data(int*, int); void print_array(int*, int); The output should look like this: Array contents are: 68 [0x7fff69f4e71c], 1352 [0x7fff69f4e720], 989 [0x7fff69f4e724], 27 [0x7fff69f4e728], 568 [0x7fff69f4e72c], 542 [0x7fff69f4e730], 1125 [0x7fff69f4e734], 810 [0x7fff69f4e738], 1324 [0x7fff69f4e73c], 660 [0x7fff69f4e740] The smallest item is 27 and it is at memory location is 0x7fff69f4e728[/quote] And mine fits all those requirements. the only weird thing is how I compare current array item vs next but its pointer arithmetic and works fine.
[QUOTE=Tukimoshi;33063814]Having some difficulty with loops in Python. It's been stumping my entire class. [code]def pattern(index): n = raw_input("Please enter a whole integer ") if n.isdigit: print n while index < 10: print n n = n + 1 index += 1 else: input("Please press enter to exit") else: print ("Please try again") return pattern(index) index = 0 pattern(index) [/code] The goal to is to use loops, I'm supposed to take an integer as an input, check that it's an integer, and print the next 10 in sequence. However I would love to use just the input method, but my teacher banned me from using exceptions, so I'm wondering how to do value checking? I'm supposed to print an error if the user does not input an integer.[/QUOTE] Well, I'm heading to bed soon and my assignment is due tommorow. I guess I'll find out tommorow then. I'll be sure to edit the post if I figure out an answer. Cheers!
[QUOTE=Tukimoshi;33063814]Having some difficulty with loops in Python. It's been stumping my entire class. [code]def pattern(index): n = raw_input("Please enter a whole integer ") if n.isdigit: print n while index < 10: print n [b]n = int(n) + 1[/b] index += 1 else: input("Please press enter to exit") else: print ("Please try again") return pattern(index) index = 0 pattern(index) [/code] The goal to is to use loops, I'm supposed to take an integer as an input, check that it's an integer, and print the next 10 in sequence. However I would love to use just the input method, but my teacher banned me from using exceptions, so I'm wondering how to do value checking? I'm supposed to print an error if the user does not input an integer.[/QUOTE] I'm not a big fan of the Type system in Python. Anyway, in your code you're reading into n, n is a string. Later, you print n as a string, no worries. Then, you try to add an integer to the string. Python don't like that. So to fix that, just change the thing I've bolded in your code block. That [i]should[/i] fix the issue. [editline]1st November 2011[/editline] Some super-useful python resources too, for anyone trying to learn python: [url=http://dl.dropbox.com/u/6929441/NCSS2009Q.zip]2009 NCSS python problems (beginner & advanced)[/url] [url=http://dl.dropbox.com/u/6929441/NCSS2010-Beginners.docx]2010 NCSS python problems (beginner)[/url] There were a bunch of notes from the national computer science school for learning python too but I don't know if I have a copy of them. If I find them I'll put them up, but there's plenty of graded problems in those two links above that should give you a bit of a head start if you work through them and teach yourself along the way.
[QUOTE=mechanarchy;33067308]I'm not a big fan of the Type system in Python. Anyway, in your code you're reading into n, n is a string. Later, you print n as a string, no worries. Then, you try to add an integer to the string. Python don't like that. So to fix that, just change the thing I've bolded in your code block. That [i]should[/i] fix the issue. [editline]1st November 2011[/editline] Some super-useful python resources too, for anyone trying to learn python: [url=http://dl.dropbox.com/u/6929441/NCSS2009Q.zip]2009 NCSS python problems (beginner & advanced)[/url] [url=http://dl.dropbox.com/u/6929441/NCSS2010-Beginners.docx]2010 NCSS python problems (beginner)[/url] There were a bunch of notes from the national computer science school for learning python too but I don't know if I have a copy of them. If I find them I'll put them up, but there's plenty of graded problems in those two links above that should give you a bit of a head start if you work through them and teach yourself along the way.[/QUOTE] Smart man, thanks for the help. Ya see, what happened is, this is our third set of assignments, each one having a theme. The first one was very basic and I used exceptions for the very first program we did (Calculating Fahrenheit to Celsius and Back), however, my teacher didn't like that, particularly because we do assembly later and it doesn't have exceptions. Anyways, thanks for the help.
[QUOTE=Tukimoshi;33067367]Smart man, thanks for the help. Ya see, what happened is, this is our third set of assignments, each one having a theme. The first one was very basic and I used exceptions for the very first program we did (Calculating Fahrenheit to Celsius and Back), however, my teacher didn't like that, particularly because we do assembly later and it doesn't have exceptions. Anyways, thanks for the help.[/QUOTE] Tell me how learning Assembly goes, I've wanted to for a while now and had a bit of a tinker but never managed to get fully into the swing of it.
[QUOTE=mechanarchy;33067565]Tell me how learning Assembly goes, I've wanted to for a while now and had a bit of a tinker but never managed to get fully into the swing of it.[/QUOTE] Will do. Should be fun, although it's probaly going to rape my brain.
[QUOTE=Tukimoshi;33067367]however, my teacher didn't like that, particularly because we do assembly later and it doesn't have exceptions.[/QUOTE] That's fucking retarded and your teacher is an idiot. When you learn a programming language you should learn it properly (in this case, learn Exception-based programming, which is a base Python paradigm), and not keep using patterns fro other languages just because you're used to them or you don't want to learn new ones.
[QUOTE=Protocol7;33066016]quick rant I've been turning in all my C++ homework the day after it's assigned (we have a week to write the program) And basically... Last assignment I basically got graded down FORTY PERCENT for approaching the problem in a different way. The code wasn't complex, it did the job exactly the same way, it just wasn't to my teacher's liking. What's up with that? :suicide: i thought my way of handling things was creative because it followed his style guidelines of using base variables so you don't have to change a lot of stuff, four spaces for an indent, plus it allowed for any future expansion LIKE A GOOD CODER DOES... Yikes :/[/QUOTE] That's dumb. In my school, the first year we aren't judged on code, but if the program (game) works. After we get comfortable with C++, we start looking at how our code could be better. I think it's wrong to grade an assignment lower because it was done in a different way. That's one of the fun things in programming, a problem can be solved in a big number of ways.
Could it be because the teacher was trying to teach the class about a certain method of programming? Seems like the only reason why you would receive a low mark is because, for example: If the teacher was trying to teach you about recursion, and you program it in a different way that did not use recursion, then you would lose marks. If that's not the case then you're teacher is pretty crazy
[QUOTE=ief014;33068806]Could it be because the teacher was trying to teach the class about a certain method of programming? Seems like the only reason why you would receive a low mark is because, for example: If the teacher was trying to teach you about recursion, and you program it in a different way that did not use recursion, then you would lose marks. If that's not the case then you're teacher is pretty crazy[/QUOTE] About the only thing specific to thst assignment is pointers and its a fundamental C++ class, and I definitely used pointers and pointer arithmetic like it said I should. His comment was "code overly complex" and he gave us a skeleton file, I just added a for loop for the pointer comparisons and another for population.
[QUOTE=q3k;33067826]That's fucking retarded and your teacher is an idiot. When you learn a programming language you should learn it properly (in this case, learn Exception-based programming, which is a base Python paradigm), and not keep using patterns fro other languages just because you're used to them or you don't want to learn new ones.[/QUOTE] Well, it's an introductory coding course and I don't think we're trying to become perfect coders in Python, the course seems more focused towards coding in general, using Python as a base-understanding because it's so similar to pseudo-code. He's actually a fantastic teacher though. He moved here from Britain and has been doing computer programming for 37 years. The whole point of this lab was loops anyways. I think he wants me to understand that while exceptions do exist and are useful, they are relatively new to programming and that I should also understand how to work without them.
Anyone want to take a look at my A* code and tell me if I'm doing something obviously wrong? [url]http://codepad.org/queem7ad[/url] (It's Java, not C. Sorry!) The pathfinder is currently doing this: [img]http://i.imgur.com/alO6x.png[/img] It'd be really helpful if someone with experience in A* could give it a quick once-over. Thanks!
Trying to follow this [url]http://www.cprogramming.com/tutorial/lesson9.html[/url] Why is it that I need to type std:: before cout and cin, but I don't need to type anything before other functions such as strcmp? Also I don't understand why I need to use << in cout. [editline]2nd November 2011[/editline] is cout and in just special?
[QUOTE=a-k-t-w;33071267]Trying to follow this [url]http://www.cprogramming.com/tutorial/lesson9.html[/url] Why is it that I need to type std:: before cout and cin, but I don't need to type anything before other functions such as strcmp? Also I don't understand why I need to use << in cout. [editline]2nd November 2011[/editline] is cout and in just special?[/QUOTE] You can use "using namespace std;" after your includes to drop the std::
i heard that that is bad practice
[QUOTE=Nigey Nige;33071097]Anyone want to take a look at my A* code and tell me if I'm doing something obviously wrong? [url]http://codepad.org/queem7ad[/url] (It's Java, not C. Sorry!) The pathfinder is currently doing this: [img]http://i.imgur.com/alO6x.png[/img] It'd be really helpful if someone with experience in A* could give it a quick once-over. Thanks![/QUOTE] Maybe I'm reading your code wrong, but it doesn't look like A* at all. It looks like a greedy algorithm. Maybe start with Dijkstra's first. It's simpler, but not too different from A*. Once you get that going it shouldn't be hard to modify into A*, you basically just add the heuristic that you're already using.
[QUOTE=a-k-t-w;33071267]is cout and in just special?[/QUOTE] Sort of. C++ implements something called the "stream." Which is basically a way to "stream" information into something. Other things use this "stream" design, but cout is the primary one. Basically, it allows you a way to output things to the console without worrying about their type. Take, for example, strings in C++. If you try to add a number to a string: [cpp]std::string myString = "I am "; myString += 18; myString += " years old.";[/cpp] C++ will assume '18' is a char, and it will not work the way a beginning C++ user would think. The stream makes it easy: [cpp]cout << "I am " << 18 << " years old.";[/cpp] Three different data types (string, int, string), all "streaming" into the console. cin is the same idea. The nice thing is, what if you wanted everything to output into a file rather than the console? Using the "stream" file classes, ifstream and ofstream, you can use the same syntax as cout for file-writing: [cpp]ofstream outfile; outfile.open("test.txt"); outfile << "I am " << 18 << " years old."; outfile.close()[/cpp] I may of gotten a little too in-depth with that, but yeah. That's why you use << in cout. :v: [QUOTE=a-k-t-w;33072136]i heard that that is bad practice[/QUOTE] It really depends on where and what you're using "using namespace std;" for. First off, let me emphasize this: NEVER USE IT IN A HEADER. If you're going to be using namespace anything, it should be [b]clear[/b] in the .cpp. Secondly, if I'm writing a math library (or whatever), and my entire math library is in the namespace "Math." If I'm writing the .cpp for my math library, it would be okay to do "using namespace Math;" because pretty much everything in the file would use Math:: otherwise. It wouldn't make sense to put it in the .h because everything that includes Math.h would "use namespace Math," and at that point, what's the use in a namespace?
So, I want to start making games, or going down that line, would you recommend just going straight intomaking them? Or making programs etc first? I'd just like to know if theres any languages out there which can start me off? If theres also any web based tutorials that'd be awesome too! Thanks
[QUOTE=WTF Nuke;33045738]Right now, I have graivity be applied when the character is not grounded. However, I have run into a problem in that the character is considered grounded one frame, and not grounded the next because the collision is fixed and the player is no longer collided with the floor. While this may seem ok at first, it screwed up moving tiles because the character has his yvelocity set to the tile one frame and to zero the next. I was thinking of just constantly applying gravity, however that seems counterproductive. Any suggestions?[/QUOTE] Repost.
[QUOTE=WTF Nuke;33073887]Repost.[/QUOTE] 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.
I managed to somewhat fix my "parent" window problem. I found that dermadesigner does exactly what I want so I took a look at the source code. [Csharp]/* @Gbps -- This is a small library for getting some C++ functions we need to make sure the * the main windows correctly focus when the main window focuses. */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; using System.Windows.Forms; namespace WindowsFormsApplication1 { public class ShowWindowInterop { private const int SW_SHOWNOACTIVATE = 4; private const int HWND_TOPMOST = -1; private const uint SWP_NOACTIVATE = 0x0010; private const int SW_HIDEWINDOW = 0; [DllImport("user32.dll", EntryPoint = "SetWindowPos")] static extern bool SetWindowPos( int hWnd, // window handle int hWndInsertAfter, // placement-order handle int X, // horizontal position int Y, // vertical position int cx, // width int cy, // height uint uFlags); // window positioning flags [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow(); public static void ShowInactiveTopmost(Form frm) { ShowWindow(frm.Handle, SW_SHOWNOACTIVATE); SetWindowPos(frm.Handle.ToInt32(), HWND_TOPMOST, frm.Left, frm.Top, frm.Width, frm.Height, SWP_NOACTIVATE); } public static void HideTarget(Form frm) { ShowWindow(frm.Handle, SW_HIDEWINDOW); } public static IntPtr GetForegroundWindowPtr() { IntPtr Active = GetForegroundWindow(); return Active; } } }[/Csharp]
[code]this.dist = this._x - _root.player._x; if (this.dist < 60 && this.dist > 10) { this._x = this.dist += 2; }[/code] Try to get an NPC to follow the player, not sure what to do, this is as2.
[QUOTE=Nigey Nige;33071097]Anyone want to take a look at my A* code and tell me if I'm doing something obviously wrong? [url]http://codepad.org/queem7ad[/url] (It's Java, not C. Sorry!) The pathfinder is currently doing this: [img]http://i.imgur.com/alO6x.png[/img] It'd be really helpful if someone with experience in A* could give it a quick once-over. Thanks![/QUOTE] Not sure what the bottom-right one is doing, but the top-right and bottom-left are showing signs of a BFS. Check [url=http://theory.stanford.edu/~amitp/GameProgramming/]this article[/url] if you haven't already. It explains the heuristics and ways to calculate your f-score (as well as many other optimisations) very nicely.
Sorry, you need to Log In to post a reply to this thread.