1     /**
2         Represents a powerup in the game
3         @author <a href="mailto:matthewcasperson@gmail.com">Matthew Casperson</a>
4         @class
5     */
6     function Powerup()
7     {
8         /** The value of the powerup
9             @type Number
10         */
11        this.value = 0;
12        /** The current position on the sine wave
13            @type Number
14         */
15        this.sineWavePos = 0;
16        /** How quickly the powerup cycles through the sine wave
17            @type Number
18         */
19        this.bounceTime = 1;
20        /** The speed to increment the sineWavePos value at
21            @type Number
22         */
23        this.bounceSpeed = Math.PI / this.bounceTime;
24        /** The height of the powerups bounce
25            @type Number
26         */
27        this.bounceHeight = 10;
28
29        /**
30            Initialises this object
31            @param value        The value (score) of this powerup
32            @param image        The image to be displayed
33            @param x            The position on the X axis
34            @param y            The position on the Y axis
35            @param z            The depth
36            @param frameCount   The number of animation frames in the image
37            @param fps          The frames per second to animate this object at
38         */
39        this.startupPowerup = function(/**Number*/ value, /**Image*/ image, /**Number*/ x, /**Number*/ y, /**Number*/ z, /**Number*/ frameCount, /**Number*/ fps)
40        {
41            this.startupAnimatedGameObject(image, x, y - this.bounceHeight, z, frameCount, fps);
42            this.value = value;
43            return this;
44        }
45
46        /**
47            Shuts this object down.
48         */
49        this.shutdownPowerup = function()
50        {
51            this.shutdownAnimatedGameObject();
52        }
53
54        /**
55            Updates the object
56            @param dt The time since the last frame in seconds
57            @param context The drawing context
58            @param xScroll The global scrolling value of the x axis
59            @param yScroll The global scrolling value of the y axis
60        */
61       this.update = function (/**Number*/ dt, /**CanvasRenderingContext2D*/context, /**Number*/ xScroll, /**Number*/ yScroll)
62        {
63            var lastSineWavePos = this.sineWavePos;
64            this.sineWavePos += this.bounceSpeed * dt;
65            this.y += (Math.sin(this.sineWavePos) - Math.sin(lastSineWavePos)) * this.bounceHeight;
66
67            if (this.collisionArea().intersects(g_player.collisionArea()))
68            {
69                this.shutdownPowerup();
70                g_score += this.value;
71                g_ApplicationManager.updateScore();
72            }
73        }
74    }
75
76    Powerup.prototype = new AnimatedGameObject;

Top