Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Timer based movement

Author
Message
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 24th Oct 2003 18:19
Some code that will help you write games that run at same speed all pc's. What may run ok'ish on your pc may run too fast on a super-duper computer.

Should be ok for 2d and 3d games.

Simply gosub the init routine before main loop and gosub other routine as first thing in main loop.

The idea being that routine counts how many loops are run every second and modifies move# accordingly. It updates once per second for smoothness sake, but you can change t9 if you want it to update more regularly.

Have included some basic objects to show how to use move#

You can therefore force objects to move a certain amount in 1 second, rotate a set number of degrees in 1 second.

Enjoy!



If your mansion house needs haunting, just call Rentaghost!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 24th Oct 2003 21:51
Very useful - I've modified the t1-t9 variables for my program so they're in a structure.


Avatar & Logo by Indi. Insert witty comment here...
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 24th Oct 2003 22:15
My naming of variables is very dodgy! I get a good ear-bending at work because all my work programs written in php, coldfusion, etc are usually like a,b,x1,x2,e.t.c instead of nice descriptive names.

It's just that I'm lazy. Why call a variable playerxposition when I can just say x

It's only when I take time off and my workmates have to modify one of my programs that it really hits the fan!

Anyway people can change the variables to whatever they want, stick em in a structure. Make em global and use functions instead. Change t9 to be a constant, blah blah blah

If your mansion house needs haunting, just call Rentaghost!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 24th Oct 2003 22:46
It bet you used to have a C64...


Avatar & Logo by Indi. Insert witty comment here...
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 24th Oct 2003 22:51
Nah, spectrum 48k, spectrum+3, amiga 500, amiga 1200.

Work computer used to be DEC PDP-11 and because screen was only 80 characters wide (green on black), it made sense to use small variable names. As I was writing most of programs I made programs as illegible as possible so they couldn't sack me! Seems to work as I am in same just 15 years later!

If your mansion house needs haunting, just call Rentaghost!
OSX Using Happy Dude
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 25th Oct 2003 01:25
Whatever works!


Avatar & Logo by Indi. Insert witty comment here...

Login to post a reply

Server time is: 2024-05-03 06:10:59
Your offset time is: 2024-05-03 06:10:59