Skip to content

Commit

Permalink
new pause and help buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahkagan committed Feb 12, 2011
1 parent b43c3bf commit 12c9901
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
17 changes: 14 additions & 3 deletions button.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,34 @@
var button = function(p, spec) {

// --- defaults ---
spec.rect.width = spec.rect.width || 100;
spec.rect.height = spec.rect.height || 35;
//spec.rect.width = spec.rect.width || 100;
//spec.rect.height = spec.rect.height || 35;

// obj to return
var obj = {};

// --- private variables ---

var next_state_fun = spec.state;
var rect = rectangle(p, spec.rect);
var active = spec.active || true;

var image = spec.rect.image ?
image_manager.get_image(spec.rect.image) : null;
var over_image = spec.rect.over_image ?
image_manager.get_image(spec.rect.over_image) : null;

// if no width is given but an image is
// use the image width
if (!spec.rect.width && image) {
spec.rect.width = image.width;
}
// and for height
if (!spec.rect.height && image) {
spec.rect.height = image.height;
}

var rect = rectangle(p, spec.rect);

// --- public methods ---

obj.draw = function() {
Expand Down
16 changes: 7 additions & 9 deletions help_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,9 @@ var help_state = function (p, prev_state) {
state : function() { sounds.play_button_back(); return prev_state; },
rect : {
pos : new p.PVector(p.width/2, button_y), //box_x+box_w-80, box_y+box_h-30),
width: 120,
height: 50,
text: "Back",
text_x_offset: 5,
text_y_offset: -8,
//text: "Back",
//text_x_offset: 5,
//text_y_offset: -8,
image: "back.png",
}
});
Expand All @@ -512,9 +510,9 @@ var help_state = function (p, prev_state) {
},
rect: {
pos: new p.PVector(p.width/2+120, button_y),
text: "Next",
//text: "Next",
image: "next.png",
style: button_style
//style: button_style
}
});

Expand All @@ -526,9 +524,9 @@ var help_state = function (p, prev_state) {
},
rect: {
pos: new p.PVector(p.width/2-120, button_y),
text: "Previous",
//text: "Previous",
image: "previous.png",
style: button_style
//style: button_style
}
});
previous_button.deactivate();
Expand Down
26 changes: 14 additions & 12 deletions pause_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ var pause_state = function (p, 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
width: 120,
height: 50
//image_x_offset: 5,
//style: button_style
}
});

Expand All @@ -43,9 +45,9 @@ var pause_state = function (p, prev_state) {
},
rect : {
pos : new p.PVector(button_x, button_top+button_sep),
text: "Settings",
//text: "Settings",
image: "settings.png",
style: button_style
//style: button_style
}
});

Expand All @@ -56,11 +58,11 @@ var pause_state = function (p, prev_state) {
},
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
//image_x_offset: 3,
//style: button_style
}
});

Expand All @@ -71,11 +73,11 @@ var pause_state = function (p, prev_state) {
},
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
//image_x_offset: -5,
//style: button_style
}
});

Expand Down Expand Up @@ -106,7 +108,7 @@ var pause_state = function (p, prev_state) {
};

obj.key_pressed = function(k) {
if (k === 112 || p.keyCode == 13 || p.keyCode === 27) { //p, enter, esc
if (k === 112 || p.keyCode === 13 || p.keyCode === 27) { //p, enter, esc
obj.exit_state();;
}
};
Expand Down
1 change: 1 addition & 0 deletions rectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var rectangle = function (p, spec) {
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;
// tints background image for mouse over
Expand Down

0 comments on commit 12c9901

Please sign in to comment.