View Full Version : Metal Slug Game
amps7
February 26th, 2005, 06:56 PM
Hey,im making a metal slug type game nd am progressing well.The problem is in metal Slug you can shoot the enemy normally but when you get close to him and press the shoot button,you can use your knife to kill the enemy.
What i need to know is how to code this in flash mx.:q:
icio
February 26th, 2005, 07:02 PM
test the distance between the characters, and then a simple if test to see if the shooting character is close enough to use the knife. if so - then play a certain animation.
and take life off of the enemy as required.
hope this helps :thumb:
Rossman
February 26th, 2005, 07:03 PM
Can you just determine the distance (in pixels) between the players character and the enemy and perform a different attack if a threshold is crossed?
amps7
February 26th, 2005, 07:05 PM
wat would the code be to do this and how would u determine the distance?
Marz
February 26th, 2005, 07:15 PM
Check out the thread Artificial Intelligence II There is a tutorial on distance a.i. :)
http://www.kirupa.com/forum/showthread.php?t=83904
amps7
February 26th, 2005, 07:19 PM
so once you know the distance,the code would be something like:
if x>whatever
_root.character.gotoandPlay(knifeanimation)?
alzor
February 26th, 2005, 07:29 PM
alter the 15 to adjust the distance to stab or shoot...
onClipEvent (enterFrame){
stab=0
if (_root.enemy._x>_root.player._x+15|_root.enemy._x<_root.player._x-15){ //if the enemy is more than 15 pxls away on either side
stab=0;
}else{
//opposite of above
stab=1;
}
if (stab==1){
// stabbing code
}
if (stab==0){
//shooting code
}
**update---the last code I gave you didnt make any sense sorry!I think this'll clear up that mistake.
amps7
February 26th, 2005, 07:31 PM
ok,il try it out.
thanx alzor :D
alzor
February 26th, 2005, 07:35 PM
no problem dude... think in variables from now on, because I cant name the amount of times I thought measuring something or doing something was impossible and I figured that by setting up variables I can control almost anything. let me know if it helped or not.
amps7
February 27th, 2005, 08:17 AM
Ive almost got it to work,just a wee problem.The full stabbing animation doesnt play when he gets close,only the start of it and it still shoots the projectile :-/
icio
February 27th, 2005, 09:07 AM
onClipEvent (enterFrame){
stab=0
x = _root.player._x - _root.enemy._x;
y = _root.player._y - _root.enemy._y;
distance = Math.sqrt(y*y + x*x);
rdir = x < 0 ? "left" : "right";
if (distance <= 15 && direction == rdir) { //check that he's close enough and facing the right way
//stab
} else {
//shoot
}
}
that should be more like it, i think.
in this code, you need to have a variable set up that stores the direction that the player is facing.
direction = "left" for example
hope this helps :thumb:
amps7
February 27th, 2005, 09:29 AM
:*( ok..somethings gone wrong with the code.The characters animations are all mixed up..heres the code:
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN)) {
this.gotoAndPlay(10)
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.DOWN) && Key.isDown(Key.RIGHT)) {
_x -= -5;
this.gotoAndPlay(10)
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.RIGHT) {
this.gotoAndPlay(1)
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
_x -= 5;
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.DOWN) {
this.gotoAndPlay(1)
}
}
onClipEvent (keyUp) {
if (Key.getCode() == Key.CONTROL) {
this.gotoAndPlay(1)
}
}
onClipEvent (load) {
fall = false;
_name = "marco";
jump = 0;
speed = 9;
jumpheight = 12;
maxfall = -20;
}
onClipEvent (enterFrame) {
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (Key.isDown(Key.SPACE) && fall == false && jump == undefined) {
this.gotoAndPlay(8)
fall = true;
jump = jumpheight;
}
if (jump<>undefined) {
if (jump>maxfall) {
jump--;
}
_y -= jump;
}
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.RIGHT)) {
_x -= -5;
this.gotoAndPlay(5)
}
}
onClipEvent (load) {
moveSpeed = 10;
_root.laser._visible = false;
laserCounter = 1;
}
onClipEvent (enterFrame){
if (Key.isDown(Key.CONTROL)) {
this.gotoAndPlay(2)
laserCounter++;
_root.laser.duplicateMovieClip("laser"+laserCounter, laserCounter);
_root["laser"+laserCounter]._visible = true;
}
}
onClipEvent (enterFrame){
stab=0
x = _root.marco._x - _root.ENEMY1._x;
y = _root.marco._y - _root.ENEMY1._y;
distance = Math.sqrt(y*y + x*x);
rdir = x < 0 ? "left" : "right";
if (distance <= 5 && direction == rdir) { //check that he's close enough and facing the right way
this.gotoAndPlay(12)
} else {
this.gotoAndPlay(2)
}
}
ar
February 27th, 2005, 10:30 AM
Hold on. I'll post a good, not that confusing code for you.
!GB! - PEACE -
amps7
March 1st, 2005, 01:00 PM
can any1 give me or teach me a code that would suite this?
icio
March 1st, 2005, 01:10 PM
coudl you post your fla ?
amps7
March 1st, 2005, 01:22 PM
Ok,but one problem...how???:puzzled:
JoMan
March 1st, 2005, 02:04 PM
When you post a reply(or edit your post), down below, there should be a panel that says "Manage Attachments". Ust those options to attach .fla's and other things.
kanpai
alzor
March 1st, 2005, 04:42 PM
sorry I didnt help you amps!
amps7
March 1st, 2005, 06:39 PM
:smirk: thanks,joMan.
Alzor you did help me!!!.(soz i didnt see ur update on ur code until now) When i tried the updated code it worked perfectly so thank you!.
Thanks to Cyberathlete and eternalstudios aswell for helping me.:beam:
amps7
March 1st, 2005, 06:47 PM
alzar,im working on gettin a tank (that has seperate controls) that the hero is able to jump into,i think i know how to do this but can i ask you if i have any problems? (or any1 else who is good at actionscript :})
ar
March 1st, 2005, 06:53 PM
so amp, you have all the codings down, and the guy can run around and shoot stuff? is metal slug the extremly fast paced shooter? I'm trying to make a game like that, but with a chicken. I can get the movement down, but the shooting is going to be a problem, do you think you can attach your fla so I can see how it's done right?
you don't need to thank me. I started writing the code for you, but had to go somewhere. well, thanks anyway
!GB! - PEACE -
amps7
March 2nd, 2005, 02:48 PM
ive got the basic movements with all the sprites i have at the moment (right side movment such as running,jumping,ducking,slashing and shooting).Metal slug isnt an extremely fast paced shooter but it has some of the coolest animations you'll see in a 2d scroller.problem tho with posting the fla,its too big and the server wont let me upload it.:upset:
Lord Rahl
March 2nd, 2005, 04:04 PM
Compress it to a zip folder. I am kindda interested in seeing this. Metal Slug is probally one of my favorite side scrollers. (With a few exceptions)
ar
March 2nd, 2005, 06:31 PM
you could export to swf, and not put any security on it, and you could just import it to flash and basically treat is an fla
nih
March 2nd, 2005, 09:50 PM
Once you get this working, switch from comparing the _x parameter to working out the actual distance using trig. Pretty simple, and someone can post an example when you're ready. This will help ensure the enemy is on the same plane (or thereabouts) as well.
amps7
March 3rd, 2005, 12:58 PM
em..i tried zipping it but its still too big,so i'll start a website and upload it if u want it
mixedtrigeno
March 3rd, 2005, 01:32 PM
wow now i see what my friend was talking about when i wrote my first game and he said that the code was too messy...:puzzled: lol i was trying to rewrite your code with only 2 onclipevents wich should easy to do but i couldnt understand your code to be able to do that...
this is how far i got on it
onClipEvent (load) {
fall= 0;
_name=marco;
jump=0;
speed=9;
jumpHeight=12;
maxfall=-20;
moveSpeed=10;
laser=_root.laser._visible;
laserCounter=1;
}
onCLipEvent(enterFrame) {
if (Key.isDown(Key.DOWN)) {
this.gotoAndPlay(10);
}else if (key.isDown(Key.RIGHT)) {
_x-=5;
this.gotoAndPlay(5);
}else if (Key,isDown(Key.LEFT)) {
_x+=5;
}else if (
for your reference you can get rid of all the onclipevents and use nested "else if" statements
HEY I TRIED SORRY
amps7
March 6th, 2005, 03:39 PM
Rite,im going to post the .fla soon on the site im building but in the mean time i need help controlling the amount of bullets that come out of my character or some kind of delay?
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.