Академический Документы
Профессиональный Документы
Культура Документы
A thing
Variable
variable
Im an object!
self
Saving the result of a method
We are objects!
Im an object!
Method
Attached to an object
Does something
Argument
Goes in a method to
effect what it does
arguments
Object
Method
Attached by a
period
if /elif / else
Boolean
True or
False
First it tries
No
Then it tries
No
Otherwise
Operators
String
This is a String
So is this
Represent
Text
in If x < 10 / else
In if enemy
In the Loop
Nested Loops
The Grid
Find the coin
To pick me up use:
coin = self.findNearestItem()
x = coin.pos.x
y = coin.pos.y
self.moveXY(x, y)
Loop:
x = self.pos.x + 10
y = self.pos.y
self.moveXY(x, y)
Comparing Coordinates
To find my position use:
enemy.pos.x and enemy.pos.y
Her y position is 4
My y position is 1
She is above me
1
2
3
4
5
Make a variable
Loop until 5
Add 1 every loop
Say the number
Numbers[4]
Make a list
Set an Index Variable
Loop once for every item
Say the number
0
1
2
Make a list
Loop through each item in the list
Say the item
Picking Up 5 Flags
Set variable to 0
loop
Find and check flag
Get flag
Increment (add 1) to variable
Check variable value
Stop the loop
Say variable (5)
Checking by Type
apple
orange
banana
Coordinate System
The enemy is at:
2,3
X: 4
Y: 6
X: 2
Y: 3
X: 6
Y: 2
I am at:
6,2
list.append(thing)
adds the thing to the list
# shortcut filtering
Types
You will say my methods and properties
soldier
archer
thrower
witch
peasant
scout
brawler
librarian
paladin
ogre
warlock
ninja
headhunter
captain
shaman
griffin-rider
peon
fangrider
sand-yak
yeti
knight
Vectors
A describes a line segment starting from (0,0)
and going to (x,y).
Characters positions are expressed as vectors.
Addition
You can add 2 vectors together. This is
useful for moving your character,
among other things
Multiplication
You can multiply a vector by a number
to change its magnitude. Multiplying
by a negative number flips it to the
other side of (0,0)
Subtraction
Subtraction often used to find the
distance between 2 objects. Note that
you have to multiply the vector by -1 to
get it going in the correct direction. It is
often easier to remember just to
subtract from end to start.
Vectors
Finding Vectors
# longhand
Normalize
Basically, it takes a triangle and makes another
triangle of the same shape, but with a
hypotenuse of 1
normalized
Multiply
x5
Going Around
Find the vector representing direction to your destination and
normalize it
If the danger is too close:
Find the vector from the danger to you and normalize it
Add that vector to the direction to your destination
Add the new vector to your position to create a position
moveTo
safeMove
meToCoin
yakToMe