def draw(self): gfx.clear() if self.moving: self.fov = self.raycast(10, 3) self.max_y = gfx.scr().getmaxyx()[0] self.max_x = int(0.60*gfx.scr().getmaxyx()[1]) for e in self.entities: e.randomMove(self) self.moving = False for y in range(self.min_y, self.max_y): for x in range(self.min_x, self.max_x): if (self.player.x, self.player.y) == (x, y): gfx.draw(y, x, "☺", "b") elif y>=0 and x>=0 and y<len(self.fov) and x<len(self.fov[0]): if self.fov[y][x] == 1: empty = True for e in self.entities: if (x, y) == (e.x, e.y): empty = False gfx.draw(y, x, e.char, "r") for c in self.chests: if (c.x, c.y) == (x, y): empty = False gfx.draw(y, x, "÷", "c") if empty: c = self.map[y][x] gfx.draw(y, x, c, "g" if c == "." else "y") self.seen[y][x] = 1 elif self.seen[y][x]: empty = True for c in self.chests: if (c.x, c.y) == (x, y): empty = False gfx.draw(y, x, "÷", "dc") if empty: c = self.map[y][x] gfx.draw(y, x, c, "dg" if c == "." else "dy")
def handle(self, c): if c == "up": self.y -= 1 elif c == "down": self.y += 1 elif c == "left": self.x -= 1 elif c == "right": self.x += 1 if c: gfx.clear() gfx.draw(self.x,self.y,'@')
def _print(self, y, x, text, col="w", limit=0): i = 0 j = 0 for char in text: if limit != 0 and i >= limit: i = 0 j += 1 gfx.draw(y+j, x+i, char, col) i+=1
def draw(self): gfx.clear() my_neighbors = view(self.player_x, self.player_y, 3) for y in range(self.h): for x in range(self.w): x_coord = 2 * x + (y % 2) if (self.player_x, self.player_y) == (x, y): gfx.draw(x_coord, y, "@") elif (x, y) in my_neighbors: gfx.draw(x_coord, y, ".")
def display_title(self): title = [(1,"It'll never catch on!"), (2,"A robot-battle roguelike (VERY) loosely based on TVTROPES"), (4," e r y u "), (5," s f h k "), (6," x c b n "), (7,"'Left stick' 'Right stick'"), (8," Aim Target Move Robot "), (10,"Press Z to shot bullet and Q to quit."), (12,"Get power ups. Kill robots. Press Enter to start.")] gfx.clear() for y,t in title: x = 40-len(t)//2 q = y==1 for c in t: gfx.draw(x,y,c,'g'+("!" if q else "")) x+= 1
def draw(self): # get reference to the back buffer scr = gfx.get_back_buffer() # clear the screen contents gfx.clear() view_center_x = self.player.x - self.view_width / 2 view_center_y = self.player.y - self.view_height / 2 if view_center_x < 1: view_center_x = 1 if view_center_y < 1: view_center_y = 1 if view_center_x + self.view_width > self.width: view_center_x = self.width - self.view_width if view_center_y + self.view_height > self.height: view_center_y = self.height - self.view_height # recompute FOV if needed (player moved or something) self._recompute_fov_if_needed() # draw the map tiles for y in range(self.view_height): for x in range(self.view_width): visible = libtcod.map_is_in_fov(self.fov_map, x + view_center_x, y + view_center_y) tile = self.map[x + view_center_x][y + view_center_y] if visible: gfx.draw(x, y, char=tile.char, color=tile.color) #since it's visible, flag it as explored self.map[x + view_center_x][y + view_center_y].explored = True elif self.map[x + view_center_x][y + view_center_y].explored: gfx.draw(x, y, char=tile.char, color=tile.dark_color) # Draw the player draw_player_x = self.player.x - view_center_x draw_player_y = self.player.y - view_center_y gfx.draw(draw_player_x, draw_player_y, self.player.char, self.player.color) # blit contents from back buffer to root window libtcod.console_blit(gfx.get_back_buffer(), 0, 0, gfx.SCREEN_WIDTH, gfx.SCREEN_HEIGHT, 0, 0, 0) libtcod.console_flush()
def draw_gui(self, vx=41, vy=0, vw=38, vh=20 ): x = vx for c in "Robot Battle": gfx.draw(x,vy,c) x += 1 x = vx for c in "Your HP: %d"%self.player.hp: gfx.draw(x,vy+1,c) x += 1 printy = self.log[-min(vh-3,len(self.log)):] y = vy+3 for p in printy: x = vx for c in p[:vw]: gfx.draw(x,y,c) x += 1 y += 1
def draw(self, cw=20, ch=20, vx=0, vy=0): cx,cy = self.camera qx,qy = self.player.x, self.player.y if self.player.target: qx,qy = self.player.target dx,dy = qx-cx, qy-cy if dx > 15 or dx < 5: cx = qx - cw/2 if dy > 15 or dy < 5: cy = qy - ch/2 self.camera = cx,cy self.anim_tick = (self.anim_tick + 1)%self.anim_speed if self.anim_tick == 0: if len(self.bullet_anim)>0: x,y = self.bullet_anim.pop(0) if not self.is_free(x,y): self.bullet_anim = [] for e in self.entities: if (e.x,e.y) == (x,y): e.hp -= self.bullet_power if e is self.player: self.gui_log("I'm hit!") if e.hp < 1: e.char = "%" self.gui_log("%s has died. :("%(e.name)) self.bullet_anim = [] for s in self.stuff[:]: if (s.x,s.y)==(self.player.x,self.player.y): self.stuff.remove(s) if s.name[0] == "+": self.player.hp += 1 self.gui_log("You feel healthier!") elif s.name[0] == "!": self.player.toughness += 1 self.gui_log("You feel tougher!") elif s.name[0] == ">": self.player.speed += 1 self.gui_log("You are faster now!") gfx.clear() if self.player.target: a = angle((self.player.x,self.player.y),self.player.target) if a is not None: self.player.angle = a my_fov = self.fov(self.player.x,self.player.y,10,[(self.player.angle-self.player.lense,self.player.angle+self.player.lense)]) #my_fov = self.fov(self.player.x,self.player.y,10) #my_fov = [] #for a in range(self.w): # for b in range(self.h): # my_fov.append((a,b)) lineee = [] if self.player.target: lineee = line((self.player.x,self.player.y),self.player.target) all_fovs = {} for e in self.entities: all_fovs[e] = self.fov(e.x,e.y,10,[(e.angle-e.lense,e.angle+e.lense)]) for y in range(self.h): odd = True if y % 2 == 1 else False for x in range(self.w): if not(x >= cx and x < cx+cw and y >= cy and y < cy+ch): continue ax = (x-cx+vx)*2 + (1 if odd else 0) ay = (y-cy+vy) # For each tile that can be seen, determine what will be drawn # there. if (x,y) in my_fov: empty = True for s in self.stuff: if (s.x,s.y) == (x,y): gfx.draw(ax,ay,s.char,"m!") empty = False for e in self.entities: if (e.x,e.y) == (x,y): gfx.draw(ax,ay,e.char,"b!" if e is self.player else "r!") empty = False if empty: c = self.map[y][x] gfx.draw(ax,ay,c,"g" if c == "." else "y") if len(self.bullet_anim)>0 and self.bullet_anim[0] == (x,y): gfx.draw(ax,ay,"*",'r') else: for e in self.entities: if (e is not self.player and (e.x,e.y)==(x,y) and (self.player.x,self.player.y) in all_fovs[e]): gfx.draw(ax,ay,"\"","r!") if self.player.target == (x,y): gfx.draw(ax-1,ay,"[") gfx.draw(ax+1,ay,"]")
def draw_edges(self, minY, minX, maxY, maxX): for i in range(minY+1, maxY-1): gfx.draw(i, minX, "║", "w") gfx.draw(i, maxX, "║", "w") for i in range(minX+1, maxX): gfx.draw(minY, i, "═", "w") gfx.draw(maxY-1, i, "═", "w") gfx.draw(minY, maxX, "╗", "w") gfx.draw(maxY-1, maxX, "╝", "w") gfx.draw(maxY-1, minX, "╚", "w") gfx.draw(minY, minX, "╔", "w")
def draw_lifebar(self, y, x, size, percent, col="g"): gfx.draw(y, x, "[", "w") gfx.draw(y, x+size, "]", "w") barsize = int((size-1)*percent) for i in range(0, barsize): gfx.draw(y, x+i+1, ":", col)
def clear(self, minY, minX, maxY, maxX): for j in range(minY, maxY): for i in range(minX, maxX): gfx.draw(j, i, " ")
def draw_separator(self, y): gfx.draw(y, self.x, "╠", "w") gfx.draw(y, self.max_x, "╣", "w") for i in range(self.x+1, self.max_x): gfx.draw(y, i, "═", "w")