[QUOTE=slayer20;23137967]The header thing is confusing, and I haven't really looked up any tutorials for it yet. I'll do that later though.
Right now I'm having a bit of trouble.
[code] if (Event.Key.Code == sf::Key::Z)
{
HealthBar_HP_S.SetScaleX(0.99);
}
[/code]When I press the Z key, the health bar only goes down once. I want to be able to repeatedly press the Z key to make the health get smaller and smaller.
How might I do this?
Edit: Nevermind I figured it out :3
Edit: Ok new problem, if I keep a hold of the Z key, the health keeps going down. I only want the health to go down once when I press the Z key.
I also can't seem to get it to do something when the scale of the health is 0. I want it to display text saying "Game Over" when the scale of the health = 0 and I can't seem to do that.[/QUOTE]
To execute something once when a key is pressed requires you to write some clever system yourself.
Here's a pseudocode showing how I might got about it
[code]OldInput = <some sort of input holder>
/* some code */
if Z key pressed and OldInput != Z key then
OldInput = Z key
// Do whatever you want it to do when you press Z
if Z key not pressed and OldInput != <no key> then
OldInput = <no key>[/code]
I think that should work. Maybe no though; it's early and I'm tired :v:
[QUOTE=NovembrDobby;23123413]Could it be lagging because you're drawing off-screen objects? If so, you could add a culling system to skip drawing them.[/QUOTE]
There was nothing on the level apart from the character and the background which is just a large movieclip (vector image). I found out about this thing called scrollRect which i used (as well as caching the background as a bitmap) to make it only draw what's on screen:
[url]http://www.gskinner.com/blog/archives/2006/11/understanding_d.html[/url]
Is there a command to make a command happen in x seconds?
When googling it, I only get date/time commands.
[QUOTE=TamTamJam;23171860]Is there a command to make a command happen in x seconds?
When googling it, I only get date/time commands.[/QUOTE]
what language?
In general, you can usually do something like
[cpp]sleep(time)
command()[/cpp]
Alternatively, without blocking, you can either move it into a thread or set a time-value and check it in your main-loop - only works if you have one of course
[cpp]loop{
//do other stuff
if(!timeForCommand && commandConditionMet)
timeForCommand = currentTime + time
else if(timeForCommand <= currentTime){
command()
timeForCommand = 0
}
}[/cpp]
[IMG]http://i25.tinypic.com/2mhc5yo.png[/IMG]
That works perfectly fine.
Now, when I want to create a new room, there is a big chance it will be created overlapping the older one.
I want my algorithm to automatically understand where a room can be made without making it overlap any other pre-existing room.
The algorithm should find a good starting point, a width and an height for the room, then create it.
And repeat itself until there is no more space for other rooms.
Can someone help me with the algorithm? I don't know how it should work.
Is it possible to have winsocks "send" function block until the packet is received?
[QUOTE=high;23182361]Is it possible to have winsocks "send" function block until the packet is received?[/QUOTE]
Until the packet is received at the other end?
I dunno, does TCP send confirmations upon receiving packets?
[QUOTE=SupahVee;23181458]
The algorithm should find a good starting point, a width and an height for the room, then create it.
And repeat itself until there is no more space for other rooms.
Can someone help me with the algorithm? I don't know how it should work.[/QUOTE]
How about, get a random position, if it doesn't intersect with other rooms, make the room bigger (increase the width or the height). Keep increasing the size until you can increase the width or the height without colliding with other rooms. Repeat.
This shouldn't be frustrating me because this is just practice coding, thought I'd test out return statements, but for some reason this isn't working properly and I want to find a solution. Basically right now it is looping tempsolution and not returning it, when it returns tempsolution it should be 52, and it even prints out 52, but but it won't move on to the makeingGuessEven method like it should.
[code]import acm.program.*;
public class Hailstone extends ConsoleProgram {
public static final int Solution = 1;
int attempts = 0;
public void init() {
int Guess = readInt("Enter a number: ");
while (Guess != Solution) {
if ((Guess % 2) == 0) {
makingGuessEven(Guess);
}
if ((Guess % 2) != 0) {
makingGuessOdd(Guess);
}
}
println("The process took " + attempts + " attempts to reach " + Solution);
}
private int makingGuessEven(int x) {
int oldsolution = x;
int tempsolution = oldsolution / 2;
println(oldsolution + " is even so I halve it: " + tempsolution);
attempts++;
return tempsolution;
}
private int makingGuessOdd(int x) {
int oldsolution = x;
int tempsolution = 3 * oldsolution + 1;
println(oldsolution + " is odd, so I perform the equation 3n + 1 to get: " + tempsolution);
attempts++;
return tempsolution;
}
}
[/code]
Yet another nooby C# question from me, let's say I have a few instances of some classes in a List<Object>. How would I go about accessing the instance variables in the list?
[QUOTE=TravisG;23191093]This shouldn't be frustrating me because this is just practice coding, thought I'd test out return statements, but for some reason this isn't working properly and I want to find a solution. Basically right now it is looping tempsolution and not returning it, when it returns tempsolution it should be 52, and it even prints out 52, but but it won't move on to the makeingGuessEven method like it should.
-snipped code-[/QUOTE]
The 'Guess' variable is never changed after initialization. You probably wanted to do:
[cpp]
Guess = makingGuessEven(Guess);
//same for makingGuessOdd
[/cpp]
[QUOTE=BAZ;23191742]Yet another nooby C# question from me, let's say I have a few instances of some classes in a List<Object>. How would I go about accessing the instance variables in the list?[/QUOTE]
[cpp]
var list = new List<MyClass>();
list.Add(new MyClass());
var myObj = list[0]; //You mean like this?
myObj.Foo();
[/cpp]
I'd really like some help figuring out what to do next. I know basic C# and C++ from those crappy books, and I have absolutely no idea what to do now. I'm also super depressed because I'm 20 and I just discovered 16 year old kids in other countries are taught this. I hate American schools. What can I do to try and increase my programming skill? I really enjoy it, I just need some direction. I've thought about XNA, or learning how to make Android applications.
(Sorry for starting every sentence with I - it looks horrible).
[editline]11:51PM[/editline]
[QUOTE=jA_cOp;23194560]words[/QUOTE]
I've been wanting to ask you, what's with the Sven-Coop avatar?
[QUOTE=Shadaez;23197732]I'd really like some help figuring out what to do next. I know basic C# and C++ from those crappy books, and I have absolutely no idea what to do now. I'm also super depressed because I'm 20 and I just discovered 16 year old kids in other countries are taught this. I hate American schools. What can I do to try and increase my programming skill? I really enjoy it, I just need some direction. I've thought about XNA, or learning how to make Android applications.
(Sorry for starting every sentence with I - it looks horrible).[/QUOTE]
I find working with another person makes you learn a lot quite fast, providing the other person doesn't mind teaching you things.
If you can't find anyone better, I wouldn't mind making something with you, but I'm not the best programmer ever :v:
[QUOTE=Shadaez;23197732]I'm also super depressed because I'm 20 and I just discovered 16 year old kids in other countries are taught this.[/QUOTE]
In the school I was in we would've been taught ToolBook :/
Seriously, goddamn fucking Toolbook from somewhere around 1990. And they even dared call that 'programming'.
So don't feel bad, at least all other programmers of my age (and younger) I know learned this stuff by themselves and not at school :P
[QUOTE=Shadaez;23197732]
I've been wanting to ask you, what's with the Sven-Coop avatar?[/QUOTE]
I wanted to change it at some point, but people complained and said I should keep it. So I just got a bigger version of it instead (it used to be much smaller).
Not sure why I chose it to begin with. Then again, Sven-Coop is awesome, so why not? :v:
Well, if anyone's doing some kind of C#, XNA, or Android programming, I'd love to help and be taught what is going on.
[editline]04:05AM[/editline]
[QUOTE=jA_cOp;23199196]I wanted to change it at some point, but people complained and said I should keep it. So I just got a bigger version of it instead (it used to be much smaller).
Not sure why I chose it to begin with. Then again, Sven-Coop is awesome, so why not? :v:[/QUOTE]
Keep it. I've been lurking so long and I've always recognized you by your avatar.
[QUOTE=jA_cOp;23194560][cpp]
var list = new List<MyClass>();
list.Add(new MyClass());
var myObj = list[0]; //You mean like this?
myObj.Foo();
[/cpp][/QUOTE]
Yeah, like that except I need the List to be in the class scope.
[QUOTE=BAZ;23200593]Yeah, like that except I need the List to be in the class scope.[/QUOTE]
What do you mean by that?
[QUOTE=jA_cOp;23200747]What do you mean by that?[/QUOTE]
Well, I want to be able to use multiple object types in the list.
[QUOTE=BAZ;23200774]Well, I want to be able to use multiple object types in the list.[/QUOTE]
You can't, unless you use a List<object> which just defeats the point of using the genericised List in the first place.
I think you need to reconsider your design.
[QUOTE=BAZ;23200774]Well, I want to be able to use multiple object types in the list.[/QUOTE]
Then they would have to derive from the same base class. Or, for any type, List<Object>.
[QUOTE=turb_;23200850]You can't, unless you use a List<object> which just defeats the point of using the genericised List in the first place.
I think you need to reconsider your design.[/QUOTE]
I second this. There's probably a better way to do what you want than diving into RTTI and reflection.
[QUOTE=turb_;23200850]You can't, unless you use a List<object> which just defeats the point of using the genericised List in the first place.
I think you need to reconsider your design.[/QUOTE]
Ah, ok.
Do you guys have any suggestions on how to manage all the objects? I was shoving them into lists, but that's not really going to work.
[QUOTE=BAZ;23201165]Ah, ok.
Do you guys have any suggestions on how to manage all the objects? I was shoving them into lists, but that's not really going to work.[/QUOTE]
What kind of objects are you needing to store?
Are they even slightly related? If not, I'd suggest using separate lists. You can always merge them temporarily if you need to manipulate them all as one.
Edit: I've assumed you haven't written the types you need to store. If you have, ignore me and listen to ja_cop below.
[QUOTE=BAZ;23201165]Ah, ok.
Do you guys have any suggestions on how to manage all the objects? I was shoving them into lists, but that's not really going to work.[/QUOTE]
Separate the part that you want to operate on into an interface (as in the language feature), then implement that interface in every class you want listed. Usually this is more practical with a traditional abstract base class, but if your classes are mostly different, an interface is a good approach.
But we really need more information about what you're trying to do if you want good advice.
[QUOTE=jA_cOp;23201292]Separate the part that you want to operate on into an interface (as in the language feature), then implement that interface in every class you want listed. Usually this is more practical with a traditional abstract base class, but if your classes are mostly different, an interface is a good approach.
But we really need more information about what you're trying to do if you want good advice.[/QUOTE]
At the moment I'm playing with XNA and screwing around with classes. I made a general sprite class, and a physicsRectangle class (Which has physics info and sprite information) To draw, I wanted to shove them all into an array and cycle through each object drawing .sprite but it seems really messy.
[QUOTE=BAZ;23202319]At the moment I'm playing with XNA and screwing around with classes. I made a general sprite class, and a physicsRectangle class (Which has physics info and sprite information) To draw, I wanted to shove them all into an array and cycle through each object drawing .sprite but it seems really messy.[/QUOTE]
There's no end to solutions to that problem. However, I know XNA provides an interface called IDrawable, you should look into how that's usually implemented and go with that. You could also implement it in a base class for all your objects holding sprites, or simply make your sprite class implement it.
It is, you probably want an interface, IDrawable which has the bare minimum requirements for drawing effectively. Then Sprite, PhysicsRectangle, etc implement it and you keep them in a List<IDrawable> or similar and everyone is happy.
zeekyhbomb along with the rest of the ppl in this thread , just wanted to say thanks, without you guys I would be failing. So i need some more help. i am writing a program, for a breakfast menu,
heres my assignment, its number 3
[URL]http://books.google.com/books?id=20xVrpISzoYC&lpg=PA27&ots=llLlOPBIRL&dq=cout%20%3C%3C%20%22this%20is%20Exercise%2016.%22%3C%3C%20endl%3B%20%20%20%20cout%20%3C%3C%20%22In%20C%2B%2B%2C%20the%20multiplication&pg=PA638#v=onepage&q&f=false[/URL]
and here is what I got so far, I have no idea on how i would write the tax part, and I am also having trouble figuring out the menu choices as well. heres my code:
[CODE]finished[/CODE]
You could use a std::vector instead of an array. And you could probably score some points from the teacher when you create the menu programatically by finding the largest entry (the biggest theItem.size), adding 1 to that number then looping through each menuItemType (hint: for-loop), outputting the current number, theItem, largestEntry minus theItem.size() times a '-' and then thePrice.
To your actual problem: Use a std::list to store all valid choices, then in printCheck, you again use a loop to list all stuff the customer ordered and add up all prices. Finally, you multiply rateOfTax to the accumulated price and voilá you've got the tax.
Sorry, you need to Log In to post a reply to this thread.