Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/data/graphics/robots
blob: 71ca5539770f73f4d4ac6df855eea72695109246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from pippy.gasp import *  #import everything from pippy.gasp

class Robot:
    #A class used to store information about a robot
    pass


class Player:
    #A class used to store information about a player
    pass

def show_level(level_num):
    # shows what level is about to start
    level_text = Text("Level "+str(level_num),(screen_size()[0]/2-50,screen_size()[1]/2),size = 30)
    sleep(2)
    remove_from_screen(level_text)
  

def place_player(robots):
    #pick a point of the screen of the player
    player = Player
    player.x = random_between(0,screen_size()[0]/10-1)
    player.y = random_between(0,screen_size()[1]/10-1)
    #make sure the player is not placed directly on top of a robot
    while player_caught(player,robots):
        player.x = random_between(0,screen_size()[0]/10-1)
        player.y = random_between(0,screen_size()[1]/10-1)
    #put the player on the screen by creating a circle
    player.shape = Circle((10*player.x+5, 10*player.y+5), 5, filled=1)
    return player

def move_player(player,robots):
    #handles the movement of the player
    key = update_when("key_pressed") #waits untill a key is pressed and then returns that key as a string
    if "t" == key:
        #if "t" is pressed the player teleports
        remove_from_screen(player.shape)
        player = place_player(robots)
    #change the players x and y location
    if "q" == key:
        if player.x > 0 and player.y < screen_size()[1]/10-1:
            player.x -= 1
            player.y += 1
    if "w" == key:
        if player.y < screen_size()[1]/10-1:
            player.y += 1
    if "e" == key:
        if player.x < screen_size()[0]/10-1 and player.y < screen_size()[1]/10-1:
            player.x += 1
            player.y += 1
    if "d" == key:
        if player.x < screen_size()[0]/10-1:
            player.x += 1
    if "c" == key:
        if player.x < screen_size()[0]/10-1 and player.y > 0:
            player.x += 1
            player.y -= 1
    if "x" == key:
        if player.y > 0:
            player.y -= 1
    if "z" == key:
        if player.x > 0 and player.y > 0:
            player.x -= 1
            player.y -= 1
    if "a" == key:
        if player.x > 0:
            player.x -= 1
    # move the players shape on screen to the new location
    move_to(player.shape,(10*player.x+5,10*player.y+5))
    return player

def place_robots(num_robots):
    #create a certain number of robots defined by num_robots
    robots = []
    for i in range(num_robots):
        robot = Robot()
        robot.x = random_between(0,screen_size()[0]/10-1)
        robot.y = random_between(0,screen_size()[1]/10-1)
        robot.junk = False
        robot.shape = Box((10*robot.x,10*robot.y),10,10)
        robots.append(robot)
    return robots

def move_robots(robots, player):
    # move all the robots towards the player
    for robot in robots:
        if not robot.junk:
            if robot.x > player.x:
                robot.x -= 1
            if robot.x < player.x:
                robot.x += 1
            if robot.y > player.y:
                robot.y -= 1
            if robot.y < player.y:
                robot.y += 1
            move_to(robot.shape,(10*robot.x,10*robot.y))

def player_caught(player, robots):
    #check if the player is caught
    for robot in robots:
        if robot.x == player.x and robot.y == player.y:
            return True
    return False

def robot_crashed(robots):
    #check if any of the robots have crashed into each other
    for robot1 in robots:
        for robot2 in robots:
            if robot1.x == robot2.x and robot1.y == robot2.y and robot1!=robot2:
                if not robot1.junk:
                    robot1.junk = True
                    remove_from_screen(robot1.shape)
                    robot1.shape = Box((10*robot1.x,10*robot1.y),10,10,filled=True)

def alive_robots(robots):
    # returns True if all the robots are dead
    for robot in robots:
        if robot.junk == False: return False
    return True


begin_graphics()            #So that you can draw things
level = 1                   #the starting level
robot_num = 5               #the number of robots to place on screen
dead = False                #set dead to False
while not dead:             #run while the player is not dead
    clear_screen()          #clear the screen at the start of each level
    show_level(level)       #show what level is about to start
    robots = place_robots(robot_num)     #create the robots
    player = place_player(robots)        #create the player
    level_complete = False
    while not level_complete and not dead:    #run this level while the player is not dead and the level is not complete
        player = move_player(player, robots)  #move the player
        move_robots(robots, player)           #move all of the robots
        dead = player_caught(player,robots)   #check if the player had been caught
        robot_crashed(robots)                 #check if any of the robots have crashed
        level_complete = alive_robots(robots)   # check if there are any robots alive
    robot_num += 3           #increase the number of robots for the next level
    level+= 1                #increase the number level number by 1
print "you died on level " + str(level)
end_graphics()              # Finished!