Download presentation
Presentation is loading. Please wait.
1
Code Combat
2
The Sarven Desert We made it to the next world! Wahoo!
3
1: The Mighty Sand Yak
4
1: The Mighty Sand Yak
5
1: The Mighty Sand Yak We will use the Sense Stone again
6
1: The Mighty Sand Yak By adding 10 to your x position, you are moving right along the x axis
7
1: The Mighty Sand Yak These lines set the x, y values which we will move to. Our x value is set to our current x value plus 10. This means we will move to right by 10 units. Note that y is set to our current y value. This essentially means we won’t move up or down.
8
1: The Mighty Sand Yak This is the line that will actually move our hero. The hero will move to the x, y coordinates we set in the lines above.
9
1: The Mighty Sand Yak
10
1: The Mighty Sand Yak ** **Don’t forget to establish a variable for yak!**
11
2: Oasis
12
2: Oasis The ask for this is pretty straightforward - can you use pos.x and pos.y?
13
2: Oasis NOTE: the and operator
14
Review: Boolean Logic True/False logic
Used in conditional expressions, as in: If a condition is true, do this
15
Boolean Operators You can combine conditions using the fundamental operators And, Or and Not Different rules determine what the combined conditions will evaluate to - either True or False
16
Boolean Operators And Operator Or Operator Not Operator and or not
17
Review: If statements If statements operate off of Boolean Logic.
An if statement will run a sequence of code only if a condition is true With and/or operators, the sequence will be run based on the boolean values of both conditions
18
And Operator condition1 and condition2 == Boolean Value
An expression that uses an and operator will evaluate to a boolean value based on the boolean values of each condition within the expression
19
And Operator True and True == True True and False == False
False and True == False False and False == False If one or more condition within an and expression is false, the entire expression evaluates to false
20
Or Operator condition1 or condition2 == Boolean Value
An expression that uses an or operator will evaluate to a boolean value based on the boolean values of each condition within the expression
21
Or Operator True or True == True True or False == True
False or True == True False or False == False If one or more condition within an and expression is true, the entire expression evaluates to true
22
And Operator condition1 and condition2 == Boolean Value
A not operator works a little differently. Not operators take one condition and evaluate to the opposite of that condition.
23
Not Operator not True == False not False == True
24
2: Oasis So the code sequence for this if statement will run if and only if both there is an enemy and the distance to that enemy is less than 10 Take a moment to explain why this won’t work
25
2: Oasis
26
2: Oasis Reminder: By subtracting 10 from your x position, you are moving left along the x axis
27
2: Oasis This might seem like the simplest solution - define x and y for each situation and move. However this is not the best solution! Take a moment to explain why this won’t work
28
2: Oasis This code is better. Less lines == more efficient
The variables are established before the loop. The loop then starts with a move and then reassigns x according to your hero’s current situation.
29
2: Oasis NOTE: += means add following to current value,
-= means subtract following from current value
30
2: Oasis
31
3: Sarven Road
32
3: Sarven Road
33
3: Sarven Road Reminder: the and operator
Note: You could also define x and y before loop and use the ++ or += operators
34
3: Sarven Road Note: You could also define x and y before loop and use the ++ or += operators
35
4: Thunderhooves
36
4: Thunderhooves
37
4: Thunderhooves
38
4: Thunderhooves
39
4: Thunderhooves
40
4: Thunderhooves
41
4: Thunderhooves
42
5: Medical Attention
43
5: Medical Attention
44
5: Medical Attention
45
5: Medical Attention
46
5: Medical Attention This is my first try - pretty basic code we have seen before. Check first that your health isn’t too low, then sequence through cleaving and bashing
47
No luck! As the level warns, you’ll need to “fight hard”
5: Medical Attention No luck! As the level warns, you’ll need to “fight hard”
48
I found a shield that adds a “bash” attack - let’s give that a try!
5: Medical Attention I found a shield that adds a “bash” attack - let’s give that a try!
49
5: Medical Attention Depending on how many coins you have, there are a multitude of helpful items you can try on your own! Feel free to branch out or try something different after you go ahead with the shield code.
50
Now let’s add bash in before attack
5: Medical Attention Now let’s add bash in before attack
51
With this additional code, we have success!
5: Medical Attention With this additional code, we have success!
52
Interested in Dueling?
53
Navigate Back... Head back to the forest and find the Dueling Grounds “level”
54
Duel This is a practice on what it will be like to attack one-on-one against other competitors
55
Duel Here is the code you start with. You can fill it with some of the attack lines we have used previously. But what if you leave the loop out?
56
Duel This is our basic nested if statement attack code.
However without the loop, this if/else if/else sequence will only be run once
57
How are you going to get the upper hand? Buy new stuff! Try lines out!
Duel Here is my final code - but remember, as the duels continue, you will be designing your own code. How are you going to get the upper hand? Buy new stuff! Try lines out!
58
Duel After you win, click Rank My Game
59
Duel
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.