Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2012-05-22 20:40:54 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2012-05-22 20:40:54 (GMT)
commitcbc047edeacbfd238cd10afe55b749df99779799 (patch)
tree838471c69a037fc3186b6fa1c9c3d21fe9b2a0b0
parent9bb2b0154f8e1e0c42a12d8f5458b3eb33a72083 (diff)
make some changes to sugargame
-rw-r--r--.gitignore3
-rw-r--r--activity.py39
-rw-r--r--sprayplay.py308
3 files changed, 199 insertions, 151 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a594d64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*.pyc
+*.py~
+
diff --git a/activity.py b/activity.py
index 1453209..f275503 100644
--- a/activity.py
+++ b/activity.py
@@ -11,7 +11,44 @@ class SprayPlay(activity.Activity):
def __init__(self, handle):
super(activity.Activity, self).__init__(handle)
- self.game = sprayplay.main()
+ self.game = sprayplay.SprayPlay()
+ self.build_toolbar()
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
self.set_canvas(self._pygamecanvas)
self._pygamecanvas.run_pygame(self.game.run)
+
+ def build_toolbar(self):
+
+ toolbox = ToolbarBox()
+ activity_button = ActivityToolbarButton(self)
+ toolbox.toolbar.insert(activity_button, -1)
+ activity_button.show()
+
+ barra = toolbox.toolbar
+
+ separator1 = gtk.SeparatorToolItem()
+ separator1.props.draw = True
+ separator1.set_expand(False)
+ barra.insert(separator1,6)
+
+ save_button = ToolButton('filesave')
+ save_button.set_tooltip(_('Save Image'))
+ save_button.connect('clicked', self._savebutton_cb)
+ barra.insert(save_button, 7)
+ save_button.show()
+
+ separator2 = gtk.SeparatorToolItem()
+ separator2.props.draw = False
+ separator2.set_expand(True)
+ barra.insert(separator2,8)
+
+ stop_button = StopButton(self)
+ stop_button.props.accelerator = '<Ctrl>q'
+ barra.insert(stop_button, 9)
+ stop_button.show()
+
+ self.set_toolbar_box(toolbox)
+
+ toolbox.show_all()
+
+
diff --git a/sprayplay.py b/sprayplay.py
index 1b84a97..d80a92a 100644
--- a/sprayplay.py
+++ b/sprayplay.py
@@ -680,162 +680,170 @@ def applyAI(player):
players = []
-def main():
- # Initialization
- pygame.init()
- screen = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT))
- background = Background()
-
- # Initial game state.
- overlay = Overlay()
- #intro = Intro()
- keyboard_intro = Intro('keyboard-',4,1000)
- intro_group = pygame.sprite.Group(overlay,keyboard_intro)
-
- clock = pygame.time.Clock()
+class SprayPlay():
- # Bullet image.
- Bullet.orig_image = pygame.image.load(data_path('ball.png')).convert_alpha()
+ def __init__(self):
+ pass
- # Star image.
- Player.star = pygame.image.load(data_path('star.png')).convert_alpha()
-
- # Players.
- global players
- a = Player((CIRCLE_BORDER + 80,SCREEN_HEIGHT//2),90,0)
- b = Player((SCREEN_WIDTH-CIRCLE_BORDER - 80,SCREEN_HEIGHT//2),-90,1)
- players = [a,b]
+ def run():
+ # Initialization
+ pygame.init()
+ screen = pygame.display.get_surface()
+ SCREEN_WIDTH = screen.width()
+ SCREEN_HEIGHT = screen.height()
+ background = Background()
+
+ # Initial game state.
+ overlay = Overlay()
+ #intro = Intro()
+ keyboard_intro = Intro('keyboard-',4,1000)
+ intro_group = pygame.sprite.Group(overlay,keyboard_intro)
+
+ clock = pygame.time.Clock()
+
+ # Bullet image.
+ Bullet.orig_image = pygame.image.load(data_path('ball.png')).convert_alpha()
- # Puck defs
- genPucks(Puck.puckTemplates)
+ # Star image.
+ Player.star = pygame.image.load(data_path('star.png')).convert_alpha()
+
+ # Players.
+ global players
+ a = Player((CIRCLE_BORDER + 80,SCREEN_HEIGHT//2),90,0)
+ b = Player((SCREEN_WIDTH-CIRCLE_BORDER - 80,SCREEN_HEIGHT//2),-90,1)
+ players = [a,b]
- newRound()
- try:
- while True:
- delta = clock.tick(25)
-
- #delta = 1.0 / 25.0
-
- for evt in pygame.event.get():
- if evt.type == pygame.QUIT:
- raise StopGame
- elif evt.type == pygame.KEYDOWN:
- if not overlay.dying:
- overlay.dying = 1
- keyboard_intro.kill()
- if evt.key == pygame.K_F5:
- newGame()
- if evt.key == pygame.K_ESCAPE:
+ # Puck defs
+ genPucks(Puck.puckTemplates)
+
+ newRound()
+ try:
+ while True:
+ delta = clock.tick(25)
+
+ #delta = 1.0 / 25.0
+
+ for evt in pygame.event.get():
+ if evt.type == pygame.QUIT:
raise StopGame
- if evt.key == pygame.K_RIGHT:
- a.turnRight = 1
- a.isHuman = 1
- if evt.key == pygame.K_LEFT:
- a.turnLeft = 1
- a.isHuman = 1
- if evt.key == pygame.K_RETURN:
- a.shootButton = 1
- a.isHuman = 1
- overlay.kill()
- if evt.key == pygame.K_d:
- b.turnRight = 1
- b.isHuman = 1
- if evt.key == pygame.K_a:
- b.turnLeft = 1
- b.isHuman = 1
- if evt.key == pygame.K_SPACE:
- b.shootButton = 1
- b.isHuman = 1
- elif evt.type == pygame.KEYUP:
- if evt.key == pygame.K_RIGHT:
- a.turnRight = 0
- a.isHuman = 1
- if evt.key == pygame.K_LEFT:
- a.turnLeft = 0
- a.isHuman = 1
- if evt.key == pygame.K_RETURN:
- a.shootButton = 0
- a.isHuman = 1
- if evt.key == pygame.K_d:
- b.turnRight = 0
- b.isHuman = 1
- if evt.key == pygame.K_a:
- b.turnLeft = 0
- b.isHuman = 1
- if evt.key == pygame.K_SPACE:
- b.shootButton = 0
- b.isHuman = 1
-
- if not a.isHuman:
- applyAI(a)
- if not b.isHuman:
- applyAI(b)
-
- # inject round-wining logic here.
- for puck in Puck.group:
- if puck.cmx > SCREEN_WIDTH - GRAVITY_DIST:
- # Player 0 gets it.
- sendPuckToPlayer(puck,players[0])
- elif puck.cmx < GRAVITY_DIST:
- # Player 1 gets it.
- sendPuckToPlayer(puck,players[1])
-
-
- # inject AI logic here.
-
- for player in players:
- if player.shootButton and player.reloaded:
- bull = player.hasAmmo()
- if bull:
- bull.kill()
- cosx = cos((player.theta - 90)/180*pi)
- sinx = sin((player.theta - 90)/180*pi)
- bulletDir = [player.bulletSpeed * cosx,player.bulletSpeed * sinx]
- x = player.rect.center[0] + cosx * PLAYER_ARM_LENGTH
- y = player.rect.center[1] + sinx * PLAYER_ARM_LENGTH
- Bullet( (x,y),bulletDir )
- player.ammo -= 1
- player.reloaded = 0
- player.reloadTimer = int((1.0 + RELOAD_RANDOM*2*(random.random()-.5))*RELOAD_DELAY)
- if not player.reloaded:
- player.reloadTimer -= 1
- if player.reloadTimer == 0:
- player.reloaded = 1
- if player.turnRight:
- player.dtheta = player.dtheta + ROTATION_SPEED / 15.0
- if player.turnLeft:
- player.dtheta = player.dtheta - ROTATION_SPEED / 15.0
-
-
- # Update phase
- Bullet.group.update(delta)
- Player.group.update(delta)
- Puck.group.update(delta)
-
- #ADDED BY ERIC 12:30
- for player in players:
- player.ammoList.update(delta)
-
- for bullet in Bullet.group:
+ elif evt.type == pygame.KEYDOWN:
+ if not overlay.dying:
+ overlay.dying = 1
+ keyboard_intro.kill()
+ if evt.key == pygame.K_F5:
+ newGame()
+ if evt.key == pygame.K_ESCAPE:
+ raise StopGame
+ if evt.key == pygame.K_RIGHT:
+ a.turnRight = 1
+ a.isHuman = 1
+ if evt.key == pygame.K_LEFT:
+ a.turnLeft = 1
+ a.isHuman = 1
+ if evt.key == pygame.K_RETURN:
+ a.shootButton = 1
+ a.isHuman = 1
+ overlay.kill()
+ if evt.key == pygame.K_d:
+ b.turnRight = 1
+ b.isHuman = 1
+ if evt.key == pygame.K_a:
+ b.turnLeft = 1
+ b.isHuman = 1
+ if evt.key == pygame.K_SPACE:
+ b.shootButton = 1
+ b.isHuman = 1
+ elif evt.type == pygame.KEYUP:
+ if evt.key == pygame.K_RIGHT:
+ a.turnRight = 0
+ a.isHuman = 1
+ if evt.key == pygame.K_LEFT:
+ a.turnLeft = 0
+ a.isHuman = 1
+ if evt.key == pygame.K_RETURN:
+ a.shootButton = 0
+ a.isHuman = 1
+ if evt.key == pygame.K_d:
+ b.turnRight = 0
+ b.isHuman = 1
+ if evt.key == pygame.K_a:
+ b.turnLeft = 0
+ b.isHuman = 1
+ if evt.key == pygame.K_SPACE:
+ b.shootButton = 0
+ b.isHuman = 1
+
+ if not a.isHuman:
+ applyAI(a)
+ if not b.isHuman:
+ applyAI(b)
+
+ # inject round-wining logic here.
for puck in Puck.group:
- puck.handleCollision(bullet,delta)
-
- # Draw phase
- Background.group.draw(screen)
- Bullet.group.draw(screen)
- Player.group.draw(screen)
- Puck.group.draw(screen)
- #ADDED BY ERIC 12:30
- for player in players:
- player.ammoList.draw(screen)
- screen.blit(player.trophyCase,player.trophyPos)
- intro_group.update(delta)
- intro_group.draw(screen)
-
- pygame.display.flip()
- except StopGame:
- pass
+ if puck.cmx > SCREEN_WIDTH - GRAVITY_DIST:
+ # Player 0 gets it.
+ sendPuckToPlayer(puck,players[0])
+ elif puck.cmx < GRAVITY_DIST:
+ # Player 1 gets it.
+ sendPuckToPlayer(puck,players[1])
+
+
+ # inject AI logic here.
+
+ for player in players:
+ if player.shootButton and player.reloaded:
+ bull = player.hasAmmo()
+ if bull:
+ bull.kill()
+ cosx = cos((player.theta - 90)/180*pi)
+ sinx = sin((player.theta - 90)/180*pi)
+ bulletDir = [player.bulletSpeed * cosx,player.bulletSpeed * sinx]
+ x = player.rect.center[0] + cosx * PLAYER_ARM_LENGTH
+ y = player.rect.center[1] + sinx * PLAYER_ARM_LENGTH
+ Bullet( (x,y),bulletDir )
+ player.ammo -= 1
+ player.reloaded = 0
+ player.reloadTimer = int((1.0 + RELOAD_RANDOM*2*(random.random()-.5))*RELOAD_DELAY)
+ if not player.reloaded:
+ player.reloadTimer -= 1
+ if player.reloadTimer == 0:
+ player.reloaded = 1
+ if player.turnRight:
+ player.dtheta = player.dtheta + ROTATION_SPEED / 15.0
+ if player.turnLeft:
+ player.dtheta = player.dtheta - ROTATION_SPEED / 15.0
+
+
+ # Update phase
+ Bullet.group.update(delta)
+ Player.group.update(delta)
+ Puck.group.update(delta)
+
+ #ADDED BY ERIC 12:30
+ for player in players:
+ player.ammoList.update(delta)
+
+ for bullet in Bullet.group:
+ for puck in Puck.group:
+ puck.handleCollision(bullet,delta)
+
+ # Draw phase
+ Background.group.draw(screen)
+ Bullet.group.draw(screen)
+ Player.group.draw(screen)
+ Puck.group.draw(screen)
+ #ADDED BY ERIC 12:30
+ for player in players:
+ player.ammoList.draw(screen)
+ screen.blit(player.trophyCase,player.trophyPos)
+ intro_group.update(delta)
+ intro_group.draw(screen)
+
+ pygame.display.flip()
+ except StopGame:
+ pass
if __name__ == '__main__':
- main()
+ g = SprayPlay()
+ g.run()