Advertisement

how do I get my sprite to move up and down once

Started by October 02, 2019 04:52 PM
75 comments, last by Tom Sloper 5 years, 1 month ago
13 minutes ago, Prototype said:

Next thing would be to replace curve drawing with image drawing.
 

what do you mean by image drawing?

8 minutes ago, phil67rpg said:

what do you mean by image drawing?

Well I guess you aren't going to make a game out of paraboles would you?

Advertisement

I am using parabolas to get my sprites to jump.

That was my take away from the GDC16 talk as well. Jump with predefined start and end location. 

I tried this out on the gd.net side scrolling game challenge. The idea is interesting but harder to work with than an impulse/gravity technique. The advantages in my eyes were improved prediction and a guarantee of an ending position somewhere precisely. 

Neat. 

Throwing stuff at my 'Hobby Game"

 thanks mark I will work on my code today.

I have almost solved my problem, I have got my sprite to jump up and down while I press the space bar key, but it only jumps when I keep pressing the space key. I want it to jump  up and down only  when I  hit the space bar once and only once. here is  my code.


float time = 0.0f;

void jumpsprite()
{
	positionX = initialvelocity * time*cos(thetaX);
	positionY = initialvelocity * time*sin(thetaY*PI / 180.0f) + (-0.5f*gravity*time*time);
	time += 0.1f;
	if (time >= 15.5f)
	{
		time = 15.5f;
	}
	cout << "positionY: " << positionY << endl;
}

void handleKeypress(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 27:
		exit(0);
		break;
	case 32:
		jumpsprite();
		break;

 

Advertisement

Phil, what feature can you use that can toggle a state? Think about it because it has been answered time and time again. I also provided the answer several times in the past when you continue to ask the same question over and over again.

Programmer and 3D Artist

you can use a Boolean to toggle a state

well I have made more progress. my sprite jumps  up and down when I  hit the space bar. but it only does this once.  I want it to do  this every time I  hit the space bar.


float time = 0.0f;

void jumpsprite()
{
	positionX = initialvelocity * time*cos(thetaX);
	positionY = initialvelocity * time*sin(thetaY*PI / 180.0f) + (-0.5f*gravity*time*time);
	time += 2.0f;
	if (time >= 15.5f)
	{
		time = 15.5f;
	}
	cout << "positionY: " << positionY << endl;
}

void Loop(int val)
{
	jumpsprite();
	glutPostRedisplay();
	glutTimerFunc(100, Loop, 0);
}

void handleKeypress(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 27:
		exit(0);
		break;
	case 32:
		Loop(0);
		break;

 

This topic is closed to new replies.

Advertisement