Sign in to follow this  
jeteran

Simple 2D game implementation

Recommended Posts

jeteran    311
Hi guys from the net. I want to implement this code to my game:
onClipEvent(load){
    jump=false; scream=false; s=6;
	this.gotoAndStop(1);
	b = this.getBounds(this);
	_root.timerID = setInterval(_root.goTime,10);
	function move(x,y){
		h=false;
		if(!_root.map.hitTest(_x+x+b.xmin,_y+y+b.ymin,true)){
			if(!_root.map.hitTest(_x+x+b.xmax,_y+y+b.ymin,true)){
				if(!_root.map.hitTest(_x+x+b.xmin,_y+y+b.ymax,true)){
					if(!_root.map.hitTest(_x+x+b.xmax,_y+y+b.ymax,true)){
						_root.map._x -= x;
						_root.map._y -= y; 
						h=true;
						} 
					}
				}
			}  
	 return h;
	}
}

onClipEvent(enterFrame){
        falling = move(0,s);
		
      if(Key.isDown(Key.SPACE) && !falling && !jump){
			jump = true; vel = -10;
			_root.jumpSound.gotoAndPlay(2);}
	 if(Key.isDown(Key.LEFT)){move(-s,0); this.play();}
     if(Key.isDown(Key.RIGHT)){move(s,0); this.play();}
			
	if (jump) {
		if(vel <= 10){
			h = move(0,vel-s);
			if(h == false && vel < 0){ vel *= -1;}
			vel++;
		}
		else{
			jump = false;
		}
	}
	if (_root.map._y<-450 && !scream) {scream=true; _root.fallSound.gotoAndPlay(2);}
    if (_root.map._y<-850) {_root.map._x=0;_root.map._y=0;scream=false;}
}

onClipEvent (keyUp) {this.gotoAndStop(1);}

And I don't know what happends, but when I put it on my code, it doesn't work! The character won't detect the collision with the floor, just keep falling, I looked at the instance names and such, but I don't know what else. Anybody can help me? Thank you!

Share this post


Link to post
Share on other sites
zabo    101
i never copy code because its like some devine mysticle force wants to stop it from working.... it sounds weird but my code( if its copied) usually only works if its saved try that(do you think its my computer or the language?).

Share this post


Link to post
Share on other sites
jeteran    311
Quote:
Original post by zabo
i never copy code because its like some devine mysticle force wants to stop it from working.... it sounds weird but my code( if its copied) usually only works if its saved try that(do you think its my computer or the language?).


Wow that's really strange, I am having that problem too, but even tho i save it, it doesn't work :( I am using other codes too

Share this post


Link to post
Share on other sites
Captain P    1092
Don't rely on copy-pasting code from tutorials if you're building a game of your own. There are so many things that can differ that you're only causing yourself trouble. Instead, learn how to program yourself. Once you can program, you can read tutorials, understand the concepts that they present, and implement these concepts yourself.

As for pinpointing problems, you can trace text to the console, which is usefull for testing which code-lines are executed and what values variabeles have. That should be helpfull when tracking down bugs and such.

Share this post


Link to post
Share on other sites
jeteran    311
Quote:
Original post by Captain P
Don't rely on copy-pasting code from tutorials if you're building a game of your own. There are so many things that can differ that you're only causing yourself trouble. Instead, learn how to program yourself. Once you can program, you can read tutorials, understand the concepts that they present, and implement these concepts yourself.

As for pinpointing problems, you can trace text to the console, which is usefull for testing which code-lines are executed and what values variabeles have. That should be helpfull when tracking down bugs and such.


Yeah I know, it's always best to create my own code. But I haven't ever build a console-type game. So I am using a code a guy made so we can use to put more levels and stuff. For now it's working, I am using his level ;);)

Thank you guys!

yayo

Share this post


Link to post
Share on other sites
jeteran    311
Don't know what happened! I was doing great, and suddently, my char stopped moving!! I Ctrl+Z a lot and even tho, it never moved again!!!! HELP! This is the code

onClipEvent(load){
jump=false; scream=false; s=8;
this.gotoAndStop(1);
b = this.getBounds(this);
_root.timerID = setInterval(_root.goTime,10);
function move(x,y){
h=false;
if(!_root.map.hitTest(_x+x+b.xmin,_y+y+b.ymin,true)){
if(!_root.map.hitTest(_x+x+b.xmax,_y+y+b.ymin,true)){
if(!_root.map.hitTest(_x+x+b.xmin,_y+y+b.ymax,true)){
if(!_root.map.hitTest(_x+x+b.xmax,_y+y+b.ymax,true)){
_root.map._x -= x;
_root.map._y -= y;
h=true;
}
}
}
}
return h;
}
}

onClipEvent(enterFrame){
falling = move(0,s);

if(Key.isDown(Key.SPACE) && !falling && !jump){
jump = true; vel = -10;
_root.jumpSound.gotoAndPlay(2);}
if(Key.isDown(Key.LEFT)){move(-s,0); this.play();}
if(Key.isDown(Key.RIGHT)){move(s,0); this.play();}

if (jump) {
if(vel <= 10){
h = move(0,vel-s);
if(h == false && vel < 0){ vel *= -1;}
vel++;
}
else{
jump = false;
}
}
if (_root.map._y<-450 && !scream) {scream=true; _root.fallSound.gotoAndPlay(2);}
if (_root.map._y<-850) {_root.map._x=0;_root.map._y=0;scream=false;}
}

onClipEvent (keyUp) {this.gotoAndStop(1);}

Thank you guys!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this