class BigStack(Object): #BIG SHAQ #In awe at the size of this lad. ABSOLUTE UNIT layers = ["Conv", "Items"] renderlayer = "Items" pickup = Img.sndget("pickup") def __init__(self, coords, item, q): super().__init__(coords) self.item = item self.q = q def interact(self, player, ppos, pos, area): self.q -= player.inv.add(self.item, self.q) if self.q == 0: area.dobj(self, pos) self.pickup.play() def render(self, layer, surf, tpos, area, scale=3): super().render(layer, surf, tpos, area, scale) if layer == self.renderlayer: Img.draw_num(surf, self.q, tpos, scale + 1, True) @property def img(self): return self.item.img
class ItemObject(Object): layers = ["Items"] pickup = Img.sndget("pickup") slayer = "Conv" def __init__(self, coords, item): super().__init__(coords) self.item = item def interact(self, player, ppos, pos, area): if player.inv.add(self.item): area.dobj(self, pos) self.pickup.play() @property def img(self): return self.item.img
class HandCrafting(Element): make = Img.sndget("make") def __init__(self, p): self.rs = Registry.get_recipes(p.team, "Crafting") def get_h(self, w): return len(self.rs) // w + 1 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) def inside(self, rpos, w): return rpos.x < w and rpos.x + rpos.y * w < len(self.rs) def on_a(self, rpos, w, p): i, (prd, q) = self.rs[rpos.x + rpos.y * w] psc = p.inv.get_counter() ic = Counter(i) if ic & psc == ic: taken = Counter() for item, n in i.items(): taken += p.inv.remove(item, n) added = p.inv.add(prd.new(), q) if added != q: p.inv.remove(prd.name, added) for item, n in taken.items(): p.inv.add(item, n) else: self.make.play() return error.play()
from .Items import Item from Lib import Img import pygame from Game import Registry,Research from Objects import War error=Img.sndget("error") bsnd=Img.sndget("break") class Pickaxe(Item): img=Img.imgx("Tools/Pickaxe") last_used=0 MAX_CONTINUOUS=200 last_mined=None stack_size = 1 singular = True continuous = True def use(self,area,tpos,tr,p): for l in reversed(area.layers): o=l[tpos] if o and o.hardness: if o is self.last_mined and pygame.time.get_ticks()-self.last_used<self.MAX_CONTINUOUS: self.prog+=1 if self.prog==o.hardness: item=o.mined() o.on_mine(area,tpos) if item is None or p.inv.add(item,1): bsnd.play() elif area.clear("Items",tpos): area.spawn_item(item,tpos) bsnd.play() else: o.on_mine(area, tpos,True)
class Lab(Element): progress = 0 pcol = (200, 200, 255) backcol = (0, 0, 0) overlay = Img.imgx("SCIENCE") done = Img.sndget("research") def __init__(self, energy, power, team): self.inputs = Items.MultiSlot([ Items.FilterSlot(Items.resources["SP%s" % n]) for n in range(1, 7) ]) self.energy = energy self.power = power / 60 self.team = team def inside(self, rpos, w): return rpos.x < len(self.inputs.slots) and not rpos.y def get_h(self, w): return 2 def render(self, screen, y, size, rcpos=None): for n, s in enumerate(self.inputs.slots): s.render(screen, (n * 64, y), 3) if rcpos is not None and n == rcpos.x: screen.blit(sel[3], (n * 64, y)) if Research.current_research[self.team]: Img.draw_with_num(screen, Research.current_research[self.team].img, Research.rprogs[self.team], ((n + 1) * 64, y), 4) draw.rect(screen, self.backcol, Rect(0, y + 64, len(self.inputs.slots) * 64, 32)) if self.progress: draw.rect( screen, self.pcol, Rect(0, y + 64, len(self.inputs.slots) * 64 * self.progress / self.energy, 32)) screen.blit(self.overlay[3], (0, y + 64)) def on_a(self, rpos, w, p): self.inputs.slots[rpos.x].transfer(p.inv) def on_drop(self, rpos, w, slot): slot.transfer(self.inputs.slots[rpos.x]) def machine_update(self, ui, machine): cr = Research.current_research[self.team] if cr: if self.progress: if self.progress == self.energy: Research.rprogs[self.team] += 1 if Research.rprogs[self.team] == cr.n: Research.on_complete(self.team) self.done.play() self.progress = 0 else: self.progress += ui.get_power( min(self.power, self.energy - self.progress)) else: if all(self.inputs.slots[n - 1] for n in cr.packs): gp = ui.get_power(self.power) if gp: for n in cr.packs: self.inputs.slots[n - 1].remove(1) self.progress += gp break
from Lib import Vector, Img from Game import Registry, Research from Engine import Items from collections import Counter from pygame import draw, Rect tfont = Img.fload("cool", 64) sel = Img.imgx("GUISelect") arrow = Img.imgx("Arrow") error = Img.sndget("error") class MUI(object): bcol = (210, ) * 3 size = Vector.zero def __init__(self, title, elements): self.re_init(title, elements) self.cdict = {} def re_init(self, title, elements): self.title = title self.es = elements def on_enter(self, j, sz): self.size = sz self.cdict[j] = Vector.zero def render(self, screen, srcj): screen.fill(self.bcol) Img.bcentrex(tfont, self.title, screen, 48) y = 0
from .Layers import Layer, TileLayer, FXLayer from Lib import Vector, Img from Engine import Items from . import Tiles, Player from random import shuffle from Objects import War V = Vector.VectorX exp = Img.sndget("bomb") class Area(object): backcol = (0, 0, 0) infinite = False large = False explored = () building = None anitick = 0 ebuffer = 0 emax = 10 def __init__(self, bounds, generator, building): self.bounds = bounds self.layers = [ TileLayer(16, "Tiles"), Layer(16, "Ore"), Layer(16, "Overlay"), Layer(16, "Conv"), Layer(16, "Items"), Layer(0, "Objects"), Layer(-32, "Air"), FXLayer("FX")