Exemplo n.º 1
0
    def add_racer(self, name):
        if name in self.racers_id:
            return self.racers_id[name]

        racer = Racer(name, self.new_racer_id())
        self.racers[racer.id] = racer
        self.racers_id[racer.name] = racer.id

        return racer.id
Exemplo n.º 2
0
 def enter_racer(self, racer_member):
     if self._status == RaceStatus['entry_open'] and not self.has_racer(
             racer_member):
         racer = Racer(racer_member)
         self.racers[racer_member.id] = racer
         asyncio.ensure_future(self.room.update_leaderboard())
         return True
     else:
         return False
Exemplo n.º 3
0
 def on_message(self, message):
     global FINISH_RACE
     print message
     if message == 'GO':
         prepare_for_race(self.racers)
         FINISH_RACE = False
         start_time = time.time()
         for racer in self.racers:
             racer.lap_times.append(start_time)
         run_race(self.racers, self.number_of_laps, self)
     elif message == 'STOP':
         print "STOP CALLED!"
         FINISH_RACE = True
         prepare_for_race(self.racers)
     elif "lapcount:" in message:
         self.number_of_laps = int(message.split(":")[-1])
     else:
         self.racers = []
         for json_racer in json.loads(message, object_hook=lambda d: namedtuple('X', d.keys())(*d.values())):
             self.racers.append(Racer(json_racer.name, json_racer.track_number))      
Exemplo n.º 4
0
    def __init__(self, window, track_num, characters, laps=3):
        self.window = window
        self.track = Track(window, self, track_num)
        self.racers = []
        self.laps = laps
        self.time = 0.  # current time in the race (will be set to 0 when the first racer starts)

        # the time counter
        self.time_label = pyglet.text.Label(color=(230, 230, 230, 255), bold=True, batch=window.batch)
        self.time_label.x = 10
        self.time_label.y = self.window.height - 30

        for i, char in enumerate(characters):
            self.racers.append(Racer(self, i, char))
        self.player1 = self.racers[0]
        if len(self.racers) >= 2:
            self.player2 = self.racers[1]
        else:
            self.player2 = None

        self.particles = []  # list of moving objects other than cars
Exemplo n.º 5
0
g_renderingSystem = RenderingSystem()
g_renderingSystem.setupObjModelShader()

g_terrain = Terrain()
#g_terrain.load("data/track_01_32.png", g_renderingSystem);
g_terrain.load("data/track_01_128.png", g_renderingSystem)
# rock and tree positions have been set > sample 20?
# create a prop manager with the sample rocks/trees positions
# loop over sample and append to g_props
g_shadowTexId, g_fbo, g_TU_shadow = shadow.setupShadowMap()
g_shadowShader = shadow.buildShadowShader()
treeSample = random.sample(g_terrain.treeLocations, 25)
rockSample = random.sample(g_terrain.rockLocations, 25)

g_racer = Racer()
g_racer.load("data/racer_02.obj", g_terrain, g_renderingSystem)

propManager = PropManager(g_terrain)
for t in treeSample:
    g_props.append(propManager.createTreeProp(g_terrain, g_renderingSystem, t))
for r in rockSample:
    g_props.append(propManager.createRockProp(g_terrain, g_renderingSystem, r))
# here we'll implement the grass texture loading//etc..
# I may place this code in a helper function in the future

currentTime = glfw.get_time()
prevMouseX, prevMouseY = glfw.get_cursor_pos(window)

while not glfw.window_should_close(window):
    prevTime = currentTime
Exemplo n.º 6
0
from turtle import Turtle, Screen, ontimer
from racer import Racer, INITIAL_POSITION
from car import Traffic
from level_board import LevelBoard

MS_INTERVAL = 500

screen = Screen()
screen.setup(width=800, height=600)
screen.colormode(255)
screen.tracer(0)

racer = Racer()
traffic = Traffic()
level_board = LevelBoard()
t = Turtle()
t.hideturtle()

screen.listen()
screen.onkey(racer.move_fwd, "Up")


def create_car():
    traffic.generate_car()
    screen.ontimer(create_car, t=MS_INTERVAL)


screen.ontimer(create_car, t=MS_INTERVAL)

game_over = False
while not game_over:
Exemplo n.º 7
0
from cars import Cars, car_list
from racer import Racer
from finishline import RaceLine
from levels import Level

# a turtle crossing game. Get the turtle to the finish line without hitting a car. Move forward with spacebar

turtle.listen()
# generate screen
screen = Screen()
screen.setup(height=600, width=600)
screen.tracer(0)

# generate game objects 
car = Cars()
racer_turtle = Racer()
finish_line = RaceLine(250)
start_line = RaceLine(-250) 
level_start = Level()
# instructions = level_start.instructions()
# start game
game_on = True
while game_on:
    time.sleep(level_start.time_set)
    screen.update()
    for car in car_list:
        car.move()
        # generate one car after previous reaches a given coordinate
        if car_list[-1].xcor() in range(200, 250):
            car = Cars()
        # Detect if turtle collides with car, end game
Exemplo n.º 8
0
from turtle import Turtle, Screen
import random
from racer import Racer

screen = Screen()
screen.setup(height=800, width=1000)

racer = Racer()
user_bet = screen.textinput(
    title="Make your bet",
    prompt="Which turtle will win the race? Enter a colour: ")

race_is_on = False

if user_bet:
    race_is_on = True
    print(f"Your choice is {user_bet}, good luck!")

racer.create_racer()

racer.print_winner(user_bet)
while race_is_on:

    racer.start_race()
    # Check for winner
    for turtle in racer.all_turtles:
        if turtle.xcor() > 450:
            race_is_on = False
            winning_color = turtle.pencolor()
            if winning_color == user_bet:
                racer.print_result(winning_color)
Exemplo n.º 9
0
       glGetString(GL_VERSION).decode("utf8")),
    flush=True)

# Enable some much-needed hardware functions that are off by default.
glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST)

impl = ImGuiGlfwRenderer(window)

g_renderingSystem = RenderingSystem()
g_renderingSystem.setupObjModelShader()

g_terrain = Terrain()
g_terrain.load("data/map.png", g_renderingSystem)

g_racer = Racer()
g_racer.load("data/athlete/athlete.obj", g_terrain, g_renderingSystem)
#g_racer.load("data/rings/rings.obj", g_terrain, g_renderingSystem);

# 2.3 - Props
g_props = PropManager()
propTypes = [['cone', 50, g_terrain.treeLocations],
             ["rings", 2, g_terrain.rockLocations]]
g_props.loadAllProps(propTypes)

currentTime = glfw.get_time()
prevMouseX, prevMouseY = glfw.get_cursor_pos(window)

while not glfw.window_should_close(window):
    prevTime = currentTime
    currentTime = glfw.get_time()