What would be the best way to get a destructible terrain such as games like Worms have?
Array's of pixels with their own collision, or masking?
I am going to make a space shooter where you have the ability to shoot armor off a ship.
[QUOTE=ROBO_DONUT;33108508]Eh?
It should be in the range [-pi/2, pi/2]. Are you sure you haven't missed something?
[/quote]
Is [QUOTE]atan2(mouseY - cubeY, mouseX - cubeX)[/QUOTE] the correct way of doing it? My math sucks, thankfully I'm going back to school after the army.
[cpp]bool IsEqual(float a, float b)
{
const float diffFactor = 3;
return fabs(a - b) <= diffFactor;
}[/cpp]
[cpp]
void CheckCollisions()
{
vBoxBottomLeft = Sprite.TransformToGlobal(sf::Vector2f(0,ySize));
vBoxBottomRight = Sprite.TransformToGlobal(sf::Vector2f(xSize,ySize));
vBoxTopRight = Sprite.TransformToGlobal(sf::Vector2f(xSize,0));
vBoxTopLeft = Sprite.TransformToGlobal(sf::Vector2f(0,0));
if(IsEqual(vBoxBottomLeft.y,App.GetHeight()) || IsEqual(vBoxBottomRight.y,App.GetHeight()))
{
if(bounceClockY.GetElapsedTime() >= 0.1f)
{
yVel = yVel * -1.f;
Clock.Reset();
bounceClockY.Reset();
}
}
if(IsEqual(vBoxTopLeft.y,0) || IsEqual(vBoxTopRight.y,0))
{
if(bounceClockY.GetElapsedTime() >= 0.1f)
{
yVel = yVel * -1.f;
Clock.Reset();
bounceClockY.Reset();
}
}
if(IsEqual(vBoxBottomRight.x,App.GetWidth()) || IsEqual(vBoxTopRight.x,App.GetWidth()))
{
if(bounceClockX.GetElapsedTime() >= 1.f)
{
xVel = xVel * -1.f;
Clock.Reset();
bounceClockX.Reset();
}
}
if(IsEqual(vBoxBottomLeft.x,0) || IsEqual(vBoxTopLeft.x,0))
{
if(bounceClockX.GetElapsedTime() >= 1.f)
{
xVel = xVel * -1.f;
Clock.Reset();
bounceClockX.Reset();
}
}
}[/cpp]
Can anyone see from this code why the sprite is colliding with an invisible wall at half the height of the renderwindow App? I think it might be something to do with my "close enough" function at the top but I can't figure it out. I'm using SFML by the way. Ignore all the clocks.
EDIT: Resolved: TransformToGlobal wasn't working right so I used Sprite.GetPosition() instead.
A question about Lua, or just global programming:
How would I check if a keycode actually belongs to a character like K 9 = / etc, and not something like a shift?
[b]eDIT;[/b]
Im now checking if the keycode is higher than 32. Should this work without bugging at some keys?
Having a difficulty with Village of Ares.
[CODE]
case "conquer":
foreach (Village village in villages)
{
if ((village.name == consolecommand[1] || village.id.ToString() == consolecommand[1]) && (village.population == 0))
{
SetColor(ConsoleColor.Red);
Write("\n\nA joyous day!\nOur glorious and powerful village has conquered and demolished " + village.name + ".\nOnly " +
villages.Count.ToString() + " villages left to conquer before we achieve supremacy!\n");
villages.Remove(village); //remove the conquered village from the list
}
}
break;
[/CODE]
I get an error that I cannot modify the villages list while inside a foreach. How would I remove it then?
[QUOTE=ROBO_DONUT;33108508]Eh?
It should be in the range [-pi/2, pi/2]. Are you sure you haven't missed something?
[/QUOTE]
For some reason I had to convert it to degrees.
[QUOTE=farmatyr;33135664]For some reason I had to convert it to degrees.[/QUOTE]
It returns a value in radians
[QUOTE=Naarkie;33135408]Having a difficulty with Village of Ares.
-snip-[/QUOTE]
Here:
[CODE]
case "conquer":
for(int i = 0; i < villages.Count; i++)
{
if ((villages[i].name == consolecommand[1] || villages[i].id.ToString() == consolecommand[1]) && villages[i].population == 0)
{
SetColor(ConsoleColor.Red);
Write("\n\nA joyous day!\nOur glorious and powerful village has conquered and demolished " + villages[i].name + ".\nOnly " + (villages.Count - 1) + " villages left to conquer before we achieve supremacy!\n");
villages.RemoveAt(i); //remove the conquered village from the list
i--;
}
}
break;
[/CODE]
also changed some stuff
[QUOTE=Map in a box;33135893]It returns a value in radians[/QUOTE]
Yes, I'm aware of that. But I was sure [I]glRotated[/I] worked with radians, my mistake.
[QUOTE=NovembrDobby;33135924]Here:
[CODE]
case "conquer":
for(int i = 0; i < villages.Count; i++)
{
if ((villages[i].name == consolecommand[1] || villages[i].id.ToString() == consolecommand[1]) && villages[i].population == 0)
{
SetColor(ConsoleColor.Red);
Write("\n\nA joyous day!\nOur glorious and powerful village has conquered and demolished " + villages[i].name + ".\nOnly " + (villages.Count - 1) + " villages left to conquer before we achieve supremacy!\n");
villages.RemoveAt(i); //remove the conquered village from the list
i--;
}
}
break;
[/CODE]
also changed some stuff[/QUOTE]
Thanks a lot, that worked :downs:
I thought you could do it with a normal for loop, but wasn't quite sure how.
C
[code]void New()
{
char string[256];
printf("Select difficulty (Easy, Medium, Hard): ");
fgets ( string, 256, stdin );
switch (string)
{
case 'Easy':
printf("Starting game on Easy...");
break;
case 'Medium':
printf("Starting game on Medium...");
break;
case 'Hard':
printf("Starting game on Hard...");
break;
default:
printf("Choice not valid.");
break;
New();
}
}
[/code]
Error: Switch case not an integer.
What am I doing wrong?
Does anyone have any idea why this might be happening with SFML?
[IMG]http://img64.imageshack.us/img64/615/unled1zoj.png[/IMG]
[QUOTE=Meatpuppet;33137781]C
[code]void New()
{
char string[256];
printf("Select difficulty (Easy, Medium, Hard): ");
fgets ( string, 256, stdin );
switch (string)
{
case 'Easy':
printf("Starting game on Easy...");
break;
case 'Medium':
printf("Starting game on Medium...");
break;
case 'Hard':
printf("Starting game on Hard...");
break;
default:
printf("Choice not valid.");
break;
New();
}
}
[/code]
Error: Switch case not an integer.
What am I doing wrong?[/QUOTE]
You can't switch on strings in C or C++
[QUOTE=NovembrDobby;33138266]You can't switch on strings in C or C++[/QUOTE]How do I do what I want to do then?
[QUOTE=Richy19;33137957]Does anyone have any idea why this might be happening with SFML?
img[/QUOTE]
I don't know but try to set the font size twice as big, then set the scale for the text object to 0.5
I had a similar problem, this solved it.
[QUOTE=Meatpuppet;33138273]How do I do what I want to do then?[/QUOTE]
Bit messier, but you could just do an if-else-else lol
[QUOTE=NovembrDobby;33138335]Bit messier, but you could just do an if-else-else lol[/QUOTE]Googling it, I find other answers that make it look cleaner, but they don't explain them. Can someone help me achieving it with something other than if-else?
[QUOTE=Meatpuppet;33138364]Googling it, I find other answers that make it look cleaner, but they don't explain them. Can someone help me achieving it with something other than if-else?[/QUOTE]
Make an enum containing all the options you need.
Use an std::map or similar to map each string to its respective enum value.
Switch on the enum instead of the string.
If you need actual code, I'd be happy to write some for you... just ask. :)
[QUOTE=Chris220;33139998]Make an enum containing all the options you need.
Use an std::map or similar to map each string to its respective enum value.
Switch on the enum instead of the string.
If you need actual code, I'd be happy to write some for you... just ask. :)[/QUOTE]Thanks, I'd rather learn myself though. I don't know what any of that means, so I'll just try to do it another way. Here's the code now.
[code]void New()
{
int difficulty;
printf("Select difficulty (Easy(1), Medium(2), Hard(3)): ");
scanf("%d", &difficulty);
switch (difficulty)
{
case 1:
printf( "Starting game on Easy..." );
break;
case 2:
printf("Starting game on Medium...");
break;
case 3:
printf("Starting game on Hard...");
break;
default:
printf("Choice not valid.");
break;
New();
}
}[/code]
You forgot to break in case 1
I fixed that since. I just pasted old code
[editline]5th November 2011[/editline]
Nevermind
[QUOTE=Felheart;33138291]I don't know but try to set the font size twice as big, then set the scale for the text object to 0.5
I had a similar problem, this solved it.[/QUOTE]
It solves the box problem but scaling it makes it fuzzy
[img]http://img850.imageshack.us/img850/4531/unled1ei.png[/img]
This is making the font small and upscaling. Making the font bigger kept the squares
[QUOTE=Richy19;33140215]It solves the box problem but scaling it makes it fuzzy
[img]http://img850.imageshack.us/img850/4531/unled1ei.png[/img][/QUOTE]
I think those lines are being caused by forced anti aliasing, try turning forced AA off in your graphic's cards control panel.
snip
[QUOTE=Mr. Smartass;33140272]I think those lines are being caused by forced anti aliasing, try turning forced AA off in your graphic's cards control panel.[/QUOTE]
Im on a craptop, I have no AA
snip
[editline]5th November 2011[/editline]
[code]int main()
{
int choice;
printf("Welcome to Generic Shooter 2. What do you want to do?\n 1. Start New Campaign\n 2. Load Campaign\n 3. Play Multiplayer Campaign\n 4. Play Multiplayer Deathmatch\n 5. Quit Game\n Selection: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
New();
break;
case 2:
Load();
break;
case 3:
Coop();
break;
case 4:
Deathmatch();
break;
case 5:
printf("Quitting...");
break;
default:
printf("Choice not valid. Returning to Main Menu...");
main();
break;
}
getchar();
}[/code]
Default doesn't work if the input is a letter. Help.
Its because a character isn't a number. Try %c
[QUOTE=Meatpuppet;33140720]snip
[editline]5th November 2011[/editline]
[code]int main()
{
int choice;
printf("Welcome to Generic Shooter 2. What do you want to do?\n 1. Start New Campaign\n 2. Load Campaign\n 3. Play Multiplayer Campaign\n 4. Play Multiplayer Deathmatch\n 5. Quit Game\n Selection: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
New();
break;
case 2:
Load();
break;
case 3:
Coop();
break;
case 4:
Deathmatch();
break;
case 5:
printf("Quitting...");
break;
default:
printf("Choice not valid. Returning to Main Menu...");
main();
break;
}
getchar();
}[/code]
Default doesn't work if the input is a letter. Help.[/QUOTE]
It's probably not a good idea to make your main function recursive. A better way to do this would be to do something like
[cpp]
bool valid_input = false;
while(!valid_input)
{
// switchy stuff here
}
[/cpp]
[QUOTE=Map in a box;33141247]Its because a character isn't a number. Try %c[/QUOTE]
Realize scanf reads character strings and converts them to integers
[editline]6th November 2011[/editline]
[QUOTE=calzoneman;33141280]It's probably not a good idea to make your main function recursive.[/QUOTE]
Stack overflow at some point, indeed.
I may be a little late, but for comparing c-strings, you use the function strcmp found in string.h. See [url=http://cplusplus.com/reference/clibrary/cstring/strcmp/]this[/url] for more information.
[cpp]int strcmp ( const char * str1, const char * str2 );[/cpp]
[quote]Returns an integral value indicating the relationship between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character that does not match has a greater value in str1 than in str2; And a value less than zero indicates the opposite.[/quote]
Sorry, you need to Log In to post a reply to this thread.