Skip to content

Commit

Permalink
Adding all changes made on server, including categorization into dev,…
Browse files Browse the repository at this point in the history
… fb, and old
  • Loading branch information
vjsingh committed Oct 13, 2011
1 parent 33b65ba commit 687f0c3
Show file tree
Hide file tree
Showing 2,645 changed files with 253,226 additions and 0 deletions.
70 changes: 70 additions & 0 deletions dev/all.js

Large diffs are not rendered by default.

93 changes: 93 additions & 0 deletions dev/animated_image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Manages an animated image. Assumes that while it is active,
// get_image is called once per game loop
// Defaults to starting immediately
// Unless you call loop, will only run through the images once
// spec:
// All optional
// anim_rate : the number of frames to display each image
// reverse : whether to go backwards in the images when you reach the end or not

var animated_image = function(image_name, spec) {

// obj to return
var obj = [];

// private vars

var all_images = image_manager.get_images(image_name);
all_images.sort(
function(i1, i2) {
//return i1.path < i2.path;
return i1.path < i2.path ? -1 : (i1.path > i2.path ? 1 : 0);
}
);
//for_each(all_images, function(i) { console.log(i.path); });
var curr_index = 0;
var active = true;
var loop = false;
var rate_counter = 0; // Goes from 0 to anim_rate - 1
var anim_rate = spec.anim_rate || 3;

// If we are reversing, add all the images in the opposite
// order to all_images
if (spec.reverse || false) {
for (var i = (all_images.length - 1); i >=0; i--) {
all_images.push(all_images[i]);
}
}

//public methods

obj.start = function() {
active = true;
};

obj.pause = function() {
active = false;
};

obj.loop = function() {
loop = true;
};

obj.is_finished = function() {
// changed to && cuz it should be not looping
// and at the end to be finished
return (!loop && curr_index === (all_images.length - 1));
};

// Returns the current image
obj.get_frame = function() {
var curr_image = all_images[curr_index].image;
update();
return curr_image;
};

obj.set_rate = function(r) {
anim_rate = r;
};

// private methods

var update = function() {
if (active) {
if (rate_counter >= (anim_rate - 1)) {
next_frame();
rate_counter = 0;
}
else {
rate_counter++;
}
}
};

var next_frame = function() {
// If not 'at the end and not looping',
// increment curr_index, restarting if we reach the end
if (!(curr_index === all_images.length && !loop)) {
curr_index = (curr_index + 1) % all_images.length;
}
}

return obj;
}
86 changes: 86 additions & 0 deletions dev/antibody.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// --- inherits from seeker.js
// spec:
// game_object spec +
// speed = how fast the tkiller approaches the target
// target = cell to move towards

var antibody = function(p, spec) {

// --- defaults ---

spec.width = spec.width || 11;
spec.height = spec.height || 7;
spec.speed = (spec.speed || 4) * g_speed_factor;
spec.no_target_speed = (spec.no_target_speed || 2) * g_speed_factor;

//spec.vel = random_vel();
// obj to return
var obj = seeker(p, spec);

obj.get_type = function() {
return "antibody";
};

// --- private variables ---

// flag denoting whether the antibody is attached to a cell
var attached = false;

// --- public methods ---

// should be called when an antibody attaches to a cell
// tar will be the cell that it is attaching to (may not be its target)
obj.attach = function(tar) {
attached = true;
obj.face_target(tar);
// scoot it out just a bit
obj.get_vel().mult(-1);
obj.move();

//obj.set_target(null);
};

// implementing game_object interface

obj.my_update = function() {
if (!attached) {
obj.set_speed(obj.get_level() / 4 + 1)
obj.move();
// don't want two antibodies attacking one cell
var tar = obj.get_target();
if (tar && (tar.has_antibody()
// also don't want them to keep target
// if the target changes level
|| tar.get_level() !== obj.get_level()
// or if it starts to die
|| tar.get_state() === "dying")) {
obj.set_target(null);
}
}
};

// should point towards target
// Y-shaped (top of Y is front)
obj.draw = function() {
p.pushMatrix();

var pos = obj.get_pos();
var w = obj.get_width();
var h = obj.get_height();
p.shapeMode(obj.mode);

p.translate(pos.x, pos.y);
p.rotate(obj.get_target_angle());

p.stroke(obj.get_color());
p.strokeWeight(2);

p.line(-w, 0, w/3, 0);
p.line(w/3, 0, w, h/2);
p.line(w/3, 0, w, -h/2);

p.popMatrix();
};

return obj;
}
Loading

0 comments on commit 687f0c3

Please sign in to comment.