Ejemplo n.º 1
0
 def out_warp(self, pos, d, spos):
     tpos = spos + d
     if abs(tpos.y) < self.bound:
         blength = self.bound - abs(tpos.y) - 1
         tpos = Vector.VectorX(
             min(max(tpos.x, -blength), blength) if d.y else
             (tpos.x + blength) % (blength * 2 + 1) - blength, tpos.y)
         return Vector.Coordinate(self[tpos], (pos + d) % AREA_SIZE)
Ejemplo n.º 2
0
 def update(self, pos, area, events):
     ls=[]
     if self.hp<=1:
         self.hp+=0.001
     if self.sleep:
         self.sleep-=1
     for t in area.targets:
         length=pos.len_to(t.coords.pos)
         if t.team is not None and t.team!=self.p.team:
             if length<=self.rng:
                 apos=t.coords.pos+t.moveoff/64
                 tar_ang=pos.angle_to(apos)%math.tau
                 d=ang_d(self.angle,tar_ang)
                 if abs(d)<=self.rspeed:
                     self.angle=tar_ang
                     if self.shoot(area,t):
                         area["FX"].add(self.fx(pos*64+Vector.VectorX(32+32*math.cos(self.angle),24-32*math.sin(self.angle)),t.coords.pos*64+t.moveoff,self.angle,pos.len_to(apos)*64-32))
                 elif d<0:
                     self.angle+=self.rspeed
                 else:
                     self.angle-=self.rspeed
                 self.angle%=math.tau
                 break
             else:
                 ls.append(length)
     else:
         self.sleep=60 if not ls else min(ls)*5
Ejemplo n.º 3
0
 def update(self, p, events):
     j = p.j
     self.cdict[j] += j.get_dir_pressed(events)
     cpos = self.cdict[j]
     if cpos.x < 0:
         cpos += Vector.up
     e, y = self.current_element(j)
     if e is None or not e.inside(cpos - Vector.VectorX(0, y), self.size.x):
         self.cdict[j] = Vector.VectorX(0, cpos.y + 1)
     if cpos.y < 0 or cpos.y >= sum(e.get_h(self.size.x) for e in self.es):
         self.cdict[j] = Vector.zero
     buttons = j.get_buttons(events)
     e, y = self.current_element(j)
     cpos = self.cdict[j]
     if buttons[0]:
         e.on_a(cpos - Vector.VectorX(0, y), self.size.x, p)
     elif buttons[3]:
         e.on_drop(cpos - Vector.VectorX(0, y), self.size.x, p.cslot)
Ejemplo n.º 4
0
 def render(self, screen, srcj):
     screen.fill(self.bcol)
     Img.bcentrex(tfont, self.title, screen, 48)
     y = 0
     cc = self.cdict[srcj]
     for e in self.es:
         h = e.get_h(self.size.x)
         e.render(screen, y * 64 + 128, self.size,
                  cc - Vector.VectorX(0, y) if y <= cc.y < y + h else None)
         y += h
Ejemplo n.º 5
0
class Tree(Object):
    hardness = 60
    img = Img.imgstripxf("World/Tree")[-1]
    layers = ["Conv", "Items", "Objects"]
    renderlayer = "Objects"
    exoff = Vector.VectorX(0, -16)
    updates = False

    def mined(self):
        return Items.resources["Log"]
Ejemplo n.º 6
0
 def __init__(self,size,walls=None):
     self.size=size*2-Vector.Vector2(1,1)
     self.basesize=size
     self.objs=set()
     self.layers=[Layer(0,"Walls"),EntityLayer(0,"Dots"),EntityLayer(0,"Enemies"),EntityLayer(0,"Players")]
     self.ldict = {l.name: l for l in self.layers}
     if walls:
         self["Walls"].objs=walls
         self["Walls"].fix(Vector.zero,self.size,self)
     else:
         self.regen()
     self.rs=self.scale*16+16
Ejemplo n.º 7
0
 def spawn(self, nobj, pos):
     for l in nobj.layers:
         self.ldict[l][pos] = nobj
     if nobj.updates:
         self.ups.add((pos, nobj))
     if nobj.targetable:
         self.targets.add(nobj)
     if nobj.coords:
         nobj.coords.area = self
         nobj.coords.pos = pos
     else:
         nobj.coords = Vector.Coordinate(self, pos)
     nobj.on_spawn(self, pos)
     return nobj
Ejemplo n.º 8
0
def starting_area(area,pos,ps,team):
    for tpos in V(5, 5).iter_space_2d(pos+V(-2, -2)):
        area.ping(tpos)
        area.super_dest(tpos)
        area.set_tile("Bridge", tpos)
    area.spawn_new(Boxes.SpawnBox, pos,team)
    sb=area.get("Objects",pos)
    for n,pp in enumerate(Vector.iter_offsets(pos,Vector.ddirs+Vector.vdirs)):
        if n<len(ps):
            area.spawn(ps[n],pp)
            ps[n].spawn=sb.area
    if ps and team is not None:
        for v in Vector.ddirs+Vector.vdirs:
            area.spawn_new(War.LaserTurret,pos+v*2,0,ps[0])
Ejemplo n.º 9
0
 def regen_uts(self, pos, area):
     at = self[pos]
     if area.infinite:
         for tpos in Vector.iter_offsets(pos, Vector.vdirs + Vector.ddirs):
             area.ping(tpos)
     surround = [at] + [
         self[tpos]
         for tpos in Vector.iter_offsets(pos, Vector.vdirs + Vector.ddirs)
         if self[tpos]
     ]
     torender = sorted(
         set(t for t in surround if
             Tiles.tileorder[t.name] <= Tiles.tileorder[surround[0].name]))
     comp = [(torender[0], (4, 4, 4, 4))]
     for t in torender[1:]:
         uts = Vector.get_uts(
             pos, self, lambda ot: ot is None or Tiles.tileorder[ot.name] >=
             Tiles.tileorder[t.name])
         if uts != (0, 0, 0, 0) or t == at:
             comp.append((t, uts))
     comp = tuple(comp)
     self.utscache[pos] = comp
     if pos in self.recache:
         self.recache.remove(pos)
Ejemplo n.º 10
0
 def render(self, screen, y, size, rcpos=None):
     for x, (i, (p, q)) in enumerate(self.rs):
         Img.draw_with_num(screen, p.img, q,
                           (x % size.x * 64, y + x // size.x * 64), 4)
     if rcpos is not None:
         screen.blit(sel[3], rcpos * 64 + Vector.VectorX(0, y))
         selr = self.rs[rcpos.x + rcpos.y * size.x]
         i, (p, q) = selr
         l = len(i)
         offset = (size.x - l - 2) * 32
         for x, (item, n) in enumerate(i.items()):
             Img.draw_with_num(screen, Items.get_item_image(item), n,
                               (offset + x * 64, (size.y - 1) * 64), 4)
         screen.blit(arrow[3], (offset + l * 64, (size.y - 1) * 64))
         Img.draw_with_num(screen, p.img, q,
                           (offset + (l + 1) * 64, (size.y - 1) * 64), 4)
Ejemplo n.º 11
0
class Tunnel(Rotatable):
    imgs=Img.imgstripxf("Transport/Tunnel")
    updates = False
    layers = ["Conv","Items","Objects"]
    renderlayer = "Objects"
    exoff = Vector.VectorX(0,-8)
    hardness = 60
    def in_warp(self,d):
        if d==Vector.vdirs[self.r]:
            for x in range(1,6):
                tc=self.coords+d*x
                o=tc.get("Objects")
                if isinstance(o,Tunnel) and o.r==(self.r+2)%4:
                    tc.pos+=d
                    return tc
    def mined(self):
        return Placeable(Tunnel)
Ejemplo n.º 12
0
 def render(self, screen, y, size, rcpos=None):
     if Research.current[self.team]:
         for x, r in enumerate(Research.current[self.team]):
             if r is Research.current_research[self.team]:
                 draw.rect(
                     screen, (100, 100, 100),
                     Rect(x % size.x * 64, y + x // size.x * 64, 64, 64))
             screen.blit(r.img[3], (x % size.x * 64, y + x // size.x * 64))
         if rcpos is not None:
             screen.blit(sel[3], rcpos * 64 + Vector.VectorX(0, y))
             selr = Research.current[self.team][rcpos.x + rcpos.y * size.x]
             l = len(selr.packs)
             offset = (size.x - l) * 32
             for x, p in enumerate(selr.packs):
                 Img.draw_with_num(screen, Items.get_item_image("SP%s" % p),
                                   selr.n,
                                   (offset + x * 64, (size.y - 1) * 64), 4)
     else:
         Img.bcentrex(tfont, "NO RESEARCH AVAILABLE", screen, y - 16)
Ejemplo n.º 13
0
class Crossover(FixedMachine):
    imgs=[Img.imgx("Transport/Crossover")]
    exoff = Vector.VectorX(0,-4)
    def input(self,d,i):
        return self.add_output(i,override_d=d)
Ejemplo n.º 14
0
 def render(self, surf, pos, scale):
     for n, s in enumerate(self.slots):
         s.render(surf, pos + Vector.VectorX(n * (scale * 16 + 16), 0),
                  scale)
Ejemplo n.º 15
0
 def render(self, screen, y, size, rcpos=None):
     for n, s in enumerate(self.inv.slots):
         s.render(screen, (n % size.x * 64, n // size.x * 64 + y), 3)
         if rcpos is not None:
             screen.blit(sel[3], Vector.VectorX(0, y) + rcpos * 64)
Ejemplo n.º 16
0
 def __getitem__(self, item):
     if item not in self.surface:
         self.surface[item] = Area.LargeArea(
             Vector.VectorX(AREA_SIZE, AREA_SIZE),
             self.bands[abs(item.y)](), PSector(self, item))
     return self.surface[item]
Ejemplo n.º 17
0
 def spawn_new(self, oc, pos, *args):
     return self.spawn(oc(Vector.Coordinate(self, pos), *args), pos)
Ejemplo n.º 18
0
 def __setitem__(self, key, value):
     self.objs[key] = value.name
     self.recache.add(key)
     self.recache.update(
         set(Vector.iter_offsets(key, Vector.vdirs + Vector.ddirs)))