POLALA.COM
welcome to my space
X
Welcome to:polala.com
Search:  
 HOME   controlling arithmetic operators
controlling arithmetic operators
Published by: cfz 2010-03-15
  • Im currently working on a game for flash with some very complex movement.
    What I need to do is to change the direction the player moves when a certain key is pressed, making it the exact opposite of the direction the player would normally.
    Java Operators « IDYN Solutions::
    Nov 17, 2006 Introduction to Java Java ⠓ Conditional Flow Control → The operands with which arithmetic operators work must have numeric values.
    http://idynsolutions.wordpress.com/2006/11/17/java-operators/
    HOME

    Example :
    up arrow key moves the player forward, when the spacebar is hit the up arrow moves the player backwards.

    So this is the code im using to move the player MC :
    if (Key.isDown(Key.UP) ) {
    if (angle == 360) {
    this._y -=10;
    }
    }

    so what needs to happen is that this._y -=10; needs to become this._y +=10;. So i thought 'ill just use a variable!', first problem was that the decision to change the operator comes from a different timeline, solved that with a _global variable, but when I entered :

    this._y variable_name=10;

    it didnt like it so I tried :

    this._y [variable_name]=10;

    that seemed ok, but when I tested the movie the player just wouldn't move, I thought it may be to do with the fact that the variable_name was a string variable of either "-" or "+"

    I would just re-write the code with the different operator, would seem the logical thing to do and then just change the conditions, but because there are so many movement statements that need to be controlled it would be to much code and a variable is the only logical way to control it.

    anyone know what im doing wrong or if theres a specific way of representing operators?
    Bitwise Operator On GlobalSpec::
    Sep 1, 1997 Table of Contents Operator Precedence Arithmetic Operators Assignment Operators Bitwise Operators Comparison Operators Error Control
    http://www.globalspec.com/industrial-directory/bitwise_operator
    HOME

    (attached a demo of what im working on)


  • It would work fine but the thing is I have 36 if statements controlling the movement in comparision to the player angle, so your method would mean writing 36 else statements and leading to to much code.
    (the only reason I have 36 if statements is because I couldn't think of any mathematical calculation that would give me the movement for both X and Y in comparision to the angle of the player)
    So I need to replace + or - with a variable which can then be reversed in everystatement in one go :-/


  • + and - cannot be manipulated in that way. You will need to find some other solution, either through method handling (i.e. this.moveFoward(speed, isReversed)) or something like SeiferTim suggested... though my approach would be more like

    speed = 2;
    reverse = (Key.isDown(Key.SPACE)) ? -1 : 1;
    myHorzMvmnt = (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))*speed*reverse;


  • Why don't you use a boolean variable, like this:

    on (keyPress.SPACE) {
    _root.SpaceDown = TRUE;
    }

    on (keyUp.SPACE) {
    _root.SpaceDown = FALSE;
    }

    if (Key.isDown(Key.UP) ) {
    if (_root.SpaceDown) {
    if (angle == 360) {
    this._y -=10;
    }
    }else {
    if (angle == 360) {
    this._y +=10;
    }
    }
    }

    I tried to peice some of it together from the code you had... and my exact AS coding is a little rusty... but that's about the jist of it.





  • Where's The Advantage In Windows Genuine Advantage?
    Stocks Bounce After S&P Joins Bear Market
    You are looking at:polala.com's controlling arithmetic operators, click polala.com to home
    #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about controlling arithmetic operators , Please add it free.
  • pascal 039 s monkeys from monkeys and why are atheists here
  • do you consider scientology a cult
  • why are there atheists here
  • what is the effect of donating blood or blood loss on life span
  • why are atheists on here so into god so much
  • why are there atheists here on this forum
  • evolution is a theory and a farse
  • do you think capital punishment is good for society
  • why are atheists atheists here
  • aids or pregnency
  • why are there so many atheists at this site
  • christians why ask why atheists are here
  • why are there so many more people who get their accounts deleted or suspended on religion spirituality
  • why are the atheists here

  • do animals aside from humans laugh and what purpose does laughter serve in survival terms
  • why do some atheists on here assume they are more intelligent than christians in general
  • again why are atheists here
  • how many new unemployed globally next year during the usa post bush economic collapse depression
  • why are some atheists here using the bible to try and prove a point
  • what is the darkest shade of pink
  • why is scientology a religion and not a cult
  • why are atheists even here
  • if humans came from monkeys then why are christians still repeatedly asking why there are atheists here
  • why are the atheists here obsessed with christians
  • how much is the usa paying iraqis to stop killing the us troops allow them to stay in iraq for 3 more years
  • why do people push some people away or keep some people at a distance do they feel threatened
  • weird evolution question
  •  Homepage | Add to favorites | Contact us | Exchange links | LOGIN | Site map | 
    Copyright© 2008 polala.com        Site made:CFZ