diff options
author | Luiz Irber <luiz.irber@gmail.com> | 2007-11-11 00:01:04 (GMT) |
---|---|---|
committer | Luiz Irber <luiz.irber@gmail.com> | 2007-11-11 00:01:04 (GMT) |
commit | 96daec740440285d4232189375a06fd592fa25bb (patch) | |
tree | df9a6288d1453d96c218a07cb3e26f0d03e4dce7 | |
parent | 6d8b59af6d16c55dd395ed9da38e6502d3ce52e9 (diff) |
V4, 10 horas
-rw-r--r-- | Gambiarra/gambiarra.py | 36 | ||||
-rw-r--r-- | Gambiarra/levels/levels.py | 59 | ||||
-rw-r--r-- | Gambiarra/objects/animals.py | 2 | ||||
-rw-r--r-- | Gambiarra/objects/balls.py | 7 | ||||
-rw-r--r-- | Gambiarra/objects/things.py | 54 | ||||
-rw-r--r-- | Gambiarra/objects/wall.py | 33 | ||||
-rw-r--r-- | MANIFEST | 5 | ||||
-rw-r--r-- | activity/activity.info | 2 | ||||
-rwxr-xr-x | data/downwall.png | bin | 0 -> 265 bytes | |||
-rwxr-xr-x | data/leftwall.png | bin | 0 -> 216 bytes | |||
-rwxr-xr-x | data/pen.png | bin | 0 -> 2205 bytes | |||
-rwxr-xr-x | data/rightwall.png | bin | 0 -> 216 bytes | |||
-rwxr-xr-x | data/upwall.png | bin | 0 -> 265 bytes |
13 files changed, 110 insertions, 88 deletions
diff --git a/Gambiarra/gambiarra.py b/Gambiarra/gambiarra.py index e2f3cad..83843fd 100644 --- a/Gambiarra/gambiarra.py +++ b/Gambiarra/gambiarra.py @@ -5,32 +5,28 @@ import pygame from pygame.locals import * import os from levels import levels as Levels +from objects.wall import * class Game(object): + fps = 30 screen = None screenSize = None run = None background = None clock = None level = 0 - allLevels = [ Levels.level1, Levels.level2, Levels.level3 ] + allLevels = [] def __init__(self): pygame.init() - actors = {} self.screen = pygame.display.set_mode((1200,900)) #omitindo flags self.screenSize = self.screen.get_size() - self.background = pygame.Surface(self.screenSize) - self.background.fill([255,0,0,]) - self.screen.blit(self.background, (0,0)) pygame.display.flip() self.run = True pygame.display.set_caption("Gambiarra") self.clock = pygame.time.Clock() + self.allLevels = Levels.init_levels() - #carregar imagens? - #vai carregar tudo de uma vez ou on demand? - #inicia o loop self.main_loop() @@ -38,9 +34,26 @@ class Game(object): #verificar o evento e tomar as acoes pass - def update_actors(self): + def update_screen(self, fps): #update dos elementos da tela - pass + self.check_collision() + for obj in self.allLevels[self.level].simulator.objects: + #obj eh um objeto na tela + if obj.mobility: + newpos = obj.rect.move((obj.speed[0],obj.speed[1])) + obj.rect = newpos + obj.speed[0] *= 0.9 + obj.speed[1] += obj.gravity + + def check_collision(self): + for obj in self.allLevels[self.level].simulator.objects: + obj.remove(self.allLevels[self.level].simulator.objects) + collision = pygame.sprite.spritecollide(obj, + self.allLevels[self.level].simulator.objects, 0) + obj.add(self.allLevels[self.level].simulator.objects) + if collision != []: + if isinstance(collision[0],DownWall): + obj.speed[1] =- obj.speed[1] def actors_clear(self): #retira ator da tela @@ -61,7 +74,8 @@ class Game(object): #loop principal while self.run: - self.clock.tick(30) + self.clock.tick(self.fps) + self.update_screen(self.fps) self.allLevels[self.level].draw() pygame.display.flip() diff --git a/Gambiarra/levels/levels.py b/Gambiarra/levels/levels.py index 32a3843..47a67c7 100644 --- a/Gambiarra/levels/levels.py +++ b/Gambiarra/levels/levels.py @@ -4,6 +4,33 @@ import pygame from objects.balls import * from objects.animals import * +from objects.wall import * + +class SimulationView(object): + """ This widget holds the objects being simulated. """ + running = None + background = None + objects = None + + def __init__(self, objects): + self.running = False + self.background = pygame.Surface((1200, 700)) + self.background.fill([0,0,150]) + self.objects = pygame.sprite.RenderPlain(objects) + LeftWall().add(self.objects) + RightWall().add(self.objects) + UpWall().add(self.objects) + DownWall().add(self.objects) + + def draw(self, pos = None): + screen = pygame.display.get_surface() + if pos: + screen.blit(self.background, (pos[0], pos[1]), pos) + else: + screen.blit(self.background, (0, 0)) + + for item in self.objects: + item.draw(screen, item.rect.topleft) class ObjectBar(object): """ This widget contains the objects available for the problem. """ @@ -11,7 +38,7 @@ class ObjectBar(object): def __init__(self, objects): self.background = pygame.Surface((1000, 200)) self.background.fill([0,255,0]) #TODO: achar uma cor melhor =D - self.objects = objects + self.objects = pygame.sprite.RenderPlain(objects) def draw(self, pos = None): screen = pygame.display.get_surface() @@ -23,8 +50,7 @@ class ObjectBar(object): objpos = [0,715] for item in self.objects: item.draw(screen, objpos) - objpos[0] += item.img.get_width() + 15 - + objpos[0] += item.image.get_width() + 15 def update(self): pass @@ -53,25 +79,30 @@ class Level(object): objects = None def __init__(self, objInPlace, objToAdd): - self.objects = objInPlace + self.simulator = SimulationView(objInPlace) self.objbar = ObjectBar(objToAdd) self.cmdbar = CommandBar() def draw(self): + self.simulator.draw() self.objbar.draw() self.cmdbar.draw() -#Sample levels -level1ObjInPlace = [ BowlingBall(200,300), BeachBall(400,800)] -level1ObjToAdd = [ Penguin(), BeachBall() ] +def init_levels(): + #FIXME: fazer de um jeito menos lusitano + #Sample levels + level1ObjInPlace = [ BowlingBall((200,300)), BeachBall((400,800))] + level1ObjToAdd = [ Penguin(), BeachBall() ] + + level2ObjInPlace = [ Penguin((300,600))] + level2ObjToAdd = [ BeachBall(), Penguin(), BowlingBall() ] -level2ObjInPlace = [ Penguin(300,600)] -level2ObjToAdd = [ BeachBall(), Penguin(), BowlingBall() ] + level3ObjInPlace = [ BowlingBall((200,700)), Penguin((500, 800))] + level3ObjToAdd = [ Penguin(), BeachBall() ] -level3ObjInPlace = [ BowlingBall(200,700), Penguin(500, 800)] -level3ObjToAdd = [ Penguin(), BeachBall() ] + level1 = Level( level1ObjInPlace, level1ObjToAdd ) + level2 = Level( level2ObjInPlace, level2ObjToAdd ) + level3 = Level( level3ObjInPlace, level3ObjToAdd ) -level1 = Level( level1ObjInPlace, level1ObjToAdd ) -level2 = Level( level2ObjInPlace, level2ObjToAdd ) -level3 = Level( level3ObjInPlace, level3ObjToAdd )
\ No newline at end of file + return [level1, level2, level3]
\ No newline at end of file diff --git a/Gambiarra/objects/animals.py b/Gambiarra/objects/animals.py index 1c6f90c..5dc5b1e 100644 --- a/Gambiarra/objects/animals.py +++ b/Gambiarra/objects/animals.py @@ -16,4 +16,4 @@ class Penguin(Thing): super(Penguin, self).__init__( pygame.image.load(abspath("../data/penguin.png")), editable, initialPosition, elasticity = 100, mobility = True, - gravity = 10) + gravity = 1) diff --git a/Gambiarra/objects/balls.py b/Gambiarra/objects/balls.py index dbdc6f0..7c08805 100644 --- a/Gambiarra/objects/balls.py +++ b/Gambiarra/objects/balls.py @@ -12,7 +12,7 @@ class BowlingBall(Thing): super(BowlingBall, self).__init__( pygame.image.load(abspath("../data/bolaBoliche.png")), editable, initialPosition, elasticity = 100, mobility = True, - gravity = 10) + gravity = 1) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) @@ -20,8 +20,9 @@ class BowlingBall(Thing): class BeachBall(Thing): def __init__(self, initialPosition=None, editable=True): super(BeachBall, self).__init__( - pygame.image.load(abspath("../data/bola.png")), editable, - initialPosition, elasticity = 100, mobility = True, gravity = 10) + pygame.image.load(abspath("../data/bola.png")), + editable, initialPosition, elasticity = 100, mobility = True, + gravity = 1) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) diff --git a/Gambiarra/objects/things.py b/Gambiarra/objects/things.py index 4aeeb7d..66633ff 100644 --- a/Gambiarra/objects/things.py +++ b/Gambiarra/objects/things.py @@ -1,7 +1,10 @@ # /gambiarra/objects/things.py # classe mais abstrata para "coisas" na tela -class Thing(object): +import pygame + +class Thing(pygame.sprite.Sprite): + img = None initialPosition = None mobility = None @@ -12,9 +15,13 @@ class Thing(object): def __init__(self, image, editable, initialPosition=None, elasticity = 100, mobility = False, gravity = 10 ): - self.img = image + pygame.sprite.Sprite.__init__(self) #call Sprite intializer + self.image = image + self.rect = image.get_rect() + if initialPosition: self.initialPosition = initialPosition + self.rect.topleft = initialPosition[0], initialPosition[1] self.elasticity = elasticity self.editable = editable self.speed = [0,0] @@ -24,46 +31,7 @@ class Thing(object): def draw(self, screen, pos ): # temos a imagem na variavel <img> e # o 'zero' (ponto onde deve ser desenhado <pos> - screen.blit(self.img, (pos[0],pos[1])) + screen.blit(self.image, (pos[0],pos[1])) def collision(self): - """Verifies if the animal has hit the floor, the ceil or any wall""" - - #the floor - centerBottom = self.centerPosition[1] + (self.heigth / 2) - if centerBottom >= 700: - # touched the floor, STOP! - self.speed[0] = 0 - self.speed[1] = 0 - - #self.speed[1] = - ( self.elasticity / 100 ) * self.speed[1] - - - #the ceil - centerTop = self.centerPosition[1] - (self.heigth / 2) - if centerTop <= 0: - # touched the ceil, STOP! - self.speed[0] = 0 - self.speed[1] = 0 - - #self.speed[1] = - ( self.elasticity / 100 ) * self.speed[1] - - #left wall - centerLeft = self.centerPosition[0] - (self.heigth / 2) - if centerLeft <= 0: - #tocou a parede esquerda, para - self.speed[0] = 0 - self.speed[1] = 0 - - #self.speed[0] = - ( self.elasticity / 100 ) * self.speed[0] - - #right wall - centerRight = self.centerPosition[0] + (heigth / 2) - if centerRight >= 1200: - #tocou a parede direita, para - self.speed[0] = 0 - self.speed[1] = 0 - - #self.speed[0] = - ( self.elasticity / 100 ) * self.speed[0] - - + pass
\ No newline at end of file diff --git a/Gambiarra/objects/wall.py b/Gambiarra/objects/wall.py index 4dc28d2..ab7954d 100644 --- a/Gambiarra/objects/wall.py +++ b/Gambiarra/objects/wall.py @@ -8,38 +8,41 @@ import pygame from objects.things import Thing class LeftWall(Thing): - def __init__(self, initialPosition=None, editable=False): - super(BowlingBall, self).__init__( + def __init__(self, initialPosition = [0,0], editable=False): + super(LeftWall, self).__init__( pygame.image.load(abspath("../data/leftwall.png")), - editable, initialPosition, elasticity = 100, mobility = True, + editable, initialPosition, elasticity = 100, mobility = False, gravity = 10) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) class RightWall(Thing): - def __init__(self, initialPosition=None, editable=False): - super(BeachBall, self).__init__( - pygame.image.load(abspath("../data/rightwall.png")), editable, - initialPosition, elasticity = 100, mobility = True, gravity = 10) + def __init__(self, initialPosition = [1185,0], editable=False): + super(RightWall, self).__init__( + pygame.image.load(abspath("../data/rightwall.png")), + editable, initialPosition, elasticity = 100, mobility = False, + gravity = 10) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) class UpWall(Thing): - def __init__(self, initialPosition=None, editable=False): - super(BeachBall, self).__init__( - pygame.image.load(abspath("../data/upwall.png")), editable, - initialPosition, elasticity = 100, mobility = True, gravity = 10) + def __init__(self, initialPosition = [15,0], editable=False): + super(UpWall, self).__init__( + pygame.image.load(abspath("../data/upwall.png")), + editable, initialPosition, elasticity = 100, mobility = False, + gravity = 10) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) class DownWall(Thing): - def __init__(self, initialPosition=None, editable=False): - super(BeachBall, self).__init__( - pygame.image.load(abspath("../data/walllwall.png")), editable, - initialPosition, elasticity = 100, mobility = True, gravity = 10) + def __init__(self, initialPosition = [15,685], editable=False): + super(DownWall, self).__init__( + pygame.image.load(abspath("../data/downwall.png")), + editable, initialPosition, elasticity = 100, mobility = False, + gravity = 10) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) @@ -5,8 +5,13 @@ data/bola.png data/helpButton.png data/penguin16.png data/penguin.png +data/pen.png data/playButton.png data/quitButton.png +data/downwall.png +data/leftwall.png +data/rightwall.png +data/upwall.png Gambiarra/__init__.py Gambiarra/gambiarra.py Gambiarra/levels/__init__.py diff --git a/activity/activity.info b/activity/activity.info index 36a81e1..4bb6019 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -4,4 +4,4 @@ activity_version = 1 host_version = 1 service_name = org.laptop.Gambiarra icon = activity-gambiarra -class = GambiarraActivity.GambiarraActivity
\ No newline at end of file +class = Gambiarra.activity.GambiarraActivity
\ No newline at end of file diff --git a/data/downwall.png b/data/downwall.png Binary files differnew file mode 100755 index 0000000..ffa7f99 --- /dev/null +++ b/data/downwall.png diff --git a/data/leftwall.png b/data/leftwall.png Binary files differnew file mode 100755 index 0000000..061f7d0 --- /dev/null +++ b/data/leftwall.png diff --git a/data/pen.png b/data/pen.png Binary files differnew file mode 100755 index 0000000..287972d --- /dev/null +++ b/data/pen.png diff --git a/data/rightwall.png b/data/rightwall.png Binary files differnew file mode 100755 index 0000000..061f7d0 --- /dev/null +++ b/data/rightwall.png diff --git a/data/upwall.png b/data/upwall.png Binary files differnew file mode 100755 index 0000000..52aa06e --- /dev/null +++ b/data/upwall.png |