Skip to content

Commit

Permalink
fixed antibody angles and more
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahkagan committed Jan 4, 2011
1 parent f2ef17d commit 1a366de
Show file tree
Hide file tree
Showing 32 changed files with 85 additions and 46 deletions.
Empty file modified README
100755 → 100644
Empty file.
14 changes: 9 additions & 5 deletions antibody.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ var antibody = function(p, spec) {

spec.width = spec.width || 15;
spec.height = spec.height || 10;
spec.speed = spec.speed || 2;
spec.no_target_speed = spec.no_target_speed || 1
spec.speed = spec.speed || 4;
spec.no_target_speed = spec.no_target_speed || 2

spec.vel = new p.PVector(Math.random() * 2 - 1,
Math.random());

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

Expand Down Expand Up @@ -71,5 +69,11 @@ var antibody = function(p, spec) {
p.popMatrix();
};

// always facing down since b_cell at top of screen
obj.random_target_angle = function() {
return p.random(0, p.PI);
};
obj.set_target_angle(obj.random_target_angle());

return obj;
}
2 changes: 1 addition & 1 deletion b_cell.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var b_cell = function(p, spec) {

spec.width = spec.width || 30;
spec.height = spec.height || 30;
spec.speed = spec.speed || 1.5;
spec.speed = spec.speed || 3.5;

// obj to return
var obj = seeker(p, spec);
Expand Down
Empty file modified background.js
100755 → 100644
Empty file.
Empty file modified button.js
100755 → 100644
Empty file.
41 changes: 26 additions & 15 deletions cell.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ var cell = function(p, spec) {

// state can be "alive", "infected", "active", or "dead"
var state = spec.state || "alive";
var arrow_angle = 0;
var arrow_dir = 1;
// random initial angle
var arrow_angle = p.random(-p.PI/2, p.PI/2);
// random dir (1 or -1)
var arrow_dir = p.random() >= 0.5 ? 1 : -1;

// indicates whether has been hit by an arrow and is being targeted
//var is_targeted = false;
Expand Down Expand Up @@ -73,18 +75,20 @@ var cell = function(p, spec) {
if (state === "alive") {
p.fill(p.color(200, 50, 50));
}
if (state === "infected") {
p.fill(obj.get_color());
}
else if (state === "active") {
drawArrow();
// red outline for now
p.stroke(255, 0, 0);
p.strokeWeight(4);
p.fill(obj.get_color());
else {
if (state === "infected") {
p.fill(obj.get_color());
}
else if (state === "active") {
drawArrow();
// red outline for now
p.stroke(255, 0, 0);
p.strokeWeight(4);
p.fill(obj.get_color());
}
p.ellipse(pos.x, pos.y, obj.get_width(), obj.get_height());
}

p.ellipse(pos.x, pos.y, obj.get_width(), obj.get_height());
p.imageMode(obj.get_mode());
p.image(cell_image, pos.x, pos.y, obj.get_width(), obj.get_height());

Expand Down Expand Up @@ -127,9 +131,7 @@ var cell = function(p, spec) {
};

// explodes this cell if it is active
// takes number of particles to generate
// returns that many particles
obj.fire = function(num_particles) {
obj.fire = function() {
if (state === "active") {
// TODO: need a slower death
obj.die();
Expand All @@ -143,13 +145,18 @@ var cell = function(p, spec) {
var x = r*p.cos(ang) + pos.x;
var y = r*p.sin(ang) + pos.y;

var num_particles = get_num_particles();
// angle between all the shots
var range = p.PI/6;
var incr = range/num_particles;

var particles = [];

ang = arrow_angle - range/2;
// special case
if (num_particles === 1) {
ang = arrow_angle;
}
while (num_particles > 0) {
var new_vel = new p.PVector(p.cos(ang), p.sin(ang));
// mult by speed scalar
Expand Down Expand Up @@ -223,5 +230,9 @@ var cell = function(p, spec) {
p.popMatrix();
};

var get_num_particles = function() {
return obj.get_mutation_info().particles;
};

return obj;
};
Empty file modified empty_cell.js
100755 → 100644
Empty file.
Empty file modified floater.js
100755 → 100644
Empty file.
4 changes: 2 additions & 2 deletions game_object.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// float radius = circle collision radius (will be auto-calced)
// p.PVector vel = initial velocity
// p.PVector accel = initial acceleration
// mutation_info = object with level and color props
// mutation_info = object with level, num_particles and color props

var game_object = function (p, spec) {

Expand All @@ -35,7 +35,7 @@ var game_object = function (p, spec) {
var radius = spec.radius // default set at bottom of file
// used for mutation
var mutation_info = spec.mutation_info ||
{ level: -1, color: p.color(0, 0, 0) };
{ level: -1, color: p.color(0, 0, 0), particles: 0 };

var alive = true;

Expand Down
Empty file modified game_over_state.js
100755 → 100644
Empty file.
Empty file modified game_state.js
100755 → 100644
Empty file.
11 changes: 5 additions & 6 deletions generator.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ var make_generator = function(p, spec) {
// - make_new = function that takes a pos and returns a new enemy
var gen_info = {
"cell": {
start: 0, num: 10, cap: 20, rate: 5000,
start: 0, num: 8, cap: 15, rate: 5000,
make_new: function(en_pos) {
return cell(p, {
pos: en_pos,
state: "alive",
//mutation : mutation
});
}
},
"wall_cell": {
start: 0, num: 1, cap: 7, rate: 20000, //non testing value: 1000
start: 0, num: 3, cap: 7, rate: 20000, //non testing value: 1000
make_new: function(en_pos) {
return wall_cell(p, { pos: en_pos });
}
Expand All @@ -67,7 +66,7 @@ var make_generator = function(p, spec) {
return tkiller(p, {
pos: en_pos,
mutation_info: game.get_mutation_info()
});
});
}
},
"multiplier": {
Expand Down Expand Up @@ -133,8 +132,8 @@ var make_generator = function(p, spec) {

//Generate random y position
// TODO change hardcoded numbers
var enemy_y = p.random(30, p.height-30);
var enemy_pos = new p.PVector(p.width+30, enemy_y);
var enemy_y = p.random(90, p.height-50);
var enemy_pos = new p.PVector(p.width+50, enemy_y);

var new_enemy = make_new(enemy_type)(enemy_pos);
assert(new_enemy, "Error in generator.update()");
Expand Down
14 changes: 12 additions & 2 deletions global_functions.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,27 @@ var for_each = function(arr, fun) {
}
};

// returns the index of an element in a list,
// otherwise false
var member = function(arr, elt) {
for (var i=0; i<arr.length; i++) {
if (arr[i] === elt) {
console.log("returning "+i);
return i;
}
}
console.log("returning -1");
return false;
};

// removes the first instance of elt from the array
var remove_elt = function(arr, elt) {
remove_index(arr, arr.indexOf(elt));
};

// removes the element at index i from the array and returns it
var remove_index = function(arr, i) {
return arr.splice(i, 1)[0];
};

// returns a random element from an array
var random_from = function(arr) {
return arr[Math.floor(Math.random()*arr.length)];
Expand Down
Empty file modified help_state.js
100755 → 100644
Empty file.
28 changes: 16 additions & 12 deletions in_game_state.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var in_game_state = function (p, previous_state) {

// whether or not we are testing
// use it wherever
var testing = true;
var testing = false;
obj.testing = function() { return testing; };

// --- constants ---
Expand All @@ -27,6 +27,7 @@ var in_game_state = function (p, previous_state) {
// multiply each object's scroll amount by this
// factor, which increases throughout the game
var scroll_factor = 1;

var game_objects = [];
var paused = false;

Expand Down Expand Up @@ -141,33 +142,29 @@ var in_game_state = function (p, previous_state) {

var startx = p.width-120;
if (testing) {
var startx = 100;
var startx = 150;
}

var initial_cells = [
cell(p, {
pos: new p.PVector(startx, p.height/2),
vel: new p.PVector(0, 0),
state: "alive",
//mutation : mutation
}),
cell(p, {
pos: new p.PVector(startx+120, p.height/2-40),
vel: new p.PVector(0, 0),
state: "alive",
//mutation : mutation
}),
cell(p, {
pos: new p.PVector(startx+120, p.height/2),
vel: new p.PVector(0, 0),
state: "alive",
//mutation : mutation
}),
cell(p, {
pos: new p.PVector(startx+120, p.height/2+40),
vel: new p.PVector(0, 0),
state: "alive",
//mutation : mutation
})
];
//var cell_level = type_to_level["cell"];
Expand All @@ -176,7 +173,7 @@ var in_game_state = function (p, previous_state) {

var initial_par = particle(p, {
pos: new p.PVector(0, p.height/2),
vel: new p.PVector(3, 0),
vel: new p.PVector(8, 0),
// start with some gray
mutation_info: mutation.get_info()//p.color(250, 250, 250)
//mutation : mutation
Expand Down Expand Up @@ -327,11 +324,9 @@ var in_game_state = function (p, previous_state) {
curr_active.set_state("infected"); //if same, about to change
}
active_cell.set_state("active");
//update the tkillers' targets

//console.log("got next "+active_cell.to_string());
}
}
};

// Returns true if source is closer to target1 than target2
// All 3 args are game_objs
Expand Down Expand Up @@ -1132,7 +1127,7 @@ var in_game_state = function (p, previous_state) {
// Set all applicable enemies to be outdated
set_all_outdated();
// update the scroll factor
//scroll_factor += 0.1;
scroll_factor += 0.1;
console.log("mutation occurred!");
}
}
Expand All @@ -1143,6 +1138,15 @@ var in_game_state = function (p, previous_state) {

//Calls draw() on every obj
obj.render = function(){

// put the active cell at the end of the list
// so it is drawn on top
if (active_cell) {
var cells = level("cell");
remove_elt(cells, active_cell);
cells.push(active_cell);
}

p.background(142, 6, 29);
//p.background(0, 0);
for (var i=0; i<game_objects.length; i++) {
Expand Down Expand Up @@ -1193,7 +1197,7 @@ var in_game_state = function (p, previous_state) {
obj.key_pressed = function(k) {
if (k === 32) { //spacebar
if (active_cell !== null) {
var particles = active_cell.fire(5);
var particles = active_cell.fire();
obj.add_objects(particles);
kill_active_cell();
}
Expand Down
Empty file modified multiplier.js
100755 → 100644
Empty file.
4 changes: 3 additions & 1 deletion mutation_obj.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ var mutation_obj = function(p) {
var rgb_arr = hsvToRgb(new_color_level, 75, 75);
return {
level: level,
color: p.color(rgb_arr[0], rgb_arr[1], rgb_arr[2])
color: p.color(rgb_arr[0], rgb_arr[1], rgb_arr[2]),
// get one new particle every 10 levels
particles: 2+p.floor(level/5)
};
};

Expand Down
Empty file modified num_status_obj.js
100755 → 100644
Empty file.
Empty file modified object_with_states.js
100755 → 100644
Empty file.
Empty file modified particle.js
100755 → 100644
Empty file.
Empty file modified pause_state.js
100755 → 100644
Empty file.
Empty file modified processing-1.0.0.min.js
100755 → 100644
Empty file.
Empty file modified random_image_selector.js
100755 → 100644
Empty file.
Empty file modified rectangle.js
100755 → 100644
Empty file.
11 changes: 10 additions & 1 deletion seeker.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var seeker = function(p, spec) {
var no_target_speed = spec.no_target_speed || 0.2;
var alive = true;
var target = spec.target || null;
var target_angle = Math.random() * (p.PI * 2) - p.PI; //random angle
// initialized to random val at bottom
var target_angle = 0;

// --- public methods ---

Expand Down Expand Up @@ -107,5 +108,13 @@ var seeker = function(p, spec) {
return target_angle;
};

// creates a random angle for init'ing
obj.random_target_angle = function() {
return p.random(-p.PI, p.PI);
//Math.random() * (p.PI * 2) - p.PI; //random angle
};
target_angle = obj.random_target_angle();


return obj;
}
Empty file modified splash_state.js
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion state_manager.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var state_manager = function (p) {

//If we have a new state to go to
if (next_state) {
console.log("next is "+next_state.get_type());
//console.log("next is "+next_state.get_type());
//Figure out if next state is an overlay
var state_type = next_state.get_type();
var is_overlay = -1;
Expand Down
Empty file modified test.html
100755 → 100644
Empty file.
Empty file modified test.js
100755 → 100644
Empty file.
Empty file modified tkiller.js
100755 → 100644
Empty file.
Empty file modified wall_cell.js
100755 → 100644
Empty file.
Empty file modified wall_segment.js
100755 → 100644
Empty file.

0 comments on commit 1a366de

Please sign in to comment.