Skip to content

Commit

Permalink
added pause screen buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahkagan committed Jan 26, 2011
1 parent 36e7e75 commit f998ef6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
2 changes: 2 additions & 0 deletions image_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ var make_image_manager = function() {
screens : { dir : "screens/" },
wall_segments : { dir : "wall_segments/" },
macrophage : {dir : "macrophage_animation/"},
burst : { dir : "burstingcell_animation/"},
buttons : { dir : "buttons/"},
// catches all images in images/
other : { dir : "" },
};
Expand Down
27 changes: 22 additions & 5 deletions in_game_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,13 @@ var in_game_state = function (p, previous_state) {
var check_collisions = (function() {
// rendering levels to check collisions for:
var to_check = [
["particle", "particle"],
//["particle", "particle"],
["particle", "cell"],
["particle", "enemy"],
["particle", "multiplier"],
["cell", "cell"],
//["cell", "cell"],
["cell", "enemy"],
["enemy", "enemy"],
//["enemy", "enemy"],
["enemy", "b_cell"],
["b_cell", "wall"],
["particle", "wall"],
Expand Down Expand Up @@ -952,6 +952,11 @@ var in_game_state = function (p, previous_state) {
bounce(b, flo);
notify("B-cell activated!", BAD_NOTIFICATION_COLOR);
}
// trying to avoid getting stuck
if (b.is_outdated()) {
bounce(b, flo);
b.set_target(null);
}
},
"wall_segment": function(b, wall) {
//console.log("collision");
Expand Down Expand Up @@ -989,10 +994,11 @@ var in_game_state = function (p, previous_state) {
//else false
}
else {
console.log("removing "+x.to_string());
offscreen = true;
}
}
return (!offscreen && (! x.is_dead()));
return (! (offscreen || x.is_dead()));
};
for (var i = 0; i < game_objects.length; i++) {
game_objects[i] = game_objects[i].filter(filter_fun);
Expand Down Expand Up @@ -1437,6 +1443,14 @@ var in_game_state = function (p, previous_state) {
remove_objs();

update_mutation();

/*
// for debugging
var count = 0;
do_to_all_objs(function() { count += 1; });
console.log(count);
console.log("fr "+p.__frameRate);
*/
}
};

Expand Down Expand Up @@ -1525,7 +1539,10 @@ var in_game_state = function (p, previous_state) {
for (var i=0; i<game_objects.length; i++) {
for (var j=0; j<game_objects[i].length; j++) {
var o = game_objects[i][j];
o.draw();
// debugging by taking out certain types
//if (!o.is("background_edge")) {
o.draw();
//}
// to test collisions
//o.draw_circle();
}
Expand Down
32 changes: 27 additions & 5 deletions pause_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,59 @@ var pause_state = function (p, prev_state) {
// a state to go to when pressed
var button_x = p.width / 2;
var button_top = 200;
var button_sep = 50;
var button_sep = 60;

var button_style = {
text_size: 14,
text_align: p.LEFT,
text_x_offset: 25,
width: 120,
height: 50,
};


var continue_button = button(p, {
state : function() { return prev_state; },
rect : {
pos : new p.PVector(button_x, button_top),
text: "Continue"
text: "Continue",
image: "continue.png",
image_x_offset: 5,
style: button_style
}
});

var options_button = button(p, {
state : function() { return options_state(p, obj); },
rect : {
pos : new p.PVector(button_x, button_top+button_sep),
text: "Settings"
text: "Settings",
image: "settings.png",
style: button_style
}
});

var help_button = button(p, {
state : function() { return help_state(p, obj); },
rect : {
pos : new p.PVector(button_x, button_top+2*button_sep),
text: "Instructions"
text: "Instructions",
//text_x_offset: 10,
image: "instructions.png",
image_x_offset: 3,
style: button_style
}
});

var quit_button = button(p, {
state : function() { return splash_state(p); },
rect : {
pos : new p.PVector(button_x, button_top+3*button_sep),
text: "Quit"
text: "Quit",
//text_x_offset: -5,
image: "quit.png",
image_x_offset: -5,
style: button_style
}
});

Expand Down
18 changes: 11 additions & 7 deletions rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
// text_size : size of text (default to processings default)
// text_align : alignment of text (default to p.CENTER)
// text_x_offset : offset for the text x coordinate
// image_x_offset: offset for the image
// rect_color : color of rectangle (defaults to white)
// image : string location of image to display instead of a rectangle
// style : object that can specify text_color, text_size, rect_color, width, height, text_align
// style : object that can specify text_color, text_size, rect_color, width, height, text_align, text_x_offset

var rectangle = function (p, spec) {

Expand All @@ -33,12 +34,14 @@ var rectangle = function (p, spec) {
var text = spec.text || "";
var text_color = spec.style.text_color || spec.text_color || 0;
var text_size = spec.style.text_size || spec.text_size || 12;
var text_x_offset = spec.style.text_x_offset || spec.text_x_offset || 0;
var text_align = spec.style.text_align || spec.text_align || p.CENTER;
var rect_color = spec.style.rect_color || spec.rect_color || 255;
var rect_image;
if (spec.image) {
rect_image = image_manager.get_image(spec.image);// p.loadImage(spec.image);
}
spec.image_x_offset = spec.image_x_offset || 0;
var rect_mode = p.CENTER;


Expand All @@ -53,8 +56,9 @@ var rectangle = function (p, spec) {
//console.log("drawing");
if (rect_image) {
p.imageMode(rect_mode);
rect_image.resize(width, height);
p.image(rect_image, pos.x, pos.y);//, width, height);
//rect_image.resize(width, height);
p.image(rect_image, pos.x+spec.image_x_offset, pos.y,
width, height);
}
else {
p.rectMode(p.CORNER);
Expand All @@ -74,22 +78,22 @@ var rectangle = function (p, spec) {
if (text_align === p.LEFT) {
text_x = pos.x - half_width + 10;
}
text_x += (spec.text_x_offset || 0);
text_x += (text_x_offset || 0);
p.textSize(text_size);
p.text(text, text_x, pos.y);
};

obj.update_text = function(t) {
text = t;
}
};

// Getters
obj.get_left_x = function() {
return leftx;
}
};
obj.get_top_y = function() {
return topy;
}
};


return obj;
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var p_code = function(p) {
};
p.mouseMoved = function() {
sm.mouse_moved(p.mouseX, p.mouseY);
}
};
};


Expand All @@ -55,7 +55,7 @@ var start_game = function() {
// note that we need to do this AFTER the canvas element is created
var canvas = document.getElementById("test_canvas");
sketch = new Processing.Sketch(p_code);
sketch.options.isTransparent = true;
//sketch.options.isTransparent = true;
var pInstance = new Processing(canvas, sketch);
};
window.onload = start_game;
Expand Down

0 comments on commit f998ef6

Please sign in to comment.