From c7d4c552b2598ff7e0389bd4fb776a347f5fa2f2 Mon Sep 17 00:00:00 2001 From: Voussoir Date: Sun, 12 Oct 2014 16:38:29 -0700 Subject: [PATCH] else --- Dodgy/README.md | 2 - Dodgy/changelog.md | 5 ++ Dodgy/dodgy.py | 123 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 103 insertions(+), 27 deletions(-) create mode 100644 Dodgy/changelog.md diff --git a/Dodgy/README.md b/Dodgy/README.md index 214e55c..ca6a3b3 100644 --- a/Dodgy/README.md +++ b/Dodgy/README.md @@ -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 -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. Enemies spawn in larger numbers as the game goes on diff --git a/Dodgy/changelog.md b/Dodgy/changelog.md new file mode 100644 index 0000000..3a18cde --- /dev/null +++ b/Dodgy/changelog.md @@ -0,0 +1,5 @@ +###12 Oct 2014 + ++ Added changelog. I probably will get lazy and stop updating this eventually + ++ Added phantom, incomplete implementation \ No newline at end of file diff --git a/Dodgy/dodgy.py b/Dodgy/dodgy.py index 9b071a1..9bef714 100644 --- a/Dodgy/dodgy.py +++ b/Dodgy/dodgy.py @@ -49,22 +49,29 @@ class tgame: #tkvar.bind('c', lambda data=self.data: spawncandy()) tkvar.bind('j', 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('h', lambda data=self.data: helpreel()) tkvar.bind('', quit) self.candylist = [] self.enemylist = [] self.bomblist = [] + self.phantomlist = [] self.entlist = [] self.symbols = {'char':'H', 'wall':'#', 'floor':' '} self.stepstaken = 0 self.collections = 0 self.bombs = 0 - self.enemyspawntime = 10 + + self.enemyspawnrate = 50 self.enemyspawnmindist = 6 + self.candyspawnrate = 4 + self.isdeath = False self.bombcost = 4 + self.phantomcost = 10 self.helplabelindex = -1 + self.helplabeltexts = [ "=Movement =Bomb =Restart ->", "=Movement =Bomb =Restart ->", @@ -86,11 +93,34 @@ class tgame: if xmove != 0: if (self.xpos > 1 or xmove > 0) and (self.xpos < (arenasize -2) or xmove < 0): 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 if ymove != 0: if (self.ypos > 1 or ymove > 0) and (self.ypos < (arenasize -2) or ymove < 0): 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 + 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) self.data = [self.symbols['wall']*arenasize, self.symbols['wall']*arenasize] for x in range(arenasize-2): @@ -108,48 +138,56 @@ class tgame: if candies.y == ycoord: if candies.x == self.xpos and candies.y == self.ypos: print('Collection') - self.collections += 1 + collect(1) self.candylist.remove(candies) self.entlist.remove(candies) - if self.collections % self.bombcost == 0: - self.bombs += 1 del candies + for enemies in self.enemylist: if enemies.y == ycoord: if enemies.x == self.xpos and enemies.y == self.ypos: print('Death') self.isdeath = True self.datalabel.configure(fg='Red') + self.entlist.sort(key=lambda p: p.x) for entities in self.entlist: if entities.y == ycoord: yl = yl[:entities.x] + entities.symbol + yl[entities.x+1:] self.data[ycoord] = yl - self.datalabel.configure(text='\n'.join(self.data)) if hasmoved: self.stepstaken += 1 - if self.stepstaken % 4 == 0: + if self.stepstaken % self.candyspawnrate == 0: spawncandy() - if self.stepstaken == self.enemyspawntime: - #spawnenemy() - pass - if self.stepstaken % 50 == 0: + if self.stepstaken % self.enemyspawnrate == 0: 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: - en.y = 1 - if en.y > (arenasize-2): - en.y = arenasize-2 - mfresh() + for en in self.enemylist: + oldx = en.x + oldy = en.y + if self.phantomlist == []: + 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 enemies in self.enemylist: @@ -160,6 +198,8 @@ class tgame: self.entlist.remove(enemies) print('Bang') mfresh() + + self.datalabel.configure(text='\n'.join(self.data)) self.stepslabel.configure(text=str(self.stepstaken) + " steps") self.collectlabel.configure(text=str(self.collections) + " candy") self.bomblabel.configure(text=str(self.bombs) + " bombs") @@ -185,6 +225,8 @@ class tgame: ydif = int(ydif) mfresh(ymove= ydif) tkvar.bind('', translatemouse) + tkvar.bind('', lambda data=self.data: restart()) + tkvar.bind('', lambda data=self.data: spawnbomb()) def helpreel(): self.helplabelindex += 1 @@ -192,6 +234,12 @@ class tgame: self.helplabelindex = 0 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(): goodtogo = True for bombs in self.bomblist: @@ -204,8 +252,22 @@ class tgame: self.bomblist.append(newbomb) self.entlist.append(newbomb) mfresh() - tkvar.bind('', lambda data=self.data: restart()) - tkvar.bind('', 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(): newx = random.randint(1, arenasize-2) @@ -253,9 +315,12 @@ class tgame: def restart(): self.xpos = int((arenasize-1)/2) self.ypos = int((arenasize-1)/2) + while self.entlist != []: + del self.entlist[0] self.candylist = [] self.enemylist = [] self.bomblist = [] + self.phantomlist = [] self.entlist = [] self.stepstaken = 0 self.collections = 0 @@ -315,6 +380,7 @@ class enemy: self.movementy = 1 if self.movementy < -1: self.movementy = -1 + if not hasmoved: self.x += self.movementx if not hasmoved: @@ -327,5 +393,12 @@ class bomb: self.y = y 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() \ No newline at end of file