AS3 coder here?

    Share

    [KHK]Antumarin
    Real Spammer
    Real Spammer

    Posts : 417
    Join date : 2013-02-01
    Age : 23

    Diary of a shitty coder

    Post by [KHK]Antumarin on Mon Jul 01, 2013 11:30 pm

    Holy crap it feels so good figuring out how to solve a problem your teacher doesn't. Specially if you barely know what you're doing Laughing (yeah, I'm so happy I even used a goddamn smiley).

    Don't ask what it was. Let's just said it help me solve a problem that, otherwise, it would have taken me a damn lot of time to code.


    _________________
     
    avatar
    [KHK]Khalid
    Admin

    Posts : 464
    Join date : 2011-05-01

    Re: AS3 coder here?

    Post by [KHK]Khalid on Tue Jul 02, 2013 1:16 am

    Interesting.


    _________________


    P.S. I DO CBUG!!
    avatar
    [KHK]BlueBaron
    Real Spammer
    Real Spammer

    Posts : 230
    Join date : 2013-02-01
    Age : 20
    Location : Skopje,Macedonia

    Re: AS3 coder here?

    Post by [KHK]BlueBaron on Tue Jul 02, 2013 11:41 am

    Seems legit.


    _________________

    Don't click this
    Still want to click it? Very well,you have been warned!



    Current work:


    KHK Freeroam - 10%
    Discontinued

    [KHK]Antumarin
    Real Spammer
    Real Spammer

    Posts : 417
    Join date : 2013-02-01
    Age : 23

    Re: AS3 coder here?

    Post by [KHK]Antumarin on Wed Jul 03, 2013 12:22 am

    Wow, lack of trust. Am I really that bad?

    Well, here it is the code I modified:

    Code:
    var walls:Array = new Array;

    walls.push(drawRect(0xff0000,800,18,0.5));
    // I made a drawRect function to create the different collisions as sprites.
    walls[walls.length -1].x = 400;
    walls[walls.length -1].y = 9;
    stage.addChild(paredes[paredes.length -1]);

    (...)

    // After the moving lines (i.e.: if (left == true) {player.x -= playerSpeed}) I call to the function "colisiones".

    public function colisiones():void
          {
             for   (var i:int = 0 ; i < walls.length ; i++)
             {
                if (player.hitTestObject(walls[i]))
                {
                   player.x = playerLastFreeX;
                   player.y = playerLastFreeY;
                   break;
                }
             }
             
             for   (var e:int = 0 ; e < walls.length ; e++)
             {
                if (!player.hitTestObject(walls[e]))
                {
                   playerLastFreeX = player.x;
                   playerLastFreeY = player.y;
                }
             }
          }

    The original (the professor's) code was something like this (as far as I remember):

    Code:
    public function colisiones():void
          {
             for   (var i:int = 0 ; i == walls.length ; i++)
             {
                if (player.hitTestObject(walls[i]))
                {
                   player.x = playerLastFreeX;
                   player.y = playerLastFreeY;
                } else {
                if (!player.hitTestObject(walls[e]))
                {
                   playerLastFreeX = player.x;
                   playerLastFreeY = player.y;
                }
             }
          }

    That ended up only working with "walls[0]" and it always caused every other collision to fail.


    _________________
     
    avatar
    [KHK]Khalid
    Admin

    Posts : 464
    Join date : 2011-05-01

    Re: AS3 coder here?

    Post by [KHK]Khalid on Wed Jul 03, 2013 12:25 am

    I didn't mistrust you. And good job there, man.


    _________________


    P.S. I DO CBUG!!
    avatar
    [KHK]BlueBaron
    Real Spammer
    Real Spammer

    Posts : 230
    Join date : 2013-02-01
    Age : 20
    Location : Skopje,Macedonia

    Re: AS3 coder here?

    Post by [KHK]BlueBaron on Wed Jul 03, 2013 10:54 am

    Yeah definitely legit, you're off the case.


    _________________

    Don't click this
    Still want to click it? Very well,you have been warned!



    Current work:


    KHK Freeroam - 10%
    Discontinued

    [KHK]Antumarin
    Real Spammer
    Real Spammer

    Posts : 417
    Join date : 2013-02-01
    Age : 23

    Re: AS3 coder here?

    Post by [KHK]Antumarin on Mon Jul 08, 2013 12:03 am

    Nevermind it. Solved.


    Last edited by [KHK]Antumarin on Tue Jul 09, 2013 4:28 am; edited 1 time in total


    _________________
     
    avatar
    [KHK]Khalid
    Admin

    Posts : 464
    Join date : 2011-05-01

    Re: AS3 coder here?

    Post by [KHK]Khalid on Mon Jul 08, 2013 3:09 am

    This needs some explanation. What's the error of the first code? Where are code1 and code2 located? Usage of cantNotas?

    Oh and I don't know how length param works in pickUpArea.lenght, but I think the > gotta be < since you're starting from index ZERO.


    _________________


    P.S. I DO CBUG!!

    Sponsored content

    Re: AS3 coder here?

    Post by Sponsored content


      Current date/time is Fri Sep 21, 2018 10:37 am