this.heartImage = gamejs.image.load('images/healthheart.png'); this.collisionImage = gamejs.image.load('images/collisioncircle.png'); this.isHighlighted = false; this.highlightDuration = 0; this.isHit = false; this.hitCount = 0; this.hitDuration = 0; this.hitPoints = hitPoints; return this; }; objects.extend(Ship, gamejs.sprite.Sprite); Ship.prototype.isSleeping = function() { return this.b2body.IsSleeping(); }; Ship.prototype.setVelocity = function(direction, speed) { var v = $v.multiply(direction, speed * 1000); var c = this.rect.center; this.b2body.ApplyImpulse(new b2Vec2(v[0], v[1]), new b2Vec2(c[0], c[1])); return; }; Ship.prototype.update = function(msDuration) { if (this.hitCount > this.hitPoints) { this.kill();
var gamejs = require('gamejs'), TextArea = require('./gramework/ui').TextArea, objects = require('gamejs/utils/objects'), Element = require('./gramework/ui').Element, config = require('./config'); var Score = require('./gramework/ui').Score; var LoseMessage = function(options) { LoseMessage.superConstructor.apply(this, arguments); this.isLoseMessage = true; } objects.extend(LoseMessage, TextArea); var LoseImage = function(options) { LoseImage.superConstructor.apply(this, arguments); this.isLoseImage = true; } objects.extend(LoseImage, TextArea); var score_opts = { pos: 'top left', margin: 2, size: [160, 10], text: ['00000000'], active: true }; var score_opts_2 = { pos: 'top right', margin: 2, size: [160, 10], text: ['00000000'],
var gamejs = require('gamejs'), FourDirection = require('./gramework/actors').FourDirection, objects = require('gamejs/utils/objects'), config = require('./config'), Tile = require('./gramework/maps').Tile, sounds = require('./gramework/sounds'); var Player = function(options) { Player.superConstructor.apply(this, arguments); this.isTarget = false; this.isBeingHunted = false; this.targetCounter = 0; this.playerScore = 0; this.targetSetTime = 0; }; objects.extend(Player, FourDirection); Player.prototype.doCollisions = function(collisions) { var actor = this; _.each(collisions, function(obj, key) { // We can be colliding with a tile or a prop object. Do a simple check // to know what route we should take if (obj instanceof Tile) { var tile = obj; if (tile.properties && tile.properties.teleportPlayer) { actor.doTeleport(tile); } if (tile.properties && tile.properties.obstacle) { actor._hitWall(tile, key); }
var gamejs = require('gamejs'); var Sprite = require('gamejs/sprite').Sprite; var draw = require('gamejs/draw'); var objects = require('gamejs/utils/objects'); var config = require('../config'); var SpriteSheet = require('./animate').SpriteSheet; var Animation = require('./animate').Animation; var Actor = exports.Actor = function(options) { Actor.superConstructor.apply(this, arguments); this.init(options); return this; }; objects.extend(Actor, Sprite); Actor.prototype.init = function(options) { this.scale = options.scale || 5; this.x = options.x; this.y = options.y; this.height = options.height; this.width = options.width; this.angle = options.angle * (Math.PI / 180) || 0; this.density = options.density || 2; this.absAngle = this.angle; this.startingAnimation = options.startingAnimation || 'static'; this.rect = new gamejs.Rect( [(this.x - this.width) * this.scale, (this.y - this.height) * this.scale], [this.width * 2 * this.scale, this.height * 2 * this.scale]);
if (options.pos.match('center')) { this.pos[0] = (config.WIDTH / 2) - (this.size[0] / 2); } if (options.pos.match('middle')) { this.pos[1] = (config.HEIGHT / 2) - (this.size[1] / 2); } } this.rect = new gamejs.Rect(this.pos, this.size); if (this.animation) { this.animation.start('static'); } return this; }; objects.extend(Element, gamejs.sprite.Sprite); Element.prototype.update = function(msDuration) { if (this.animation) { this.animation.update(msDuration); this.image = this.animation.image; this.image._context.webkitImageSmoothingEnabled = false; } return; }; Element.prototype.start = function() { this.active = true; return; };
}; var p2Mapping = { 'LEFT': gamejs.event.K_a, 'RIGHT': gamejs.event.K_d, 'UP': gamejs.event.K_w, 'DOWN': gamejs.event.K_s, 'BUTTON1': gamejs.event.K_p, 'BUTTON2': gamejs.event.K_l }; var Player = exports.Player = function(options) { Player.superConstructor.apply(this, arguments); return this; }; objects.extend(Player, Actor); Player.prototype.init = function(options) { Actor.prototype.init.call(this, options); this.physics = options.physics || null; if (options.player == 2) { this.controls = p2Mapping; } else { this.controls = defaultMapping; } if (this.physics) { this.body = new Body(this.physics, { type: options.type || 'dynamic', x: this.x, y: this.y,
/** * constructor */ // sets image & RECT this.rect = new Rect(0,0); this.rect.center = pos; var center = pos; this.setAnimation(meta.idle); if (!IMAGES[spritesPath]) { IMAGES[spritesPath] = {}; for (var ani in animations) { IMAGES[spritesPath][ani] = image.load(getImagePath(spritesPath, ani)); }; } return this; }; objects.extend(AnimatedSprite, sprite.Sprite); /** * Overwrite for custom update() */ AnimatedSprite.prototype.customUpdate = function() { }; function getImagePath(root, animation) { return root + animation.replace(' ', '%20') + '.png'; };
var gamejs = require('gamejs'); var config = require('./config'); var objects = require('gamejs/utils/objects'); var Actor = require('./gramework/actors').Actor; var Turtle = exports.Turtle = function(options) { Turtle.superConstructor.apply(this, arguments); //this.init(options); return this; } objects.extend(Turtle, Actor); var radius = 0; Turtle.prototype.init = function(options) { Actor.prototype.init.call(this, options); this.radius = 0; this.angle = 0; this.top_offset = 118; this.left_offset = 100; this._canSlam = true; this._isSlamming = false; this._isReturning = false; var turtle_opts = { scale: 1, height: 13, width: 25, x: 0,
this.elapsed = 0; this.initScene(sceneConfig); return this; }; BaseScene.prototype.initScene = function(sceneConfig) { this.width = sceneConfig.width || 1024; this.height = sceneConfig.height || 500; this.scale = sceneConfig.scale || 1; }; var GameScene = exports.GameScene = function(director, sceneConfig) { GameScene.superConstructor.apply(this, arguments); return this; }; objects.extend(GameScene, BaseScene); GameScene.prototype.initScene = function(sceneConfig) { gamejs.log(sceneConfig); BaseScene.prototype.initScene.apply(this, arguments); sounds.playsound(config.music_main, true); var that = this; this.buttons = new gamejs.sprite.Group(); this.gates = new gamejs.sprite.Group(); this.lights = new gamejs.sprite.Group(); this.wallState = 0; this.scores = []; this.players = [];