-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding all changes made on server, including categorization into dev,…
… fb, and old
- Loading branch information
Showing
2,645 changed files
with
253,226 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.