This commit is contained in:
Voussoir 2014-10-12 16:38:29 -07:00
parent b02c2dc025
commit c7d4c552b2
3 changed files with 103 additions and 27 deletions

View file

@ -15,8 +15,6 @@ Smokescreen pickup: Exclamators cannot detect player. Will wander randomly for 5
Gold candy: Special candy which gives quadruple points. Is invisible, flashes every 5 steps, relocates if not found fast enough Gold candy: Special candy which gives quadruple points. Is invisible, flashes every 5 steps, relocates if not found fast enough
Decoy: Create a phantom player which will move opposite of the player's controls. Exclamators will follow it instead of the player. Fades after 10 steps
Hats. Hats.
Enemies spawn in larger numbers as the game goes on Enemies spawn in larger numbers as the game goes on

5
Dodgy/changelog.md Normal file
View file

@ -0,0 +1,5 @@
###12 Oct 2014
+ Added changelog. I probably will get lazy and stop updating this eventually
+ Added phantom, incomplete implementation

View file

@ -49,22 +49,29 @@ class tgame:
#tkvar.bind('c', lambda data=self.data: spawncandy()) #tkvar.bind('c', lambda data=self.data: spawncandy())
tkvar.bind('j', lambda data=self.data: spawnbomb()) tkvar.bind('j', lambda data=self.data: spawnbomb())
tkvar.bind('z', lambda data=self.data: spawnbomb()) tkvar.bind('z', lambda data=self.data: spawnbomb())
tkvar.bind('k', lambda data=self.data: spawnphantom())
tkvar.bind('r', lambda data=self.data: restart()) tkvar.bind('r', lambda data=self.data: restart())
tkvar.bind('h', lambda data=self.data: helpreel()) tkvar.bind('h', lambda data=self.data: helpreel())
tkvar.bind('<Control-w>', quit) tkvar.bind('<Control-w>', quit)
self.candylist = [] self.candylist = []
self.enemylist = [] self.enemylist = []
self.bomblist = [] self.bomblist = []
self.phantomlist = []
self.entlist = [] self.entlist = []
self.symbols = {'char':'H', 'wall':'#', 'floor':' '} self.symbols = {'char':'H', 'wall':'#', 'floor':' '}
self.stepstaken = 0 self.stepstaken = 0
self.collections = 0 self.collections = 0
self.bombs = 0 self.bombs = 0
self.enemyspawntime = 10
self.enemyspawnrate = 50
self.enemyspawnmindist = 6 self.enemyspawnmindist = 6
self.candyspawnrate = 4
self.isdeath = False self.isdeath = False
self.bombcost = 4 self.bombcost = 4
self.phantomcost = 10
self.helplabelindex = -1 self.helplabelindex = -1
self.helplabeltexts = [ self.helplabeltexts = [
"<WASD>=Movement <J>=Bomb <R>=Restart ->", "<WASD>=Movement <J>=Bomb <R>=Restart ->",
"<UDLR>=Movement <Z>=Bomb <R>=Restart ->", "<UDLR>=Movement <Z>=Bomb <R>=Restart ->",
@ -86,11 +93,34 @@ class tgame:
if xmove != 0: if xmove != 0:
if (self.xpos > 1 or xmove > 0) and (self.xpos < (arenasize -2) or xmove < 0): if (self.xpos > 1 or xmove > 0) and (self.xpos < (arenasize -2) or xmove < 0):
self.xpos += xmove self.xpos += xmove
if self.phantomlist != []:
ph = self.phantomlist[0]
ph.x -= xmove
if ph.x < 1:
ph.x = 1
if ph.x > (arenasize-2):
ph.x = arenasize-2
hasmoved = True hasmoved = True
if ymove != 0: if ymove != 0:
if (self.ypos > 1 or ymove > 0) and (self.ypos < (arenasize -2) or ymove < 0): if (self.ypos > 1 or ymove > 0) and (self.ypos < (arenasize -2) or ymove < 0):
self.ypos += ymove self.ypos += ymove
if self.phantomlist != []:
ph = self.phantomlist[0]
ph.y -= ymove
if ph.y < 1:
ph.y = 1
if ph.y > (arenasize-2):
ph.y = arenasize-2
hasmoved = True hasmoved = True
if hasmoved:
if self.phantomlist != []:
ph = self.phantomlist[0]
ph.lifespan -= 1
if ph.lifespan <= 0:
self.phantomlist.remove(ph)
self.entlist.remove(ph)
del ph
#print(self.xpos, self.ypos, '|', self.stepstaken) #print(self.xpos, self.ypos, '|', self.stepstaken)
self.data = [self.symbols['wall']*arenasize, self.symbols['wall']*arenasize] self.data = [self.symbols['wall']*arenasize, self.symbols['wall']*arenasize]
for x in range(arenasize-2): for x in range(arenasize-2):
@ -108,48 +138,56 @@ class tgame:
if candies.y == ycoord: if candies.y == ycoord:
if candies.x == self.xpos and candies.y == self.ypos: if candies.x == self.xpos and candies.y == self.ypos:
print('Collection') print('Collection')
self.collections += 1 collect(1)
self.candylist.remove(candies) self.candylist.remove(candies)
self.entlist.remove(candies) self.entlist.remove(candies)
if self.collections % self.bombcost == 0:
self.bombs += 1
del candies del candies
for enemies in self.enemylist: for enemies in self.enemylist:
if enemies.y == ycoord: if enemies.y == ycoord:
if enemies.x == self.xpos and enemies.y == self.ypos: if enemies.x == self.xpos and enemies.y == self.ypos:
print('Death') print('Death')
self.isdeath = True self.isdeath = True
self.datalabel.configure(fg='Red') self.datalabel.configure(fg='Red')
self.entlist.sort(key=lambda p: p.x) self.entlist.sort(key=lambda p: p.x)
for entities in self.entlist: for entities in self.entlist:
if entities.y == ycoord: if entities.y == ycoord:
yl = yl[:entities.x] + entities.symbol + yl[entities.x+1:] yl = yl[:entities.x] + entities.symbol + yl[entities.x+1:]
self.data[ycoord] = yl self.data[ycoord] = yl
self.datalabel.configure(text='\n'.join(self.data))
if hasmoved: if hasmoved:
self.stepstaken += 1 self.stepstaken += 1
if self.stepstaken % 4 == 0: if self.stepstaken % self.candyspawnrate == 0:
spawncandy() spawncandy()
if self.stepstaken == self.enemyspawntime: if self.stepstaken % self.enemyspawnrate == 0:
#spawnenemy()
pass
if self.stepstaken % 50 == 0:
spawnenemy() spawnenemy()
if self.stepstaken > self.enemyspawntime:
for en in self.enemylist:
en.approach(self.xpos, self.ypos)
#print(dist(en.x, en.y, self.xpos, self.ypos))
if en.x < 1:
en.x = 1
if en.x > (arenasize-2):
en.x = arenasize-2
if en.y < 1: for en in self.enemylist:
en.y = 1 oldx = en.x
if en.y > (arenasize-2): oldy = en.y
en.y = arenasize-2 if self.phantomlist == []:
mfresh() en.approach(self.xpos, self.ypos)
else:
ph = self.phantomlist[0]
en.approach(ph.x, ph.y)
for otheren in self.enemylist:
if en != otheren:
if en.x == otheren.x and en.y == otheren.y:
#print('Enemy collision at', en.x, en.y)
en.x = oldx
en.y = oldy
#print(dist(en.x, en.y, self.xpos, self.ypos))
if en.x < 1:
en.x = 1
if en.x > (arenasize-2):
en.x = arenasize-2
if en.y < 1:
en.y = 1
if en.y > (arenasize-2):
en.y = arenasize-2
mfresh()
for bombs in self.bomblist: for bombs in self.bomblist:
for enemies in self.enemylist: for enemies in self.enemylist:
@ -160,6 +198,8 @@ class tgame:
self.entlist.remove(enemies) self.entlist.remove(enemies)
print('Bang') print('Bang')
mfresh() mfresh()
self.datalabel.configure(text='\n'.join(self.data))
self.stepslabel.configure(text=str(self.stepstaken) + " steps") self.stepslabel.configure(text=str(self.stepstaken) + " steps")
self.collectlabel.configure(text=str(self.collections) + " candy") self.collectlabel.configure(text=str(self.collections) + " candy")
self.bomblabel.configure(text=str(self.bombs) + " bombs") self.bomblabel.configure(text=str(self.bombs) + " bombs")
@ -185,6 +225,8 @@ class tgame:
ydif = int(ydif) ydif = int(ydif)
mfresh(ymove= ydif) mfresh(ymove= ydif)
tkvar.bind('<Button-1>', translatemouse) tkvar.bind('<Button-1>', translatemouse)
tkvar.bind('<Button-2>', lambda data=self.data: restart())
tkvar.bind('<Button-3>', lambda data=self.data: spawnbomb())
def helpreel(): def helpreel():
self.helplabelindex += 1 self.helplabelindex += 1
@ -192,6 +234,12 @@ class tgame:
self.helplabelindex = 0 self.helplabelindex = 0
self.helplabel.configure(text=self.helplabeltexts[self.helplabelindex]) self.helplabel.configure(text=self.helplabeltexts[self.helplabelindex])
def collect(score):
for x in range(score):
self.collections += 1
if self.collections % self.bombcost == 0:
self.bombs += 1
def spawnbomb(): def spawnbomb():
goodtogo = True goodtogo = True
for bombs in self.bomblist: for bombs in self.bomblist:
@ -204,8 +252,22 @@ class tgame:
self.bomblist.append(newbomb) self.bomblist.append(newbomb)
self.entlist.append(newbomb) self.entlist.append(newbomb)
mfresh() mfresh()
tkvar.bind('<Button-2>', lambda data=self.data: restart())
tkvar.bind('<Button-3>', lambda data=self.data: spawnbomb()) def spawnphantom():
goodtogo = True
if self.collections < self.phantomcost:
goodtogo = False
if self.phantomlist != []:
goodtogo = False
if goodtogo:
life = 10
self.collections = 0
life += round(self.collections / 3)
newphantom = phantom(self.xpos, self.ypos, life)
self.phantomlist.append(newphantom)
self.entlist.append(newphantom)
mfresh()
def spawncandy(): def spawncandy():
newx = random.randint(1, arenasize-2) newx = random.randint(1, arenasize-2)
@ -253,9 +315,12 @@ class tgame:
def restart(): def restart():
self.xpos = int((arenasize-1)/2) self.xpos = int((arenasize-1)/2)
self.ypos = int((arenasize-1)/2) self.ypos = int((arenasize-1)/2)
while self.entlist != []:
del self.entlist[0]
self.candylist = [] self.candylist = []
self.enemylist = [] self.enemylist = []
self.bomblist = [] self.bomblist = []
self.phantomlist = []
self.entlist = [] self.entlist = []
self.stepstaken = 0 self.stepstaken = 0
self.collections = 0 self.collections = 0
@ -315,6 +380,7 @@ class enemy:
self.movementy = 1 self.movementy = 1
if self.movementy < -1: if self.movementy < -1:
self.movementy = -1 self.movementy = -1
if not hasmoved: if not hasmoved:
self.x += self.movementx self.x += self.movementx
if not hasmoved: if not hasmoved:
@ -327,5 +393,12 @@ class bomb:
self.y = y self.y = y
self.symbol = bomb.symbol self.symbol = bomb.symbol
class phantom:
symbol = "H"
def __init__(self, x, y, lifespan):
self.x = x
self.y = y
self.lifespan = lifespan
self.symbol = phantom.symbol
t = tgame() t = tgame()