Skip to content

Commit fc07729

Browse files
committed
initial commit
0 parents  commit fc07729

File tree

7 files changed

+226
-0
lines changed

7 files changed

+226
-0
lines changed

USAGE.txt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Blackboard Entity for impactJS
2+
3+
This is a simple rather limited means to draw text on the screen. My game
4+
requires text description during the tutorial phases so this was my
5+
solution to that.
6+
7+
The limitations are primarily that the "writing" area is limited at design
8+
time. You have a fixed blackboard on which to write. You write all
9+
messages in the Weltmeister using the parameters (text.1, text.2, text.3).
10+
Your text has to fit into the given space.
11+
12+
To use:
13+
14+
1) Add the lines from this project's main.js into your own main.js. For
15+
the update function, it is important that the billboard code come in right
16+
at the beginning as its purpose is to stop all other events from happening
17+
while we've got our billboard up (and blocking). I commented up the
18+
main.js pretty heavily with more details.
19+
20+
2) Drop an EntityTrigger at the point where you want a player's presence to
21+
kick off a blackboard. This trigger is an entity from the sample code that
22+
comes with impactJS.
23+
24+
3) Drop an EntityBlackboardst anywhere on the level. (I may have noticed
25+
some odd interactions with overlapping on other Entities, so you might want
26+
to move it all the way to the edge -- more experimentation may be required
27+
on this point). Set the name of the Blackboardst using the entity
28+
settings. We'll call it "bb_example1". Also set the text.1... as needed.
29+
30+
4) Click back to the trigger. Set target.1 for this entity and give it the
31+
same name as your blackboard, "bb_example1". You should see a line
32+
connecting the two entities now.
33+
34+
35+
That should be it. You may have to tune your text (and possibly your
36+
billboard graphic) to work properly. There's probably some programmatic
37+
way to have a couple of different sizes of graphic work with various
38+
lengths of text, but I haven't needed it (yet).
39+

billboard_screenshot.png

44.6 KB
Loading

entities/billboard.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
3+
Entity in center of screen
4+
5+
Keys for Weltmeister:
6+
7+
name -- used by trigger to invoke
8+
text.1, text.2, text.3 -- text to be written to billboard
9+
10+
*/
11+
12+
ig.module(
13+
'game.entities.billboard'
14+
)
15+
.requires(
16+
'impact.entity'
17+
)
18+
.defines(function(){
19+
EntityBillboard = ig.Entity.extend({
20+
size: {x: 150, y: 64},
21+
name: "billboard",
22+
textlist:[],
23+
24+
animSheet: new ig.AnimationSheet("media/blackboard.png", 150, 64),
25+
init: function(x,y,settings) {
26+
// Add animations for the animation sheet from
27+
// Weltmeister settings
28+
if(settings.text) {
29+
this.textlist = settings.text;
30+
}
31+
this.addAnim("blank", 1, [0]);
32+
this.parent(x,y,settings);
33+
},
34+
draw: function(){
35+
this.parent();
36+
var offset=0;
37+
var ddrawX = this.pos.x - ig.game.screen.x + this.size.x/2;
38+
var ddrawY = this.pos.y - ig.game.screen.y + 10;
39+
for (x in this.textlist) {
40+
ig.game.font.draw( this.textlist[x],
41+
ddrawX, ddrawY+offset,
42+
ig.Font.ALIGN.CENTER );
43+
offset=offset+10;
44+
}
45+
// hardcoded for now/simplicity
46+
ig.game.font.draw( "[space] to continue",
47+
ddrawX, ddrawY+offset + 15,
48+
ig.Font.ALIGN.CENTER );
49+
50+
// flip this boolean in game -- this pauses all activity
51+
ig.game.fBillboardPause = true;
52+
53+
// if you want music to pause too -- uncomment below (or
54+
// add flags
55+
//
56+
// ig.music.pause();
57+
}
58+
});
59+
60+
});

entities/billboardst.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
3+
Static (invisible) entity only used to spawn EntityBillboard via EntityTrigger.
4+
5+
Keys for Weltmeister:
6+
7+
name -- used by trigger to invoke
8+
text.1, text.2, text.3 -- text to be written to billboard
9+
10+
*/
11+
12+
ig.module(
13+
'game.entities.billboardst'
14+
)
15+
.requires(
16+
'impact.entity',
17+
'game.entities.billboard'
18+
)
19+
.defines(function(){
20+
EntityBillboardst = ig.Entity.extend({
21+
_wmDrawBox: true,
22+
_wmBoxColor: 'rgba(0, 0, 255, 0.7)',
23+
size: {x: 150, y: 64},
24+
name: null,
25+
settings:null,
26+
27+
init: function(x,y,settings) {
28+
this.name = settings.name;
29+
this.settings = settings;
30+
this.parent(x,y,settings);
31+
},
32+
triggeredBy: function( entity, trigger ) {
33+
// pretty much all here for this
34+
ig.game.spawnEntity(EntityBillboard,
35+
ig.game.screen.x + ig.system.width/2 - this.size.x/2,
36+
ig.game.screen.y + ig.system.height/2 - this.size.y/2,
37+
this.settings);
38+
},
39+
update: function(){}
40+
});
41+
42+
});

license.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2011 by James Francis
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+

main.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* include main to show how we pause EVERYTHING in game when the billboard is up */
2+
ig.module(
3+
'game.main'
4+
)
5+
.requires(
6+
'impact.game',
7+
'impact.font',
8+
/* I use Dominic's sample trigger code here */
9+
"game.entities.trigger",
10+
"game.entities.billboard",
11+
"game.entities.billboardst",
12+
)
13+
.defines(function(){
14+
15+
MyGame = ig.Game.extend({
16+
17+
fBillboardPause: false,
18+
19+
init: function() {
20+
ig.input.bind( ig.KEY.SPACE, 'space' );
21+
},
22+
23+
update: function() {
24+
/*
25+
if we've toggled the boolean for Pause
26+
AND we're pressing the billboard close button then we
27+
can clear the billboard.
28+
29+
Here, I make multiple use of "space" key -- it also is
30+
player "fire" button.
31+
*/
32+
if(this.fBillboardPause && ig.input.state("space")) {
33+
// get our billboard
34+
var ent = ig.game.getEntitiesByType(EntityBillboard)[0];
35+
if(ent == undefined ){
36+
// catch this if we somehow get a space bar press
37+
// before boolean flag is toggled BACK
38+
console.log("billboard kill: ent undefined")
39+
return;
40+
};
41+
42+
// destroy the entity
43+
ent.kill();
44+
// reset the flag
45+
this.fBillboardPause=false;
46+
47+
// if you have a flag for music, wrap this with it
48+
// assuming you want to toggle music
49+
//
50+
//ig.music.play();
51+
}
52+
53+
/*
54+
this next line catches the update loop while the billboard is
55+
up on the screen. If this weren't here, baddies would continue
56+
assault on player UNDER the billboard. Effectively, this is
57+
a Pause GAME.
58+
*/
59+
if(this.fBillboardPause) { return;}
60+
this.parent();
61+
},
62+
});
63+
64+
ig.main( '#canvas', MyGame, 60, 220, 200, 2 );
65+
66+
});

media/blackboard.png

3.3 KB
Loading

0 commit comments

Comments
 (0)