Computer Science Canada Accessing variables |
Author: | Junaid2pac [ Sun Jan 20, 2008 1:39 pm ] | ||||
Post subject: | Accessing variables | ||||
i am making a game in which 2 thread classes (ball and enemy) are used and the collision math is inside the enemy class since i want the enemy to basically stop after the collision of the ball happens. I want to get the position values from the ball class. Would this be how it would look This is inside the ball class....after the ball has changed position
and inside enemy class:
but when using x and y inside the enemy class, i don't think the variables are getting the value properly Please help |
Author: | Junaid2pac [ Sun Jan 20, 2008 2:06 pm ] |
Post subject: | Re: Accessing variables |
it just uses the original x and y value of the ball, and not the updated real time x and y value position |
Author: | Junaid2pac [ Sun Jan 20, 2008 2:07 pm ] |
Post subject: | Re: Accessing variables |
i can post the ball class and/or enemy class if that would help |
Author: | HellblazerX [ Sun Jan 20, 2008 2:35 pm ] |
Post subject: | Re: Accessing variables |
The Enemy object e1 you created only exists inside the Ball class. You need to create a pointer in the Ball and Enemy class for the opposite class, and methods in each one to set those pointers. But I have a question for you: why do you need each class to be a separate thread? You could simply have a main thread that would do the calculations, and your Ball and Enemy classes would simply for storing values. |
Author: | Junaid2pac [ Sun Jan 20, 2008 3:00 pm ] |
Post subject: | Re: Accessing variables |
i would like to do that but i want the enemy class going if i click another button first and then the ball class for the other button....or is there some way to make 2 buttons for accessing one part of the class? Originally i wanted the enemy to be created when the game starts and have a button so that the ball can be created pls help if this is possible |
Author: | Junaid2pac [ Sun Jan 20, 2008 3:10 pm ] | ||
Post subject: | Re: Accessing variables | ||
currently in my main class:
is there a way to just have one class for ball and enemy yet i want the enemy to be created by a one button and ball created by a second button |
Author: | Junaid2pac [ Sun Jan 20, 2008 4:13 pm ] | ||||
Post subject: | Re: Accessing variables | ||||
I figured out how to put both ball and enemy in the same class, and when i click new game, only the enemy is created and it runs fine because i mad a runEnemy and runBall boolean. when the new game button is clicked, the runEnemy = true, while runBall = false. When the shoot button is pressed, runBall = true, and i set runEnemy = false. But when i click start both the enemy and new ball are created. This is all i need to fix now Main class:
Ball and enemy class combined:
|