I want to make a jumping system for my game, and I have basic gravity, a force pushing down the player. But, I want it, so if you press spacebar, it does a full jump, and not if you hold spacebar, it just keeps going up.
if player is on floor
can jump = true
else
can jump = false
I have a question related to Box2D. I'm trying to make the current object follow the mouse while the mouse button is held down such that it is unaffected by gravity but can still collide with other things. My b2World's gravity vector is set to (0.f, -9.81f). If I do this:
[cpp]
b2Vec2 magnitude(0.f, 9.81f);
object->ApplyForce(magnitude, object->GetWorldCenter());
[/cpp]
Then it gradually floats upward relative to the mouse cursor and when I release the mousebutton it flies up. If I manually set the position of the object each tick but don't apply an upward force, the same phenomenon happens but downward (it gradually sinks and then when I let go it flies into the ground). How can I effectively cancel out the gravity acting on a single object (b2Body) while still being able to set the position of the object to follow the mouse?
Edit: What happened to the cpp tags?
Edit: Never mind
I'm working on a todo-list application (C++ on C::B with SFML2) and I have a question: what's the best way to save the name of the task? Right now I have a "Task" class that has all of it's properties + a string named "name", however, to draw text on the screen with SFML it has to be a sf::string.
So, should I keep a unique sf::string that I change everytime I'm gonna draw a task or should each task object have a sf::string of it's own?
[QUOTE=Samuka97;30138670]I'm working on a todo-list application (C++ on C::B with SFML2) and I have a question: what's the best way to save the name of the task? Right now I have a "Task" class that has all of it's properties + a string named "name", however, to draw text on the screen with SFML it has to be a sf::string.
So, should I keep a unique sf::string that I change everytime I'm gonna draw a task or should each task object have a sf::string of it's own?[/QUOTE]
Just make each task have a string of its own
[editline]30th May 2011[/editline]
Dont know if anyone has used mogre but im trying to load a plain sphere
when ever i do this tho i get
[quote]External component has thrown an exception[/quote]
[csharp]using Mogre;
using Mogre.TutorialFramework;
using System;
namespace Mogre.Tutorials
{
class Tutorial : BaseApplication
{
public static void Main()
{
new Tutorial().Go();
}
protected override void CreateScene()
{
mSceneMgr.AmbientLight = new ColourValue(1, 1, 1);
Entity ent = mSceneMgr.CreateEntity("sphere", "SphereCus.mesh");
SceneNode node = mSceneMgr.RootSceneNode.CreateChildSceneNode("HeadNode");
node.AttachObject(ent);
}
}
}[/csharp]
I have tried both my own meshes (simple sphere exported with blender) and te spheres that come with Mogre
Alright. But now I get an error when trying to load the font from a file :saddowns:
[cpp]sf::Font fnt_task_name;
if (!fnt_task_name.LoadFromFile("arial.ttf", 20))
{
return 1;
}[/cpp]
[cpp]error: no matching function for call to 'sf::Font::LoadFromFile(const char [10], int)[/cpp]
[editline]30th May 2011[/editline]
Oh. The new LoadFromFile function is not supposed to get a second argument now.
C#
What's the best way to store a list of unicode characters in human readable format? I have my characters in a string delimited by semicolons, but that doesn't really work with invisible and control characters (their effects still take place), so I want to store them in a good format (ideally stored as \u, \x, etc).
[QUOTE=Dragonblz;30139399]C#
What's the best way to store a list of unicode characters in human readable format? I have my characters in a string delimited by semicolons, but that doesn't really work with invisible and control characters (their effects still take place), so I want to store them in a good format (ideally stored as \u, \x, etc).[/QUOTE]
Not really sure what you mean, but cant you just use a list of chars?
List<char> myCharList;
or a char array?
I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree
like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered
[QUOTE=icantread49;30139764]I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree
like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered[/QUOTE]
I agree with most people only check the WAYWO thread, but i dont think everything should go in it
[QUOTE=icantread49;30139764]I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree
like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered[/QUOTE]
Nah, i don't visit waywo to see "Im having a problem with something" which is generally a misunderstanding of how a language operates
[QUOTE=Richy19;30139744]Not really sure what you mean, but cant you just use a list of chars?
List<char> myCharList;
or a char array?[/QUOTE]
I don't know, I'm extremely new to c# (about... 8 hours total?); The value is pulled from a textbox, but has a default value like so:
[csharp]CharacterBlacklist = "*;*;*;";[/csharp]
(the forums star out the control characters in my blacklist)
and I use it like this
[csharp]
private string Filter(String filterMe, Boolean fileName)
{
if (!string.IsNullOrEmpty(sets.CharacterBlacklist))
{
char[] delim = {';'};
string[] blacklist = sets.CharacterBlacklist.Split(delim, StringSplitOptions.RemoveEmptyEntries);
foreach (string c in blacklist)
{
filterMe = filterMe.Replace(c, ""); //Get rid of all those nasty nasty unicode chars
}
if (!fileName)
{
filterMe = filterMe.Replace("\r", "").Replace("\n", "\r\n"); //Fix the line endings for multiline pastes when logging
}
}
return filterMe; // HAVE AT THEE
}
[/csharp]
I don't know what a List is (yet).
Ideally I'd like to be able to auto-convert characters added to the textbox into \u format (so if you put f in the textbox and then saved, it would show as \u0066), but I'm getting confused in my head how that would work and how to read them back in
... a blacklist of unicode characters? There are hundred of thousands of unicode characters. What exactly are you trying to do?
[QUOTE=jA_cOp;30140228]... a blacklist of unicode characters? There are hundred of thousands of unicode characters. What exactly are you trying to do?[/QUOTE]
It's user customizable (no way in hell I would maintain a generic blacklist of bad unicode chars), and it's for chat logging, so the logger just doesn't log those characters to file.
[QUOTE=Dragonblz;30140266]It's user customizable (no way in hell I would maintain a generic blacklist of bad unicode chars), and it's for chat logging, so the logger just doesn't log those characters to file.[/QUOTE]
Why does the chat user want to maintain a blacklist of unicode characters for logging?
[QUOTE=jA_cOp;30140301]Why does the chat user want to maintain a blacklist of unicode characters for logging?[/QUOTE]
Because people like to put certain special characters in their steam names and some of them royally fuck up (the ability to read) logging as a result.
Can I actually get some help?
[QUOTE=icantread49;30139764]I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree
like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered[/QUOTE]
I visit WDYNHW regularly, and I think questions belong here, not in WAYWO.
Actually, I don't think I read WAYWO v17 at all, because the level of "traffic" in WAYWO sometimes takes more time to read and respond to than I really want to devote to it.
[QUOTE=Dragonblz;30140335]Because people like to put certain special characters in their steam names and some of them royally fuck up (the ability to read) logging as a result.[/QUOTE]
You should convert the input string to UTF-32 (i.e. int[]), and also store the blacklist as a list of UTF-32 characters. That way you can simply compare their numeric values, and easily generate a string of the "\uXXXX" format should you need it.
You can use the StringInfo class to convert a string to UTF-32 characters.
[QUOTE=Dragonblz;30140335]Can I actually get some help?[/QUOTE]
I wasn't insinuating that the user didn't need it, I genuinely wanted to know why.
I really broke this. First time writing such a complex script (for me). The switch and cases are all messed up. Wants case 2: to become case 3; and wants else to become else;
Its a while loop with a switch then a if then with another two ifs inside of that.
[code]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int hhp = 5; //I'll just declare all (most) my variables here for safe keeping
int mhp = 5;
int mhp2;
int mhp3;
int hdmg;
int mdmg;
int nom;
int fight;
int name;
int hacc;
int def;
string choice;
string mname = "CRAP";
Console.WriteLine("Text Based Battle System Tech Demo"); //intro text
Console.ReadLine();
Random nomr; // How many monster will you fight, 1 - 3.
nomr = new Random();
nom = nomr.Next(1, 4);
Random namer; //Random Name
namer = new Random();
name = namer.Next(0, 4);
if (nom == 1) //Random Naming
{
switch (name)
{
case 1:
mname = "Hogworm";
break;
case 2:
mname = "Boar";
break;
case 3:
mname = "Death Claw";
break;
}
}
else
{
switch (name)
{
case 1:
mname = "Hogworms";
break;
case 2:
mname = "Boars";
break;
case 3:
mname = "Death Claws";
break;
}
}
Random fightr; //If you find a fight
fightr = new Random();
fight = fightr.Next(1, 10);
if (fight >= 1)
{
Console.WriteLine("You encounter " + nom + " wild " + mname + ".");
Console.ReadLine();
}
else
{
Console.WriteLine("You dont encounter any enemies!");
Console.ReadLine();
goto A;
}
A:while (hhp>0 && fight>0 && hhp>0)
{
switch (nom)
{
case 1:
Console.WriteLine("What would you like to do?");
Console.WriteLine("attack ---- defend");
Console.WriteLine("Health " + hhp + ".");
choice = Console.ReadLine();
if (choice == "attack" || choice == "Attack")
{
Random hdmgr;
hdmgr = new Random();
hdmg = hdmgr.Next(1, 25);
Random haccr;
haccr = new Random();
hacc = haccr.Next(0, 101);
if (hacc >= 20) //I should add the monsters damage in here too.
{
mhp = mhp - hdmg;
Console.WriteLine(" Your attack hits the enemy. The monster has " + mhp + " health remaining");
goto A;
}
else
{
Console.WriteLine ("You miss the monster!");
goto A;
}
else;
{
Random defr;
defr = new Random();
def = defr.Next(1, 101);
if (def >= 35)
{
Console.WriteLine("You defended the enemy's attack!");
goto A;
}
else
{
mhp = mhp - hdmg;
mhp = mhp + 5;
Console.WriteLine ("You were unable to protect yourself from the attack!");
goto A;
}
}
break;
case 2:
Console.WriteLine("What would you like to do?");
Console.WriteLine("attack ---- defend");
Console.WriteLine("Health " + hhp + ".");
Console.ReadLine();
break;
case 3:
Console.WriteLine("What would you like to do?");
Console.WriteLine("attack ---- defend");
Console.WriteLine("Health " + hhp + ".");
Console.ReadLine();
break;
default;
Console.WriteLine ("CRAP");
break;
}
}
}
}
}
}
}}
[/code]
Lists 18 errors in it. Primarily
; expected on else and cases
invalid expression term ':' on the cases
invalid expression term 'case'
invalid expression terme 'ese'
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Syntax error, '(' expected
Type or namespace definition, or end-of-file expected
[QUOTE=MadPro119;30140639]-snip-[/QUOTE]
A good idea is to start with the first error and fix that, because later errors can be caused by that one original error
[QUOTE=icantread49;30139764]I feel like WDYNHW is unsuccessful because a large # of good programmers only visit WAYWO, anyone agree
like i think questions should just go in WAYWO, not only is it relevant but there is a higher chance of it being answered[/QUOTE]
It's usually the smaller problems that go here, as larger ones can often qualify as something you're working on for a longer time already.
[editline]30th May 2011[/editline]
Did I just arrive a page late to the party?
[QUOTE=MadPro119;30140639]I really broke this. First time writing such a complex script (for me). The switch and cases are all messed up. Wants case 2: to become case 3; and wants else to become else;
Its a while loop with a switch then a if then with another two ifs inside of that.
Lists 18 errors in it. Primarily
; expected on else and cases
invalid expression term ':' on the cases
invalid expression term 'case'
invalid expression terme 'ese'
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
Syntax error, '(' expected
Type or namespace definition, or end-of-file expected[/QUOTE]
There's a " ; " on one of your else and the case default needs a " : ", not a " ; ".
And why do you use goto ?
[QUOTE=evil-tedoz;30141910]There's a " ; " on one of your else and the case default needs a " : ", not a " ; ".
And why do you use goto ?[/QUOTE]
Not sure why I had the goto. I fixed the errors you mentioned and removed the goto. Now I am up to 22 errors just doing that.... Hmmm
[editline]30th May 2011[/editline]
[QUOTE=Icedshot;30141098]A good idea is to start with the first error and fix that, because later errors can be caused by that one original error[/QUOTE]
Do you mean the first error you encounter or the first in the Error List (VS2010)?
[editline]30th May 2011[/editline]
Okay got it down to 20 Errors.
[editline]30th May 2011[/editline]
Fuck yes. 3 errors left
[editline]30th May 2011[/editline]
Okay, 1 error left
[b] fix'd no errors[/b]
[editline]30th May 2011[/editline]
Okay, still errors but at least it compiles now.
Can C# save/load a struct to file? I know it's possible in C++, I think I did fopen on the file, casted the pointer as a byte and then casted it as my struct and that filled the struct for me.
However, I don't see a simple way to do it in C# - Maybe I'm just missing the function?
[editline]30th May 2011[/editline]
Here's how I did it in C++
[code]
studiohdr_t *StudioModel::LoadModel(char *modelname)
{
//If they didn't specify a modelname, return 0
if (!modelname)
return 0;
//Load the File as a pointer
FILE *pFile;
long size;
void *buffer;
if( (pFile = fopen( modelname, "rb" )) == NULL)
{
//Couldn't read the file
return 0;
}
//Find the end of the file
fseek( pFile, 0, SEEK_END );
//Set the size as the end (Number of Bytes in the file)
size = ftell( pFile );
//Find the start of the file again
fseek( pFile, 0, SEEK_SET );
//Set the buffer to the memory allocated for the model
buffer = malloc( size );
if (!buffer)
{
//Couldn't allocate the memory for it
fclose( pFile ); //Close the file
return 0;
}
//Read the entire file (buffer = location in memory,
//size = how much memory to read, 1 = how many 'blocks' of that
//much to read, and pFile = file to read
fread( buffer, size, 1, pFile );
fclose( pFile ); //Close the file
byte *pin;
studiohdr_t *phdr;
mstudiotexture_t *ptexture;
char *pCdtexture2;
//Version Header/ID
pin = (byte *)buffer;
//Cast the Version Header/ID as a studioheader struct.
phdr = (studiohdr_t *)pin;
//Texture
ptexture = (mstudiotexture_t *) (pin + phdr->textureindex );
pCdtexture2 = phdr->pCdtexture( 0 );
if (strncmp( (const char*) buffer, "IDST", 4) && strncmp( (const char*) buffer, "IDSQ", 4))
{
//ToDo: IDSQ is probably only a HL1 header. Don't need support for it.
//See studio_utils.cpp line 166 from real renderer
//strncmp
//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.
//Wrong File Header!
MessageBoxA( NULL, "Wrong file header!", "MDL Loader", MB_OK );
free( buffer );
return 0;
}
if (phdr->textureindex > 0 && phdr->numtextures <= MAXSTUDIOSKINS )
{
int n = phdr->numtextures;
for ( int i = 0; i < n; i++)
{
if (!m_ptexturecd[i])
m_ptexturecd[i] = phdr->pCdtexture( i );
}
}
if (!m_pstudiohdr)
m_pstudiohdr = (studiohdr_t *) buffer;
if (!m_ptexturehdr)
m_ptexturehdr = (mstudiotexture_t *) (pin + phdr->textureindex );
return (studiohdr_t *)buffer;
}[/code]
Whenever this code gets to the pixel 8, 27 I get a run time error saying "vector subscript out of range"
[cpp]
void WorldGen::CreateWorld()
{
for (int x=0; x < WorldSize.x; x++)
{
for (int y=0; y < WorldSize.y; y++)
{
sf::Color MapValue;
float Rand = PerlinNoise(x,y);
if (Rand > 1.f)
Rand = 1.f;
if (Rand < 0)
Rand = 0;
MapValue.r = floor(Rand * 255);
MapValue.g = floor(Rand * 255);
MapValue.b = floor(Rand * 255);
if (x > 7 && y > 26)
std::cout << "Break";
ImgTexture.SetPixel(x,y, MapValue);
}
}
Texture.SetImage(ImgTexture);
Texture.SetPosition(0,0);
Texture.SetScale(2.f,2.f);
}
[/cpp]
The error is in the Image.SetPixel function itself where it tries to update the pixel (8, 27) but the image is 32 by 32. So this shouldn't be out of range. Anyone got a clue what is wrong?
[b] God dammit. Its one if statement and it fucks me over for an hour[/b]
Same code as before, well modified a bit. One if statement is giving me some troubles.
[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int hhp = 100; //I'll just declare all (most) my variables here for safe keeping
int mhp = 100;
int mhp2 = 100;
int mhp3 = 100;
int hdmg;
int mdmg;
int nom;
int fight;
int name;
int hacc;
int macc;
int def;
string choice;
string mname = "CRAP";
A:Console.WriteLine("Text Based Battle System Tech Demo"); //intro text
Console.ReadLine();
Random nomr; // How many monster will you fight, 1 - 3.
nomr = new Random();
nom = nomr.Next(1, 4);
Random namer; //Random Name
namer = new Random();
name = namer.Next(1, 4);
if (nom == 1) //Random Naming
{
switch (name)
{
case 1:
mname = "Hogworm";
break;
case 2:
mname = "Boar";
break;
case 3:
mname = "Death Claw";
break;
}
}
else
{
switch (name)
{
case 1:
mname = "Hogworms";
break;
case 2:
mname = "Boars";
break;
case 3:
mname = "Death Claws";
break;
}
}
Random fightr; //If you find a fight
fightr = new Random();
fight = fightr.Next(1, 10);
if (fight >= 1)
{
Console.WriteLine("You encounter " + nom + " wild " + mname + ".");
Console.ReadLine();
}
else
{
Console.WriteLine("You dont encounter any enemies!");
Console.ReadLine();
goto A;
}
while (hhp>0 && fight>0 && hhp>0)
{
switch (nom)
{
case 1:
B:Console.WriteLine("What would you like to do?");
Console.WriteLine("attack ---- defend");
Console.WriteLine("Health " + hhp + ".");
Console.WriteLine("Monster's Health " + mhp + ".");
choice = Console.ReadLine();
if (choice == "attack" || choice == "Attack")
{
Random hdmgr;
hdmgr = new Random();
hdmg = hdmgr.Next(1, 25);
Random haccr;
haccr = new Random();
hacc = haccr.Next(0, 101);
if (hacc >= 20) //I should add the monsters damage in here too.
{
mhp = mhp - hdmg;
Console.WriteLine("Your attack hits the enemy. The monster has " + mhp + " health remaining");
Random mdmgr;
mdmgr = new Random();
mdmg = mdmgr.Next(1, 25)- hdmg;
hhp = hhp - mdmg;
switch (hdmg)
{
case (hdmg>=1 && hdmg <=4):
hhp = hhp - mdmg;
hhp = hhp - 5;
Console.WriteLine("Your weak attack barely hurts the monster who strikes back with ease for " +(mdmg+5)+" damage");
break;
case (hdmg>=5 && hdmg <=16):
Random maccr;
maccr = new Random();
macc = maccr.Next (1, 100);
if (macc >= 40)
{
hhp = hhp - mdmg;
Console.WriteLine("The monster powers on attacking you for " +mdmg+ " health.");
}
else
{
Console.WriteLine("The monster misses it's attack!");
}
break;
case (hdmg>=17):
Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
break;
}
[b] else[/b]
{
Console.WriteLine("You miss the monster!");
Random maccr;
maccr = new Random();
macc = maccr.Next (1, 100);
if (macc >= 15)
{
hhp = hhp - mdmg;
Console.WriteLine("The monster hits you for " +mdmg+" health.");
}
}
}
}
else
{
Random defr;
defr = new Random();
def = defr.Next(1, 101);
if (def >= 35 && choice == "defend" || choice == "Defend")
{
Console.WriteLine("You defended the enemy's attack!");
}
else if (choice == "defend" || choice == "Defend")
{
Random hdmgr;
hdmgr = new Random();
hdmg = hdmgr.Next(1, 25);
Random mdmgr;
mdmgr = new Random();
mdmg = mdmgr.Next(5, 11);
hhp = hhp - mdmg;
Console.WriteLine ("You were unable to protect yourself from the attack but took less damage!");
}
else
{
Console.WriteLine("That is not a valid choice");
goto B;
}
}
break;
case 2:
Console.WriteLine("What would you like to do?");
Console.WriteLine("attack ---- defend");
Console.WriteLine("Health " + hhp + ".");
Console.ReadLine();
break;
case 3:
Console.WriteLine("What would you like to do?");
Console.WriteLine("attack ---- defend");
Console.WriteLine("Health " + hhp + ".");
Console.ReadLine();
break;
default:
Console.WriteLine ("CRAP");
break;
}
}
}
}
}
[/code]
[editline]30th May 2011[/editline]
The else I bolded is the one giving me problems.
[editline]30th May 2011[/editline]
Error 1 Invalid expression term 'else' 146 29 Text Based Battle System
[editline]30th May 2011[/editline]
And also it seems to think in the switch and cases involving hdmg that they are bools?
Error 3 Cannot implicitly convert type 'bool' to 'int' 121 43 Text Based Battle System
[QUOTE=MadPro119;30145648][b] God dammit. Its one if statement and it fucks me over for an hour[/b]
Same code as before, well modified a bit. One if statement is giving me some troubles.
[editline]30th May 2011[/editline]
The else I bolded is the one giving me problems.
[editline]30th May 2011[/editline]
Error 1 Invalid expression term 'else' 146 29 Text Based Battle System[/QUOTE]
Dude, seriously? ...
Your missing a } before the else
I'm working on an XNA game library and I have absolutely no idea how I'm going to compile content to the XNB Format.
Basically I'm making a tool to convert images & xml to xnb.
[QUOTE=Richy19;30145709]Dude, seriously? ...
Your missing a } before the else[/QUOTE]
Are you sure?
Like this?
[code] Console.WriteLine("Your attack is so powerful the enemy is unable to counter it!");
break;
}
}
else
{
Console.WriteLine("You miss the monster!");
Random maccr;
maccr = new Random();
macc = maccr.Next (1, 100);
if (macc >= 15)
{
hhp = hhp - mdmg;
Console.WriteLine("The monster hits you for " +mdmg+" health.");
}
[/code]
That outputs an error. I'm probly just and idiot.
[editline]30th May 2011[/editline]
Or is that the wrong else?
[QUOTE=Kukks;30145770]I'm working on an XNA game library and I have absolutely no idea how I'm going to compile content to the XNB Format.
Basically I'm making a tool to convert images & xml to xnb.[/QUOTE]
Is there meant to be a question in there?
Sorry, you need to Log In to post a reply to this thread.