From f8324d6c1bfdafa884d926ca4da317ab8f8e96f5 Mon Sep 17 00:00:00 2001 From: Luiz Irber Date: Sun, 11 Nov 2007 02:03:22 +0000 Subject: V5, aa meia-noite buscarei sua ALMA! (versao sem crase, e nem til) --- diff --git a/Gambiarra/gambiarra.py b/Gambiarra/gambiarra.py index 83843fd..a6a0d25 100644 --- a/Gambiarra/gambiarra.py +++ b/Gambiarra/gambiarra.py @@ -7,6 +7,40 @@ import os from levels import levels as Levels from objects.wall import * +def check_collision(sprite_list, wall_list): + new_objects = pygame.sprite.RenderPlain() + for obj in sprite_list: + obj.remove(sprite_list) + obj.add(new_objects) + + for s in sprite_list: + #TODO: verifica colisao de objetos dinamicos + pass + + for w in wall_list: + if obj.rect.colliderect(w.rect): + if isinstance(w, DownWall): + obj.speed[1] = -0.7*obj.speed[1] + if obj.rect.bottom > w.rect.top: + obj.rect.bottom = w.rect.top - 1 + + if isinstance(w, UpWall): + obj.speed[1] = -0.7*obj.speed[1] + if obj.rect.top < w.rect.bottom: + obj.rect.top = w.rect.bottom + 1 + + if isinstance(w, LeftWall): + obj.speed[0] = -0.9*obj.speed[0] + if obj.rect.left < w.rect.right: + obj.rect.left = w.rect.right + 1 + + if isinstance(w, RightWall): + obj.speed[0] = -0.9*obj.speed[0] + if obj.rect.right > w.rect.left: + obj.rect.right = w.rect.left - 1 + + return new_objects + class Game(object): fps = 30 screen = None @@ -36,49 +70,63 @@ class Game(object): def update_screen(self, fps): #update dos elementos da tela - self.check_collision() + objs = check_collision(self.allLevels[self.level].simulator.objects, + self.allLevels[self.level].simulator._walls) + self.allLevels[self.level].simulator.objects = objs 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 + if obj.speed[0]: + obj.speed[0] *= 0.9 + else: + obj.speed[0] = 20 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 - pass - - def actors_draw(self): - #desenha ator na tela - pass - def start_window(self): #desenha a tela inicial (abstrato -chama os outros metodos predefinidos) pass def next_level(self): pass + + def mouse_event(self, mousePos, mouseButtonsPressed ): + if mouseButtonsPressed[0]: + #verificar colisao com thing + #colidiu = verificar Colisao!!! + collided = False + #Pegar o objeto + obj = None + mouseMove = python.mouse.get_rel() + if collided: + while mouseButtonsPressed[0]: + pass + + mouseMove = python.mouse.get_rel() + #comentado porque por enquanto obj eh None + #obj.rect = obj.rect.move(mouseMove) def main_loop(self): #loop principal + #-definir e desenhar o nivel + #-esperar por eventos do mouse: + # -clique sobre um thing, arrasta + # -clique sobre um botao - while self.run: - self.clock.tick(self.fps) - self.update_screen(self.fps) - self.allLevels[self.level].draw() + #quando clicar em play transformar o botao em stop + playPressed = True + if playPressed: + while self.run: + self.clock.tick(self.fps) + self.update_screen(self.fps) + self.allLevels[self.level].draw() - pygame.display.flip() + pygame.display.flip() + for event in pygame.event.get(): + if event.type == MOUSEBUTTONDOWN: + self.mouse_event( pygame.mouse.get_pos(), + pygame.mouse.get_pressed() ) def main(): game = Game() diff --git a/Gambiarra/levels/levels.py b/Gambiarra/levels/levels.py index 47a67c7..0c62e4a 100644 --- a/Gambiarra/levels/levels.py +++ b/Gambiarra/levels/levels.py @@ -5,6 +5,7 @@ import pygame from objects.balls import * from objects.animals import * from objects.wall import * +from objects.esteira import * class SimulationView(object): """ This widget holds the objects being simulated. """ @@ -14,13 +15,14 @@ class SimulationView(object): def __init__(self, objects): self.running = False - self.background = pygame.Surface((1200, 700)) + self.background = pygame.Surface((1200, 770)) 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) + self._walls = [] + self._walls.append(LeftWall()) + self._walls.append(RightWall()) + self._walls.append(UpWall()) + self._walls.append(DownWall()) def draw(self, pos = None): screen = pygame.display.get_surface() @@ -29,6 +31,9 @@ class SimulationView(object): else: screen.blit(self.background, (0, 0)) + for wall in self._walls: + wall.draw(screen, wall.rect) + for item in self.objects: item.draw(screen, item.rect.topleft) @@ -36,18 +41,18 @@ class ObjectBar(object): """ This widget contains the objects available for the problem. """ def __init__(self, objects): - self.background = pygame.Surface((1000, 200)) + self.background = pygame.Surface((1000, 130)) self.background.fill([0,255,0]) #TODO: achar uma cor melhor =D self.objects = pygame.sprite.RenderPlain(objects) def draw(self, pos = None): screen = pygame.display.get_surface() if pos: - screen.blit(self.background, (pos[0], 700 + pos[1]), pos) + screen.blit(self.background, (pos[0], 770 + pos[1]), pos) else: - screen.blit(self.background, (0, 700)) + screen.blit(self.background, (0, 770)) - objpos = [0,715] + objpos = [0, 785] for item in self.objects: item.draw(screen, objpos) objpos[0] += item.image.get_width() + 15 @@ -59,16 +64,16 @@ class CommandBar(object): """ This widget contains the commands: play, help, and quit. KISS! =D """ def __init__(self): - self.background = pygame.Surface((200, 200)) + self.background = pygame.Surface((200, 130)) self.width, self.height = self.background.get_size() self.background.fill([0,0,255]) #TODO: achar uma cor melhor =D def draw(self, pos=None): screen = pygame.display.get_surface() if pos: - screen.blit(self.background, (1000 + pos[0], 700 + pos[1]), pos) + screen.blit(self.background, (1000 + pos[0], 770 + pos[1]), pos) else: - screen.blit(self.background, (1000, 700)) + screen.blit(self.background, (1000, 770)) def update(self): pass @@ -92,10 +97,10 @@ class Level(object): def init_levels(): #FIXME: fazer de um jeito menos lusitano #Sample levels - level1ObjInPlace = [ BowlingBall((200,300)), BeachBall((400,800))] + level1ObjInPlace = [ BowlingBall((200,300)), BeachBall((100,100))] level1ObjToAdd = [ Penguin(), BeachBall() ] - level2ObjInPlace = [ Penguin((300,600))] + level2ObjInPlace = [ Penguin((300,600)), Esteira((20,650))] level2ObjToAdd = [ BeachBall(), Penguin(), BowlingBall() ] level3ObjInPlace = [ BowlingBall((200,700)), Penguin((500, 800))] diff --git a/Gambiarra/objects/balls.py b/Gambiarra/objects/balls.py index 7c08805..5960c73 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 = 1) + gravity = 10) # TODO: substituir pela imagem correta #self.img = pygame.Surface((170, 170)) #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) @@ -22,7 +22,7 @@ class BeachBall(Thing): super(BeachBall, self).__init__( pygame.image.load(abspath("../data/bola.png")), editable, initialPosition, elasticity = 100, mobility = True, - gravity = 1) + gravity = 10) # 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/esteira.py b/Gambiarra/objects/esteira.py new file mode 100644 index 0000000..ea4fb01 --- /dev/null +++ b/Gambiarra/objects/esteira.py @@ -0,0 +1,14 @@ +# /gambiarra/esteira.py + +from os.path import abspath + +import pygame + +from objects.things import Thing + +class Esteira(Thing): + def __init__(self, initialPosition = [0,0], editable=False): + super(Esteira, self).__init__( + pygame.image.load(abspath("../data/esteira.png")), + editable, initialPosition, elasticity = 100, mobility = False, + gravity = 10) \ No newline at end of file diff --git a/Gambiarra/objects/wall.py b/Gambiarra/objects/wall.py index ab7954d..b30fc46 100644 --- a/Gambiarra/objects/wall.py +++ b/Gambiarra/objects/wall.py @@ -38,7 +38,7 @@ class UpWall(Thing): #pygame.draw.circle(self.img, [0,10,0], (85, 85), 80) class DownWall(Thing): - def __init__(self, initialPosition = [15,685], editable=False): + def __init__(self, initialPosition = [15,755], editable=False): super(DownWall, self).__init__( pygame.image.load(abspath("../data/downwall.png")), editable, initialPosition, elasticity = 100, mobility = False, diff --git a/MANIFEST b/MANIFEST index 9e22117..3fb1171 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3,7 +3,6 @@ activity/activity.info data/bolaBoliche.png data/bola.png data/helpButton.png -data/penguin16.png data/penguin.png data/pen.png data/playButton.png @@ -22,6 +21,7 @@ Gambiarra/objects/animals.py Gambiarra/objects/balls.py Gambiarra/objects/wall.py Gambiarra/objects/things.py +Gambiarra/objects/esteira.py olpcgames/activity.py olpcgames/camera.py olpcgames/canvas.py diff --git a/activity/activity-gambiarra.svg b/activity/activity-gambiarra.svg index b76fb6c..e8528dd 100644 --- a/activity/activity-gambiarra.svg +++ b/activity/activity-gambiarra.svg @@ -5,6 +5,32 @@ ]> - + + + + + + Sérgio Luiz Araújo Silva + + + + + Sérgio Luiz Araújo Silva + + + + + + + + + + + + + \ No newline at end of file diff --git a/data/bola.png b/data/bola.png index acc48b0..9412552 100755 --- a/data/bola.png +++ b/data/bola.png Binary files differ diff --git a/data/bolaBoliche.png b/data/bolaBoliche.png index 4b87478..3cb862b 100755 --- a/data/bolaBoliche.png +++ b/data/bolaBoliche.png Binary files differ diff --git a/data/leftwall.png b/data/leftwall.png index 061f7d0..78a220f 100755 --- a/data/leftwall.png +++ b/data/leftwall.png Binary files differ diff --git a/data/penguin.png b/data/penguin.png index 7d2f2b4..0b585f8 100755 --- a/data/penguin.png +++ b/data/penguin.png Binary files differ diff --git a/data/penguin16.png b/data/penguin16.png deleted file mode 100644 index 9525bd3..0000000 --- a/data/penguin16.png +++ /dev/null Binary files differ diff --git a/data/rightwall.png b/data/rightwall.png index 061f7d0..c9655c1 100755 --- a/data/rightwall.png +++ b/data/rightwall.png Binary files differ -- cgit v0.9.1