~ubuntu-branches/ubuntu/natty/quickly/natty

« back to all changes in this revision

Viewing changes to data/templates/ubuntu-pygame/project_root/python/homingmissle.py

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-03-29 19:00:48 UTC
  • mfrom: (8.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100329190048-olhobq492x3xnztz
Tags: 0.3.90-0ubuntu1
* New release:
  Quickly core:
  - check now that --template has one argument
  - -- enables to give options to templates (unknown options and arguments
    are still given to templates but -- specify explicity what to give to
    templates commands like -h, --version...)
  - check and enable recreation of the credential if user deletes it on
    Launchpad
  - Use realpath so that we can symlink to the binary in trunk.
    (Jonathan Lange)
  - project_path_not_found is raised when data_path_not_found should be
    (originated from Philip Peitsch's patch). (LP: #497688)
  - importing command in one template from another template is now possible
    support as well "all" keyword to import all commands from a template
    into another one (take care of overridden commands too)
    (LP: #452306, #487301)
  - add an apport hook to get installed templates (LP: #411127)
  - enable option completion for templates
  - handle now version upgrade, launching script for templates and handling
    versionning on them
  - change getstarted wording (LP: #486180) - Grant
  - Quickly ship now "version" tag instead of "format" tag
  - add some templatetools to check X display
  - if a commands exit with 4, do not show "ERROR:" (case of wrong command
    usage, for instance)
  - Rewrote importing module in both bin/quickly and ubuntu-project binary
  - Add get_camel_case_name() and get_sentence_name() to templatetools
  - Refactor some code in pre_create hook()
  - Now dashes and spaces support in project name! Dealing with python and
    packaging issues for you. (LP: #493130)
  - Provide Quickly API (LP: #426480)
  - Fix some issues in the man page
  ubuntu-application Template:
  - Enabling upload to team or user ppa, as well as any ppa.
    Use --ppa ppaname or --ppa team/ppaname
    .quickly file can be used as well with ppa = ppaname or
    ppa = team/ppaname (LP: #470192)
    ppa completion is also available
  - Change BSD header by full license
  - Add MIT license
  - Fixes an error when launchpad display name contains unicode character
    (Petar Vasić)
  - Fix typo in quickly help save (Petar Vasić)
  - Adds logo.png as logo property in about dialog (LP: #478389)
    (Petar Vasić)
  - Remove lp-project-change command and add configure command.
    configure lp-project [project_name] to set/reset lp project binded to
    your Quickly project
    ppa <ppa name> to set a default ppa with your project
  - Fix ~/.selected-editor being ignored (LP: #484730)
  - Fix wrong shell completion when in a template (it wrongly proposed
    all commands followed by templates)
  - Check if we have a X display available before running "run" or launching
    GUI in "create" command.
  - add -- support in quickly run to pass options like --help, --version so
    that Quickly core don't take them.
  - enable preferences save call being called multiple times (Philip Peitsch)
  - Use realpath so that we can symlink to the binary in trunk.
  - Fixed some errors in the tutorial (Brian) (LP: #499356)
  - Fix missing import sys in setup.py (Philip Peitsch) (LP: #499712)
  - rename ubuntu-project to ubuntu-application
  - enhance quickly license (no more Copyright file, only one AUTHORS file)
    personal license needs COPYING file now (and the header will be copied in
    every files). No more # needed in those files too. Some other little
    refactoring too (LP: #469330)
  - autolicence by default on first share/release (with LP info and on GPL-3)
  - change versionning support in ubuntu application: (LP: #476814)
   + quickly share just adds -publicX to current version where X is bumped
     at each "quicky share" execution
   + quickly release remove -publicX (if any) and release with current YY.MM.
     If there is already a release with that version, it will be YY.MM.1, 
     then YY.MM.2
  - add accelerators to menu items (jens persson)
  - set correctly title dialog (Philip Peitsch) (LP: #501999)
  - about dialog box is now fully automated: (LP: #478414)
   + update copyright, authors, license (when licensing)
   + version (when sharing and releasing)
   + homepage (when changing launchpad project: release and configure)
  - add an 'add' command. $ quickly dialog … is now $ quickly add dialog …
    (LP: #438320)
  - enable automatic release and milestone built in LP, releasing and pushing
    upstream tarball (LP: #470344)
  - automatic collect and publish changelog message from commits and save
    messages used during devlopment. (LP: #476572)
  - add i18n to boiler plate (LP: #423529)
  - enable adding manual depdencies to quickly project (LP: #474639)
  - enable configure its own bzr branch and resetting parent branch even once
    already configured (quickly configure bzr <branch-path>)
  - now recommends seahorse-plugins to have a graphical prompt for signing
    package
  - rename quickly glade to quickly design (LP: #528664)
  - create command is now more flexible and enable people to inherit from
    other template more easily
  - add translation domain to gtkbuilder and fix some items that shouldn't
    been translatable (Łukasz Jernaś)
  - add apport and launchpadintegration to new and existing project once
    bounded to LP (Philip Peitsch)
  - fix spelling mistake "connexion" (Łukasz Jernaś) (LP: #532667)
  - the ubuntu-application tutorial is now internationalized and use docbook
    format. Translators, it's yours! (Shane Fagan) (LP: #525168)
  - package/share/release are now more quiet and only print something on error
    warning as a summary as with unfound packages, and so on (LP: #482915)
  - new algorithm to select good email automatically. Try to get the preferred
    email and update the AUTHOR file with it.
  - test GPG key and create one automatically if none is available. The
    corresponding public key availabity in launchpad is also checked.
    (LP: #427730, #408993)
  - add devscripts as a dependency (bug #465833), will fix all the depends
    mess later
  - bump python-distutils-extra (>= 2.18bzr1)
  ubuntu-cli Template:
  - first release using import command feature (no command written into the
    template itself). This is a basic ubuntu CLI application
  ubuntu-pygame Template:
  - first release using import command feature. python-pygame added as a
    depends
* debian/control:
  - renamed and separate in multiple packages to get a -common used with
    Quickly widgets (LP: #519633)
  - suggests python-quickly-widgets

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
homing_missle - contains the HomingMissle class, a sample sublcass
 
3
of BaseSprite
 
4
 
 
5
"""
 
6
 
 
7
import pygame
 
8
from python_name.base_sprite import BaseSprite
 
9
import math
 
10
from python_name import python_nameconfig
 
11
 
 
12
class HomingMissle(BaseSprite):
 
13
    """
 
14
    HomingMissle - A useful sample class that derives from BaseSprite and 
 
15
    has some very simple AI.
 
16
 
 
17
    """
 
18
 
 
19
    def __init__(self, target, img):
 
20
        """
 
21
        Create a HomingMissle. Useful as an emeny or a as weapon
 
22
        for the player.
 
23
 
 
24
        arguments:
 
25
        target - A sprite that the homing missle atempts to track down
 
26
        and shoot
 
27
 
 
28
        img - A path to an image to use for the missle
 
29
 
 
30
        """
 
31
 
 
32
        BaseSprite.__init__(self, img)
 
33
        self.init_position()
 
34
        self.target = target
 
35
        self._rotating_left = False
 
36
        self._rotating_right = False
 
37
 
 
38
        #the missle starts out moving
 
39
        self._accelerating = True
 
40
 
 
41
        #the missle starts out not knowing if it is
 
42
        #pointed at the target
 
43
        self.targetted = False
 
44
        self.explode_stage = 0
 
45
        self.exploding = False
 
46
        self.explosion_sound = pygame.mixer.Sound(project_nameconfig.enemy_explode_sound)
 
47
        self.points = 1
 
48
 
 
49
    def update(self):
 
50
        """update - update internal data and position.
 
51
        Typically called by the game controller each game
 
52
        tick.
 
53
 
 
54
        """
 
55
 
 
56
        BaseSprite.update(self)
 
57
        if self.exploding: 
 
58
            #do an explosion image for each tick
 
59
            self.explode_stage += 1
 
60
            e = self.explode_stage
 
61
            if e < 8:
 
62
                e = str(e)
 
63
                img_name = project_nameconfig.enemy_explode_stage + e  + ".png"
 
64
                self.master_image = pygame.image.load(img_name)
 
65
                self._update_image()
 
66
                return
 
67
 
 
68
            else:#explosion is done
 
69
                self.visible = False
 
70
                self.exploding = False
 
71
                self.kill()
 
72
                return
 
73
 
 
74
        self.targetted = False
 
75
        #calculate target angle
 
76
        targx = self.target.x - self.x
 
77
        targy = self.target.y - self.y
 
78
        target_angle = ((math.atan2(targy,targx)) * 180)/ math.pi
 
79
        if target_angle < 0:
 
80
            target_angle = 360 + target_angle
 
81
 
 
82
        #translate the orientation to the
 
83
        # same system as the target angle
 
84
        fire_angle = 360 - self.orientation
 
85
        if fire_angle == 360:
 
86
            fire_angle = 0
 
87
        fire_angle += 270
 
88
        if fire_angle >= 360:
 
89
            fire_angle -= 360
 
90
 
 
91
        #rotate to face the target
 
92
        delta = fire_angle - target_angle
 
93
        if delta > 5:
 
94
            self._rotating_left = True
 
95
            self._rotating_right = False
 
96
        elif delta < -5:
 
97
            self._rotating_left = False
 
98
            self._rotating_right = True
 
99
        else:
 
100
            self._rotating_left = False
 
101
            self._rotating_right = False
 
102
            self.targetted = True
 
103
 
 
104
    def explode(self):
 
105
        """explode - called when the homing missle is destroyed in
 
106
        game play. Sets the alive flag to False, and sets a flag to
 
107
        start animating an explosion in the update function. Also
 
108
        plays the explosion sound.
 
109
 
 
110
        """
 
111
 
 
112
        if self.alive:
 
113
            self.explosion_sound.play()
 
114
            self.alive = False
 
115
            self.exploding = True
 
116