Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vjsingh/Virus-Game
Browse files Browse the repository at this point in the history
  • Loading branch information
vjsingh committed Apr 5, 2011
2 parents 6d294a5 + d22d21a commit 2af4842
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 49 deletions.
17 changes: 11 additions & 6 deletions b_cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ var b_cell = function(p, spec) {

p.popMatrix();

if (ascending === true) {
counter++;
}
else if (ascending === false) {
counter--;
}
if (!anim_paused) {
if (ascending === true) {
counter++;
}
else if (ascending === false) {
counter--;
}
}
if (counter === c_max) {
ascending = false;
}
Expand Down Expand Up @@ -237,12 +239,15 @@ var b_cell = function(p, spec) {
}
};

var anim_paused = false;
obj.stop_animation = function() {
b_anim.pause();
anim_paused = true;
};

obj.resume_animation = function() {
b_anim.start();
anim_paused = false;
};

return obj;
Expand Down
5 changes: 2 additions & 3 deletions cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ var cell = function(p, spec) {
// Make sounds
sounds.play_sound("cell_fire");

// TODO: need a slower death
obj.die();

var pos = obj.get_pos();
Expand Down Expand Up @@ -310,15 +309,15 @@ var cell = function(p, spec) {
if (num_particles === 1) {
ang = arrow_angle;
}
num_dots = 3
var num_dots = 5;
while (num_particles > 0) {
var offset = 4;
p.fill(153);
p.noStroke();
for (var i = 0; i < num_dots; i++) {
x = r*p.cos(ang)*offset + pos.x ;
y = r*p.sin(ang)*offset + pos.y ;
p.ellipse(x, y, 3, 3);
p.ellipse(x, y, 2, 2);
offset += 2;
}

Expand Down
2 changes: 1 addition & 1 deletion floater.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var floater = function(p, spec) {
macrophage_active.pause();
};

obj.stop_animation = function() {
obj.resume_animation = function() {
macrophage_alive.start();
macrophage_active.start();
};
Expand Down
14 changes: 6 additions & 8 deletions help_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var help_state = function (p, prev_state) {
img_left: false
}));
s1.add_item(item({
title: "Infectable Cells",
title: "Infectable (Permissive) Cells",
text: "Hit an infectable cell with a virion to infect it. After penetrating the cell wall, the virion will use the cell's machinery to make copies of itself.",
//image: cimg,
illustration: {
Expand Down Expand Up @@ -232,8 +232,8 @@ var help_state = function (p, prev_state) {
img_left: false
}));
s1.add_item(item({
title: "Tolerant Cells",
text: "Some cells can be infected, but will not let your virion replicate. A virion that infects a tolerant cell is as good as dead.",
title: "Non-permissive Cells",
text: "Some cells can be infected, but will not let your virion replicate. A virion that infects a non-permissive cell is as good as dead.",
illustration: {
width: 50, height: 60,
draw: (function() {
Expand Down Expand Up @@ -336,8 +336,8 @@ var help_state = function (p, prev_state) {
img_left: false
}));
s2.add_item(item({
title: "Killer T Cells",
text: "If an infected cell is marked with an antibody, the killer T cell will hunt it down and destroy it, along with all the virions inside!",
title: "Granulocytes",
text: "If an infected cell is marked with an antibody, the granulocyte will hunt it down and destroy it, along with all the virions inside!",
//image: image_manager.get_image("tcell_2.png"),
illustration: {
width: 60, height: 60,
Expand Down Expand Up @@ -400,7 +400,7 @@ var help_state = function (p, prev_state) {
img_left: false
}));
s3.add_item(item({
text: "Macrophages, B cells, T cells, and antibodies are created to attack a specific strain of a virus. So when your virus mutates, the new strain will be safe from the old enemies.",
text: "Macrophages, B cells, granulocytes, and antibodies are created to attack a specific strain of a virus. So when your virus mutates, the new strain will be safe from the old enemies.",
//image: image_manager.get_image("macrophage_1.png"),
padding: 15,
illustration: {
Expand Down Expand Up @@ -572,8 +572,6 @@ var help_state = function (p, prev_state) {
//Not ordered
var all_buttons = [ previous_button, back_button, next_button ];

var instruction_text = "You've managed to infiltrate the human body's defenses and get your virus particle into the bloodstream! Now you must infect cells and use them to make more copies of your virus before the immune system wipes you out.\n\nAfter a particle infects a cell, the virus will use the cell's machinery to start making copies of itself. Once the cell is full of new virus particles, press the SPACEBAR or click the MOUSE to kill the cell, causing virus particles to burst through the cell wall towards other cells in the direction the arrow is pointing. You can pick which cell to burst using the LEFT and RIGHT arrow keys.\n\nAim carefully though, because the immune system has sent out macrophages to absorb your particles. If a particle hits a macrophage, it will signal a B-cell, which will start producing antibodies. If an antibody attaches to an infected cell, a T-cell will attack it. If you don't burst the cell in time, the T-cell will kill it, destroying all the particles inside!\n\nLuckily, your virus can mutate and temporarily escape the immune system. Every time the virus replicates, there are errors when copying the virus's genetic material. These errors may cause mutations in the virus. Each time you infect a cell, the virus becomes more and more likely to mutate. Once you mutate, the immune system will not be able to attack you until a macrophage absorbs a virus particle from the new strain.";

// --- public methods ---

obj.get_type = function() {
Expand Down
125 changes: 95 additions & 30 deletions in_game_state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
// *** game ***
// NOTE: get_type() returns "game" not "in_game"

// defined up here cuz instructions need them
// and a game might not be init'd before reading instr
g_speed_factor = 1; // multiply all speed constants in the game by this, for easy mode

// Global Variable so cell arrows can draw dots
GLOBAL_is_easy = false;

// flag for whether the tutorial has been played through
// if false, easy mode will include the tutorial
g_tut_done = false;

// game_type is:
// 0 - easy
// 1 - tutorial
Expand Down Expand Up @@ -36,7 +47,6 @@ var in_game_state = function (p, previous_state, game_type) {
// multiply each object's scroll amount by this
// factor, which increases throughout the game
var scroll_factor = 1;
g_speed_factor = 1; // multiply all speed constants in the game by this, for easy mode
if (game_type < 2) {
g_speed_factor = 0.75;
}
Expand Down Expand Up @@ -114,59 +124,98 @@ var in_game_state = function (p, previous_state, game_type) {


var is_tutorial = false;
if (game_type === 1) {
if (game_type === 1
// if the tutorial hasn't been done, do on easy mode
|| (game_type === 0 && !g_tut_done) ){
is_tutorial = true;
}
// Global Variable so cell arrows can draw dots
GLOBAL_is_easy = false;
if (game_type < 2) {
GLOBAL_is_easy = true;
}

// the tutorial will have been done once by now
// (although the player might have died and not seen the whole thing)
// TODO change to ensure that player sees whole tutorial??
g_tut_done = true;

// the popup to draw at a given time
// null if there is none
var tut_window = null;
// Call tut_manager.popup(type) when you want to signal a tutorial message
// All the types are in tut_flags
var tut_manager = (function() {

// object to store all the msgs
var tut_msgs = {
spacebar: "Press SPACEBAR or CLICK the mouse to shoot virions out of an infected cell in the direction of the arrow.",
arrows: "Use the LEFT and RIGHT arrow keys to switch between infected cells.",
macrophage: "Watch out for macrophages! They will kill your virion and alert a B cell.",
antibodies: "Oh no! The B cell is producing antibodies! If an antibody attaches to an infected cell, the cell will be marked for destruction by a granulocyte.",
killer: "A granulocyte just destroyed one of your infected cells and all the virions inside it! Your virus won't be safe from the granulocyte until it mutates, creating a new strain.",
mutation: "Your virus just mutated to a new strain! Now it will be safe from the immune system until you hit another macrophage. Each virion can only be attacked by immune cells that know about its strain. Immune cells that know about a certain strain will be filled with the same color as virions of that strain.",
};

// These flags are set to false when they've already occured
var tut_flags = {
initial_controls : true,
macrophage : true,
mutation : true,
// built based on tut_msgs
var tut_flags = {};
for_each(
keys(tut_msgs),
function(type) {
tut_flags[type] = true;
}
);

var tut_popup = function(txt) {
var obj = {};

var x = p.width/2;
var y = p.height/2;
var w = 400;
var h = 200;
var tw = w-50;
obj.draw = function() {
p.noStroke();
p.fill(100);
p.rectMode(p.CENTER);
p.rect(x, y, w, h);
p.fill(0);
p.textSize(14);
p.textAlign(p.CENTER, p.CENTER);
p.text(txt, x-tw/2, y-h/2, tw, h-50);
};

return obj;
};
var show_button = function(text) {

var show_popup = function(text) {
var close_button = button(p, {
state: function() {
tut_window = null;
obj.resume();
all_buttons.pop() // DANGEROUS... Hope we're not adding any other buttons anytime soon
return obj; // the current state
},
rect: {
pos: new p.PVector(100, 100),
pos: new p.PVector(p.width/2, p.height/2+80),
width: 50, height: 50,
text: text
text: "OK"
}
});
all_buttons.push(close_button);

tut_window = tut_popup(text);
};

var tut_obj = {
popup : function(type) {
if (is_tutorial && tut_flags[type]) {
do_pause();
var type_to_text = function(t) {
switch(t) {
case "initial_controls":
return "initial controls";
break;
case "macrophage":
return "macrophage";
break;
}
}
text = type_to_text(type);
show_button(text)
text = tut_msgs[type];
show_popup(text);
tut_flags[type] = false;
}
}
}
};
return tut_obj;
})()

Expand Down Expand Up @@ -501,7 +550,6 @@ var in_game_state = function (p, previous_state, game_type) {
// Chooses the next left cell to be active
var choose_left_cell = function() {
choose_cell_helper(function (x, y) {return x < y;});

};

// Same in the right dir
Expand All @@ -527,6 +575,12 @@ var in_game_state = function (p, previous_state, game_type) {

var curr_active = active_cell;
if (infecteds.length > 0) {

// tutorial msg about switching cells
if (infecteds.length > 1) {
tut_manager.popup("arrows");
}

active_cell = infecteds[0];
//If same as current
if (curr_active) { // for the beginning
Expand Down Expand Up @@ -871,7 +925,7 @@ var in_game_state = function (p, previous_state, game_type) {
par.die();
}
if (cell.get_state() === "alive") {
tut_manager.popup("initial_controls");
tut_manager.popup("spacebar");
//Play sound
sounds.play_sound("cell_infect");

Expand All @@ -882,7 +936,7 @@ var in_game_state = function (p, previous_state, game_type) {
mutation.infected_cell();
}

cell.set_state("infected");
cell.set_state("infected");
cell.set_mutation_info(par.get_mutation_info());

// Add 10 to score
Expand Down Expand Up @@ -998,6 +1052,7 @@ var in_game_state = function (p, previous_state, game_type) {
cell.get_state() === "active")
&& cell.has_antibody()
&& same_mutation_level(tk, cell)) {
tut_manager.popup("killer");
cell.die();
sounds.play_sound("kill");
tk.set_target(null);
Expand Down Expand Up @@ -1055,6 +1110,7 @@ var in_game_state = function (p, previous_state, game_type) {
"wall_segment": function(b, wall) {
//console.log("collision");
if (b.is_activated()) {
tut_manager.popup("antibodies");
// start making antibodies
b.make_antibodies();
// make a tkiller
Expand Down Expand Up @@ -1686,11 +1742,20 @@ var in_game_state = function (p, previous_state, game_type) {
remove_elt(all_notifications, n);
}
});

// render the tut msg window if there is one currently
if (tut_window) {
tut_window.draw();
}
};

var do_pause = function() {
paused = true;
sounds.pause_background_music();
tut_pause();
};

var tut_pause = function() {
paused = true;
// stop the animations
do_to_all_objs(
function(o) {
Expand All @@ -1699,7 +1764,7 @@ var in_game_state = function (p, previous_state, game_type) {
}
}
);
}
};

var do_fire = function() {
if (active_cell !== null) {
Expand Down Expand Up @@ -1785,7 +1850,7 @@ var in_game_state = function (p, previous_state, game_type) {
//var render_level = type_to_level[type];
//game_objects[render_level].push(o);
if (o.get_type() === "tkiller") {
notify("Killer T Cell Incoming!", BAD_NOTIFICATION_COLOR);
notify("Granulocyte Incoming!", BAD_NOTIFICATION_COLOR);
}
level(o.get_type()).push(o);
};
Expand Down
2 changes: 1 addition & 1 deletion index1.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
Your browser does not support the HTML5 canvas element. Upgrade to Chrome, Firefox 4, Safari, or Opera to play this game.
</canvas>
<div style="float:right; margin: 1.5em -5px 0.5em 1.5em; padding:0.5em; border: 1px dashed black; font-size:0.8em; width:200;">
<div style="margin-bottom:0.5em; font-weight:bold;">Virion was created as an entry in the Hidden Agenda contest.<br/> If you like the game, leave some feedback on the Hidden Agenda page to help Virion win!</div>
<div style="margin-bottom:0.5em; font-weight:bold;">Virion was created as an entry in the Hidden Agenda contest.<br/> If you like the game, <a href="http://www.facebook.com/topic.php?uid=114956308585&topic=16096" target="_blank">leave some feedback</a> on the Hidden Agenda page to help Virion win!</div>
<a href="http://www.facebook.com/haproject" target="_blank"><img src="images/halogo.jpg" width="200" /></a>
</div>
<div style="margin-top:0.8em;">
Expand Down

0 comments on commit 2af4842

Please sign in to comment.