Score interacting with time/position

Non-platform specific questions.

Score interacting with time/position

Postby MudRat_02 » Sun Jul 08, 2007 8:13 am

Hi,
Ok, I need help with a scoring system for my game. I have a target area in the middle of the screen and I want the size of the score points awarded to increase as the mouse pointer nears the co-ordinates (0, 0). Also, at the same time, I want the score points to be awarded each time a second passes on the clock. Heres a section of my code (excuse the newbness)


if ((xmouse >= 0) && (xmouse <= 34))
{
xmouseSCR = xmouse;
}

else if ((xmouse <= 0) && (xmouse >= -34))
{
xmouseSCR = (xmouse * (-1));
}

else
{
xmouseSCR = 0;
}


if ((ymouse >= 0) && (ymouse <= 34))
{
ymouseSCR = ymouse;
}

else if ((ymouse <= 0) && (ymouse >= -34))
{
ymouseSCR = ymouse * (-1);
}

else
{
ymouseSCR = 0;
}

score = score + (70 - (xmouseSCR + ymouseSCR));

*edit*
Ok, so this code executes when your in teh 'score zone'. I've got it on collision (a box wiht the below dimensions represents the zone), repeat,
but I want it to only execute every half a second or so.
*edit*

Points are awarded once the pointer reaches a box who's corner coordinates are (34, 34), (34, -34), (-34, -34), (-34, 34). The score is supposed to increase as you reach the center, but instead the score goes wild as soon as I enter the zone, and pays no heed to the clock counter :(. Any help would be greatly appreciated!
MudRat_02
 
Posts: 21
Joined: Thu Feb 01, 2007 2:04 am
Score: 0 Give a positive score

Postby MudRat_02 » Sun Jul 08, 2007 2:34 pm

i also tried using a counter, so the points go up every time a counter reaches a certain number, however for that second (or 1/10 second, or 12 milliseconds) the count goes nuts, making it obsolete anyway. Stalling tactics with a loop a few threads down made the game laggy. Any ideas?
MudRat_02
 
Posts: 21
Joined: Thu Feb 01, 2007 2:04 am
Score: 0 Give a positive score

Postby DocRabbit » Tue Jul 10, 2007 11:57 am

Maybe you should be using Mouse Enter and Mouse Leave events, use these to set a global variable to dictate if you are over the target. Make a 1 second(1000ms) timer 1 time that is created when mouse enter fires, On the view actor. Then on the ontimer event of view actor, do your scoring and check variable to see if you are in the target zone, and if so, create a new timer. Haven't tested this method yet, but I would think it would work.

***Update*** I made you a demo to show how to do it.These both use a single repeating timer that is destroyed when you mouse exit the area. The boxzone Mouse Enter and Exit codes set variable and start or destroy the timer. The view ontimer event is where most of the code lies. This code is in the global code:
Code: Select all
#define mousex (xmouse+view.x)
#define mousey (ymouse+view.y)


I included a version here that uses the code you had, although I did have to put some global code in to get mouse coordinates converted to game coordinates.
Attachments
TargetYourCode.zip
Here is the same using code you supplied.
(213.68 KiB) Downloaded 120 times
targetscoredemo.zip
Here's a demo to show what I am talking about.
(212.91 KiB) Downloaded 115 times
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score

Postby MudRat_02 » Wed Jul 11, 2007 4:29 am

thanx for the help :D i'll take the code for a spin and see how it goes
MudRat_02
 
Posts: 21
Joined: Thu Feb 01, 2007 2:04 am
Score: 0 Give a positive score

Postby MudRat_02 » Wed Jul 11, 2007 2:05 pm

it worked flawlessly man, thanks again for the help :D
MudRat_02
 
Posts: 21
Joined: Thu Feb 01, 2007 2:04 am
Score: 0 Give a positive score

Postby DocRabbit » Sun Jul 22, 2007 2:01 pm

No problem, glad I could help.
User avatar
DocRabbit
 
Posts: 114
Joined: Fri Oct 27, 2006 2:56 am
Score: 10 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest