Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.13 / 5.00 17,637 ViewsBasic Movement
Left, right, down, up, and diagonal movement
On the main stage, select the MC you wish to make move
Add Actions:
onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
_x+=Key.isDown(Key.RIGHT)*speed;
_x-=Key.isDown(Key.LEFT)*speed;
_y+=Key.isDown(Key.DOWN)*speed;
_y-=Key.isDown(Key.UP)*speed;
}
Unfortunately, this one doesn't allow for changing the orientation (eg walking)... so
Left, right, down, up movement with orientation
Create a new MC with 4 frames.
On the first frame, add your character walking right.
On the second frame, add your character walking down.
Third frame, left. Fourth frame, up.
Put the MC on the stage and add these actions:
onClipEvent(load){
speed=10; stop();
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){_x+=speed; gotoAndStop(1);}
if (Key.isDown(Key.DOWN)){_y+=speed; gotoAndStop(2);}
if (Key.isDown(Key.LEFT)){_x-=speed; gotoAndStop(3);}
if (Key.isDown(Key.UP)){_y-=speed; gotoAndStop(1);}
}
---------------------------------
If you wish to use the WASD keys, the keycodes are:
WASD -- ARROWS -- A.KEYS
- (68) ------ (39) ------ (Key.RIGHT)
- (65) ------ (37) ------ (Key.LEFT)
- (87) ------ (38) ------ (Key.UP)
- (83) ------ (40) ------ (Key.DOWN)
Use them like this:
_x+=Key.isDown(39)
or
if (Key.isDown(39)){_x+=speed;}
Other useful ones:
SPACE -------- (32)
ALT ------------ (18)
ENTER -------- (13)
BACKSPACE --- (8)
SHIFT --------- (16)
Z --------------- (90)
X --------------- (88)
C -------------- (67)
Denvish.
My anti drug.
Sweet job man, I learned a few things myself.
I hope this and your many other text tutorials help all in need.
omg my saviour! i am the ultimate n00b wen it comes to AS but this will allow me to make a crude "game" to make my friends laugh =P
Basic side-scroller (walking) movement
The variable 'dir' just holds the direction in which the character is moving, so he knows which direction to face when stopped
onClipEvent(load){
speed=10; stop(); dir=0;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)){
_x+=speed; gotoAndStop(2); dir=0;
}else if (Key.isDown(Key.LEFT)){
_x-=speed; gotoAndStop(3); dir=1;
}else{
if (dir==0){
gotoAndStop(1);
}else{
gotoAndStop(4);
}
}
}
At 2/10/05 06:34 PM, Denvish wrote: Basic side-scroller (walking) movement
That snippet assumes that frame 1 is stationary facing right, frame 2 is moving right, frame 3 is moving left, frame 4 is stationary facing left. Don't ask why they're in that order... ;)
for(i=0;i<numPlats;i++){
if(this.hitTest(_root["plat"+i])){
this.jump = false;
}
}
This is a really basic multi-object hitTester. What it does is it goes through and checks to see if the hero is hitting plat0, plat1, plat2, etc. and stops the character's jump if he is touching the platform. All you have to do is put this on the hero mc's enterFrame handler, then rename ALL the platforms according to this pattern: plat0, plat1, plat2, plat3, plat4, plat5... Then, on the hero, create a numPlats variable and set it equal to the number of platforms on the stage.
Sorry guys, I n00bulated. The above code is an addition to the Side-Scroller tutorialette that Denvish wrote (2 posts up).
At 2/10/05 10:57 PM, Deathcon7 wrote: Sorry guys, I n00bulated.
lol @ n00bulation.
At 2/10/05 10:58 PM, -JParodox- wrote:At 2/10/05 10:57 PM, Deathcon7 wrote: Sorry guys, I n00bulated.lol @ n00bulation.
NO!
*Artery Clogs*
*Dies*
At 2/10/05 11:03 PM, Deathcon7 wrote: NO!
*Artery Clogs*
*Dies*
Heh. Thanks for the input me ol' china. I'm probably going to a jumping/gravity thread at some point, your snippet will probably suit that or the hitTest one better. But it's all good.
see now the thing is that if I put make it so the character attacks when the user clicks D it wont work, here is the code I put for the attack,Key Up being the attack key, but its not working
onClipEvent (enterFrame) {
if (Key.isDown(Key.UP)) {
_x += speed;
gotoAndStop(5);
}
if (Key.isDown(Key.RIGHT)) {
_x += speed;
gotoAndStop(2);
dir = 0;
} else if (Key.isDown(Key.LEFT)) {
_x -= speed;
gotoAndStop(3);
dir = 1;
} else {
if (dir == 0) {
gotoAndStop(1);
} else {
gotoAndStop(4);
}
}
}
any help
You are quite the useful man, my good mod Denvish. Thanks for this!
Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------
wot is teh code for n + b?
+ heres a chicken 4 all u chicken fans!
Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------
There is a tutorial similiar to this one in my forum,made by DEADSIM.At least threads can't die in my foeum :D
How do i make checkboard movement? like in the game frogger? so that rather than him moving smoothly he takes big movements at a time, but not right away, so even when holding down the arrow key, he doesnt keep moving super fast, it takes like a second between eahc move?
I don't know n and b by heart, but i know e is 69. Or is it 65? One of those, for sure.
wtfbbqhax
wots a and s, cos i need them 4 my new game
Decima: The Last Story of Vald has a Facebook page and a development blog. Give them a look!
------------------------------
how can i make my mouse extend only a certain radios around my guy???
aquaticmole.
you guys still don't help me, i need to create a singel button, that's all i need
please help me with it, and don't just give the code/script, but explain to me please
Thanks already, and very much if it works ;D
At 2/10/05 04:58 PM, Denvish wrote:
speed=10; stop();
What does speed=10; stop(); mean?
At 7/14/05 05:40 PM, DarkJeroyd2000 wrote:At 2/10/05 04:58 PM, Denvish wrote:speed=10; stop();What does speed=10; stop(); mean?
For "speed = 10;" , have a look at my Variables tutorial
At 2/10/05 06:03 PM, madmeater wrote: omg my saviour! i am the ultimate n00b wen it comes to AS but this will allow me to make a crude "game" to make my friends laugh =P
dam right