Sie sind auf Seite 1von 18

# Object

A thing

Variable

## Used to save info

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

## Make the code work

Only when ___ is true

Boolean

True or
False

First it tries
No
Then it tries
No
Otherwise

Operators

## Allow for better

If statements

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 find my position use:

self.pos.x and self.pos.y

## Find coins x and y

move to x, y

To pick me up use:
coin = self.findNearestItem()
x = coin.pos.x
y = coin.pos.y
self.moveXY(x, y)

## This will move you right forever.

X

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

## #Build a fence 5m above an enemy

Her y position is 4
My y position is 1
She is above me

## Counting with While

Make a variable
Loop
Say the number
Stop the loop at 5

1
2
3

4
5

Make a variable
Loop until 5
Say the number

Numbers

## A list or array starts counting at 0

The first item on the list is:
List

Numbers

Make a list
Set an Index Variable
Loop once for every item
Say the number

0
1
2

## The first time this is:

numbers
The second time it is:
numbers

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
Check variable value
Stop the loop
Say variable (5)

Checking by Type

## Lists and Arrays

apple
orange
banana

Coordinate System
The enemy is at:
2,3

X: 4
Y: 6

X: 2
Y: 3
X: 6
Y: 2

4,6

I am at:
6,2

## # makes a list of enemies without yaks

list.append(thing)
adds the thing to the list

## # sorts friends by type

# shortcut filtering

## If you want to know what I can do use:

Types
You will say my methods and properties

soldier

archer

thrower

witch

peasant

scout

brawler

librarian

ogre

warlock

ninja

captain

shaman

griffin-rider

peon

fangrider

sand-yak

yeti

knight

## Find Best Target

Find Closest (for)

## Comparing distance and value

Vectors
A describes a line segment starting from (0,0)
and going to (x,y).
Characters positions are expressed as vectors.

You can add 2 vectors together. This is
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

## Generally vectors are used to represent either a

point or a direction and magnitude (distance).
To make visualization easier, a vector
representing direction will be shown coming
from an object, rather than from origin.
# quick version

Vector(2,3)

## Always subtract end from start

Vector.subtract( end , start )
Vector(1,1)

## How to Run Away

Normalize
Basically, it takes a triangle and makes another
triangle of the same shape, but with a
hypotenuse of 1
normalized

## Always subtract end from start

Vector.subtract(end, start)

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