While Ogres Were Sleeping Discussion


#1

I like the concept of this level, but I have a couple of comments.

  1. I don’t like that I can only attack those with less than 10 health. It should be anyone that I can one-hit without veering from the path. (So a ranger with a powerful bow can take out more enemies.) Though you could scale the enemy health to counter this. Of course maybe this level is before the player knows about hero.attackDamage?

  2. This is a bigger deal. It seems dangerous to be using the global variable step the way it is in the program. I think the code could be changed to work based on the hero position instead couldn’t it?

hero.moveXY(hero.pos.x + 12, 8)


#2

Hi. Thank you for the feedback.

  1. This level should be simple, that’s why we chose the fixed value.

  2. Yeah, we had some discussions about the default code, but other alternatives were worse in our opinion.


#3

Newbie here. No code experience. I’m having a really hard time understanding how the code works to move the character using the code provided in this level. I understand perfectly what the code nemoyatpeace wrote above:

I’ve been trying to figure out what the code provided means for the past two days. Maybe I’m just being thick-headed and can’t see the forest through the trees but I simply can’t understand it. All I want to know is how the code, and in particular the mathematical equations for generating coordinates work to move the character. Sure, I can finish the level but I like to understand what I’m doing in order to learn. Right now I’m baffled.

step = 0

# This is how the hero moves around the level:
def moveHero(stage):
    if stage == 0:
        hero.moveXY(9 + step * 12, 8)
    elif stage == 1:
        hero.moveXY(68, 8 + (step - 5) * 10)
    elif stage == 2:
        hero.moveXY(68 - (step - 10) * 12, 58)
    return step + 1

Thanks.


#5

step here is a global variable. Below you can see the next line:

step = moveHero(1)

So for each step the function use the global (outside) value of the step and returns the increased value of it. Which one we reassign for the step. As the result step is increased after each call of the function and reassignment of step.


#6

P.S.: I’m going to rework that sample code, because global variable usage is not readable and I prefer to avoid them.