Correcciones de los textos en ingles
[tajundrathegame.git] / taju.py
blobb420cd4a5f4f485389432c733f651a60cfaedb03
1 #!/usr/bin/python
2 # encoding: UTF-8
4 import pygame
5 import random
6 import math
7 from stage import Stage
8 from qwesprites import *
10 pygame.init()
12 size = width, height = 640, 480
13 speed = [4,4]
15 screen = pygame.display.set_mode(size
16 , pygame.DOUBLEBUF # | pygame.FULLSCREEN
20 stage_file="stage_00_game_menu.st"
21 ######################################################
22 STAGE=Stage(stage_file)
26 ######################################################
28 spriteTajundra = STAGE.Tajundra
30 ######################################################
36 reloj_juego=pygame.time.Clock()
37 Salir=False
38 keys={}
39 time_o=pygame.time.get_ticks()
41 for ch in STAGE.simbolos:
42 SpriteClass=None
43 if ch=='@': SpriteClass=Tajundra
44 if ch=='|': SpriteClass=LanzaBolas
45 if ch=='$': SpriteClass=Dragon
47 if SpriteClass:
48 for n in range(0,len(STAGE.simbolos[ch])):
49 SpriteClass(STAGE)
51 STAGE.draw(screen)
52 pygame.display.update()
54 #STAGE.sprites+=[spriteTajundra, t2,]
55 cpu_friendly=True
56 frame=0
57 accum_idle=0
58 cpu=0
59 benchmark=0
60 txtEndGame=None
61 fuerza=0
62 while not Salir:
63 frame+=1
64 if frame>60:
65 frame=0
66 cpu=100-accum_idle/10.0
67 print len(STAGE.sprites), "%.2f%%" % cpu
68 accum_idle=0
69 if benchmark:
70 if cpu<80:
71 if frame > cpu-20 or frame==0 or frame==30:
72 x,y,w,h=spriteTajundra.rect
73 pos=x,y
74 vel=300
75 if spriteTajundra.dx<0: vel=-300
76 vely=-120
77 if keys.has_key(pygame.K_DOWN): vely=200
78 if keys.has_key(pygame.K_UP): vely=-200
79 Hacha(STAGE,pos,spriteTajundra.dx+vel,vely)
80 elif frame==0:
81 del STAGE.sprites[-1:]
83 for event in pygame.event.get():
84 if event.type == pygame.QUIT: Salir=True
85 if event.type == pygame.KEYDOWN:
86 if event.key==pygame.K_ESCAPE:
87 Salir=True
88 else:
89 keys[event.key]=True
91 if event.type == pygame.KEYUP:
92 if keys.has_key(event.key):
93 del keys[event.key]
94 if spriteTajundra.alive:
95 if event.key==pygame.K_SPACE:
96 sLife=spriteTajundra.Life
97 sMLife=spriteTajundra.MaxLife
98 if (fuerza>4000): fuerza=4000
99 fuerza*=sLife*sLife/(sMLife*sMLife)
100 x,y,w,h=spriteTajundra.rect
101 pos=x,y
102 vel=210+fuerza/100.0
103 vely=-vel/2
104 if keys.has_key(pygame.K_DOWN): vely=vel/2
105 if keys.has_key(pygame.K_UP): vely=-vel
106 if spriteTajundra.dx<0: vel=-vel
107 p=Hacha(STAGE,pos,spriteTajundra.dx+vel,vely)
108 p.Life+=fuerza/100.0-.5
109 fuerza=0
111 if spriteTajundra.alive:
112 if keys.has_key(pygame.K_s):
113 spriteTajundra.alive=False
114 spriteTajundra.LevelFinished=True
116 if spriteTajundra.in_ground:
118 if keys.has_key(pygame.K_LEFT): spriteTajundra.dx-=15
119 if keys.has_key(pygame.K_RIGHT): spriteTajundra.dx+=15
120 if keys.has_key(pygame.K_UP): spriteTajundra.dy=-140
121 if keys.has_key(pygame.K_DOWN): spriteTajundra.dy+=5
123 else:
125 if spriteTajundra.dy<0:
126 if not keys.has_key(pygame.K_UP): spriteTajundra.dy/=1.02
127 if keys.has_key(pygame.K_LEFT): spriteTajundra.dx-=0.5
128 if keys.has_key(pygame.K_RIGHT): spriteTajundra.dx+=0.5
129 else:
130 if keys.has_key(pygame.K_UP): spriteTajundra.dy/=1.02
131 if keys.has_key(pygame.K_DOWN): spriteTajundra.dy+=2
133 else:
134 if not txtEndGame:
135 if spriteTajundra.LevelFinished:
136 txtEndGame=qweTextBIG(STAGE,320,240,"Level Completed")
137 else:
138 txtEndGame=qweTextBIG(STAGE,320,240,"Game Over")
139 qweTextBIG(STAGE,320,300,"press return")
141 if keys.has_key(pygame.K_RETURN):
142 if spriteTajundra.LevelFinished:
143 stage_file=STAGE.NextStage
145 for sprite in STAGE.sprites:
146 del sprite
148 del STAGE
149 txtEndGame=None
150 STAGE=Stage(stage_file)
151 spriteTajundra = STAGE.Tajundra
152 for ch in STAGE.simbolos:
153 SpriteClass=None
154 if ch=='@': SpriteClass=Tajundra
155 if ch=='|': SpriteClass=LanzaBolas
156 if ch=='$': SpriteClass=Dragon
158 if SpriteClass:
159 for n in range(0,len(STAGE.simbolos[ch])):
160 SpriteClass(STAGE)
161 STAGE.draw(screen)
162 pygame.display.update()
165 # Render
167 if cpu_friendly:
168 time_aux=pygame.time.get_ticks()
169 msec=time_aux-time_o;
170 idle=1000/60-msec
171 if idle<1: idle=1
172 pygame.time.wait(idle)
173 accum_idle+=pygame.time.get_ticks()-time_aux
174 time_aux=pygame.time.get_ticks()
175 msec=time_aux-time_o;
176 time_o=time_aux
177 else:
178 msec=reloj_juego.tick(60)
180 if keys.has_key(pygame.K_SPACE): fuerza+=msec
182 STAGE.fulldraw(screen,msec)