示例#1
0
    def display_start_button(self):
        start_square = codesters.Rectangle(0, -80, 100, 50, 'green')
        start_square.event_click(self.start_level)
        self.sprites.append(start_square)

        button_text = codesters.Text('Start', 0, -80)
        button_text.set_color('#ffffff')
        self.sprites.append(button_text)

        goal_text = codesters.Text('Goal: ' + str(self.num_goal) + ' points')
        goal_text.set_color('#ffffff')
        self.sprites.append(goal_text)
示例#2
0
def collision(sprite, hit_sprite):
    global pitcher
    global caught
    global baseball
    global safeatfirst
    global batter
    global held
    if hit_sprite==pitcher:
        caught=True
        baseball.set_y_speed(0)
        baseball.set_x_speed(0)
        pitcher.collision_off()
    if hit_sprite==firstBase:
        held=True
        baseball.set_y_speed(0)
        baseball.set_x_speed(0)
        firstBase.collision_off()
        if safeatfirst == False and outatfirst==False:
            outatfirst==True
            batter.set_y_speed(0)
            batter.set_x_speed(0)
            # text = codesters.Text("text", x, y)
            text = codesters.Text("OUT", 0, 100)
            text.set_size(3)
    if hit_sprite==secondBase:
        held=True
        baseball.set_y_speed(0)
        baseball.set_x_speed(0)
        secondBase.collision_off()
    if hit_sprite==thirdBase:
        held=True
        baseball.set_y_speed(0)
        baseball.set_x_speed(0)
        thirdBase.collision_off()
示例#3
0
    def start_level(self):
        self.clean_up()
        global level_running
        level_running = True

        self.score = 0

        self.score_text = codesters.Text('0', -230, 205)
        self.score_text.set_color('#ffffff')
        self.sprites.append(self.score_text)

        goal_text = codesters.Text('Goal: ' + str(self.num_goal) + ' points',
                                   -180, 230)
        goal_text.set_color('#ffffff')
        self.sprites.append(goal_text)

        self.make_circles()
        stage.event_click(self.click_circle)
        self.user_has_clicked = False
示例#4
0
def collision():
    game_over = True
    sprite.go_to(0, 0)
    sprite.set_y_speed(0)
    sprite.set_gravity_off()
    flappiness = 0

    text = codesters.Text("Game Over!", 0, 100, "red")
    for pipe in pipe_list:
        pipe.set_x_speed(0)
示例#5
0
 def end_level(self):
     self.clean_up()
     if self.score >= self.num_goal:
         end_text = codesters.Text('You Win!')
         self.sprites.append(end_text)
         next_button = codesters.Rectangle(0, -80, 100, 50, 'green')
         next_button.event_click(self.next_level)
         self.sprites.append(next_button)
         button_text = codesters.Text('Continue', 0, -80)
         button_text.set_color('#ffffff')
         self.sprites.append(button_text)
     else:
         end_text = codesters.Text('Close! Try again.')
         self.sprites.append(end_text)
         next_button = codesters.Rectangle(0, -80, 100, 50, 'green')
         next_button.event_click(self.restart_level)
         self.sprites.append(next_button)
         button_text = codesters.Text('Restart', 0, -80)
         button_text.set_color('#ffffff')
         self.sprites.append(button_text)
示例#6
0
def interval():
    global safeatfirst
    global outatfirst
    runx=batter.get_x()
    runy=batter.get_y()
    # print(str(runx) + " " +str(runy))
    # print("x?: "+str(220<runx<230))
    # print("y?: "+str(-15<runy<25))
    # print(outatfirst)
    # print(safeatfirst)
    if 220<runx<230 and -15<runy<25:
        if outatfirst==False and safeatfirst==False:
            safeatfirst=True
            batter.set_y_speed(0)
            batter.set_x_speed(0)
            # text = codesters.Text("text", x, y)
            text = codesters.Text("SAFE", 0, 100)
            text.set_size(3)
示例#7
0
def mouse_move():
    global held
    global caught
    global stage
    x = stage.mouse_x()
    y = stage.mouse_y()
    pitcher.set_position(x, y)
    if caught:
        held=True
        pitcher.collision_off()
        baseball.set_position(x,y)
        if 220<x<230 and -15<y<25:
            if outatfirst==False and safeatfirst==False:
                batter.set_y_speed(0)
                batter.set_x_speed(0)
                # text = codesters.Text("text", x, y)
                text = codesters.Text("OUT", 0, 100)
                text.set_size(3)
                stage.remove_sprite(batter)
示例#8
0
## VOLLEYBALL BY SHIRLY
## LOCATED HERE: https://www.codesters.com/preview/2abfa838e59334f3c287194a0ecc8fbf625f9e3a/

import codesters
stage = codesters.Environment()

global ball, start_txt, win_text, player1, player2, barrier, net, player1_area, player2_area
start_txt = codesters.Text("PRESS SPACE TO START", 0, 75, "red")
ball = codesters.Circle(0, 0, 40, "blue")
ball.set_gravity_off()
win_text = codesters.Text(" ", 0, 175, "black")


def space_bar():
    ball.set_x_speed(random.randint(-6, 6) + 1)
    ball.set_gravity_on()
    start_txt.hide()
    win_text.hide()


stage.event_key("space", space_bar)

player1 = codesters.Sprite("hedgehog", -210, -225)
player1.set_size(.6)

player2 = codesters.Sprite("kitten", 210, -225)
player2.set_size(.5)
player2.flip_right_left()
barrier = codesters.Line(0, 250, 0, -250, "gray")
barrier.set_gravity_off()
net = codesters.Rectangle(0, -210, 20, 80, "darkgray")
back.set_gravity_off()
back.set_size(0.5)
back.cannot_collide()

hoop = codesters.Sprite('hoop', 170, -150)
hoop.set_gravity_off()
hoop.cannot_collide()
hoop.set_size(0.5)
hoop.is_goal()

ball = codesters.Sprite('basketball')
ball.set_size(0.4)
stage.set_gravity(10)

score = 0
t = codesters.Text('0', 200, 200)


def click():
    ball.set_gravity_off()
    ball.go_to(stage.click_x(), stage.click_y())
    ball.set_y_speed(0)
    ball.set_x_speed(0)


stage.event_click(click)


def click_up():
    ball.set_gravity_on()
    new_velx = ball.get_x() - stage.click_x()
示例#10
0
stage.event_key("left", left_key)


def right_key():  # EVENT
    frogger.set_x(frogger.get_x() + 50)
    print frogger.xcor, frogger.future_x
    print frogger.ycor, frogger.future_y
    frogger.print_corners()
    # add other actions...


stage.event_key("right", right_key)

stage.disable_all_walls()

result = codesters.Text(" ", 0, 0, "red")
global result  # GLOBALS


# detecting what was collided with by color / shape seems like the easiest way
def collision(
    sprite, hit_sprite
):  # COLLISIONS MARK REALLY WEIRDLY IN THIS PROJECT. TRYING TO FIGURE THAT OUT.
    # print '############'
    # hit_sprite.get_name()
    # print '############'
    # if frogger hits a lilypad
    if hit_sprite.get_name() == "circle":
        '''
        print frogger.xcor, ', ', sprite.xcor, ',', hit_sprite.xcor  # FOR BUG TESTING
        print frogger.ycor, ', ', sprite.ycor, ',', hit_sprite.ycor  # FOR BUG TESTING
示例#11
0
import codesters
import random
#global hedgey, stage, text
global hedgey, text

stage = codesters.Environment()
stage.set_background("moon")

hedgey = codesters.Sprite("hedgehog")
hedgey.go_to(0, -210)

points = 0
text = codesters.Text(str(points), 190, -65, "black")


def interval():
    x = random.randint(-230, 230)
    y = random.randint(0, 230)
    star = codesters.Star(x, y, 5, 20, "yellow")


stage.event_interval(interval, 2)


def left():
    hedgey.turn_left(10)


stage.event_left_key(left)

示例#12
0
 def restart_level(self):
     if self.current_level < len(self.levels):
         l = self.levels[self.current_level]
         l.display_start_button()
     else:
         end_text = codesters.Text('Game Over', 0, 0)
示例#13
0
        is_drawing = sprite.get_pen_down()
        if is_drawing:
            sprite.pen_up()
        if not is_drawing:
            sprite.pen_down()
stage.event_click(click)

def mouse_move():
    x = stage.mouse_x()
    y = stage.mouse_y()
    sprite.set_position(x, y)
    # add other actions...
stage.event_mouse_move(mouse_move)

finish_bg = codesters.Rectangle(-150, -225, 100, 30, None, "black")
finish_btn = codesters.Text("Done drawing?", -150, -225)
finish_btn.set_size(.7)

def click_finish():
    sprite.pen_up()
    print("done")
    announcer.say("Time to guess!")
    stage.wait(1)
    guess = " "
    while guess != word:
        stage.wait(1)
        guess = announcer.ask("What is the word?")
        if guess != word:
            announcer.say("Sorry, that's wrong!")
        else:
            announcer.say("Great job, you got it!")
示例#14
0
gravity = 3
flappiness = 12

# Stage setup
stage.set_background("moon")
stage.set_gravity(gravity)
stage.disable_all_walls()

# Dino setup
sprite = codesters.Sprite("fox")
sprite.set_size(0.5)
sprite.go_to(-200, 0)

# Score setup
score = 0
score_display = codesters.Text("Flappy Points: ", 0, 200, "white")

game_over = False
pipe_list = []


def space():
    sprite.jump(flappiness)
    # add other actions...


stage.event_space_key(space)

floor = codesters.Rectangle(0, -240, 500, 20, "black")
floor.set_gravity_off()
示例#15
0
                stage_move_right)  # The left key makes the stage move right


# Do the same thing for the other direction
def stage_move_left():
    for p in presents:
        p.set_x(p.get_x() - 20)
    for f in flowers:
        f.set_x(f.get_x() - 20)


stage.event_key('right', stage_move_left)

# We can give the fox points when the fox gets a present
points = 0
points_text = codesters.Text(str(points), -220, 200)


# Make a function for when the fox finds a present
def get_present(fox, present):

    # the present disappears
    stage.remove_sprite(present)

    # the fox spins
    fox.left(720)
    fox.set_rotation(0)

    # we get a point
    global points
    points = points + 1