Beispiel #1
0
  void ExprCompiler::visit(IfExpr& expr, int dest)
  {
    // Compile the condition.
    compile(expr.condition(), dest);

    // Leave a space for the test and jump instruction.
    int jumpToElse = startJump(expr);

    // Compile the then arm.
    compile(expr.thenArm(), dest);

    // Leave a space for the then arm to jump over the else arm.
    int jumpPastElse = startJump(expr);

    // Compile the else arm.
    endJump(jumpToElse, OP_JUMP_IF_FALSE, dest);

    if (!expr.elseArm().isNull())
    {
      compile(expr.elseArm(), dest);
    }
    else
    {
      // A missing 'else' arm is implicitly 'nothing'.
      write(expr, OP_BUILT_IN, BUILT_IN_NOTHING, dest);
    }

    endJump(jumpPastElse, OP_JUMP, 1);
  }
Beispiel #2
0
  void ExprCompiler::visit(OrExpr& expr, int dest)
  {
    compile(expr.left(), dest);

    // Leave a space for the test and jump instruction.
    int jumpToEnd = startJump(expr);

    compile(expr.right(), dest);

    endJump(jumpToEnd, OP_JUMP_IF_TRUE, dest);
  }
Beispiel #3
0
  void ExprCompiler::visit(CatchExpr& expr, int dest)
  {
    // Register the catch handler.
    int enter = startJump(expr);

    // Compile the block body.
    compile(expr.body(), dest);

    // Complete the catch handler.
    write(expr, OP_EXIT_TRY);

    // Jump past it if an exception is not thrown.
    int jumpPastCatch = startJump(expr);

    endJump(enter, OP_ENTER_TRY);

    // TODO(bob): Can we use "dest" here or does it need to be a temp?
    // Write a pseudo-opcode so we know what slot to put the error in.
    write(expr, OP_MOVE, dest);

    compileMatch(expr.catches(), dest);

    endJump(jumpPastCatch, OP_JUMP, 1);
  }
Beispiel #4
0
void Koppa::Update() {
	if (minionState == 0) {
		updateXPos();
		if(jumpState == 0) {
			startJump(1);
		}
	} else if(minionState == 1) {
		updateXPos();
	} else if(minionState == 2) {
		updateXPos();
	} else if(minionState == -2) {
		Minion::minionDeathAnimation();
	} else if (minionState != 3 && SDL_GetTicks() - 500 >= (unsigned)deadTime) {
		minionState = -1;
	}
}
Beispiel #5
0
  void ExprCompiler::visit(ForExpr& expr, int dest)
  {
    // TODO(bob): Hackish. An actual intermediate representation would help
    // here.
    int iterateMethod = compiler_.findMethod(String::create("0:iterate"));
    ASSERT(iterateMethod != -1, "Should have 'iterate' method in core.");

    int advanceMethod = compiler_.findMethod(String::create("0:advance"));
    ASSERT(advanceMethod != -1, "Should have 'advance' method in core.");

    // Evaluate the iteratable expression.
    int iterator = makeTemp();
    compile(expr.iterator(), iterator);

    // Then call "iterate" on it to get an iterator.
    // TODO(bob): Hackish. An actual intermediate representation would help
    // here.
    write(expr, OP_CALL, iterateMethod, iterator, iterator);

    int loopStart = startJumpBack();

    // Call "advance" on the iterator.
    write(expr, OP_CALL, advanceMethod, iterator, dest);

    // If done, jump to exit.
    int doneSlot = makeTemp();
    write(expr, OP_BUILT_IN, BUILT_IN_DONE, doneSlot);
    write(expr, OP_EQUAL, dest, doneSlot, doneSlot);

    int loopExit = startJump(expr);
    releaseTemp(); // doneSlot.

    // Match on the loop pattern.
    compile(expr.pattern(), dest);

    // Compile the body.
    Loop loop(this);
    compile(expr.body(), dest);

    endJumpBack(expr, loopStart);
    endJump(loopExit, OP_JUMP_IF_TRUE, doneSlot);
    loop.end();
    
    releaseTemp(); // iterator.

    // TODO(bob): Need to figure out what the result value should be.
  }
Beispiel #6
0
  void ExprCompiler::visit(WhileExpr& expr, int dest)
  {
    int loopStart = startJumpBack();

    // Compile the condition.
    int condition = makeTemp();
    compile(expr.condition(), condition);
    int loopExit = startJump(expr);
    releaseTemp(); // condition

    Loop loop(this);
    compile(expr.body(), dest);

    endJumpBack(expr, loopStart);
    endJump(loopExit, OP_JUMP_IF_FALSE, condition);
    loop.end();
  }
Beispiel #7
0
  void ExprCompiler::compileMatch(const Array<MatchClause>& clauses, int dest)
  {
    Array<int> endJumps;

    // Compile each case.
    for (int i = 0; i < clauses.count(); i++)
    {
      const MatchClause& clause = clauses[i];
      bool lastPattern = i == clauses.count() - 1;

      // Compile the pattern (if there is one and it isn't the "else" case).
      PatternCompiler compiler(*this, !lastPattern);
      if (!clause.pattern().isNull())
      {
        clause.pattern()->accept(compiler, dest);
      }

      // Compile the body if the match succeeds.
      compile(clause.body(), dest);

      // Then jump past the other cases.
      if (!lastPattern)
      {
        endJumps.add(startJump(*clause.body()));

        // If this pattern fails, make it jump to the next case.
        compiler.endJumps();
      }
    }

    // Patch all the jumps now that we know where the end is.
    for (int i = 0; i < endJumps.count(); i++)
    {
      endJump(endJumps[i], OP_JUMP, 1);
    }
  }
Beispiel #8
0
 int ExprCompiler::startJump(const Expr& expr)
 {
   return startJump(expr.pos());
 }
void AvatarEntity::updateExternal(std::string message, float value)
{
	m_terrainPosition[0] = value;

	if(message == "idle#")
	{
		startIdle();
	}
	else if(message == "punch")
	{
		startPunch();
	}
	else if(message == "jab##")
	{
		startJab();
	}
	else if(message == "kick#")
	{
		startKick();
	}
	else if(message == "lower")
	{
		startLower();
	}
	else if(message == "loweS")
	{
		if(m_lowerSoundid != -1) stopSfxSound(m_lowerSoundid);
		startIdle();
	}
	else if(message == "move#")
	{
		startMove();
	}
	else if(message == "move-")
	{
		m_direction = -1;
	}
	else if(message == "move+")
	{
		m_direction = 1;
	}
	else if(message == "moveJ")
	{
		if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
		startJump();
	}
	else if(message == "moveS")
	{
		if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
		startIdle();
	}
	else if(message == "jump#")
	{
		startJump();
	}

	else if(message == "cover")
	{
		if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
		startDefense();
	}

}
void AvatarEntity::updateState()
{
	ActionManager::actions actions = Core::singleton().actionManager().getplayeractions(m_index);
	
	if (actions.up == false
		&& actions.defense == false
		&& actions.down == false
		&& actions.left == false
		&& actions.right == false
		&& actions.punch == false
		&& actions.kick == false
		&& actions.megapunch == false
		&& actions.up == false)
	{
		//si no hay accion debemos detener el movimiento 
		if(m_state == MOVE )
		{
			if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
			startIdle();
		}
		else if(m_state == DEFENSE)
		{
			startIdle();
		}
		else if(m_state == LOWER)
		{
			if(m_lowerSoundid != -1) stopSfxSound(m_lowerSoundid);
			startIdle();
		}
	}
	else
	{

		if(actions.punch == true && m_state == IDLE)
		{
			startPunch();
		}
		else if(actions.megapunch == true && m_state == IDLE)
		{
			startJab();
		}
		else if(actions.kick == true && m_state == IDLE)
		{
			startKick();
		}
		else if(actions.down == true && m_state == IDLE)
		{
			if(m_state != LOWER) startLower();
		}
		else if(actions.left == true && m_state!= JUMP && actions.up == false)
		{
			m_direction = -1;
			if(m_state == IDLE || m_state == DEFENSE) startMove();
		}
		else if(actions.right == true && m_state!= JUMP && actions.up == false)
		{
			m_direction = 1;
			if(m_state == IDLE || m_state == DEFENSE) startMove();
		}
		else if(actions.left == true && actions.up == true && (m_state == IDLE || m_state == MOVE))
		{
			m_direction = -1;
			if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
			startJump();
		}
		else if(actions.right == true && actions.up == true && (m_state == IDLE || m_state == MOVE))
		{
			m_direction = 1;
			if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
			startJump();
		}
		else if(actions.up == true && m_state == IDLE)
		{
			m_direction = 0;
			startJump();
		}

		else if(actions.defense == true && m_state == IDLE)
		{
			if(m_moveSoundid != -1) stopSfxSound(m_moveSoundid);
			startDefense();
		}
	}

	m_action = IDLE_ACT;
}
Beispiel #11
0
/*
 * This updates the planes offsets and frame
 *
 * @param input is used to check for player input
 * @param deltaTime is used to update the frame of the plane
 */
void Plane::update(Input* input, int deltaTime)
{

    //std::cout << "Delta is: " << deltaTime << std::endl;
    //If player press the space key then make the plane jump
    if (input->isKeyHit(SDLK_SPACE))
    {
        startJump();
    }

    //If plane is falling
    if (motion_ == MOTION_Falling)
    {
        setVelocityY(getVelocityY() + GRAVITY * (deltaTime/1000.0f));
        setOffsetY(getOffsetY() + getVelocityY());
        //Check if the plane has reach the bottom maximum bounds
        if (getOffsetY() >= SPRITE_MAX_BOTTOM)
        {
            setOffsetY(getOffsetY() - getVelocityY());

        }

    }

    //Else if plane is jumping
    else if (motion_ == MOTION_Jumping)
    {
        jump_.update(deltaTime);

        if (jump_.getJumpTimeRemaining() > 0)
        {
            //Set the velocity
            setVelocityY( getVelocityY() + JUMP_VELOCITY);
            setOffsetY(getOffsetY() - getVelocityY());

            //Check if the plane has reach the top maximum bounds
            if (getOffsetY() <= SPRITE_MAX_TOP) {
                setOffsetY(getOffsetY() + getVelocityY());
                //Stop jumping
                stopJump();
            }
        }
        //Max jump is reach
        else
        {

            stopJump();
        }
    }

    elapseTime_ += deltaTime;
    if (elapseTime_ > FPS)
    {
        frameCounter_++;
        if (frameCounter_ == 3)
        {
            frameCounter_ = 0;
        }
        elapseTime_ = 0;
    }

    //Update the puff cloud
    puffCloud_.setOffsetY(getOffsetY() + 10.0f);
    puffCloud_.update(deltaTime);

    //Shift the collision boxes
    shiftCollisionBoxes();
}