timing loop

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 2825 Views - Last Post: 20 June 2018 - 07:17 PM Rate Topic: -----

#1 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

timing loop

Posted 16 June 2018 - 06:35 PM

I have made some progress
void collision(int value)
{
	if (value >= 0)
	{
		if ((value % 2) == 0)
		{
			collision_bug_one(0.0f, 10.0f);
			glutPostRedisplay();
			glutTimerFunc(1000, collision, value--);
		}
		else
		{
			collision_bug_one(0.0f, 10.0f);
			glutPostRedisplay();
			glutTimerFunc(1000, collision, value--);
		}
		cout << value << endl;
	}
}

void coll_bug_one()
{
	float x = -0.5f + scroll;
	float y = -8.0f + up;
	float oWidth = 0.5f;
	float oHeight = 0.5f;

	float xTwo = 0.0f;
	float yTwo = 9.0f;
	float oTwoWidth = 0.5f;
	float oTwoHeight = 0.5f;

	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
	{
		glutTimerFunc(1000, collision, 5);
		board[0][0] = 1;
	}
}


I have some code that snoopy is helping with. I am trying to get a collision sprite to be drawn and then erased after the bug is shot with a bullet. this is my space invaders game I am still working on. I am able to the value variable to count to 4 but I want it to count down from 5 to 0. I am sure that I am very close to solving my problem.

Is This A Good Question/Topic? 0
  • +

Replies To: timing loop

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,615
  • Joined: 12-June 08

Re: timing loop

Posted 16 June 2018 - 10:24 PM

Is your if and else bodies the same?
Was This Post Helpful? 0
  • +
  • -

#3 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: timing loop

Posted 17 June 2018 - 01:58 PM

actually they are but I guess they are not supposed to be, I got this code from snoopy. I am tying to setup a counter that counts down as a wait loop that draws a collision sprite for a small period of time after the bug is hit by a bullet.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,615
  • Joined: 12-June 08

Re: timing loop

Posted 17 June 2018 - 02:02 PM

Then actually decrement your counter 'myCounter -=1'..
And do what ever. You are not doing that.
Also you should be cognizant of what your code is doing.. There shouldn't be a surprise if you looked at your if/else bodies and realized they are the same.
Was This Post Helpful? 1
  • +
  • -

#5 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: timing loop

Posted 17 June 2018 - 02:06 PM

I am counting down the "value" variable but it only goes from 5 to 4 it only cout's 4 as output.
sometimes it takes someone else to see if code is identical

This post has been edited by pbivens85: 17 June 2018 - 02:07 PM

Was This Post Helpful? 0
  • +
  • -

#6 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: timing loop

Posted 18 June 2018 - 02:14 PM

what does "bumping" mean as applied to threads.
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,615
  • Joined: 12-June 08

Re: timing loop

Posted 18 June 2018 - 02:26 PM

Adding a reply, with zero content, in the hopes to have it jump to the top of the list.

Quote

I am counting down the "value" variable

Where? Certainly not in the code you are showing.

Quote

I am counting down the "value" variable

Where? Certainly not in the code you are showing.
Was This Post Helpful? 0
  • +
  • -

#8 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: timing loop

Posted 18 June 2018 - 02:30 PM

I PM snoopy about his code but got no reply. can you give me a hint modi123_1 as to how to progress. I will work on this problem some more, I hate getting stuck. I have also done a lot of research using google.

well value is output on line 17 in my code above.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,615
  • Joined: 12-June 08

Re: timing loop

Posted 18 June 2018 - 02:31 PM

Again.. I don't see you decrementing a value.. and then that whole busted IF/ELSE. Perhaps clean up the IF/ELSE and show where a variable is counting down.. it may be helpful
Was This Post Helpful? 0
  • +
  • -

#10 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: timing loop

Posted 18 June 2018 - 08:45 PM

well I have worked on my code I finally got the bug to disappear after it is hit by a bullet after a second. I want collision sprite to be drawn after the bullet hits the bug and then erase the sprite.
void collision(int value)
{
	board[0][0] = 1;
	glutPostRedisplay();
}

void coll_bug_one()
{
	float x = -0.5f + scroll;
	float y = -8.0f + up;
	float oWidth = 0.5f;
	float oHeight = 0.5f;

	float xTwo = 0.0f;
	float yTwo = 9.0f;
	float oTwoWidth = 0.5f;
	float oTwoHeight = 0.5f;

	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
	{
		glutTimerFunc(1000, collision, 5);
	}
}

void coll_sprite()
{
	if (board[0][0] == 1)
	{
		collision_bug_one(0.0f, 10.0f);
		flag[0][0] = 1;
	}
}

void erase_sprite()
{
	if (flag[0][0] == 1)
	{
		glColor3f(0.0f, 0.0f, 0.0f);
		glBegin(GL_POLYGON);
		glVertex3f(0.0f, 10.0f, 0.0f);
		glVertex3f(0.0f, 9.0f, 0.0f);
		glVertex3f(1.0f, 9.0f, 0.0f);
		glVertex3f(1.0f, 10.0f, 0.0f);
		glEnd();
	}
}


Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,615
  • Joined: 12-June 08

Re: timing loop

Posted 18 June 2018 - 08:57 PM

... okay, so what is stopping you, or was there even a question?
Was This Post Helpful? 0
  • +
  • -

#12 pbivens85   User is offline

  • D.I.C Addict

Reputation: -13
  • View blog
  • Posts: 507
  • Joined: 22-October 13

Re: timing loop

Posted 18 June 2018 - 09:00 PM

I just want to draw a collision sprite before I erase it.
Was This Post Helpful? 0
  • +
  • -

#13 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14929
  • View blog
  • Posts: 59,615
  • Joined: 12-June 08

Re: timing loop

Posted 18 June 2018 - 09:02 PM

So.. do that?
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101   User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12566
  • View blog
  • Posts: 45,688
  • Joined: 27-December 08

Re: timing loop

Posted 18 June 2018 - 09:06 PM

View Postpbivens85, on 19 June 2018 - 12:00 AM, said:

I just want to draw a collision sprite before I erase it.


This is a comment, not a question.
Was This Post Helpful? 0
  • +
  • -

#15 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 976
  • View blog
  • Posts: 3,849
  • Joined: 13-June 14

Re: timing loop

Posted 19 June 2018 - 01:06 AM

View Postmodi123_1, on 18 June 2018 - 10:31 PM, said:

Again.. I don't see you decrementing a value..



Lines 9 and 15 in the original code decrement value. Having said that, pbivens85, you probably want to go and learn about the difference between pre and post increment (and naturally, pre and post decrement work the same way). I really also suggest that you use meaningful names for all your variables - value is as non-descriptive as you can get. What is it a value for?
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2