Flash, Drag and select multiple characters in game - actionscript-3

I am learning to make games in Flash. I know I should probably use HTML5 or other platforms but let it be like this. I will learn those stuff later..
My question is like this, I want to select multiple characters in game. For example, I have 5 tanks. I want to drag-select them and move them to a point. How can I do that? Any mouseEvent or function for that? Moving them to a point is a different criteria I guess, but selecting a group of tanks. That's what I want to learn.
I am going to use Flixel game engine for this.
PSST! ~ If you guys don't want to help me, step by step by giving me exact code. I am fine! Just guide me in the right path and I will learn it myself.

First of all, do you know how to select one tank and move it where player clicked?
I'm not sure Is it an easy task for you. I'll give you some ideas about selection and how to detect it.
Bounds and Rectangles. Every tank has bounds represented as Rectangle, and by dragging your selection over tanks, you are forming also Rectangle. So you could check intersection of these rectangles
If you don't want to work with bounds, but with ready to use display object methods. By dragging Rectangle selection, you could form transparent shape, and check if it intersects with tanks This approach is slower than first.

Related

Actionscript 3 starling how to drag and only drop if it is over one of many squares

I am making a tower defense game for a class of mine. I decided to use starling with Flash and I am having a bit of trouble. Is there any was for me to specify that the towers can only be dropped into place if they are with in the bounds of a specific image/ in a 100px range of a specified center point? I would want to be able to store the points to be able to reference as I will have about 10-20 spots to place the towers. I feel like I might just be over thinking this.
Any help or guidance would be great.
Maybe you can try the hitTest method and add some dummies for locate the placing. If your hitTest method returns a dummy object you know that you are on a good place.
see Starling DisplayObject:hitTest();

Moving character on a specific stage Actionscript 3

I'm making a game with ActionScript 3.0. There's is one thing I can't figure out:
I have a big circle on the background. On this circle I want to let a character randomly move. But this character can only move on this circle, so it can't go to the background. Where do I need to start with this, how can i specify a specific stage like this?
P.S. I can't upload a picture yet, I've not enough "reputation points", otherwise I would have uploaded some pictures to get my question more clearly.
A general idea around which you can evolve is using hitTestPoint() method on your stage using current player's coordinates as the point being tested, and if this method returns false, this means the player has left the stage, and you need to put him back. Using previous location is the failsafe method, but you might also invent some other more smart way to do this.
The manual on hitTestPoint()

Actionscript 3 I need someon to help me with Collision Detecting(hiTestObject)

I will try to explain the issue as good as possible.
What I want to do is to check for collision between to objects. Also the bullet and the enemy, if it was 1 of the bullet and 1 of the enemy it would be no problem, but after one day on google and tryed like every solutions I can't get it to work, or I find a solution that's absolutely terrible explained.
Im going to make it easyer. I have MainClass.as that document class.
It's one class for the Enemy and one for the Bullet. As I hope everyone understand I wan't to check if the bullet hit's the Enemy. Or the other way. Since the bullet's are been made while clicking for example it is not possible to direct refere to the bullet. What I have tryed is using sprite container, it does work if i place the bullet on the enemy just to check, but if I place one under and on over that's NOT hit the Enemy it's still says that the enemy got hit.
Note, the Enemy are dragged on stage, since im going to have multiple of them. I could also add them with code. Ive tryed to use Array to shuffle between all the enemys but I can't get it to work.
I know this was much text. Hope someon are willing to help me out, it is so frustrating...
Best regards HFherasen!:):)
Well, if you don't use a physics engine, like Box2DFlash, it can be frustrating.
First, you have to know the speed/frame of the bullet, because if it goes beyond the target in one frame, simple detection won't work.
Than, you should have a velocity and direction of the bullet.. For simplicity, lets use one point of it. (the head of the bullet, or the middle)
The bullet usually moves a lot faster than the targets, so you can assume the targets fixed.
The target is a rectangle, or polygon possibly rotated.
Now you have a target, and a line for the bullet (from the point and direction).
http://keith-hair.net/blog/2008/08/04/find-intersection-point-of-two-lines-in-as3/
You can use this (converted to as3), with all sides of the target (or only the ones facing to a bullet), and if one matches, the shot will hit a target.
If your bullet is slower, you can have the position change of the frames as your first line. Than you'll know, when it hits a target. This is pretty fast, and works well. Hope it helped.

hitTestObject() collide somehow not working how it should

Or that's what I think, at least.
I just began with AS3 and I'm trying to do a little game where one ball moves on its own and the other one is handled by the player. So far, so good. That works.
What isn't working is hitTestObject(); it just returns true when it's like 2 cm from the other object. Here's a picture so you can see: http://dl.dropbox.com/u/37057843/coll2.jpg
I've read that hitTestObject just creats a rectangle around the objects and then tests for collisions on those rectangles, is it because of that?
If you need any piece of code I'll deliver. I know there are some other opensource libraries/engines like Box2D to solve this in a better way, but I don't want to jump to engines directly.
Thanks for reading!
Yes, hitTestObject will use the clips bounding box.
Check out this link, it has a lot of great information as well as a class that will do what you're looking for
http://sierakowski.eu/list-of-tips/39-collision-detection-methods-hittest-and-hittestobject-alternatives.html
Direct link to the package
http://code.google.com/p/collisiondetectionkit/

Representing a Monopoly board in flash?

I'm brand new to Flash (and game programming, really), but want to learn a bit of it. My overall learning project is to create a Monopoly clone in Flash. Unfortunately, I'm struggling to get over even my first hurdle - how to create the board graphically, and how then to deal with it in the code. So far, my thoughts are to break the board down into the different sizes of tiles (the normal property ones, the corner 4 and a large one for the middle section), then somehow place these all in the correct position relative to each other and keep that positioning correct as the pieces (and thus the camera view) move about the board. (And, hopefully some day have a zooming ability too...)
Is this a good approach, or is there a better one? Does anyone know where I can find a tutorial specifically on creating board games in Flash (any sort really, wouldn't have to be Monopoly but just a game that has a board which tokens move across - and preferably which has to pan as well).
Also, as an aside, is there any way to have a dynamically coloured rectangle in a flash MovieClip (like you can have dynamic textboxs)? I ask because it would be useful if there was, as I could generate every property tile with just one MovieClip which took a name, a value and a colour...
everything you describe here you can do pretty easily once you get the hang of component sprites. personally i would make a single sprite that will then hold all of the "tiles" in the game, this would allow you to "zoom" the board while keeping all the pieces relative:
if you create this parent to have an addTile() and getTile(index:int):Sprite method then you can easily push the tiles and retrieve them from an array, so that Go is at index 0, old kent road is at 1 etc. that way you can use a single integer value to determine the position of the player piece as you can then use getTile(int).x etc.
the position of the tiles themselves can be worked out relative to the others. if you have a tile that is 20px wide and 40px high then you can position the tile as x = index * 20 for the first row, after the initial 11, you need to rotate them all and then use the y index instead (rotation = 90; x = 11*20; y = (index-11)*20) this will depend exactly on your origin point of your Sprite.
to draw coloured boxes you use the graphics of the Sprite, there are plenty of tuts on API drawing out there, but here is a basic box of 10x10px:
var drawing:Sprite = new Sprite();
drawing.graphics.beginFill(0x0000FF);
drawing.graphics.drawRect(0, 0, 10, 10);
drawing.graphics.endFill();
Another approach to your question could be to learn about Object Oriented Programming. That may not solve your representing the board graphically straight away, but it would definitely help you structure your game.
With OOP, you could define a "Property" Class with a set of properties such as streetName , color , price etc... I haven't played Monopoly in a while but you can get the general idea, i.e. to create a base object and make it specific by setting the object's properties. Your question about the colored rectangle can actually apply to other properties, a great way to avoid unnecessary repetition.
Broadly speaking OOP tends to emulate real life situations, so you could actually look at your Monopoly game, break it into its various parts, find common properties etc... I won't start a lesson here :) I'd be pretty bad at it, but there's plenty of resources out there . Look for OOP, Design Patterns & Actionscript3.
After a little research, you may find that your question about how to handle graphics may not be such a problem after all.
Your questions are way too general. I'm sure you don't want us to walk you through your whole project right?
Now to gain some experience, I suggest to you simply work through a few flash gaming tutorials. There are a LOT of those, I googled for 2-3 seconds and found this:
http://pelfusion.com/tutorials/35-flash-game-development-tutorials-fla-files/
I'm sure you feel disappointed by this answer, but this is the first step in solving your own problems. The internet has more than enough general game tutorials already. If you have specific problems, we might be of better help to you.
I assume with dynamically colored rectangles, you mean simply changing the color during runtime. Well you simply give the rectangle a name, and change the color property of it in code. Like this: rectangle.Color = Something.
You might want to start out with a simpler project just to learn some of the basics, maybe a little game where the player has to move a rectangle from one side of the screen to the other using the arrow keys or mouse, upon which a score is incremented or something. This will help teach you how the coordinate system works, among other things.
To draw stuff using code, you can create a new Sprite or MovieClip object and use its graphics property to draw primitive shapes (rectangles, etc.) to it at runtime.