def timer_init(self): t = to_ns({}) t.ticks = 0 t.frames = 0 t.ticks_per_sec = self.GAME.ticks_per_sec t.tick_len = 1e6 / (t.ticks_per_sec) # [us] t.prev_sec, t.prev_usec = 0, 0 t.sec, t.usec = 0, 0 t.us_elapsed = 0 self.timer = t
def make_regions(self): '''Creates screen regions''' v = self.ui_vars self.regions = to_ns({}) self.regions.board = pg.Rect(0, 0, v.disp_w, v.disp_h - v.cns_ss) self.regions.notch = pg.Rect(v.cns_ss, v.disp_h - v.cns_ss, v.disp_w - 2 * v.cns_ss, v.cns_ss - v.cns_ch) self.regions.cmnds = pg.Rect(v.ccmd_ofx, v.ccmd_ofy, v.ccmd_cols * (v.cicos + v.cspc), v.ccmd_rows * (v.cicos + v.cspc))
def load_config(self): '''Loads configuration files''' Log.debug('Loading config files') self.CORE = internal.to_ns(yaml.load(open('cnf/core.yml', 'r'))) self.TEXT = internal.to_ns(yaml.load(open('cnf/text.yml', 'r'))) self.CLRS = internal.to_ns(yaml.load(open('cnf/clrs.yml', 'r'))) self.GAME = internal.to_ns(yaml.load(open('cnf/game.yml', 'r'))) self.LNCH = internal.to_ns(yaml.load(open('cnf/lnch.yml', 'r'))) self.USER = internal.to_ns(yaml.load(open('cnf/user.yml', 'r'))) self.KBDS = internal.to_ns(yaml.load(open('cnf/kbds.yml', 'r')))
def make_ui_vars(self): self.ui_vars = to_ns({}) v = self.ui_vars disp = pg.display.Info() brd = self.session.board home = self.player.home_cc_pos c = self.CORE # Constants v.subc_px = c.pix_per_sub #SubCell:Size v.cell_px = v.subc_px*c.sub_per_cell #Cell:Size # Interface (Constants) v.rsr_icos = 30 #Resources:Icons:Size v.rsr_spc = 10 #Resources:Spacing v.cns_ch = 200 #Console:Center:Size:Y v.cns_ss = 320 #Console:Sides:Size v.ccap_crty = -28 #Console:Cap:Correction:Y v.ccap_crtx = -48 #Console:Cap:R:Correction:X v.cicos = 40 #Console:Icons:Size v.cspc = 2 #Console:Spacing v.csel_th = 32 #Console:Selection:Text:Y v.csel_cols = 8 #Console:Selection:Columns v.csel_rows = 3 #Console:Selection:Rows v.csel_spc = 8 #Console:Selection:Spacing v.ccmd_cols = 5 #Console:Commands:Columns v.ccmd_rows = 5 #Console:Commands:Rows v.ccmd_crtx = 20 #Console:Commands:Correction v.ccmd_crty = 20 #Console:Commands:Correction # Session- or Device- specific v.disp_w = disp.current_w #Display:Size:X v.disp_h = disp.current_h #Display:Size:Y v.disp_cx = v.disp_w//2 #Display:Center:X v.disp_cy = v.disp_h//2 #Display:Center:Y v.db_w = disp.current_w #Display:Board:Size:X v.db_h = disp.current_h-v.cns_ch #Display:Board:Size:Y v.db_cx = v.db_w//2 #Display:Board:Center:X v.db_cy = v.db_h//2 #Display:Board:Center:Y v.brd_w = brd.size[0]*v.cell_px #Board:Size:X[px] v.brd_h = brd.size[1]*v.cell_px #Board:Size:Y[px] # Current view v.v_sx = home.x*v.cell_px-v.db_cx #View:Shift:X v.v_sy = home.y*v.cell_px-v.db_cy #View:Shift:Y v.bidx = ceil(v.db_w/v.cell_px) #View:CellsInDisplay:X v.bidy = ceil(v.db_h/v.cell_px) #View:CellsInDisplay:Y v.b_sx = v.v_sx//v.cell_px #Board:Shift:X v.b_sy = v.v_sy//v.cell_px #Board:Shift:Y # Interface (Calculated) v.csel_ofx = v.disp_w//2 -2*v.cicos #Console:Selection:Offxet:X v.csel_ofy = v.csel_th+v.disp_h-v.cns_ch #Console:Selection:Offset:Y v.ccmd_ofx = v.ccmd_crtx+v.disp_w-v.cns_ss #Console:Selection:Offxet:X v.ccmd_ofy = v.ccmd_crty+v.disp_h-v.cns_ss #Console:Selection:Offset:Y
def load_gfx(self, vr): '''Loads graphics (vr parameter is terrain textures variant)''' v = self.ui_vars self.gfx = to_ns({}) self.gfx.terrain = self.get_all_gfx('img/terrain/{}/'.format(vr), '.png') self.gfx.ui = self.get_all_gfx('img/ui/', '.png') self.gfx.icons = self.get_all_gfx('img/icons/', '.png') self.gfx.objs = self.get_all_gfx('img/objects/', '.png', pil=True) for key, image in self.gfx.objs.items(): Log.debug('Creating color variants of {} texture'.format(key)) self.gfx.objs[key] = self.make_clr_variants(image) self.gfx.grayed = self.get_all_gfx('img/objects/', '.png', pil=True) for key, image in self.gfx.grayed.items(): gray = image.convert('L') gray = gray.resize((v.cicos,v.cicos)) self.gfx.grayed[key] = self.pil_to_srf(gray.convert('RGB'))
def make_colors(self): self.colors = to_ns({}) self.colors.white = pg.Color(255,255,255) self.colors.gdark = pg.Color( 46, 46, 46) # Standard dark gray self.colors.vdark = pg.Color( 35, 35, 35) self.colors.black = pg.Color( 0, 0, 0)