Exemplo n.º 1
0
 def check_for_win(self):
     for i in range(M):
         for j in range(N):
             if grid[i][j].color == Color.WHITE:
                 return
     print("You win!")
     Scheduler.wait(2, window.close)
Exemplo n.º 2
0
 def on_create(self):
     self.scale = 3
     self.layer = 5
     self.image = "bomb.gif"
     self.power = 1
     Scheduler.wait(1, self.explosion)
     Scheduler.wait(1, self.delete)
Exemplo n.º 3
0
 def test_win(self):
     for i in range(M):
         for j in range(N):
             if grid0[i][j].color == Color.AZURE:
                 return
     print("YOU WIN! huh!")
     Scheduler.wait(2, w.close)
Exemplo n.º 4
0
def map(dt):
    global count
    i = randint(0, M - 1)
    j = randint(0, N - 1)
    grid[i][j].toggle_neighbors()
    count += 1
    if count > 4:
        Scheduler.cancel_update(map)
Exemplo n.º 5
0
def ran(dt):
    global c
    i = randint(0, M - 1)
    j = randint(0, N - 1)
    grid0[i][j].toggle_neghbor()
    c += 1
    if c > 9:
        Scheduler.cancel_update(ran)
Exemplo n.º 6
0
        self.delete()
        self.label.delete()

    def on_left_click(self):
        if state == GameMode.Noun and self.label.text in nouns:
            self.process_click(1)
        elif state == GameMode.Verb and self.label.text in verbs:
            self.process_click(1)
        elif state == GameMode.Adjective and self.label.text in adjectives:
            self.process_click(1)
        else:
            self.process_click(-1)


def change_to_random_state():
    global state
    state = random.choice([GameMode.Noun, GameMode.Verb, GameMode.Adjective])
    goal_label.text = str(state)


Scheduler.update(change_to_random_state, 5)


def make_a_word():
    window.create_sprite(Word)


Scheduler.update(make_a_word, 1)

window.run()
Exemplo n.º 7
0
class Pipe(Sprite):
    def on_create(self):
        self.add_tag("piper")
        self.image = "pipe.png"
        self.scale = 0.65
        self.x = w.width + self.width / 2

    def on_update(self, dt):
        self.x -= 4
        if self.x < -self.width / 2:
            self.delete()


def create_pipe01(dt):
    dpipe = w.create_sprite(Pipe)
    upipe = w.create_sprite(Pipe)
    xy = random.randint(-int(dpipe.width / 2), int(dpipe.width / 2))
    upipe.rotation = 180
    upipe.y = w.height
    dpipe.y += xy
    upipe.y += xy
    gapxy = random.randint(-50, 50)
    dpipe.y -= gapxy
    upipe.y += gapxy


Scheduler.update(create_pipe01, delay=1.6)

bird = w.create_sprite(Bird)

w.run()
Exemplo n.º 8
0
    
        def on_create(self):
            self.image = '1.png'
            self.scale = 0.4
            self.x = 500
            self.y = 50
            self.is_on_ground = True

        def on_update(self, dt):
            if not self.is_on_ground:
                self.y += 10
                if self.y > window.height:
                    self.delete()
                if self.is_touching_sprite(ufo):
                    self.delete()
        
        def on_left_click(self):
            self.is_on_ground = False



def my_custom_update(dt):
    s3 = window.create_sprite(Alien)
    s3.x = random.randint(0, window.width)



Scheduler.update(my_custom_update, delay=2)

ufo = window.create_sprite(UFO)
window.run()
Exemplo n.º 9
0
        self.add_tag('block')

    def on_update(self, dt):
        if game_manager.timer > 5:
            self.y += 3
            if self.touching_window_edge():
                self.delete()


def spawn_blocks():
    if game_manager.timer > 5:
        window.create_sprite(Block)
        window.create_sprite(Block)


Scheduler.update(spawn_blocks, delay=1)


class SecondPlayer(Sprite):
    def on_create(self):
        self.image = 'nano.png'
        self.x = 300
        self.y = 265
        self.scale = 0.35
        self.x_speed = 10
        self.is_on_block = False
        self.y_speed = 0
        self.add_tag('p2')

    def on_update(self, dt):
        if game_manager.timer > 5:
Exemplo n.º 10
0
class Score(Label):
    def on_create(self):
        self.y = w.height
        self.x = w.width / 2
        self.current = 0
        self.highscore = int(self.read_high_score())
        self.text = "High Score:" + self.read_high_score()

    def read_high_score(self):
        file_4 = os.path.dirname(__file__) + "/score.txt"
        return str(get_words(file_4)[0])


def work1(dt):
    word = w.create_sprite(Word)
    word.setup(random.randint(0, w.width), w.height, random.choice(all))


Scheduler.update(work1, delay=1)


def change_state(dt):
    global current_state
    current_state = random.choice(states)
    state_label.text = str(current_state)


Scheduler.update(change_state, delay=10)

score = w.create_label(Score)
w.run()
Exemplo n.º 11
0
                if grid0[i][j].color == Color.AZURE:
                    return
        print("YOU WIN! huh!")
        Scheduler.wait(2, w.close)


grid0 = [[w.create_sprite(Cell0) for j in range(N)] for i in range(M)]

x0 = y0 = CELL_SIZE / 2

for i in range(M):
    for j in range(N):
        grid0[i][j].x = x0 + j * CELL_SIZE
        grid0[i][j].y = y0 + i * CELL_SIZE
        grid0[i][j].grid_ij(i, j)
c = 0


def ran(dt):
    global c
    i = randint(0, M - 1)
    j = randint(0, N - 1)
    grid0[i][j].toggle_neghbor()
    c += 1
    if c > 9:
        Scheduler.cancel_update(ran)


Scheduler.update(ran, delay=0.1)

w.run()
Exemplo n.º 12
0
class Pipe(Sprite):
    def on_create(self):
        self.image = "pipe.png"
        self.x = w.width + self.width / 2

    def on_update(self, dt):
        self.x -= 2
        if self.x < -self.width / 2:
            self.delete()


class Score(Label):
    def on_create(self):
        self.text = "Score:"


def make_pipe(dt):
    buttom_pipe = w.create_sprite(Pipe)
    top_pipe = w.create_sprite(Pipe)
    a = int(buttom_pipe.height / 2)
    offset = random.randint(-a, a)
    buttom_pipe.y += offset
    top_pipe.y = w.height + offset
    top_pipe.rotation += 180


Scheduler.update(make_pipe, 5)
w.create_label(Score)
w.create_sprite(Player)
w.run()
Exemplo n.º 13
0
    ANIMSLS = 1
    WEAPONS = 2


state = [State.ELEMENT, State.ANIMSLS, State.WEAPONS]
nstate = State.ELEMENT


def cstate():
    global nstate
    n = choice(state)
    nstate = n
    lstate.text = (str(nstate))


Scheduler.update(cstate, delay=4)


class Tword(Sprite):

    score = 0

    def on_create(self):
        self.lw = w.create_label()
        self.lw.color = Color.random_rgb()
        self.lw.font_size = 40
        self.lw.font = "Comic Sans MS"
        self.color = Color.random_rgb()
        self.score = 0

    def sposition(self, text, x, y):
Exemplo n.º 14
0
    SPORTS = 0
    CARS = 1
    ANIMALS = 2


states = [State.SPORTS, State.CARS, State.ANIMALS]
current_state = choice(states)


def change_state():
    global current_state
    current_state = choice(states)
    print(current_state)


Scheduler.update(change_state, delay=3)


class Word(Sprite):
    point = 0

    def on_create(self):
        self.label = w.create_label()
        self.label.font_size = 40
        self.label.color = Color.WHITE
        self.color = Color.random_rgb()
        self.image = 'block.png'

    def background(self, text, x, y):
        self.label.text = text
        self.height = self.label.content_height
Exemplo n.º 15
0
    def on_create(self):
        self.image = "pipe.png"
        self.scale = 0.7
        self.x = window.width + self.width/2

    def on_update(self, dt):
        self.x -= 4
        if self.x < -self.width/2:
            self.delete()
        
def makes_pipe ():
    bottom_pipe = window.create_sprite(Pipe)
    top_pipe = window.create_sprite(Pipe)
    top_pipe.y = window.height
    top_pipe.rotation += 180
    a = int(bottom_pipe.height/2)
    offset = random.randint(-a,a)
    bottom_pipe.y += offset
    top_pipe.y += offset                     


class Score(Label):
    def on_create(self):
       self.text = "score"
    

Scheduler.update(makes_pipe ,1.6)
window.create_sprite(Pipe)
window.create_label(Score)

window.run()
Exemplo n.º 16
0
 def on_create(self):
     self.layer = 5
     self.image = "explosion_gifs/center.gif"
     self.add_tag("explosion")
     Scheduler.wait(1, self.delete)
Exemplo n.º 17
0
                    return
        print("You win!")
        Scheduler.wait(2, window.close)


grid = [[window.create_sprite(Cell) for j in range(N)] for i in range(M)]

x0 = y0 = CELL_SIZE / 2

for i in range(M):
    for j in range(N):
        grid[i][j].x = x0 + j * CELL_SIZE
        grid[i][j].y = y0 + i * CELL_SIZE
        grid[i][j].set_ij(i, j)

count = 0


def map(dt):
    global count
    i = randint(0, M - 1)
    j = randint(0, N - 1)
    grid[i][j].toggle_neighbors()
    count += 1
    if count > 4:
        Scheduler.cancel_update(map)


Scheduler.update(map, delay=0.1)

window.run()
Exemplo n.º 18
0
            self.time = 0
            b = window.create_sprite(Enemy_Bullet)
            b.position = self.position
        self.move_forward(self.speed)
        if self.touching_window_edge():
            self.delete()
        if self.touching_any_sprite_with_tag('Bullet'):
            self.delete()
        self.time += 1


def spawn_enemy(dt):
    window.create_sprite(Enemy)


Scheduler.update(spawn_enemy, delay=2)


class Enemy_Bullet(Sprite):
    def on_create(self):
        self.color = Color.VIOLET
        self.scale = 15
        self.speed = 10
        self.add_tag("Enemy_Bullet")

    def on_update(self, dt):
        self.point_toward_sprite(player)
        self.move_forward(self.speed)
        if self.touching_window_edge():
            self.delete()
        if self.touching_any_sprite_with_tag("player"):
Exemplo n.º 19
0
        elif self.touching_any_sprite_with_tag("bb"):
                self.delete()
        elif self.touching_any_sprite_with_tag('aa'):
                self.delete()
                player.health -= 1 
                scllabel.text = "HEALTH: " +str(player.health)


sclabel = Label("POINT: 0",x=200,y=600)
w.create_label(sclabel)
scllabel = Label("HEALTH: 100",x=20,y=600)
w.create_label(scllabel)

li01 = Label("You LOSE!",x=600,y=600)
li02 = Label("You WIN!",x=600,y=600)

player = w.create_sprite(Duck)
EM = Emeny
def spawn_enemy():
    w.create_sprite(Emeny)


Scheduler.update(spawn_enemy, delay=0.99)


# if float(player.health) == 0:
#     w.add_label(li01)
# if float(player.point) == 100:
#     w.add_label(li02)

w.run()