A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Sniper Game

Hybrid View

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Location
    Afganistan(at the moment)
    Posts
    11

    Sniper Game

    YAY, my first thread.
    Alright, I'm making a sniper game. The problem I'm having is that I want the "target" (right now it's just a circle) to appear as if it is inside the window.
    So far I have it so you click on one of the two targets and it randomly places itself somewhere else. This kind of works but, the target can appear between windows and it is always the same size.
    What I want:

    If the target is in a small window(far away) it becomes smaller (x and y scale)
    If the target is in a medium window (closer) it’s medium sized (x and y scale)
    Ect.
    When the target is clicked it randomly moves to a different window.

    I’ve thought of making my windows MCs and doing this on hitTest and keeping the random placement but, then what happens if it hits two windows??
    I also thought this might be what an array is for. Then I read some tut’s and I’m not sure it would apply in this situation.
    Thanks for the help in advance.
    And if you think I should be using an array can you direct me to a good tutorial.

  2. #2
    my x booty it is that BIG
    Join Date
    Jun 2004
    Location
    New York
    Posts
    696
    for the target size problem once you checked what you window your targetMc is you set up a flag to true/false if it is true change the height/width of the mc to match the window mc.
    if targetMc location is on smallerW then...
    sm=true;
    if sm is true then
    targetMC._height=smallerW._height;
    targetMC._width=smallerW._width;
    and same thing for medium sized window
    Project||[GAME]-on hold for now
    ------------------
    [Hero]-80%
    [Enemies]-1%
    [Weapons]-90%
    [Items]-0%
    [Levels]-10%

  3. #3
    Junior Member
    Join Date
    Sep 2009
    Location
    Afganistan(at the moment)
    Posts
    11
    That works thanks, that's acutally better then doing x and y scale.
    But I still have the problem of how do I get my target to randomly pick a window to show up in?

  4. #4
    Senior Member bluemagica's Avatar
    Join Date
    Jun 2008
    Posts
    766
    lets use arrays:-

    winArr = [[10,10,.5],[100,10,2.5],[10,50,1]];

    Basically, that is a 2d array, with each row having 3 values, defining, x,y,and scale of the window..... and since there are 3 sets, we are passing data for 3 windows.

    In the target thingy, pick
    jumpTo = Math.floor(Math.random(winArr.length));
    this.x = winArr[jumpTo][0];
    this.y = winArr[jumpTo][1];
    this.scaleX = this.scaleY = winArr[jumpTo][2];

    you can also use height and width, but this is the basic idea!
    If you like me, add me to your friends list .

    PS: looking for spriters and graphics artists for a RPG and an Arcade fighting project. If you can help out, please pm me!

    My Arcade My Blog

    Add me on twitter:

  5. #5
    Junior Member
    Join Date
    Sep 2009
    Location
    Afganistan(at the moment)
    Posts
    11
    Thank you bluemagica.
    And actually last night I had a stroke of genius and came up with a way to make it work >< lol
    I just used switch. Seems like a dumb way of doing it but, it works. I have a case for each window (25 of them ><) I'm going to post the code as I have it, if you think a 2d array would be a better/more effective way to program this let me know.


    the registration point for my target is in the middle, for my windows it's at the bottom

    Code:
    function reset(sprite){
    resetpo=Math.ceil(Math.random() * 25);
    //random number 1 - 25
    //resetpo short for reset position
    sprite._xscale = 100;
    sprite._yscale = 100;
    //sets target back to normal size
    switch(resetpo){
    case 1:
    sprite._x = mw1._x;
    sprite._y = mw1._y - sprite._height/2
    //divide height by 2 and subtract form y so target sits on bottom ledge of window
    break;
    //mw1 = medium window 1
    //don't change x and y scale cause normal size fits medium window
    
    ect. for other medium windows...
    
    case 16:
    sprite._xscale = 150;
    sprite._yscale = 150;
    //change scale first or it offsets the target
    spirte._x = bw1._x;
    sprite._y = bw1._y - spirte._height/2;
    break;
    //bw1 = big window 1
    
    ect. for other big windows...
    
    case 22:
    sprite._xscale = 80;
    sprite._yscale = 80;
    sprite._x = sw1._x;
    sprite._y = sw1._y - spirte._height/2;
    break;
    //sw1 = small window 1
    
    ect. for other small windows...
    
    }//end switch
    }//end reset
    Last edited by MMJR; 09-24-2009 at 11:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center