Skip to content

Commit

Permalink
Added score submission, updated win page, added healthbar
Browse files Browse the repository at this point in the history
  • Loading branch information
seken committed Jan 9, 2011
1 parent 8cd32f2 commit a976f5a
Showing 12 changed files with 216 additions and 20 deletions.
6 changes: 2 additions & 4 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
* Slow loading
* Packaging
* Health Bar
* submit results
* website
* Enemy drop gold
* Performance
* change heart
95 changes: 89 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
from enemy import Enemy
from gold import Gold
from arrow import Arrow
import time
import webbrowser, hashlib

def clamp(start, end, value):
'''
@@ -57,6 +57,10 @@ def __init__(self, map_name):
self.winTexture = Texture.open('images/win.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
self.make_menu_mesh()

# Healthbar
self.heart = Texture.open('images/heart.png', unit=GL_TEXTURE0, filter=GL_NEAREST)
self.make_heart_meshes()

# Sounds
self.bg_music = pyglet.media.load('sound/TIGshot.mp3')
self.win_sound = pyglet.media.load('sound/win.wav')
@@ -78,6 +82,7 @@ def __init__(self, map_name):
self.program.vars.tex = Sampler2D(GL_TEXTURE0)

# Map
self.map_name = map_name
mapimg = pyglet.image.load('map/'+map_name+'.png')
self.ground = self.create_ground(mapimg)
self.walls = self.create_walls(mapimg)
@@ -254,7 +259,13 @@ def on_update(self, delta):
map(self.arrows.remove, arrow_delete)

# Update friends
map(lambda i : i.update(delta, self), self.friendly)
dead_friends = map(lambda i : i.update(delta, self), self.friendly)
dead_friends.reverse()
i = len(dead_friends)
for j in dead_friends:
i -= 1
if j == True:
self.friendly.pop(i)

# Update enemy
map(lambda i : i.update(delta, self), self.enemy)
@@ -302,16 +313,24 @@ def fire_arrow(self, person):
arrow = Arrow(self.arrowTex, self.program, 1, 1, position, person.collisionMap, self.normal_mesh)
arrow.point(person.angle)
self.arrows.append(arrow)

def fire_sword(self, person, other):
if person.cooldown < 0:
person.cooldown = 0.75
self.arrow_sound.play()
other.hit()

def test_arrows(self):
hit_enemies = []
hit_arrows = []
for a in self.arrows:
for e in self.enemy:
if (a.position - e.position).len() < e.x/2:
hit_enemies.append(e)
hit_arrows.append(a)
self.goblin_death_sound.play()
e.hit()
if e.health <= 0:
hit_enemies.append(e)
self.goblin_death_sound.play()
break
remove = self.enemy.remove
map(remove, hit_enemies)
@@ -331,6 +350,8 @@ def on_draw(self):

for i in transparency:
i.draw(self.projection, self.camera, self.player.position, light)

self.draw_hearts()
else:
self.draw_menu(self.game)

@@ -353,6 +374,18 @@ def draw_menu(self, mode):

with nested(self.program, tex):
self.menu_mesh.draw(GL_QUADS)

def draw_hearts(self):
self.program.vars.mvp = Matrix()
self.program.vars.modelview = Matrix()
self.program.vars.playerPosition = (0.0, 0.0, 0.0)
self.program.vars.playerLight = random.random()*0.1 + 0.9
with nested(self.program, self.heart):
count = int(self.player.health/10)
if self.player.health < 10 and self.player.health > 0:
count = 1
for i in range(count):
self.heart_mesh[i].draw(GL_QUADS)

def make_menu_mesh(self):
position = [
@@ -380,6 +413,36 @@ def make_menu_mesh(self):
position_3=position,
texCoord_2=texCoord,
normal_3=normal)

def make_heart_meshes(self):
texCoord = [
0, 1,
0, 0,
1, 0,
1, 1,
]
normal = [
0, 0, 1,
0, 0, 1,
0, 0, 1,
0, 0, 1,
]
texCoord = (c_float*len(texCoord))(*texCoord)
normal = (c_float*len(normal))(*normal)

self.heart_mesh = []
for i in range(10):
position = [
-0.95+i*0.05, 0.90, 0,
-0.95+i*0.05, 0.95, 0,
-0.95+i*0.05 + 0.05, 0.95, 0,
-0.95+i*0.05 + 0.05, 0.90, 0,
]
position = (c_float*len(position))(*position)
self.heart_mesh.append(VBO(4,
position_3=position,
texCoord_2=texCoord,
normal_3=normal))

def update_camera(self):
pPos = self.player.position
@@ -390,10 +453,30 @@ def on_key_press(self, symbol, modifiers):
if self.game == 0:
self.game = 1
self.bg_music = self.bg_music.play()
elif self.game == 2 or self.game == 3 or self.game == 4:
elif self.game == 2 or self.game == 3:
exit()
elif self.game == 4:
md5 = self.calc_map_code()
score = self.calc_score()
webbrowser.open_new_tab('http://nink.seken.co.uk/?map=%s&score=%s'%(md5, str(score)))
exit()

elif symbol == key.ESCAPE or symbol == key.Q:
exit()

def calc_map_code(self):
m = hashlib.md5()
m.update(open('map/%s.png'%(self.map_name), 'rb').read())
m.update(open('map/%s.txt'%(self.map_name), 'rb').read())
return m.hexdigest()

def calc_score(self):
score = 0.0
for i in self.friendly:
if (i.position - self.start_point).len() < 4:
score += i.gold
score = score * (600-self.time)
return score

def on_mouse_motion(self, x, y, dx, dy):
return pyglet.event.EVENT_HANDLED
@@ -423,5 +506,5 @@ def on_resize(self, width, height):
return pyglet.event.EVENT_HANDLED

if __name__ == '__main__':
window = Application('ground5')
window = Application('ground3')
pyglet.app.run()
1 change: 1 addition & 0 deletions enemy.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ class Enemy(Protagonist):
def __init__(self, texture, program, x, y, position, collisionMap, mesh):
super(Enemy, self).__init__(texture, program, x, y, position, collisionMap, mesh)
self.cooldown = 0.0
self.health = 30

def update(self, delta, state):
self.cooldown -= delta
4 changes: 3 additions & 1 deletion friendly.py
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ def update(self, delta, state):
else:
if distance.len() < 1.0:
self.point(-distance.toAngle() + 0.25)
state.fire_arrow(self)
state.fire_sword(self, i)
uMoved = True
break

@@ -67,6 +67,8 @@ def update(self, delta, state):
if distance.len() > 2.0:
self.move(Vector(2.0, 0, 0)*delta)
super(Friendly, self).update(delta, state)

return self.health <= 0

def poked(self):
self.pokeTimer = 4.0
23 changes: 14 additions & 9 deletions genMap.py
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ def __init__(self):
self.mapSize = 64
self.mapTexture = Texture(self.mapSize, self.mapSize, data=[0,0,0,255]*(self.mapSize*self.mapSize))

self.probContinue = 0.75
self.probContinue = 0.79
self.minSquares = 10

# keep away from start and friends (and gold)
@@ -55,11 +55,11 @@ def __init__(self):
self.husband_distance = 30

# probability of placement
self.prob_goblin = 0.03
self.prob_friend = 0.03
self.prob_gold = 0.03
self.prob_king = 0.008
self.prob_husband = 0.008
self.prob_goblin = 0.1
self.prob_friend = 0.1
self.prob_gold = 0.1
self.prob_king = 0.01
self.prob_husband = 0.01

self.new_map()

@@ -120,7 +120,8 @@ def save_map(self):
p = open('points.txt', 'w')
p.write('start, %d, %d\n'%(self.start_point[0], self.mapSize - self.start_point[1]))
p.write('husband, %d, %d\n'%(self.husband[0], self.mapSize - self.husband[1]))
p.write('king, %d, %d\n'%(self.king_goblin[0], self.mapSize - self.king_goblin[1]))
if self.king_goblin != None:
p.write('king, %d, %d\n'%(self.king_goblin[0], self.mapSize - self.king_goblin[1]))
for i in self.friendly:
p.write('friend, %d, %d\n'%(i[0], self.mapSize - i[1]))
for i in self.gold:
@@ -157,9 +158,9 @@ def new_map(self):
point = points[0]
points = points[1:]

if point[0] < 0 or point[0] >= self.mapSize:
if point[0] < 1 or point[0] >= self.mapSize-1:
continue
if point[1] < 0 or point[1] >= self.mapSize:
if point[1] < 1 or point[1] >= self.mapSize-1:
continue

if self.can_add(point):
@@ -205,6 +206,10 @@ def new_map(self):
self.add_goblin_king((x,y))
self.add_friend((x,y))

print 'goblins: %s'%(len(self.goblin))
print 'friendly: %s'%(len(self.friendly))
print 'gold: %s'%(len(self.gold))

self.mapTexture.update()
with nested(self.mapTexture):
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
Binary file added images/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/win.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/win.xcf
Binary file not shown.
Binary file added map/ground6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions map/ground6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
start, 41, 29
husband, 50, 37
king, 36, 52
friend, 37, 56
friend, 37, 55
gold, 39, 53
friend, 34, 52
enemy, 46, 43
friend, 48, 43
gold, 38, 42
friend, 39, 42
enemy, 47, 42
gold, 39, 41
friend, 43, 41
gold, 39, 40
friend, 51, 40
gold, 48, 37
friend, 49, 36
gold, 47, 45
gold, 44, 44
gold, 46, 42
gold, 39, 41
gold, 38, 40
gold, 39, 40
gold, 40, 39
gold, 42, 39
gold, 47, 39
gold, 50, 39
gold, 51, 38
gold, 51, 32
enemy, 21, 43
enemy, 18, 42
enemy, 28, 42
enemy, 25, 40
enemy, 25, 36
enemy, 20, 35
enemy, 21, 35
enemy, 22, 35
enemy, 22, 34
enemy, 28, 34
enemy, 25, 33
enemy, 31, 33
enemy, 23, 31
Binary file added map/ground9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions map/ground9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
start, 32, 26
husband, 12, 8
king, 24, 31
friend, 24, 47
friend, 22, 44
friend, 16, 43
friend, 25, 42
friend, 19, 39
friend, 20, 39
friend, 17, 38
friend, 20, 38
friend, 27, 38
friend, 29, 38
friend, 24, 37
friend, 25, 36
friend, 27, 36
friend, 21, 31
friend, 11, 6
gold, 24, 47
gold, 22, 43
gold, 18, 42
gold, 20, 41
gold, 23, 41
gold, 20, 38
gold, 25, 37
gold, 26, 36
gold, 17, 35
gold, 15, 32
gold, 23, 31
gold, 10, 28
gold, 21, 21
gold, 21, 20
gold, 12, 10
gold, 12, 9
gold, 11, 8
gold, 12, 8
enemy, 10, 28
enemy, 11, 27
enemy, 9, 23
enemy, 10, 22
enemy, 41, 21
enemy, 44, 21
enemy, 4, 20
enemy, 6, 20
enemy, 7, 20
enemy, 21, 20
enemy, 41, 19
enemy, 42, 18
enemy, 4, 17
enemy, 35, 16
enemy, 39, 16
enemy, 37, 15
enemy, 26, 14
enemy, 27, 14
enemy, 28, 14
enemy, 30, 14
enemy, 32, 14
enemy, 37, 14
enemy, 22, 13
enemy, 25, 13
enemy, 39, 13
enemy, 26, 12
enemy, 36, 11
enemy, 25, 10

0 comments on commit a976f5a

Please sign in to comment.