PDA

View Full Version : Making a game like A.L.I.A.S.



drosa10
March 28th, 2005, 09:04 PM
I want to make a battle system just like the one in ALIAS (http://www.compfused.com/directlink/693/ (http://www.compfused.com/directlink/693/)). But how do I make it so that the gun aims where the mouse is, and how do make the screen scroll once I reace halfway across the screen? I understand everything else.

eiefai
March 28th, 2005, 10:07 PM
its a cool game, i like it very much

well, i think should be simply, you need some code to aim (some code to get the mouse position and rotation of your char weapon), code for firing (on mouse clic) and i think that's it, maybe i can show you a small example, just give time, i'll try to finish it tonight

eiefai
March 28th, 2005, 11:10 PM
well, here's the example, but has a little bug, when you fire you can only fire one bullet, i try to fix it later...

it moves it arrow keys, and fire with a clic

hope this help you

Lomadrian
March 28th, 2005, 11:31 PM
Here's a small code snippet I know works pretty well. It assumes that you have a gun movie clip named "gun_mc" pointing to the right with an empty movie clip at its tip named "tip" (inside the movie clip), and a bullet movie clip in your library with a linkage of "bullet" (this is with AS 2.0. If you want it in 1.0, just post your preference, and I'll rewrite it):


var bullet:Object = {counter:0, speed:10};
gun_mc.onMouseMove = function():Void {
updateAfterEvent();
var x:Number = _root._xmouse - this._x;
var y:Number = _root._ymouse - this._y;
var angle:Number = Math.atan2(y, x) * 180/Math.PI;
this._rotation = angle;
};
gun_mc.onMouseDown = function():Void {
bullet.counter++;
if (bullet.counter>100) { bullet.counter = 1; }
var name:String = "bullet_"+bullet.counter;
var point:Object = {x:this.tip._x, y:this.tip._y};
this.localToGlobal(point);
var bullet_mc:MovieClip = _root.attachMovie("bullet", name, bullet.counter, {_x:point.x, _y:point.y});
var angle:Number = this._rotation * Math.PI/180;
bullet_mc.xmov = Math.cos(angle)*bullet.speed;
bullet_mc.ymov = Math.sin(angle)*bullet.speed;
bullet_mc.onEnterFrame = function():Void {
this._x += this.xmov;
this._y += this.ymov;
if (this._x<0 || this._y<0 || this._x>Stage.width || this._y>Stage.height) {
this.removeMovieClip();
}
};
};
Mouse.addListener(gun_mc);


This code isn't really like A.L.I.S., but it does show how easy it can be to aim and shoot on a basic level.

drosa10
March 29th, 2005, 12:31 AM
I get it now! It uses what I learned in Algebra. Thanx guys!

drosa10
March 29th, 2005, 01:08 AM
New problem.(This is simular to my last question). My character has a sword in some levels. The arm and the sword rotate with the mouse so that it aims with the mouse. How do I make it so that it's swing power depends on how fast you swing the sword with the mouse?

Joppe
March 29th, 2005, 12:34 PM
Omg! thats exactly what im trying to make! , Thanks Thank you so much .. I owe you one ;)

drosa10
March 29th, 2005, 12:47 PM
Actuall, your blatent madness combat wannabe game is different then mine. In yours, you have to throw the weapon. In mine, you have to swing the weapon with a lot of force, but it is still in your arm.

Joppe
March 29th, 2005, 01:02 PM
you talking to me?

drosa10
March 29th, 2005, 01:46 PM
no, just the person named joppe

Joppe
March 29th, 2005, 02:04 PM
Im not trying to make an
blatent madness combat wannabe game
Im making an very original platform styled game with the possibility to shoot like in A.L.I.A.S And In Madness Combat .. And you cant throw anything in my game just Shoot! and change weapon and blow people up!

Lomadrian
March 29th, 2005, 06:13 PM
I'm not sure exactly how to do that, but I do know Madness Interactive has done something similar. You can download it here. (http://www.flecko.net/view.php?id=6)

drosa10
March 29th, 2005, 06:18 PM
wow this is not really helping at all. And Lomadrian, your link doesn't work.

Lomadrian
March 29th, 2005, 06:25 PM
I think you could use an onEnterFrame() method and an object array to store mouse positions. When a collision is detected, use the last few mouse positions in the array to figure out how fast it went, and how hard it should hit.

I'll try to come up with an example soon

Lomadrian
March 29th, 2005, 06:42 PM
OK, here's a small example I came up with:


var mousePositions:Array = [null, {x:_root._xmouse, y:_root._ymouse}];
_root.onEnterFrame = function():Void {
mousePositions[0] = mousePositions[1];
mousePositions[1] = {x:this._xmouse, y:this._ymouse};
if (collision) {
var prev:Object = mousePositions[0];
var curr:Object = mousePositions[1];
var xdist:Number = curr.x-prev.x;
var ydist:Number = curr.y-prev.y;
var vel:Number = Math.sqrt((xdist*xdist)+(ydist*ydist));
}
};


In this, the variable "collision" in the if statement is just what you use to test for collisions. So, if you apply your collision method, just insert that before the if statement.

As the onEnterFrame method refreshes, it adds the newest mouse positions in to the object at mousePositions[1], and moves the one that was in 1 to 0. These mouse positions are used in the calculations of the velocity, which is just the distance between these two mouse points.

Hope this helps!

drosa10
March 29th, 2005, 07:14 PM
how do I use this code?

squishy
March 30th, 2005, 10:56 AM
Im not trying to make an
Im making an very original platform styled game with the possibility to shoot like in A.L.I.A.S And In Madness Combat .. And you cant throw anything in my game just Shoot! and change weapon and blow people up! hint: no blood

Joppe
March 30th, 2005, 05:25 PM
hint: no blood
:P lol! :to: never blood in a funny fantasy land game :P

squishy
March 30th, 2005, 05:43 PM
good. bloody game = bad game :to:

Lomadrian
March 30th, 2005, 06:11 PM
OK, I made a small Flash file that does something close to what you're looking for. The only problem I'm having with it is the collision detection. I know there are frame-independant collision detection methods out there, but I'm not that good at it.

It has a small black ball as your weapon which follows the cursor, and when you hit the orange rectangle, it slides in the other direction.

Again, like I said, you have to move it kind of slowly because the collision detection stinks. I'll try to come up with a solution.

drosa10
March 30th, 2005, 10:13 PM
It's a great and useful .fla but I don't want the user to have a free movement weapon. The weapon has to only stay in one spot. It can only rotate. It rotates to follow the mouse. When it hits an object, the force of it is calculated by ow fast you swing the mouse/sword.

drosa10
March 30th, 2005, 10:29 PM
forget it. I think i get it now. All i need is help on how to keep the character in the center and make the screen scroll when he moves.

Lomadrian
March 30th, 2005, 10:36 PM
OK, sorry. I misunderstood what you meant.

I think the same concept would work, except you store the weapon's rotation, not its position. Check out this .fla.

Lomadrian
March 30th, 2005, 10:41 PM
For the scrolling thing, you can keep the character in one spot, just move the background movie clip. The problem with this is that it goes really slowly.

If you're doing a tile-based game with this, I would suggest checking out Tonypa's site. (http://www.tonypa.pri.ee/tbw/tut13.html)

If it's not tile-based, I'm afraid I can't help you much.

drosa10
March 31st, 2005, 02:08 PM
what about in a side-scroller?

Lomadrian
March 31st, 2005, 04:58 PM
Tonypa's tutorials work for side-scrolling too. You just change the way the character moves. The concept is exactly the same, though.

AdamZZ
June 15th, 2006, 05:16 PM
lomadrian can you put up an example fla of the first code snippet you posted her cause i cant make it work :S

AdamZZ
June 18th, 2006, 10:54 AM
ok it works perfect now :D