Is it possible to play 2 wav sounds at once using winmm.dll?
Are there some special flags for that?
I tried using ASYNC but as soon as another sound is played, the first one stops.
Is there a way in Visual Studio to have it automatically create the source and header files in a /src folder instead of having it pile them all in the root directory? It gets very annoying.
[QUOTE=shill le 2nd;23018486]That article is very helpful, but unfortunately it doesn't talk about collision detection (and none of the articles on his site really do, except for the one about networking). I know people (myself included) have been having problems figuring out what to do when some object is travelling at such a velocity that it travels a significant distance past the paddle (or whatever it has to bounce off of) in a single timestep.
(although this is much more of a problem when you're simulating something that accelerates, like gravity, instead of constant speeds like Pong)[/QUOTE]
The pong ball actually accelerates in true pong.
You need to look up methods of CCD (continuous collision detection).
You don't need to implement anything complex for simple ball and line collision. After updating the ball, check if the line is at that y position, and move it to an x position to the opposite side of the paddle and reverse velocity.
[QUOTE=Jawalt;23022805]You don't need to implement anything complex for simple ball and line collision. After updating the ball, check if the line is at that y position, and move it to an x position to the opposite side of the paddle and reverse velocity.[/QUOTE]
You do if it's moving very fast. Since in pong after a certain point it would simply be counted as a goal.
All you would really have to do is line/line intersection.
[QUOTE=Darwin226;23019070]Is it possible to play 2 wav sounds at once using winmm.dll?
Are there some special flags for that?
I tried using ASYNC but as soon as another sound is played, the first one stops.[/QUOTE]
You could try to put it in a thread.
Or use a real audio library :v:
[QUOTE=Overv;23026014]All you would really have to do is line/line intersection.[/QUOTE]
If the ball is actually round, you need the closest distance between two lines so you can check that against the radius.
Collisions between the paddle and the ball in pong is piss easy:
[code]
; see if ball hits paddles
mov al, [ballx]
mov ah, [bally]
mov dl, [ply1py]
mov dh, [ply2py]
cmp al, 6
je .ply1
cmp al, 80-7
je .ply2
jmp .endpaddcheck
.ply1:
cmp ah, dl
jl .endpaddcheck
add dl, 6
cmp ah, dl
jg .endpaddcheck
jmp .flipx
.ply2:
cmp ah, dh
jl .endpaddcheck
add dh, 6
cmp ah, dh
jg .endpaddcheck
.flipx:
mov ah, 0
mov al, [velx]
add ax, 128
mov [velx], al
.endpaddcheck:
[/code]
[QUOTE=ZeekyHBomb;23026602]You could try to put it in a thread.
Or use a real audio library :v:
If the ball is actually round, you need the closest distance between two lines so you can check that against the radius.[/QUOTE]
Well, with line/line collision, you'd obviously do this:
[img]http://www.imgdumper.nl/uploads3/4c2c7457c5e95/4c2c7457c3b6e-pong_collision.png[/img]
Is there a way to make SFML draw a random number generated by rand()?
[QUOTE=NotMeh;23027978]Is there a way to make SFML draw a random number generated by rand()?[/QUOTE]
SFML has its own String implementation. I'm pretty sure you can convert numbers to strings using it.
[url]http://www.sfml-dev.org/documentation/1.4/classsf_1_1String.htm[/url]
[QUOTE=robowurmz;23028051]SFML has its own String implementation. I'm pretty sure you can convert numbers to strings using it.
[url]http://www.sfml-dev.org/documentation/1.4/classsf_1_1String.htm[/url][/QUOTE]
Yeah but how?
[QUOTE=NotMeh;23027978]Is there a way to make SFML draw a random number generated by rand()?[/QUOTE]
Yes.
[cpp]
// For our ToString function
#include <sstream>
#include <string>
template <class T>
std::string ToString(T object)
{
std::ostringstream os;
os << object;
return(os.str());
}
[/cpp]
[cpp]
// We need to load a font.
sf::Font font;
font.LoadFromFile("VeraMono.ttf");
[/cpp]
[cpp]
sf::String text;
text.SetFont(font);
text.SetText(ToString(rand()%10 + 1); // int between 1 and 10
text.SetColor(sf::Color(255,255,255,255));
text.SetSize(22);
text.SetPosition(20, 20);
[/cpp]
[cpp]
// Put this with your other drawing code between clear + display
renderwindow->Draw(text);
[/cpp]
[QUOTE=Jallen;23028076]Yes.
[cpp]
// For our ToString function
#include <sstream>
#include <string>
template <class T>
std::string ToString(T object)
{
std::ostringstream os;
os << object;
return(os.str());
}
[/cpp]
[cpp]
// We need to load a font.
sf::Font font;
font.LoadFromFile("VeraMono.ttf");
[/cpp]
[cpp]
sf::String text;
text.SetFont(font);
text.SetText(ToString(rand()%10 + 1); // int between 1 and 10
text.SetColor(sf::Color(255,255,255,255));
text.SetSize(22);
text.SetPosition(20, 20);
[/cpp]
[cpp]
// Put this with your other drawing code between clear + display
renderwindow->Draw(text);
[/cpp][/QUOTE]
Thank you Jallen <3
What is the fastest way to work with sprite sheets in SFML.
SetSubRect
I'm trying to recursively load a folder and all it's subfolders, but exclude folders that don't have any files with a .xbt extension. How would I go about determining which nodes never lead to a .xbt file? Right now I'm recursively adding all the nodes and filtering out all non-.xbt files. This leaves me with a whole bunch of empty directories. Here's my current code (C#):
[cpp] public void FillTreeNode(string dir_root, TreeNode node)
{
DirectoryInfo dir = new DirectoryInfo(dir_root);
foreach (DirectoryInfo d in dir.GetDirectories())
{
FileInfo[] xbtFiles = dir.GetFiles("*.xbt");
TreeNode n = new TreeNode(d.Name);
FillTreeNode(d.FullName, n);
if (xbtFiles.Length >= 1)
{
node.Nodes.Add(n);
}
}
foreach (FileInfo file in dir.GetFiles())
{
TreeNode n = new TreeNode(file.Name);
if (file.Extension == ".xbt")
{
node.Nodes.Add(n);
}
}
}[/cpp]
[editline]12:28AM[/editline]
switching to a listview seems like it would not only look better but be easier to work with, I won't categorize anything into folders, maybe just have a column with a relative location of the files.
[editline]lol[/editline]
Ok, so now it works fine, and the code is a bit slimmer and looks cleaner...
[cpp] public void FillItemList(string dir_root)
{
DirectoryInfo dir_info = new DirectoryInfo(@dir_root);
foreach (DirectoryInfo d in dir_info.GetDirectories())
{
foreach (FileInfo f in d.GetFiles("*.xbt"))
{
ListViewItem tempItem = new ListViewItem(f.Name);
tempItem.SubItems.Add(f.DirectoryName);
listView.Items.Add(tempItem);
}
FillItemList(d.FullName);
}
}[/cpp]
I'm making a little particle system (you may have seen the video over in WAYWO), and I want to know how I can build it to be as efficient as possible.
At the moment, I simply have a Particle class, and a BaseEmitter class, which contains an array of Particle objects
When spawning particles, I just loop through the array until I find an inactive particle, and then set its position/velocity ETC
Obviously, this means it gets quite slow when there are lots of particles on the screen. How can I improve this?
I know this sounds like another retard trying to get answers to his homework, but ive looked everywhere for these answers, and I cant seem to figure it out, and out of a 100 questions these are the only ones i couldnt get
[CODE]
finished[/CODE]
[QUOTE=Chris220;23050666]I'm making a little particle system (you may have seen the video over in WAYWO), and I want to know how I can build it to be as efficient as possible.
At the moment, I simply have a Particle class, and a BaseEmitter class, which contains an array of Particle objects
When spawning particles, I just loop through the array until I find an inactive particle, and then set its position/velocity ETC
Obviously, this means it gets quite slow when there are lots of particles on the screen. How can I improve this?[/QUOTE]
Why don't you set the properties when spawning or keep a reference/pointer/something to that particle to set its properties right after spawning?
[QUOTE=shemer77;23053118]I know this sounds like another retard trying to get answers to his homework, but ive looked everywhere for these answers, and I cant seem to figure it out, and out of a 100 questions these are the only ones i couldnt get
[CODE]-questionssnip-[/CODE][/QUOTE]
1) Lookup/Google sequential search.
2) Lookup/Google bubble search and check each possibility.
3) Lookup/Google sequential search (unless you already did due to question No. 1).
4) Lookup/Google the worst-case complexity of binary search and calculate the outcome.
5) Lookup/Google the average-case complexity of sequential search and calculate the outcome.
6) Why can you not answer that? (Tip: 2 are right)
[QUOTE=ZeekyHBomb;23053447]
6) Why can you not answer that? (Tip: 2 are right)[/QUOTE]
Tip: none are correct, context information is required.
Well, I'm implying that (s)he's using C++ and that necessary conditions are met.
[QUOTE=ZeekyHBomb;23053447]Why don't you set the properties when spawning or keep a reference/pointer/something to that particle to set its properties right after spawning?[/QUOTE]
By properties you mean position, velocity ETC? Or what?
[editline]03:06PM[/editline]
[QUOTE=nullsquared;23053599]Tip: none are correct, context information is required.[/QUOTE]
Here it goes again :v:
[QUOTE=Chris220;23053678]By properties you mean position, velocity ETC? Or what?[/QUOTE]
Wait, I just understood what you meant.
If you use a doubly linked list, then you could put the inactive ones at the end or something, so you just check if the last member is inactive, if so put him on the front and set its properties.
[QUOTE=ZeekyHBomb;23053707]Yep.[/QUOTE]
In that case, I'm not sure what you mean :P
I'm already setting those properties as I "spawn" the particle, indeed setting those is about 2/3rds of spawning it anyway. The remaining 1/3rd is just setting the Active property to true
Alternatively you could also use a memory-pool to allocate new elements from and remove/add to the list freely.
[editline]04:12PM[/editline]
I was too slow editing :eng99:
And way too late for automerge.
I figured the most inefficient part of my code was looping through potentially thousands of array elements to find an inactive one.
Would it perhaps be a better idea to keep track of the closest-to-the-start available index, and then just use that particle?
[QUOTE=ZeekyHBomb;23053652]Well, I'm implying that (s)he's using C++ and that necessary conditions are met.[/QUOTE]
Using C++, the "necessary conditions" could either be creating a vector type with a constructor that takes an int, or including <vector> and bringing it into the current namespace. Either way, only one of the answers is correct, not two.
[cpp]template<typename T = int>
struct vector{
vector(int){}
};
vector intList(10); //correct
vector<int> intList(10); //also correct[/cpp]
Though not at once, since the variable names would overlap.
Right. Which is why I said that "either way" only one of the answers is correct. Probably just a misunderstanding of words.
Sorry, you need to Log In to post a reply to this thread.