Be a Supporter!

Hey could someone help me with this

  • 338 Views
  • 10 Replies
New Topic Respond to this Topic
SketchistGames
SketchistGames
  • Member since: Mar. 2, 2012
  • Offline.
Forum Stats
Member
Level 05
Game Developer
Hey could someone help me with this 2012-05-23 14:53:21 Reply

Ok, could someone help me? I am making a new platformer game but I wan't it to have a twist, the main character has the ability to "travel back in time" like in the game Dusk 2 If this is in the wrong forum I will delete it and post it in the correct one thanks :D! Please help however you can!

Hey could someone help me with this


Current Trophies: Weekly Fourth Place for Blast the Bunny 2 ~SketchistGames :P

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Hey could someone help me with this 2012-05-23 15:14:20 Reply

At 5/23/12 02:53 PM, SketchistGames wrote: Ok, could someone help me? I am making a new platformer game but I wan't it to have a twist, the main character has the ability to "travel back in time" like in the game Dusk 2 If this is in the wrong forum I will delete it and post it in the correct one thanks :D! Please help however you can!

I've actually thought about this before (i've never implemented it, was just thinking for fun) - but i've never solved it.
I'll think aloud here (just some things that come to mind), and see if any of this helps.

Think of time as a variable
use arrays to store the last movement data? (Ie ran left for x seconds, right for x seconds, jumped...) - use the time variable to control how far back it goes

that's all i'm able to come up with at the moment


Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Hey could someone help me with this 2012-05-23 15:29:10 Reply

At 5/23/12 03:14 PM, egg82 wrote:
At 5/23/12 02:53 PM, SketchistGames wrote: Ok, could someone help me? I am making a new platformer game but I wan't it to have a twist, the main character has the ability to "travel back in time" like in the game Dusk 2 If this is in the wrong forum I will delete it and post it in the correct one thanks :D! Please help however you can!
I've actually thought about this before (i've never implemented it, was just thinking for fun) - but i've never solved it.
I'll think aloud here (just some things that come to mind), and see if any of this helps.

Think of time as a variable
use arrays to store the last movement data? (Ie ran left for x seconds, right for x seconds, jumped...) - use the time variable to control how far back it goes

that's all i'm able to come up with at the moment

thought about it some more. I can get more specific on my theory

you can do this one of two ways:

one: create one array for movement. You could constantly record the player's position (every quarter or half-second) and reverse those steps be moving backward through that array, clearing each variable it passes. The reason you clear them as you pass them is if the player wants a "drop-off point" somewhere in the middle of that array, then you still have the start of the array as a buffer in case they want to go back again.

or two (this is the one I like): create one array for movement and one array for time. Each time the player presses a key, record the key and the time started. When the player releases the key record the end time. This will decrease the size of the array and speed up your program (as compared to the first method, which is constantly checking. This method only "checks" when something happens) - then use logic to run back through the steps, same as method one. The reason for the time array (if it isn't obvious) is because the timer isn't a constant. It's an unknown.

I'm forgetting something, but I can't remember what. Anyway, I hope that explains more.


Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Hey could someone help me with this 2012-05-23 17:07:15 Reply

I finally decided to get off my lazy ass and throw something together quickly.
Here's a few warnings: This is not proper programming. It looks like crap - it works. If you want to use it, you'll have to do some clean-up.
I'm not sure how "buggy" it is. It hasn't been stress-tested. It gets the "character" to around 8 or so pixels from where they were supposed to be at that point (at 30 FPS)

alrighty, here's the code

_root.rtime = [];
_root.rmove = [];
_root.rtime.push(getTimer());
_root.rmove.push(-1);
_root.ntime = getTimer();
_root.nmove = -1;
_root.newdir = false;
_root.stime = getTimer();
_root.stime2 = getTimer();
_root.inarray = false;
_root.keydown = false;

_root.onEnterFrame = function(){
	if(Key.isDown(87) or Key.isDown(Key.UP) or (_root.newdir == true and _root.nmove == 0)){
		_root.box._y -= 5;
		if(_root.newdir == false){
			if(_root.rmove[_root.rmove.length-1] != 1){
				_root.rtime.push(getTimer());
				_root.rmove.push(1);
			}
		}else{
			if(getTimer()-_root.stime >= _root.stime2-_root.ntime){
				_root.newdir = false;
			}
		}
		_root.keydown = true;
	}else if(Key.isDown(83) or Key.isDown(Key.DOWN) or (_root.newdir == true and _root.nmove == 1)){
		_root.box._y += 5;
		if(_root.newdir == false){
			if(_root.rmove[_root.rmove.length-1] != 0){
				_root.rtime.push(getTimer());
				_root.rmove.push(0);
			}
		}else{
			if(getTimer()-_root.stime >= _root.stime2-_root.ntime){
				_root.newdir = false;
			}
		}
		_root.keydown = true;
	}else if(Key.isDown(65) or Key.isDown(Key.LEFT) or (_root.newdir == true and _root.nmove == 2)){
		_root.box._x -= 5;
		if(_root.newdir == false){
			if(_root.rmove[_root.rmove.length-1] != 3){
				_root.rtime.push(getTimer());
				_root.rmove.push(3);
			}
		}else{
			if(getTimer()-_root.stime >= _root.stime2-_root.ntime){
				_root.newdir = false;
			}
		}
		_root.keydown = true;
	}else if(Key.isDown(68) or Key.isDown(Key.RIGHT) or (_root.newdir == true and _root.nmove == 3)){
		_root.box._x += 5;
		if(_root.newdir == false){
			if(_root.rmove[_root.rmove.length-1] != 2){
				_root.rtime.push(getTimer());
				_root.rmove.push(2);
			}
		}else{
			if(getTimer()-_root.stime >= _root.stime2-_root.ntime){
				_root.newdir = false;
			}
		}
		_root.keydown = true;
	}else if(_root.keydown == false or (_root.newdir == true and _root.nmove == -1)){
		if(_root.newdir == false){
			if(_root.rmove[_root.rmove.length-1] != -1){
				_root.rtime.push(getTimer());
				_root.rmove.push(-1);
			}
			_root.inarray = false;
		}else{
			if(getTimer()-_root.stime >= _root.stime2-_root.ntime){
				_root.newdir = false;
			}
		}
	}else{
		_root.keydown = false;
	}
	if(Key.isDown(Key.SPACE)){
		if(_root.newdir == false){
			if(_root.rmove.length>1){
				_root.stime = getTimer();
				if(_root.inarray == false){
					_root.stime2 = getTimer();
					_root.inarray = true;
				}else{
					_root.stime2 = _root.ntime;
				}
				_root.ntime = _root.rtime[_root.rtime.length-1];
				_root.nmove = _root.rmove[_root.rmove.length-1];
				trace(_root.stime2-_root.ntime);
				temptime = [];
				tempmove = [];
				for(i=0;i<_root.rmove.length-1;i++){
					temptime.push(_root.rtime[i]);
					tempmove.push(_root.rmove[i]);
				}
				_root.rtime = temptime;
				_root.rmove = tempmove;
				_root.newdir = true;
			}
		}
		_root.keydown = true;
	}
}

Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
ProfessorFlash
ProfessorFlash
  • Member since: Oct. 6, 2007
  • Offline.
Forum Stats
Member
Level 32
Programmer
Response to Hey could someone help me with this 2012-05-23 17:33:04 Reply

From what I gathered from his post, he wants us to give him a plot twist for his platformer where the main character can travel back in time.

So maybe after he has traveled back in time, he finds out he was never born and that his mother is really his father and that insects have taken over the world because he stepped on a ladybug when traveling back in time and that gave the nazis a technology advantage in the world war two which they used to make experiments on bugs who then turned like godzilla and half of the world is now a desert wasteland where water is very rare so it costs like a lot of silver which is now the main resource of the world because you can make drinking cups out of silver which only the humans can use because the insects don't have thumbs on their hands.


You can solve pretty much any problem you may have with AS3 by consulting the AS3 Language reference.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Hey could someone help me with this 2012-05-23 17:38:55 Reply

At 5/23/12 05:33 PM, ProfessorFlash wrote: From what I gathered from his post, he wants us to give him a plot twist for his platformer where the main character can travel back in time.

So maybe after he has traveled back in time, he finds out he was never born and that his mother is really his father and that insects have taken over the world because he stepped on a ladybug when traveling back in time and that gave the nazis a technology advantage in the world war two which they used to make experiments on bugs who then turned like godzilla and half of the world is now a desert wasteland where water is very rare so it costs like a lot of silver which is now the main resource of the world because you can make drinking cups out of silver which only the humans can use because the insects don't have thumbs on their hands.

haha, that's pretty interesting. Anyway, I thought it was obvious what he was asking - especially after I played some of the game that he linked to.

Side-note: I probably should have used a positional array rather than a directional array. Would be much more accurate, and possibly faster.
ie. at the moment it uses directions and time to get to its new destination. Instead, I could simply use one array with a position. That would only work for "walking", though. For jumping, special effects, etc it would be better to use the Key.isDown approach


Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
caseymacneil
caseymacneil
  • Member since: Nov. 19, 2008
  • Offline.
Forum Stats
Member
Level 06
Programmer
Response to Hey could someone help me with this 2012-05-23 18:48:04 Reply

OP i would just like to point out that your sig has incorrect syntax, it is

if(youarereading = true){
me == "SketchistGames";
}

where it should be

if(youarereading == true){
me = "SketchistGames";
}
Sandremss128
Sandremss128
  • Member since: Aug. 22, 2009
  • Offline.
Forum Stats
Supporter
Level 11
Programmer
Response to Hey could someone help me with this 2012-05-23 19:28:05 Reply

that game just makes cheap snapshots of the current position and velocity of the player and has an option to revert it; the environment stays the same (those moving platforms were unaffected).

If you truly want to have a good time thing you need to either:

1. make A LOT of snapshots
2. store the user input and calculate time steps back from it.

The second method is more deterministic than the first one because you can invert your position determining functions and get the actual position of the previous time step.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Hey could someone help me with this 2012-05-23 19:46:33 Reply

At 5/23/12 07:28 PM, Sandremss128 wrote: that game just makes cheap snapshots of the current position and velocity of the player and has an option to revert it; the environment stays the same (those moving platforms were unaffected).

If you truly want to have a good time thing you need to either:

1. make A LOT of snapshots
2. store the user input and calculate time steps back from it.

The second method is more deterministic than the first one because you can invert your position determining functions and get the actual position of the previous time step.

I used the second method, though it's very basic - though there may be a third option (branching from the second a bit)
Again, I used time as not only a variable but a major determining factor of the "backward time" script. If you remove that (aside from the "pauses" in which the player does nothing) you can just store points in the array and use the game's logic to get from point a to point b - though that's a bit more complex, as you will have to basically create an AI and in the case of jumping, increase the effect of gravity on the player (i'm thinking about jumping onto a platform. It would look weird if the character just jumped backwards)

All the complexities aside, after everything's done it would probably be a small amount faster than described in method two, though honestly not enough to warrant that big of a headache. I'd just go with the user input method.


Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Hey could someone help me with this 2012-05-23 20:01:38 Reply

I used the second method, though it's very basic - though there may be a third option (branching from the second a bit)
Again, I used time as not only a variable but a major determining factor of the "backward time" script. If you remove that (aside from the "pauses" in which the player does nothing) you can just store points in the array and use the game's logic to get from point a to point b - though that's a bit more complex, as you will have to basically create an AI and in the case of jumping, increase the effect of gravity on the player (i'm thinking about jumping onto a platform. It would look weird if the character just jumped backwards)

All the complexities aside, after everything's done it would probably be a small amount faster than described in method two, though honestly not enough to warrant that big of a headache. I'd just go with the user input method.

Ah, a fourth option appears! egg82 uses the master ball!

how about combining them? Yes, you'd end up with another array, but here's the upside:
at the moment the key/time is not perfect. In fact, if you move around for 20 seconds you end up way off from the starting position. The time/space isn't quite right either. It leaves a gaping hole for AI to fill (which is a pain in the arse by itself)
but if you did a ket/space/time combo, it would remove all adverse effects. Use the script posted above, but add the space points to it and check the x and y axis for collision (math only, please), then stop and get a new point when the collision is true. In theory, it would be perfect. You wouldn't even need an AI.


Programming stuffs (tutorials and extras) PM me (instead of MintPaw) if you're confuzzled. thank Skaren for the sig :P

BBS Signature
Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to Hey could someone help me with this 2012-05-24 03:51:21 Reply

Surely you would just need to take note of the players position periodically - such as every half a second. "Velocity" doesn't need to be noted because if it's already programmed into the players movement then just taking note of positions would be enough.

I'm intrigued. I might give it a go.