View Full Version : 2d platforms scripts
whats up? having a great life?
i have a problem with my 2d platform game. how do you do that so if you pick up a box and then you have a weapon in your hands and then you can smash enemies with it? and how do i general smash enemies out with my headperson?
i need a AS thanks :D
I also need a script to make a person bounce off a wall. If he jumps in it he bounce off. Thanks...
do you honestly think there is code for smashing someone over the head with a weapon?
work it out for yourself, your making a platformer so you should be able to.
Insane Knux
06-26-2005, 09:51 PM
He's right. We're not doing the AS for you. It's your platform game, you're the one with all the skills...
Oh shut up Insane Knux, just because he's better than u in actionscript
so if i tell you exactly how i making this you maybe will help? okay.
a have the movieclip with the hero. the movieclips instance name is hero. inside the movieclip there is 3 frames. the first its where the hero stand still the 2. is where the hero walks and the 3. is where he jumps. then i make a movieclip out side the real movieclip with to frames. the first is what movieclip before and the 2. is where he shoot an enemy and the 3. is another weopen osv. outside the movieclips there is this AS:
onClipEvent (load) {
gravity = 12;
scale = _xscale;
walkSpeed = 20;
maxjump = 5;
}
onClipEvent (enterFrame) {
if (air == true) {
_y += gravity;
state = 3;
}
if (_root.platforms.hitTest(_x, _y, true)) {
air = false;
} else {
air = true;
}
if (Key.isDown(Key.UP) && jump == true) {
_y -= jumpSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (Key.isDown(Key.UP)) {
jumpcount += 1;
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
onClipEvent (load) {
if (Key.isDown(Key.RIGHT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
_xscale = scale;
}
}
onClipEvent (keyUp) {
if (Key.getCode() == 83) {
jump = false;
}
}
then i have the platform like alien hominids with this action and its instance name is platforms:
onClipEvent (load) {
scale = _xscale;
walkSpeed = 50;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT) && !_root.leftbound.hitTest(_x, _y, true)) {
_x -= walkSpeed;
}
if (Key.isDown(Key.LEFT) && !_root.rightbound.hitTest(_x, _y, true)) {
_x += walkSpeed;
}
if (air == false) {
jump = true;
jumpcount = 0;
jumpSpeed = 22;
}
if (jumpcount>maxjump && jumpSpeed>-2) {
jumpSpeed -= 2;
}
if (air == false && !Key.isDown(Key.LEFT) && !Key.isDown(65) && _currentframe<4 or air == false && !Key.isDown(Key.RIGHT) && !Key.isDown(65) && _currentframe<4) {
state = 1;
}
if (Key.isDown(Key.LEFT) && air == false && !Key.isDown(65) && _currentframe<4 or Key.isDown(Key.RIGHT) && air == false && !Key.isDown(65) && _currentframe<4) {
state = 2;
}
if (!Key.isDown(65)) {
gotoAndStop(state);
}
_root.statetxt = state;
}
så the person stand still but the platforms moves. to the "weapons there kills enemies" have i think about a new movieclip outside the old movieclip with instance name hero2. if you have pick up a weapon in "hittest mode" there will root a dynamic text box to maybe 300 and only if you click on a button and have 300 in the dynamic text box you can kick the enemy or shoot him. so i was making a AS on the main frame out side all the movieclips with this action:
if (weapon1 >= 0 && weapon1 < 300) {
if (Key.isDown(Key.D)) {
hero2.gotoAndStop(2);
} else {
hero2.gotoAndStop(1);
}
}
thats not my main problem. that is how a hittest inside a movieclip can hit a enemy outside the movieclip. there must be an action for that.
then you got my skills:P
Nexus
06-27-2005, 08:21 AM
Ouch. Looking at all that unformatted code is an eyesore. Try using the forum code tags to preserve the spacing of your code as well as the format.
This isn't an answer to your question, it is however, a suggestion.
You currently have an air variable that determines whether or not the player is currently in the air. If air is true, then you add to the hero's _y property, thus creating the effects of "gravity".
A better way of doing this would be to just keep gravity at a constant (meaning you wouldn't have an air variable that tells you when to start falling, you just fall every frame). Advantages to this method are that you don't need to constantly be worrying about changing the state of the air variable, so all that code you have concerning it will be redundant. You will have to make changes to your platform code so that it blocks the hero from falling.
Anyway, as for your person bouncing off a wall, just do a hitTest to see if the hero's colliding with the wall, then reverse the x vector of your player (xSpeed *= -1).
zoidburgfan
06-27-2005, 04:24 PM
While i was looking at that coding i noticed it looks a lot like the script that gamemaker program uses. It is a great program for making games for new people to programing to use. I just started using flash a few days ago.
do you work for game maker? sounds like it....
zoidburgfan
06-28-2005, 04:39 PM
No i do not work for gamemaker (i wish i did) but it is the program i used to make games before i found flash.
arkhan
06-28-2005, 06:49 PM
I never did anything on this gamemaker thing..I did get it once, but I was a lil kid with no idea how it worked...
now, however I do work for gameCreator XD.......man..that joke was just not funny at all..so...
I didnt really read that code in-depth, coz as soon as I looked at that outside the code thing its just...painfull you know...and then, after cheking it out I was about sure you basicly copied-pasted it from somewhere,wich leaves me in an acward position here...coz ene if we try to help you wont understand ****, making those words useless..
use the [ code] [ /code] to type your code, or else we wont really understand it all just by looking at it...and I dont like to have to find the loops on eye and stuff...so..yeah..good luck..
Insane Knux
06-29-2005, 08:06 PM
Oh shut up Insane Knux, just because he's better than u in actionscript
OMG, you're so right. I'm sorry dude, you're the best. You own me.
Lmao...
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.