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 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(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 move(self): #self.head.update() self.movephead() colid = self.currect.collidelist(self.snacks) if colid >= 0: snack = self.snacks[colid] self.snacks.remove(snack) gfx.clear(snack) self.tlen += 1 tailcolid = self.currect.collidelist(self.tail) if tailcolid >= 0 and tailcolid < len(self.tail)-TAILCOLLERR: deadevent = pygame.event.Event(USEREVENT, code=TAILCOLLIDE) pygame.event.post(deadevent) #print "DEAD" self.updatetail() self.disptaillen() self.dispfps()
def updatetail(self): x = self.x #- HEAD_RADIUS*self.x_v/speed y = self.y #- HEAD_RADIUS*self.y_v/speed ox = self.tailx oy = self.taily xd = abs(ox - x) yd = abs(oy - y) dist = math.sqrt(xd*xd+yd*yd) #print dist if dist > TAIL_PIECE_LEN: self.tailx = x self.taily = y newt = gfx.ptail((ox, oy), (x , y)) self.tail.append(newt) if len(self.tail) > self.tlen * TAIL_PIECE_PER_SNACK: last = self.tail.pop(0) gfx.clear(last)
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 dispfps(self): gfx.clear(self.dispfpsr) self.dispfpsr = gfx.writen(int(self.clock.get_fps()), FONTSIZE, (self.status_area.right-5-FONTSIZE*3*3*1.2, self.status_area.y+4))
def disptaillen(self): if len(self.tail) > self.lastprint: self.lastprint = len(self.tail) gfx.clear(self.disptail) self.disptail = gfx.writen(len(self.tail)/TAIL_PIECE_PER_SNACK, FONTSIZE, (self.status_area.x+5, self.status_area.y+4))
def movephead(self): if self.currect: gfx.clear(self.currect) self.updatepos() self.currect = gfx.phead((self.x, self.y))
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,"]")