Forum Topic: I'm here to learn

(116 views • 16 replies)

This topic is 1 page long.

<< < > >>
None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 03:22 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

well I made a pretty cool castle crashers game

and well the main problem was the combat, so i was wondering if any one knows how to do this, or can point me in the direction of a tutorial that can teach me how to code this.

now what I know is that I'm probably gonna have to use a code similar to

if (key.isDown(key.SPACE)) {
_root.play.gotoAndStop (4);
}

however when ever I tag that onto the end of my engine, it doesn't work.
my engine is as followed

onClipEvent (load) {
var grav:Number = 0;
// gravity
var speed:Number = 6;
// how fast you walk
var jumpHeight:Number = 9.3;
// how high you jump
var slow:Number = .6;
// sets water falling speed
var slowspd:Number = speed/1.5;
// sets water walking speed
var setspeed:Number = speed;
var scale:Number = _xscale;
var ex:Number = 5;
// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
this.gotoAndStop(2);
}
onClipEvent (enterFrame) {
grav++;
_y += grav;
while (_root.ground.hitTest(_x, _y, true)) {
_y--;
grav = 0;
}
if (_root.water.hitTest(_x, _y, true)) {
if (grav>0) {
grav *= slow;
}
speed = slowspd;
} else {
speed = setspeed;
}
if (Key.isDown(68)) {
_x += speed;
_xscale = scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else if (Key.isDown(65)) {
_x -= speed;
_xscale = -scale;
if (_root.ground.hitTest(_x, _y+3, true)) {
this.gotoAndStop(1);
} else {
this.gotoAndStop(2);
}
} else {
if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
this.gotoAndStop(3);
}
}
if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
this.gotoAndStop(5);
}
if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
this.gotoAndStop(4);
}
if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
grav = -jumpHeight;
_y -= 4;
this.gotoAndStop(2);
}
if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
_x -= speed;
}
if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
_x += speed;
}
if (_root.ground.hitTest(_x, _y-_height-15, true)) {
grav = 1;
}
if (this.hitTest(_root.ground.FB1.Trigger)) {
_root.ground.FB1.gotoAndPlay(2);
}
if (key.isDown(key.SPACE)) {
_root.player.gotoAndStop(4);
}
}

so...can anyone help?


Questioning

fluffkomix

Reply To Post Reply & Quote

Posted at: 12/24/08 03:27 PM

fluffkomix EVIL LEVEL 10

Sign-Up: 05/05/08

Posts: 1,963

i would if i understood any of that, and this is just a guess but...

try making anchors in your frames so that way it goes to that anchor. makes it safer than saying frame numbers.

click on frame properties > frame label > label type

to truly appreciate newgrounds | my store
Lemon Demon: fancy pants manifesto collab
Here ends another post by the grand master of all things: fluffkomix

BBS Signature

None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 03:40 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

At 12/24/08 03:27 PM, fluffkomix wrote: i would if i understood any of that, and this is just a guess but...

try making anchors in your frames so that way it goes to that anchor. makes it safer than saying frame numbers.

click on frame properties > frame label > label type

thanks for the tip


None

mooseisloose

Reply To Post Reply & Quote

Posted at: 12/24/08 03:41 PM

mooseisloose FAB LEVEL 34

Sign-Up: 12/06/04

Posts: 2,404

WOW. I mean really... WOW.

Don't just copy codes off sites, put in a lot of time and effort to learn it so you can create your own combat engine. WHile people wont give you the code to do it OR point you to a site that has it, people will be willing to help if you have small problems while you're learning the code yourself, so go and read some tutorials, have a play around.

What you're asking just isn't gonna happen.


None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 04:03 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

At 12/24/08 03:41 PM, mooseisloose wrote: WOW. I mean really... WOW.

Don't just copy codes off sites, put in a lot of time and effort to learn it so you can create your own combat engine. WHile people wont give you the code to do it OR point you to a site that has it, people will be willing to help if you have small problems while you're learning the code yourself, so go and read some tutorials, have a play around.

What you're asking just isn't gonna happen.

I know what your saying, and i know what all the code means, i just prefer the engine over the one i wrote, all I'm asking is if I'm heading in the right direction and if some one could tell me where to start to learn this or if they could explain it to me etc.

i admit I'm not the best coder, and I'm trying to learn how, and i simply have no idea where to start other than that small but of code I wrote (the space bar one)


None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 12/24/08 04:10 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,858

well, for the Key.SPACE part, heres what you messed up on.

Your Code:

...
if(Key.isDown(Key.SPACE)) {
     _root.play.gotoAndStop(4);
}

Well, the part you messed up on what the _root.play (Unless play is your mc) That does not work. Try this (BTW, the ... just means all of your other code, then it gets to this part, so dont include the ...)

...
if(Key.isDown(Key.SPACE)) {
     player.mcattack.play(); //The mcattack is the mc of the attack inside the player moveclip
}

Thats just a example, but thats just to get the point across.

Now, for the main engine. I changed around a bit, and made it a bit neater for you. Try this

Main Engine:

onClipEvent (load) {
	var grav:Number = 0;
	// gravity
	var speed:Number = 6;
	// how fast you walk
	var jumpHeight:Number = 9.3;
	// how high you jump
	var slow:Number = .6;
	// sets water falling speed
	var slowspd:Number = speed/1.5;
	// sets water walking speed
	var setspeed:Number = speed;
	var scale:Number = _xscale;
	var ex:Number = 5;
	// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
	this.gotoAndStop(2);
}

onClipEvent (enterFrame) {
	grav++;
	_y += grav;
	while (_root.ground.hitTest(_x, _y, true)) {
		_y--;
		grav = 0;
	}
	if (_root.water.hitTest(_x, _y, true)) {
		if (grav>0) {
			grav *= slow;
		}
		speed = slowspd;
	} else {
	speed = setspeed;
	}
	if (Key.isDown(68)) {
		_x += speed;
		_xscale = scale;
		if (_root.ground.hitTest(_x, _y+3, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else if (Key.isDown(65)) {
		_x -= speed;
		_xscale = -scale;
	if (_root.ground.hitTest(_x, _y+3, true)) {
		this.gotoAndStop(1);
	} else {
		this.gotoAndStop(2);
	}  else {
		if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
			this.gotoAndStop(3);
		}
	}
	if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
				this.gotoAndStop(5);
	}
	if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
		this.gotoAndStop(4);
	}
	if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
		grav = -jumpHeight;
		_y -= 4;
		this.gotoAndStop(2);
	}
	if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
		_x -= speed;
	}
	if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
		_x += speed;
	}
	if (_root.ground.hitTest(_x, _y-_height-15, true)) {
		grav = 1;
	}
	if (this.hitTest(_root.ground.FB1.Trigger)) {
		_root.ground.FB1.gotoAndPlay(2);
	}
	if (key.isDown(key.SPACE)) {
		_root.player.gotoAndStop(4);
	}
}

Newgrounds... where all us freaks head to for great fun!


None

fluffkomix

Reply To Post Reply & Quote

Posted at: 12/24/08 04:14 PM

fluffkomix EVIL LEVEL 10

Sign-Up: 05/05/08

Posts: 1,963

well he was probably more helpful than i was.

but still, when coding games, use anchors. it makes it a lot less confusing and a lot less partial to making mistakes.

to truly appreciate newgrounds | my store
Lemon Demon: fancy pants manifesto collab
Here ends another post by the grand master of all things: fluffkomix

BBS Signature

None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 04:18 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

thanks that's actually very helpful
it did have some errors though..I fixed some of them but i can't figure out this one

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 49: 'else' encountered without matching 'if'
} else {

Total ActionScript Errors: 1 Reported Errors: 1


None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 12/24/08 04:19 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,858

Try this, I fixed up a few things I missed aswell

onClipEvent (load) {
	var grav:Number = 0;
	// gravity
	var speed:Number = 6;
	// how fast you walk
	var jumpHeight:Number = 9.3;
	// how high you jump
	var slow:Number = .6;
	// sets water falling speed
	var slowspd:Number = speed/1.5;
	// sets water walking speed
	var setspeed:Number = speed;
	var scale:Number = _xscale;
	var ex:Number = 5;
	// makes hitTests better, change for a closer hitTest (warning, more buggy if smalle, less real if further)
	this.gotoAndStop(2);
}

onClipEvent (enterFrame) {
	grav++;
	_y += grav;
	while (_root.ground.hitTest(_x, _y, true)) {
		_y--;
		grav = 0;
	}
	if (_root.water.hitTest(_x, _y, true)) {
		if (grav>0) {
			grav *= slow;
		}
		speed = slowspd;
	} else {
	speed = setspeed;
	}
	if (Key.isDown(68)) {
		_x += speed;
		_xscale = scale;
		if (_root.ground.hitTest(_x, _y+3, true)) {
			this.gotoAndStop(1);
		} else {
			this.gotoAndStop(2);
		}
	} else if (Key.isDown(65)) {
		_x -= speed;
		_xscale = -scale;
	}
	if (_root.ground.hitTest(_x, _y+3, true)) {
		this.gotoAndStop(1);
	} else {
		this.gotoAndStop(2);
	} 
	if (_root.ground.hitTest(_x, _y+3, true) && !Key.isDown(79) && !Key.isDown(73)) {
			this.gotoAndStop(3);
	}
	if (Key.isDown(79) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(73)) {
				this.gotoAndStop(5);
	}
	if (Key.isDown(73) && !Key.isDown(87) && !Key.isDown(65) && !Key.isDown(68) && !Key.isDown(79)) {
		this.gotoAndStop(4);
	}
	if (Key.isDown(87) && _root.ground.hitTest(_x, _y+3, true)) {
		grav = -jumpHeight;
		_y -= 4;
		this.gotoAndStop(2);
	}
	if (_root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/2), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-(_height/6), true) || _root.ground.hitTest(_x+(_width/2)+ex, _y-_height, true)) {
		_x -= speed;
	}
	if (_root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/2), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-(_height/6), true) || _root.ground.hitTest(_x-(_width/2)-ex, _y-_height, true)) {
		_x += speed;
	}
	if (_root.ground.hitTest(_x, _y-_height-15, true)) {
		grav = 1;
	}
	if (this.hitTest(_root.ground.FB1.Trigger)) {
		_root.ground.FB1.gotoAndPlay(2);
	}
	if (key.isDown(key.SPACE)) {
		_root.player.gotoAndStop(4);
	}
}

Newgrounds... where all us freaks head to for great fun!


None

fluffkomix

Reply To Post Reply & Quote

Posted at: 12/24/08 04:25 PM

fluffkomix EVIL LEVEL 10

Sign-Up: 05/05/08

Posts: 1,963

well was i right billy? cuz i was pretty much guessing

to truly appreciate newgrounds | my store
Lemon Demon: fancy pants manifesto collab
Here ends another post by the grand master of all things: fluffkomix

BBS Signature

None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 12/24/08 04:27 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,858

At 12/24/08 04:25 PM, fluffkomix wrote: well was i right billy? cuz i was pretty much guessing

Really, Ive never used anchors. I find that they are useless. But it depends on who you are and how you like to code, anchors can be good and bad in some cases.

Newgrounds... where all us freaks head to for great fun!


None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 04:35 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

thanks you guys are being helpful but my main problem still remains, he doesn't attack


None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 12/24/08 04:42 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,858

ok, what you arent understand is.. make a movieclip with your attack animation in it. Then, inside of your MAIN characters movieclip, have each different movieclip on a seperate frame, each with a stop(); command on the frames actions.

Then, once that is done, on each movieclip inside your main movieclip, make a instance name for each. Then, in your main movieclips actions, put the code

...
if(Key.isDown(Key.SPACE)) {
     this.gotoAndStop(2); //Or whatever the frame your movieclip is on
     this.attack.play();
} else
     this.gotoAndStop(1); //Or whatever your standing frame is on
     this.standing.play();
}

Hope you understand what I mean

Newgrounds... where all us freaks head to for great fun!


None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 04:45 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

i understand what you mean, and on frame 4 of the main character is the attacking frame

so i should give that movie clip and instance name?


None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 12/24/08 04:46 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,858

correct, and you would just tell the code to go to the frame its on, then when its on that frame, you make the animation play. Thats basically what it does.

Newgrounds... where all us freaks head to for great fun!


None

jds74

Reply To Post Reply & Quote

Posted at: 12/24/08 04:54 PM

jds74 NEUTRAL LEVEL 01

Sign-Up: 03/21/08

Posts: 820

well it works and it doesn't
when i hold space bar, it just stays on the first frame of the attack and doesn't play it all, and i had to take out the else statement, because basically it put u in the standing frame all the time.
if you want me to i could maybe upload the fla some where for u to take a look at?


None

BillysProgrammer

Reply To Post Reply & Quote

Posted at: 12/24/08 04:55 PM

BillysProgrammer LIGHT LEVEL 15

Sign-Up: 09/17/08

Posts: 1,858

That would help. Then it would be easier for me to fix the problems im creating/fixing lol.

Send it to me through a PM to keep people from claiming it as there own. Nobody probably will, but just incase.

Newgrounds... where all us freaks head to for great fun!


All times are Eastern Standard Time (GMT -5) | Current Time: 04:05 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!