Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add.messages #15

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c983162
MessageBoxes instanciable + text size adaptation
sebferrer Nov 2, 2018
f2f8746
Oops, remove useless file
sebferrer Nov 2, 2018
066abe1
MessageBox scrolling
sebferrer Nov 3, 2018
56cb80b
cleanup
bastienguillon Feb 4, 2019
cbe5f71
draw characters one by one
bastienguillon Feb 5, 2019
c304440
add shaky messages animation
bastienguillon Feb 5, 2019
b1a548b
handle choices and select them + handle closing dialog
bastienguillon Feb 6, 2019
31ee4c3
small fix
bastienguillon Feb 6, 2019
0baf67a
tweaking
bastienguillon Feb 6, 2019
19f3c2b
Animation factor directly included in IDialogAnimation
sebferrer Feb 6, 2019
010288d
TOEIC: 780
sebferrer Feb 6, 2019
55b050a
Blur audio button on click
sebferrer Feb 6, 2019
79a8692
fix dialog answers animation
bastienguillon Feb 8, 2019
12d6a06
Add pause system
sebferrer Feb 10, 2019
313a832
Messages are no more requiring _line_width_in_characters and Monospac…
sebferrer Feb 11, 2019
8e815a6
Add 3 glitchy effects (spinny, splitted, uppercase)
sebferrer Feb 11, 2019
d0f5d61
upgrade gulp 3 --> 4
sebferrer Apr 20, 2021
69d77c3
entities height perspective + WIP actionable objects
sebferrer Apr 21, 2021
47a8663
[WIP] actionable objects
sebferrer Apr 21, 2021
38aa953
actionable entities linked to floor + room
sebferrer Apr 22, 2021
ee76000
spread entities
sebferrer Apr 22, 2021
bfdf7d8
entities - floor/room link
sebferrer Apr 22, 2021
8b46094
actionable entities in a separate file
sebferrer Apr 23, 2021
3af06d0
drawable entities + [WIP] rocks
sebferrer Apr 26, 2021
b3944e0
[WIP] spread entities + random locations
sebferrer Apr 29, 2021
14e9a3f
spread entities + random locations --> some improvements
sebferrer Apr 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
Binary file added assets/sounds/sfx/msg_1.wav
Binary file not shown.
File renamed without changes.
6 changes: 5 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ canvas {
#main-layers {
position: fixed;
left: 50%;
outline: 1px solid red;
}
#main-layers canvas {
position: absolute;
Expand Down Expand Up @@ -77,4 +76,9 @@ body {

.no-pointer-events {
pointer-events: none;
}

.messageBox {
z-index: 2;
border-radius: 1rem;
}
2 changes: 1 addition & 1 deletion src/character/tear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class TearBasic extends Tear {
public speed: number;
public range: number;

private static _basic_tear_firing_sound = new AudioFile("assets/sounds/pew.mp3");
private static _basic_tear_firing_sound = new AudioFile("assets/sounds/sfx/pew.mp3");
public get firing_sound(): AudioFile { return TearBasic._basic_tear_firing_sound; }

constructor(pos: Point, direction: Direction, id?: string, current_sprite?: Sprite, width?: number, height?: number) {
Expand Down
9 changes: 9 additions & 0 deletions src/conversation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { MessageBox } from "./message_box";

export class Conversation {
public messages: Array<MessageBox>;

constructor(messages: Array<MessageBox>) {
this.messages = messages;
}
}
2 changes: 1 addition & 1 deletion src/environment/floors/one/temple_floor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class TempleFloor extends Floor {

constructor() {
super();
this._base_music = new AudioFile("assets/sounds/dungeon.mp3");
this._base_music = new AudioFile("assets/sounds/musics/dungeon.mp3");
this.base_music.loop = true;
}
}
8 changes: 8 additions & 0 deletions src/gamestate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Timer } from "./timer";
import { TIMERS } from "./timers";
import { TouchHelper } from "./touch_helper";
import { ArrayUtil, SetUtil } from "./util";
import { MessageBox } from "./message_box";

export class GameState {
public current_room: RoomMap;
Expand All @@ -25,6 +26,7 @@ export class GameState {
public tears: Tear[];
public joysticks: Joysticks;
public touches: TouchList;
public current_message: MessageBox;

constructor() {
this.current_floor = new TempleFloor();
Expand Down Expand Up @@ -231,8 +233,14 @@ export class GameState {

this.jays.draw(dynamic_ctx);

if(this.current_message != null) {
this.current_message.draw();
}

this.touch_move();

dynamic_ctx.restore();

const self = this;
window.requestAnimationFrame(() => self.update());
}
Expand Down
10 changes: 10 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ImageBank } from "./image_bank";
import { Renderer } from "./renderer";
import { KeyMapper } from "./settings/keymapper";
import { Settings } from "./settings/settings";
import { MessageBox } from "./message_box";

export const canvas_W = 660;
export const canvas_H = 480;
Expand Down Expand Up @@ -33,6 +34,15 @@ window.onload = () => {
renderer.autoScale();
gameState = new GameState();
Settings.init();

const msg = new MessageBox(new Array<string>(
"Twilight is shining through the barrier. It seems your journey is finally over. You're filled with DETERMINATION.",
"Welcome to The Blunder of JayS",
"This is the first test message",
"We're awesomes!"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

animals

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je te hais.


msg.start();

gameState.get_timer("tear").interval = gameState.jays.tear_delay;
gameState.update();
});
Expand Down
126 changes: 126 additions & 0 deletions src/message_box.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { AudioFile } from "./audio_file";
import { static_canvas, renderer, gameState } from "./main";

/**
* TODO: Triggers, Next messages, Stop, Text scrolling, Storage
*/
export class MessageBox {
public canvas: HTMLCanvasElement;
public context: CanvasRenderingContext2D;
public character: string | null;
public characterFont: string;
public content: Array<string>;
public sound: AudioFile;
public font: string;
public fontColor: string;
public backgroundColor: string;
public borderColor: string;
public left: number;
public top: number;
public width: number;
public height: number;
public scrolling_index: number;
public scrolling_text: string;
public scrolling_line_index: number;

constructor(content: Array<string>, character?: string, characterFont?: string,
sound?: AudioFile, font?: string, fontColor?: string,
backgroundColor?: string, borderColor?: string) {
this.content = content;
this.character = character;
this.characterFont = characterFont == null ? "5px 'Arial'" : characterFont;
this.sound = sound == null ? new AudioFile("assets/sounds/sfx/msg_1.wav") : sound;
this.fontColor = fontColor == null ? "white" : fontColor;
this.backgroundColor = backgroundColor == null ? "black" : backgroundColor;
this.borderColor = borderColor == null ? "black" : backgroundColor;
this.width = static_canvas.width / 2;
this.height = static_canvas.height / 5;
this.top = static_canvas.offsetTop + static_canvas.height - this.height - (static_canvas.height / 20);
this.font = font == null ? (this.height / 6) + "px 'Comic Sans MS'" : font;
this.scrolling_index = 0;
this.scrolling_text = "";
this.scrolling_line_index = 0;
}

public start() {
this.canvas = document.createElement("canvas");
this.context = this.canvas.getContext("2d", { alpha: true });
renderer.disableCanvasSmoothing(this.context);
this.canvas.classList.add("messageBox");
this.canvas.style.backgroundColor = this.backgroundColor;
this.canvas.width = this.width;
this.canvas.height = this.height;
this.canvas.style.position = "absolute";
this.canvas.style.top = this.top + "px";
this.context.font = this.font;
this.context.fillStyle = this.fontColor;

document.getElementById("main-layers").appendChild(this.canvas);
gameState.current_message = this;
}

public draw() {
const text = this.content[0];
const text_x = this.width / 60;
const text_y = (1 + this.scrolling_line_index) * this.height / 4;
const text_width = this.context.measureText(text).width + text_x;
if (text_width > this.canvas.width) {
const lines = this.split_text_canvas(text, this.context, text_x, this.canvas.width);
if (this.scrolling_line_index < lines.length) {
if(this.fill_scrolling_text(lines, text_x, text_y)) {
++this.scrolling_line_index;
}
}
}
else {
if(this.fill_scrolling_text(new Array<string>(text), text_x, text_y)) {
++this.scrolling_line_index;
}
}
}

public fill_scrolling_text(lines: Array<string>, x: number, y: number): boolean {
const timer = gameState.get_timer("textbox");
timer.enable();
if(this.scrolling_index < lines[this.scrolling_line_index].length) {
if(timer.next_tick()) {
this.context.save();
this.context.clearRect(0, 0, this.width, this.height);
for(let i = 0; i < this.scrolling_line_index; i++) {
this.context.fillText(lines[i], x, (1 + i) * this.height / 4);
}
this.scrolling_text += lines[this.scrolling_line_index][this.scrolling_index];
this.context.fillText(this.scrolling_text, x, y);
this.sound.play();
++this.scrolling_index;
this.context.restore();
}
}
else if(this.scrolling_index > 0) {
this.scrolling_index = 0;
this.scrolling_text = "";
return true;
}
return false;
}

public split_text_canvas(text: string, context: CanvasRenderingContext2D, text_x: number, canvas_width: number): Array<string> {
const words = text.split(" ");
const lines = new Array<string>();
let line = "";
for (let i = 0; i < words.length; i++) {
const space = line === "" ? "" : " ";
const next_length = context.measureText(line + space + words[i]).width + text_x;
if (next_length < canvas_width) {
line += space + words[i];
}
else {
lines.push(line);
line = words[i];
}
}
lines.push(line);
return lines;
}

}
10 changes: 7 additions & 3 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ export class Renderer {

public disableSmoothing(): void {
main_layers.forEach(layer => {
layer.ctx["webkitImageSmoothingEnabled"] = false;
layer.ctx["mozImageSmoothingEnabled"] = false;
layer.ctx.imageSmoothingEnabled = false;
this.disableCanvasSmoothing(layer.ctx);
});
}

public disableCanvasSmoothing(context: CanvasRenderingContext2D): void {
context["webkitImageSmoothingEnabled"] = false;
context["mozImageSmoothingEnabled"] = false;
context.imageSmoothingEnabled = false;
}

public scale(zoomScale?: number): void {
this.zoomScale = zoomScale == null ? this.zoomScaleNext.get(this.zoomScale) : zoomScale;
main_layers.forEach(layer => {
Expand Down
3 changes: 2 additions & 1 deletion src/timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import { Timer } from "./timer";
export const TIMERS: Timer[] = [
new Timer("tear", 0),
new Timer("jays_sprites", 80),
new Timer("joysticks", 34)
new Timer("joysticks", 34),
new Timer("textbox", 100)
];