Skip to content

Commit

Permalink
Day 3 - ugh :/
Browse files Browse the repository at this point in the history
Overhaul/simplify Item carrying. Carry one item at a time. - #9
Add item use callback - #9
Add mana collection and mycelial network - #7
Add construction spinner and buildSites - #5
  • Loading branch information
v4nz666 committed Mar 10, 2016
1 parent 774abf4 commit aaf027f
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 36 deletions.
12 changes: 7 additions & 5 deletions RoguePy/Game/Entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ def __init__(self, map, x, y, name, ch, fg):
self.name = name
self.ch = ch
self.fg = fg
self.inventory = []
self.item = None

def pickup(self, item):
if not self.item:
self.item = item
return True
return False

self.inventory.append(item)
def drop(self, item):
if item in self.inventory:
self.inventory.remove(item)
def drop(self):
self.item = None

def tryMove(self, dx, dy):
# Rest / skip check.
Expand Down
14 changes: 7 additions & 7 deletions RoguePy/Game/Item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def __init__(self, name, ch, fg):
self.ch = ch
self.fg = fg

def spawn(self, map, x, y):
if map.addItem(self, x, y):
self.map = map
self.x = x
self.y = y
return True
return False
self.desc = ""



def use(self, x, y):
print self.name, " used"
pass
2 changes: 2 additions & 0 deletions chars.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
__author__ = 'jripley'

shroom = 26
spore = 9
node = 10
water = 30
tree = 24
grass = 25
mountain = 27


19 changes: 16 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from RoguePy.libtcod import libtcod

manaRate = 0.025

### Random
seed = 666
rand = libtcod.random_new_from_seed(seed)
Expand All @@ -11,10 +13,21 @@ def randint(max, min=0):
ui = {
'uiWidth': 96,
'uiHeight': 60,

'msgW': 24,
'msgH': 16,
'msgX': 96 - 24,
'msgY': 60 - 16
'msgY': 60 - 16,

'invX': 96 - 24,
'invY': 4,
'invW': 24,
'invH': 10,

'manaX': 96 - 24,
'manaY': 14,
'manaW': 24,
'manaH': 16
}

world = {
Expand All @@ -25,5 +38,5 @@ def randint(max, min=0):
}

player = {
'viewRadius': 12
}
'viewRadius': 16
}
2 changes: 2 additions & 0 deletions entities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
__author__ = 'jripley'

from construct import Construct
from node import Node
from shroom import Shroom
9 changes: 9 additions & 0 deletions entities/construct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from RoguePy.Game import Entity

__author__ = 'jripley'

class Construct(Entity):
def setRequired(self, req):
self.required = req
return self

12 changes: 12 additions & 0 deletions entities/node.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__author__ = 'jripley'

from RoguePy.Game import Entity


class Node(Entity):
active = False
radius = 8




22 changes: 19 additions & 3 deletions entities/shroom.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
from RoguePy.Game import Entity
from entities import Node
from sporenetwork import SporeNetwork

__author__ = 'jripley'

class Shroom(Entity):
class Shroom(Node):
active = False
radius = 12

def activate(self, player):
self.active = True
self.player = player

self.active = True


self.initNetwork()

def initNetwork(self):
print "initing spore network"
self.net = SporeNetwork(self.map)

def inNetwork(self, x, y):
return self.net.field[x + y * self.map.width]

@property
def netSize(self):
return self.net.size
8 changes: 8 additions & 0 deletions items.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from RoguePy.Game.Item import Item
from RoguePy.UI import Colors
import chars

__author__ = 'jripley'

spore = Item("Spore", chars.spore, Colors.white)
#.desc("Plant the spore to increase the size of your mycelial network")
68 changes: 68 additions & 0 deletions sporenetwork.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from RoguePy.UI import Colors
from RoguePy.libtcod import libtcod
import chars
import config as cfg

__author__ = 'jripley'

class SporeNetwork():
def __init__(self, map):
self.map = map

self.nodes = [map.shroom]

self.initField()
self.calculateField()

def initField(self):
self.field = [0 for _i in range(self.map.width * self.map.height)]

def addNode(self, node):
if not node in self.nodes:
self.nodes.append(node)
self.calculateField(node)

def removeNode(self, node):
if node in self.nodes:
self.nodes.remove(node)
self.initField()
self.calculateField()

def calculateField(self, node=None):
if node is None:
nodes = self.nodes
else:
nodes = [node]

w = self.map.width
h = self.map.height

#TODO should probably be looping on nodes, and only checking x-rad to x+rad
for y in range(h):
for x in range(w):
for node in nodes:
if self.withinRadius(x, y, node):
self.field[x + y * w] = 1
break

@property
def size(self):
return self.field.count(1)

@staticmethod
def withinRadius(x, y, node):
dx = abs(x-node.x)
dy = abs(y-node.y)
R = node.radius

if dx>R:
return False
if dy>R:
return False
if dx + dy <= R:
return True

if dx**2 + dy**2 <= R**2:
return True
else:
return False
3 changes: 2 additions & 1 deletion states/generatestate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chars
from entities import Shroom

__author__ = 'jripley'
Expand Down Expand Up @@ -192,7 +193,7 @@ def spawnShroom(self):
y = minY + config.randint(maxY)

if self.map.getCell(x, y).type == 'grass':
self.map.shroom = Shroom(self.map, x, y, 'Shroom', 26, Colors.white)
self.map.shroom = Shroom(self.map, x, y, 'Shroom', chars.shroom, Colors.white)
else:
self.spawnShroom()

Expand Down
Loading

0 comments on commit aaf027f

Please sign in to comment.