I hope this is okay in the tech forum, I've never posted in here... but it feels like it may be a bit more than a beginners question...
So how would one [if it's possible] go about doing a clock that always shows what the actual time is. As per the topic subject - just like the one on the clock tower in CMI.
I'm not really very proficient at scripting, so it may be a little [a lot] over my head, but if someone can point me in the right direction (or just do the whole thing for me :P) that'd be helpful, thanks.
do a search its been answered many times
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=8559.0
should explain it.
Basically, all you need is:
int hour = GetTime(1);
int minute = GetTime(2);
int second = GetTime(3);
And once you have the minute and hour, you can either:
- create 24 hour hand sprites and 24 minute hand sprites, and raw draw the appropriate one onto the clock face every time the time changes
- use the raw drawing functions and the floating point maths plugin to raw draw triangles representing the hands when the time changes
eg in the room script
int currHour = 0;
int currMinute = 0;
function drawClockHand(int x, int y, int length, int width, int angle)
{
int fx = int_to_float(x);
int fy = int_to_float(y);
int fl = int_to_float(length);
int fw = int_to_float(width);
int fa = angle_from_degrees(int_to_float(angle));
int sina = sin(fa);
int cosa = cos(fa);
// the point
int p1x = fadd(fx, fmul(fl, sina));
int p1y = fsub(fy, fmul(fl, cosa));
// the base
int dx = fadd(fx, fmul(fw, sina));
int dy = fsub(fy, fmul(fw, cosa));
int p2x = fadd(fsub(fx, dx), fmul(fw, cosa));
int p2y = fadd(fsub(fy, dy), fmul(fw, sina));
int p3x = fsub(fsub(fx, dx), fmul(fw, cosa));
int p3y = fsub(fsub(fy, dy), fmul(fw, sina));
RawDrawTriangle(p1x, p1y, p2x, p2y, p3x, p3y);
}
in the room's repeatedly_execute_always:
int nextHour = GetTime(1);
int nextMinute = GetTime(2);
if (nextMinute != currMinute || nextHour != currHour)
{
currMinute = nextMinute;
currHour = nextHour;
RawDrawImage(140, 10, SPRITE_CLOCKWITHNOHANDS);
int minuteAngle = 6*nextMinute; // 360/60 = 6
int hourAngle = 15*nextHour; // 360/24 = 15
// draw an offset shadow
RawSetColour(0); // black
drawClockHand(161, 31, 20, 1, minuteAngle);
drawClockHand(161, 31, 14, 2, hourAngle);
// draw the hands
RawSetColour(25620); // gunmetal
drawClockHand(160, 30, 20, 1, minuteAngle);
drawClockHand(160, 30, 14, 2, hourAngle);
}
Totally untested but you get the idea.
Cheers,
Steve
Quote from: SteveMcCrea on Sun 22/08/2004 19:05:27
- create 24 hour hand sprites and 24 minute hand sprites, and raw draw the appropriate one onto the clock face every time the time changes
well unless he'd want a very original clock, i think he'd only need 12 sprites for each hand ;)
unless you were referring to in-betweens ... :-\ hmm