Ejemplo n.º 1
0
    def __init__(self, image_filename, data_filename, extra_names=True):
        if extra_names:
            extra_names = ('_normal', '_occlude', '_displace')
            extra_names = [
                image_filename[:-4] + extra + image_filename[-4:]
                for extra in extra_names
            ]
        else:
            extra_names = []

        self.texture = Texture(image_filename, *extra_names)
        self.subimages = {}
        #data_filename = os.path.join(globals.dirs.resource,data_filename)
        with open(data_filename, 'rb') as f:
            for line in f:
                subimage_name,\
                image_name   ,\
                x            ,\
                y            ,\
                w            ,\
                h            = line.strip().split(':')
                #print image_name,image_filename
                #assert(image_name) == image_filename
                w = int(w)
                h = int(h)
                if subimage_name.startswith('font_'):
                    subimage_name = chr(int(subimage_name[5:7], 16))
                    h -= 4
                subimage_name = '_'.join(subimage_name.split('/'))
                self.subimages[subimage_name] = SubImage(
                    Point(
                        float(x) / self.texture.width,
                        float(y) / self.texture.height), (Point(w, h)))
Ejemplo n.º 2
0
def Init():
    """Initialise everything. Run once on startup"""
    w,h = (1280,720)
    globals.tile_scale            = Point(1,1)
    globals.scale                 = Point(3,3)
    globals.screen                = Point(w,h)/globals.scale
    globals.screen_root           = ui.UIRoot(Point(0,0),globals.screen)
    globals.quad_buffer           = drawing.QuadBuffer(131072)
    globals.screen_texture_buffer = drawing.QuadBuffer(131072)
    globals.ui_buffer             = drawing.QuadBuffer(131072)
    globals.nonstatic_text_buffer = drawing.QuadBuffer(131072)
    globals.colour_tiles          = drawing.QuadBuffer(131072)
    globals.mouse_relative_buffer = drawing.QuadBuffer(1024)
    globals.line_buffer           = drawing.LineBuffer(16384)
    globals.tile_dimensions       = Point(16,16)*globals.tile_scale
    globals.sounds                = sounds.Sounds()
    globals.zoom_scale            = None

    globals.dirs = globals.types.Directories('resource')

    pygame.init()
    screen = pygame.display.set_mode((w,h),pygame.OPENGL|pygame.DOUBLEBUF)
    pygame.display.set_caption('The Gosh Signal')
    drawing.Init(globals.screen.x,globals.screen.y)

    globals.text_manager = drawing.texture.TextManager()
Ejemplo n.º 3
0
 def __init__(self,parent,gameview,computer,background,foreground):
     bl = Point(13,13).to_float()/parent.absolute.size
     tr = (Point(1,1) - bl)
     super(Emulator,self).__init__(parent,bl,tr)
     self.background_colour = background
     self.foreground_colour = foreground
     self.scale = 3
     self.gameview = gameview
     self.computer = computer
     self.text_buffer = ''
     self.last = 0
     
     self.size = (self.absolute.size/(globals.text_manager.GetSize(' ',self.scale).to_float())).to_int()
     self.quads = []
     
     for x in xrange(self.size.x):
         col = []
         for y in xrange(self.size.y):
             q = globals.text_manager.Letter(' ',drawing.texture.TextTypes.SCREEN_RELATIVE,self.foreground_colour)
             bl = (Point(x,self.size.y - 1 - y).to_float())/self.size
             tr = (Point(x+1,self.size.y - y).to_float())/self.size
             q.SetVertices(self.GetAbsolute(bl),self.GetAbsolute(tr),drawing.constants.DrawLevels.ui + self.level + 1)
             col.append(q)
         self.quads.append(col)
     self.cursor_flash = None
     self.cursor_flash_state = False
     self.current_buffer = []
         
     self.cursor = Point(0,0)
     self.start = None
     
     self.AddMessage(self.GetBanner())
Ejemplo n.º 4
0
    def __init__(self, parent):
        self.parent = parent
        self.blurb = self.blurb
        self.blurb_text = None
        self.handlers = {
            TitleStages.TEXT: self.TextDraw,
            TitleStages.SCROLL: self.Wait,
            TitleStages.WAIT: self.Wait
        }
        self.backdrop = ui.Box(parent=globals.screen_root,
                               pos=Point(0, 0),
                               tr=Point(1, 1),
                               colour=(0, 0, 0, 0.6))

        bl = self.parent.GetRelative(Point(0, 0))
        tr = bl + self.parent.GetRelative(globals.screen)
        self.blurb_text = ui.TextBox(
            parent=globals.screen_root,
            bl=bl,
            tr=tr,
            text=self.blurb,
            textType=drawing.texture.TextTypes.SCREEN_RELATIVE,
            scale=3)

        self.start = None
        self.blurb_text.EnableChars(0)
        self.stage = TitleStages.TEXT
        self.played_sound = False
        self.skipped_text = False
        self.letter_duration = 20
        self.continued = False
Ejemplo n.º 5
0
    def PhysUpdate(self):
        if self.dead:
            return
        if self.squirting:
            if not self.UpdateLevel(-1):
                self.StopSquirting()
                return
            thrust = -0.5
            vector = cmath.rect(thrust, self.GetDirection())
            point_phys = self.parent.body.GetWorldPoint(self.middle.to_vec())
            point_screen = Point(
                *point_phys) / self.parent.physics.scale_factor

            self.parent.body.ApplyForce(
                (vector.real, vector.imag),
                self.parent.body.GetWorldPoint(self.middle.to_vec()))
            if len(self.squirters) < 100:
                angle = self.GetDirection() + (random.random() -
                                               0.5) * self.squirt_range
                distance = random.random(
                ) * self.squirt_distance + self.min_squirt_distance
                vector = cmath.rect(distance, angle)
                vector = Point(vector.real, vector.imag)
                start = point_screen
                self.squirters.append(Squirt(start, vector, 1000))
        #Always update the squirters even if not squirting
        self.squirters = [
            squirt for squirt in self.squirters if squirt.Update() == True
        ]

        for i, vertex in enumerate(self.shape.vertices):
            screen_coords = Point(*self.parent.body.GetWorldPoint(
                vertex)) / self.parent.physics.scale_factor
            self.quad.vertex[self.parent.vertex_permutation[i]] = (
                screen_coords.x, screen_coords.y, self.z_level)
Ejemplo n.º 6
0
    def SetVertices(self):
        for i in xrange(4):
            self.hover_quads[i].SetColour((1,0,0,1))

        #top bar
        self.hover_quads[0].SetVertices(Point(self.absolute.bottom_left.x,self.absolute.top_right.y-self.line_width),
                                        self.absolute.top_right,
                                        drawing.constants.DrawLevels.ui+1)
        #right bar
        self.hover_quads[1].SetVertices(Point(self.absolute.top_right.x-self.line_width,self.absolute.bottom_left.y),
                                        self.absolute.top_right,
                                        drawing.constants.DrawLevels.ui+1)

        #bottom bar
        self.hover_quads[2].SetVertices(self.absolute.bottom_left,
                                        Point(self.absolute.top_right.x,self.absolute.bottom_left.y+self.line_width),
                                        drawing.constants.DrawLevels.ui+1)

        #left bar
        self.hover_quads[3].SetVertices(self.absolute.bottom_left,
                                        Point(self.absolute.bottom_left.x+self.line_width,self.absolute.top_right.y),
                                        drawing.constants.DrawLevels.ui+1)
        if not self.enabled:
            for i in xrange(4):
                self.hover_quads[i].Disable()
Ejemplo n.º 7
0
 def __init__(self, physics, bl, angle=0):
     self.dead = False
     self.arms = []
     self.selected = False
     self.unset = None
     self.fire_extinguisher = None
     self.push_start = None
     self.squirting = False
     self.subimage = globals.atlas.SubimageSprite(self.texture_name)
     self.texture_coords = globals.atlas.TextureSpriteCoords(
         self.texture_name)
     self.selected_subimage = globals.atlas.SubimageSprite(
         self.selected_name)
     self.selected_texture_coords = globals.atlas.TextureSpriteCoords(
         self.selected_name)
     tr = bl + self.subimage.size
     super(Player, self).__init__(physics, bl, tr, self.texture_coords,
                                  angle)
     self.joints = []
     self.other_obj = None
     self.filter_group = Player.filter_id
     Player.filter_id -= 1
     self.resting_hand_positions = (self.midpoint * Point(0.8, 1),
                                    self.midpoint * Point(-0.8, 1))
     self.current_hand_positions = self.resting_hand_positions
     self.shoulders = (self.midpoint * Point(0.8, 0),
                       self.midpoint * Point(-0.8, 0))
     self.arms = [
         PlayerArm(self, (self, self.shoulders[0]),
                   (self, self.resting_hand_positions[0])),
         PlayerArm(self, (self, self.shoulders[1]),
                   (self, self.resting_hand_positions[1]))
     ]
Ejemplo n.º 8
0
    def __init__(self, parent):
        self.parent = parent
        self.blurb = self.blurb
        self.blurb_text = None
        pygame.mixer.music.load('end_music.ogg')
        pygame.mixer.music.play(-1)
        pygame.mixer.music.set_volume(0.6)
        self.handlers = {
            TitleStages.TEXT: self.TextDraw,
            TitleStages.SCROLL: self.Wait,
            TitleStages.WAIT: self.Wait
        }
        self.backdrop = ui.Box(parent=globals.screen_root,
                               pos=Point(0, 0),
                               tr=Point(1, 1),
                               colour=(0, 0, 0, 0.6))

        bl = Point(0.3, 0.5)
        tr = Point(0.7, 0.7)
        self.blurb_text = ui.TextBox(
            parent=globals.screen_root,
            bl=bl,
            tr=tr,
            text=self.blurb,
            textType=drawing.texture.TextTypes.SCREEN_RELATIVE,
            scale=3)

        self.start = None
        self.blurb_text.EnableChars(0)
        self.stage = TitleStages.TEXT
        self.played_sound = False
        self.skipped_text = False
        self.letter_duration = 20
        self.continued = False
Ejemplo n.º 9
0
 def __init__(self,parent,bl,tr,text,scale,colour = None,textType = drawing.texture.TextTypes.SCREEN_RELATIVE,alignment = drawing.texture.TextAlignments.LEFT):
     if tr == None:
         #If we're given no tr; just set it to one row of text, as wide as it can get without overflowing
         #the parent
         self.shrink_to_fit = True
         text_size          = (globals.text_manager.GetSize(text,scale).to_float()/parent.absolute.size)
         margin             = Point(text_size.y*0.06,text_size.y*0.15)
         tr                 = bl + text_size + margin*2 #Add a little breathing room by using 2.1 instead of 2
         #We'd like to store the margin relative to us, rather than our parent
         self.margin = margin/(tr-bl)
     else:
         self.shrink_to_fit = False
     super(TextBox,self).__init__(parent,bl,tr)
     if not self.shrink_to_fit:
         #In this case our margin is a fixed part of the box
         self.margin      = Point(0.05,0.05)
     self.text        = text
     self.current_enabled = len(self.text)
     self.scale       = scale
     self.colour      = colour
     self.text_type   = textType
     self.alignment   = alignment
     self.text_manager = globals.text_manager
     self.ReallocateResources()
     #self.quads       = [self.text_manager.Letter(char,self.text_type) for char in self.text]
     self.viewpos     = 0
     #that sets the texture coords for us
     self.Position(self.bottom_left,self.scale,self.colour)
     self.Enable()
Ejemplo n.º 10
0
    def SetPointer(self):
        offset = self.offsets[self.index]

        pointer_bl = Point(offset,0.3) - (Point(2,10)/self.clickable_area.absolute.size)
        pointer_tr = pointer_bl + (Point(7,14)/self.clickable_area.absolute.size)
        self.pointer_ui.SetBounds(pointer_bl,pointer_tr)
        self.pointer_quad.SetVertices(self.pointer_ui.absolute.bottom_left,self.pointer_ui.absolute.top_right,self.uilevel + 0.1)
        self.pointer_quad.SetColour(self.pointer_colour)
Ejemplo n.º 11
0
class Clock(object):
    range = math.pi * 2 * 0.77
    start = math.pi / 4
    name = 'clock.png'
    hour_hand_name = 'hour_hand.png'
    minute_hand_name = 'minute_hand.png'
    start_pos = Point(0.8, 0.81)
    centre = Point(16, 16)
    hour_hand_coords = ((-1, -1), (-1, 6), (1, 6), (1, -1))
    minute_hand_coords = ((-0.5, -1), (-0.5, 13), (0.5, 13), (0.5, -1))
    seconds_to_hours = 0.01

    def __init__(self, train, initial_level=0.0):
        self.train = train
        self.quad = drawing.Quad(globals.screen_texture_buffer,
                                 tc=globals.atlas.TextureSpriteCoords(
                                     self.name))
        self.size = globals.atlas.SubimageSprite(self.name).size
        self.hour_hand_quad = drawing.Quad(
            globals.screen_texture_buffer,
            tc=globals.atlas.TextureSpriteCoords(self.hour_hand_name))
        self.hour_hand_size = globals.atlas.SubimageSprite(
            self.hour_hand_name).size
        self.minute_hand_quad = drawing.Quad(
            globals.screen_texture_buffer,
            tc=globals.atlas.TextureSpriteCoords(self.minute_hand_name))
        self.minute_hand_size = globals.atlas.SubimageSprite(
            self.minute_hand_name).size
        bl = self.start_pos * globals.screen
        tr = bl + self.size
        self.pos = bl
        self.hour_hand_pos = bl + self.centre
        self.minute_hand_pos = bl + self.centre
        self.quad.SetVertices(bl, tr, 5.4)
        self.Update(0)

    def set_dial(self, hour, minute):
        hour_angle = -2 * math.pi * float(hour) / 12
        minute_angle = -2 * math.pi * float(minute) / 60
        for quad, coords, angle in ((self.hour_hand_quad,
                                     self.hour_hand_coords, hour_angle),
                                    (self.minute_hand_quad,
                                     self.minute_hand_coords, minute_angle)):
            vertices = [0, 0, 0, 0]
            for i, coord in enumerate(coords):
                p = coord[0] + coord[1] * 1j
                distance, old_angle = cmath.polar(p)
                c = cmath.rect(distance, old_angle + angle)
                vertices[i] = self.pos + self.centre + Point(c.real, c.imag)
            quad.SetAllVertices(vertices, 5.5 + i + 1)

    def Update(self, elapsed):
        time = self.train.parent.start_time_hours + self.seconds_to_hours * float(
            globals.time - self.train.parent.start_time) / 1000
        minutes = (time % 1.0) * 60
        hours = time % 12

        self.set_dial(hours, minutes)
Ejemplo n.º 12
0
 def set_pos(self, pos):
     self.world_pos = pos
     pos = pos * globals.tile_dimensions
     self.pos = (pos.x, pos.y, self.z)
     box = (globals.tile_scale * Point(self.width, self.height))
     bl = Point(*self.pos[:2]) - box * 0.5
     tr = bl + box
     bl = bl.to_int()
     tr = tr.to_int()
     self.quad.SetVertices(bl, tr, 4)
Ejemplo n.º 13
0
 def SetSelected(self, n):
     if n < 0:
         n = 0
     if n > 3:
         n = 3
     self.selected = n
     self.screen.selected.bottom_left = Point(self.selected * 0.25, -0.05)
     self.screen.selected.top_right = Point((self.selected + 1) * 0.25,
                                            0.15)
     self.screen.selected.UpdatePosition()
Ejemplo n.º 14
0
 def __init__(self):
     self.dish_door = None
     self.atlas = globals.atlas = drawing.texture.TextureAtlas(
         'tiles_atlas_0.png', 'tiles_atlas.txt')
     self.map = GameMap('level1.txt', self)
     self.map.world_size = self.map.size * globals.tile_dimensions
     self.viewpos = Viewpos(Point(915, 0))
     self.player_direction = Point(0, 0)
     self.game_over = False
     self.computer = None
     self.info_box = ui.Box(parent=globals.screen_root,
                            pos=Point(0, 0),
                            tr=Point(1, 0.05),
                            colour=(0, 0, 0, 0.9))
     self.info_box.text = ui.TextBox(
         self.info_box,
         bl=Point(0, 0),
         tr=Point(1, 0.7),
         text='Space to interact, I for inventory, DEL to toggle music',
         textType=drawing.texture.TextTypes.SCREEN_RELATIVE,
         colour=(1, 1, 0, 1),
         scale=3,
         alignment=drawing.texture.TextAlignments.CENTRE)
     self.info_box.Disable()
     #pygame.mixer.music.load('music.ogg')
     self.music_playing = False
     super(GameView, self).__init__(Point(0, 0), globals.screen)
     #skip titles for development of the main game
     self.mode = modes.Titles(self)
     #self.mode = modes.LevelOne(self)
     super(GameView, self).__init__(Point(0, 0),
                                    Point(*self.map.world_size))
Ejemplo n.º 15
0
    def __init__(self,parent,bl,tr,points,callback):
        super(Slider,self).__init__(parent,bl,tr)
        self.points   = sorted(points,lambda x,y:cmp(x[0],y[0]))
        self.callback = callback
        self.lines    = []
        self.uilevel  = utils.ui_level+1
        self.enabled  = False
        self.clickable_area = UIElement(self,Point(0.05,0),Point(0.95,1))
        line          = drawing.Quad(globals.ui_buffer)
        line_bl       = self.clickable_area.absolute.bottom_left + self.clickable_area.absolute.size*Point(0,0.3)
        line_tr       = line_bl + self.clickable_area.absolute.size*Point(1,0) + Point(0,2)
        line.SetVertices(line_bl,line_tr,self.uilevel)
        line.Disable()

        low  = self.points[ 0][0]
        high = self.points[-1][0]
        self.offsets = [float(value - low)/(high-low) if low != high else 0 for value,index in self.points]
        self.lines.append(line)
        self.index    = 0
        self.pointer_quad = drawing.Quad(globals.ui_buffer)
        self.pointer_colour = (1,0,0,1)
        self.lines.append(self.pointer_quad)
        self.pointer_ui = UIElement(self.clickable_area,Point(0,0),Point(0,0))
        self.SetPointer()
        self.pointer_quad.Disable()
        self.dragging = False
        #now do the blips
        for offset in self.offsets:
            line    = drawing.Quad(globals.ui_buffer)
            line_bl = self.clickable_area.absolute.bottom_left + Point(offset,0.3)*self.clickable_area.absolute.size
            line_tr = line_bl + self.clickable_area.absolute.size*Point(0,0.2) + Point(2,0)
            line.SetVertices(line_bl,line_tr,self.uilevel)
            line.Disable()
            self.lines.append(line)
Ejemplo n.º 16
0
 def set_vertices(self):
     if self.parent.incline == 0:
         return self.quad.SetVertices(self.pos, self.pos + self.size, 0.2)
     bl = self.pos - globals.rotation_offset
     tr = bl + self.size
     vertices = [0, 0, 0, 0]
     for (i, coord) in enumerate((Point(bl.x, bl.y), Point(bl.x, tr.y),
                                  Point(tr.x, tr.y), Point(tr.x, bl.y))):
         vertices[i] = globals.rotation_offset + coord.Rotate(
             self.parent.incline)
     self.quad.SetAllVertices(vertices, 0.2)
Ejemplo n.º 17
0
    def __init__(self, name, parent):
        self.size = Point(120, 50)
        self.data = [[TileTypes.GRASS for i in xrange(self.size.y)]
                     for j in xrange(self.size.x)]
        self.object_cache = {}
        self.object_list = []
        self.actors = []
        self.doors = []
        self.player = None
        self.parent = parent
        y = self.size.y - 1
        player_pos = None
        with open(name) as f:
            last = None
            for line in f:
                line = line.strip('\n')
                if len(line) < self.size.x:
                    line += ' ' * (self.size.x - len(line))
                if len(line) > self.size.x:
                    line = line[:self.size.x]
                for inv_x, tile in enumerate(line[::-1]):
                    x = self.size.x - 1 - inv_x

                    #try:
                    if 1:
                        #hack, also give the adjacent tile so we know what kind of background to put it on...
                        td = TileDataFactory(self, self.input_mapping[tile],
                                             Point(x, y), last, parent)
                        last = self.input_mapping[tile]
                        for tile_x in xrange(td.size.x):
                            for tile_y in xrange(td.size.y):
                                if self.data[x + tile_x][
                                        y + tile_y] != TileTypes.GRASS:
                                    self.data[x + tile_x][y + tile_y].Delete()
                                    self.data[x +
                                              tile_x][y +
                                                      tile_y] = TileTypes.GRASS
                                if self.data[x + tile_x][
                                        y + tile_y] == TileTypes.GRASS:
                                    self.data[x + tile_x][y + tile_y] = td
                        if self.input_mapping[tile] == TileTypes.PLAYER:
                            player_pos = Point(x + 0.2, y)
                        if self.input_mapping[tile] == TileTypes.ENEMY:
                            self.parent.enemy_positions.append(
                                Point(x + 0.2, y))
                    #except KeyError:
                    #    raise globals.types.FatalError('Invalid map data')
                y -= 1
                if y < 0:
                    break
        if not player_pos:
            raise Exception('No player defined')
        self.player = actors.Player(self, player_pos)
        self.actors.append(self.player)
Ejemplo n.º 18
0
 def Update(self):
     vertices = []
     for i, (obj, vertex) in enumerate(
         ((self.start_object, self.start_pos - Point(0.1, 0)),
          (self.start_object, self.start_pos + Point(0.1, 0)),
          (self.end_object, self.end_pos + Point(0.1, 0)),
          (self.end_object, self.end_pos - Point(0.1, 0)))):
         screen_coords = Point(*obj.body.GetWorldPoint(
             vertex.to_vec())) / self.parent.physics.scale_factor
         self.quad.vertex[i] = (screen_coords.x, screen_coords.y,
                                self.z_level)
Ejemplo n.º 19
0
class PressureGauge(object):
    range = math.pi * 2 * 0.77
    start = math.pi / 4
    name = 'pressure.png'
    arrow_name = 'arrow.png'
    start_pos = Point(-0.02, 0.72)
    wobble = 0.2
    centre = Point(24, 32)
    arrow_coords = ((-11, -3), (-11, 3), (9, 3), (9, -3))

    def __init__(self, train, initial_level=0.0):
        self.train = train
        self.quad = drawing.Quad(globals.screen_texture_buffer,
                                 tc=globals.atlas.TextureSpriteCoords(
                                     self.name))
        self.size = globals.atlas.SubimageSprite(self.name).size
        self.arrow_quad = drawing.Quad(globals.screen_texture_buffer,
                                       tc=globals.atlas.TextureSpriteCoords(
                                           self.arrow_name))
        self.arrow_size = globals.atlas.SubimageSprite(self.arrow_name).size
        bl = self.start_pos * globals.screen
        tr = bl + self.size
        self.pos = bl
        self.arrow_pos = bl + self.centre
        self.quad.SetVertices(bl, tr, 5.4)
        self.Update(initial_level, 0)

    def set_dial(self):
        new_angle = -self.level * self.range + self.start
        vertices = [0, 0, 0, 0]
        for i, coord in enumerate(self.arrow_coords):
            p = coord[0] + coord[1] * 1j
            distance, old_angle = cmath.polar(p)
            c = cmath.rect(distance, old_angle + new_angle)
            vertices[i] = self.arrow_pos + Point(c.real, c.imag)
        self.arrow_quad.SetAllVertices(vertices, 5.5)

    def Update(self, level, elapsed):
        self.level = level
        if level < 0.05:
            #no wobble
            pass
        elif level < 0.5:
            self.level += self.wobble * random.random() * elapsed
        if level > 0.5:
            self.level += self.wobble * random.random() * elapsed * 20 * (
                level - 0.5)

        if self.level < 0:
            self.level = 0
        if self.level > 1:
            self.level = 1.0
        self.set_dial()
Ejemplo n.º 20
0
 def NewLight(self):
     row = self.current_size / self.num_points
     light = Quad(self)
     #Now set the vertices for the next line ...
     bl = Point(0, row)
     tr = Point(globals.screen_abs.x, (row + 1))
     print bl, ':', tr
     #bl = Point(0,0)
     #tr = Point(drawing.opengl.ShadowMapBuffer.WIDTH,drawing.opengl.ShadowMapBuffer.HEIGHT)
     light.SetVertices(bl, tr, row)
     light.shadow_index = row
     return light
Ejemplo n.º 21
0
    def AdjustZoom(self,amount,pos):
        pos_coords = self.viewpos.Get() + (pos/self.zoom)
        oldzoom = self.zoom
        self.zoom -= (amount/10.0)
        if self.zoom < self.min_zoom:
            self.zoom = self.min_zoom
        if self.zoom > self.max_zoom:
            self.zoom = self.max_zoom
        
        #if we've zoomed so far out that we can see an edge of the screen, fix that
        top_left= Point(0,globals.screen.y/self.zoom)
        top_right = globals.screen/self.zoom
        bottom_right = Point(globals.screen.x/self.zoom,0)

        new_viewpos = self.viewpos.Get()
        if new_viewpos.y < 0:
            new_viewpos.y = 0

        if new_viewpos.x < 0:
            new_viewpos.x = 0
        
        #now the top left
        new_top_right = new_viewpos+top_right
        if new_top_right.y  > self.absolute.size.y:
            new_viewpos.y -= (new_top_right.y - self.absolute.size.y)

        if new_top_right.x > self.absolute.size.x:
            new_viewpos.x -= (new_top_right.x - self.absolute.size.x)
        
        try:
            if new_viewpos.y < 0:
                raise ValueError

            if new_viewpos.x < 0:
                raise ValueError

            #now the top left
            new_top_right = new_viewpos+top_right
            if new_top_right.y  > self.absolute.size.y:
                raise ValueError

            if new_top_right.x > self.absolute.size.x:
                raise ValueError

        except ValueError:
            #abort! This is a bit shit but whatever
            self.zoom = oldzoom
            return

        new_pos_coords = self.viewpos.Get() + pos/self.zoom
        self.viewpos.Set(self.viewpos.Get() + (pos_coords - new_pos_coords))
        self.ClampViewpos()
Ejemplo n.º 22
0
    def Move(self,amount):
        amount = Point(amount.x,amount.y)
        dir = None
        if amount.x > 0:
            dir = Directions.RIGHT
        elif amount.x < 0:
            dir = Directions.LEFT
        elif amount.y > 0:
            dir = Directions.UP
        elif amount.y < 0:
            dir = Directions.DOWN
        if dir != None and dir != self.dir:
            self.dir = dir
            self.quad.SetTextureCoordinates(self.dirs[self.dir])
        #check each of our four corners
        for corner in self.corners:
            pos = self.pos + corner
            target_x = pos.x + amount.x
            if target_x >= self.map.size.x:
                amount.x = 0
                target_x = pos.x
            elif target_x < 0:
                amount.x = -pos.x
                target_x = 0
            target_tile_x = self.map.data[int(target_x)][int(pos.y)]
            if target_tile_x.type in game_view.TileTypes.Impassable:
                amount.x = 0
                
            elif (int(target_x),int(pos.y)) in self.map.object_cache:
                obj = self.map.object_cache[int(target_x),int(pos.y)]
                if obj.Contains(Point(target_x,pos.y)):
                    amount.x = 0

            target_y = pos.y + amount.y
            if target_y >= self.map.size.y:
                amount.y = 0
                target_y = pos.y
            elif target_y < 0:
                amount.y = -pos.y
                target_y = 0
            target_tile_y = self.map.data[int(pos.x)][int(target_y)]
            if target_tile_y.type in game_view.TileTypes.Impassable:
                amount.y = 0
            elif (int(pos.x),int(target_y)) in self.map.object_cache:
                obj = self.map.object_cache[int(pos.x),int(target_y)]
                if obj.Contains(Point(pos.x,target_y)):
                    amount.y = 0
            

        self.SetPos(self.pos + amount)
Ejemplo n.º 23
0
class CoalDial(PressureGauge):
    start_pos = Point(0.47, 0.85)
    name = 'dial.png'
    arrow_name = 'needle.png'
    wobble = 0.2
    start = 0
    centre = Point(16, 4)
    range = math.pi
    max_level = 4
    arrow_coords = ((-11, -2), (-11, 2), (0, 3), (0, -3))

    def Update(self, level, elapsed):
        level = float(level) / self.max_level
        super(CoalDial, self).Update(level, elapsed)
Ejemplo n.º 24
0
    def set_coords(self):
        for (i, quad) in enumerate(self.quads):
            view_offset = Point((i - 2) * self.size.x + self.moved, 0)

            bl = self.pos - globals.rotation_offset + view_offset
            tr = bl + self.size
            vertices = [0, 0, 0, 0]
            for (j, coord) in enumerate((Point(bl.x, bl.y), Point(bl.x, tr.y),
                                         Point(tr.x, tr.y), Point(tr.x,
                                                                  bl.y))):
                vertices[j] = globals.rotation_offset + coord.Rotate(
                    self.angle)

            quad.SetAllVertices(vertices, self.z)
Ejemplo n.º 25
0
    def update(self, t):
        self.t = t
        elapsed = t - self.last_update
        self.last_update = t

        if self.shake_end:
            if t >= self.shake_end:
                self.shake_end = None
                self.shake = Point(0, 0)
            else:
                left = (self.shake_end - t) / self.shake_duration
                radius = left * self.shake_radius
                self.shake = Point(random.random() * radius,
                                   random.random() * radius)

        if self.follow:
            #We haven't locked onto it yet, so move closer, and lock on if it's below the threshold
            fpos = (self.follow.GetPosCentre() * globals.tile_dimensions
                    ).to_int() + globals.screen * Point(0, 0.03)
            if not fpos:
                return
            target = fpos - (globals.screen * 0.5).to_int()
            diff = target - self._pos
            #print diff.SquareLength(),self.follow_threshold
            direction = diff.direction()

            if abs(diff.x) < self.max_away.x and abs(diff.y) < self.max_away.y:
                adjust = diff * 0.02 * elapsed * 0.06
            else:
                adjust = diff * 0.03 * elapsed * 0.06
            #adjust = adjust.to_int()
            if adjust.x == 0 and adjust.y == 0:
                adjust = direction
            self._pos += adjust
            return

        elif self.target:
            if t >= self.target_time:
                self._pos = self.target
                self.NoTarget()
                if self.callback:
                    self.callback(t)
                    self.callback = None
            elif t < self.start_time:  #I don't think we should get this
                return
            else:
                partial = float(t - self.start_time) / self.duration
                partial = partial * partial * (3 - 2 * partial)  #smoothstep
                self._pos = (self.start_point +
                             (self.target_change * partial)).to_int()
Ejemplo n.º 26
0
 def __init__(self, train):
     self.train = train
     self.last_screech = 0
     self.size = Point(64, 48)
     self.knob_quad = drawing.Quad(globals.screen_texture_buffer,
                                   tc=globals.atlas.TextureSpriteCoords(
                                       self.knob_name))
     self.knob_coords = ((-30, -29), (-30, 19), (34, 19), (34, -29))
     self.knob_settings = (0.45, 0.13, -0.25)
     bl = self.start_pos * globals.screen
     #tr = bl + self.size
     self.knob_pos = bl + Point(30, 29)
     self.pos = bl
     self.level = 0
     self.Reset()
Ejemplo n.º 27
0
    def SetVertices(self, bl, tr):
        #top bar
        self.quads[0].SetVertices(Point(bl.x, tr.y - self.line_width), tr,
                                  drawing.constants.DrawLevels.ui + 1)
        #right bar
        self.quads[1].SetVertices(Point(tr.x - self.line_width, bl.y), tr,
                                  drawing.constants.DrawLevels.ui + 1)

        #bottom bar
        self.quads[2].SetVertices(bl, Point(tr.x, bl.y + self.line_width),
                                  drawing.constants.DrawLevels.ui + 1)

        #left bar
        self.quads[3].SetVertices(bl, Point(bl.x + self.line_width, tr.y),
                                  drawing.constants.DrawLevels.ui + 1)
Ejemplo n.º 28
0
 def __init__(self, tex_coords, xoffset, yoffset, width, height, opacity=0):
     self.tex_coords = tex_coords
     sf = 1.05
     self.outline_vertices = numpy.array(
         ((0, 0, 0), (0, height * sf, 0), (width * sf, height * sf, 0),
          (width * sf, 0, 0)), numpy.float32)
     self.width = width
     self.height = height
     self.size = Point(width, height)
     self.outline_size = self.size * sf
     self.offset = Point(xoffset, yoffset)
     self.opacity = opacity
     self.outline_offset = Point(
         float(self.width) / 40,
         float(self.height) / 40)
Ejemplo n.º 29
0
 def SetPos(self,pos):
     self.pos = pos
     bl = pos * globals.tile_dimensions
     tr = bl + (globals.tile_scale*Point(self.width,self.height))
     bl = bl.to_int()
     tr = tr.to_int()
     self.quad.SetVertices(bl,tr,4)
Ejemplo n.º 30
0
 def RemoveFromMap(self):
     if self.pos != None:
         bl = self.pos.to_int()
         tr = (self.pos + self.size).to_int()
         for x in xrange(bl.x, tr.x + 1):
             for y in xrange(bl.y, tr.y + 1):
                 self.map.RemoveActor(Point(x, y), self)