Commit 811e6211 authored by Dave Newton's avatar Dave Newton 🍺
Browse files

initial import

parent 979d44d2
# Eclipse
.classpath
.project
.settings
# IntelliJ
out
.idea
*.ipr
*.iws
*.iml
atlassian-ide-plugin.xml
# Netbeans
nbproject/private/
# Krita
*.kra
# Gimp
*.xcf
# Libresprite
*.ase
# Tiled
*~
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"request": "launch",
"reAttach": true,
"name": "Launch index.html",
"file": "${workspaceFolder}/index.html"
}
]
}
\ No newline at end of file
MIT License
Copyright (c) 2020 devnewton
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
import * as Playnewton from "./playnewton.js"
import Title from "./scenes/title.js"
export default class Capuchine {
async Start() {
Playnewton.GPU.SetVideoOutput(/** @type HTMLCanvasElement */(document.getElementById('game')));
let scene = new Title();
scene.Start();
let redraw = (timestamp) => {
if (Playnewton.GPU.fpsLimiter.ShouldDraw()) {
if (scene.ready) {
Playnewton.GPU.SetDrawLoadingOnly(false);
Playnewton.GPU.HUD.SetLoadingText("");
Playnewton.CTRL.Poll();
Playnewton.CLOCK.Update();
if (scene.pausable) {
let pad = Playnewton.CTRL.GetMasterPad();
if (pad.TestStartAndResetIfPressed()) {
if (Playnewton.CLOCK.paused) {
Playnewton.APU.PlaySound("sounds/pause_resume.wav");
Playnewton.CLOCK.Resume();
Playnewton.GPU.HUD.SetPausedText("");
} else {
Playnewton.APU.PlaySound("sounds/pause_resume.wav");
Playnewton.CLOCK.Pause();
Playnewton.GPU.HUD.SetPausedText("Paused: press ⌨️enter or 🎮start to resume");
}
}
}
if (!Playnewton.CLOCK.paused) {
scene.UpdateBodies();
Playnewton.PPU.Update();
scene.UpdateSprites();
}
Playnewton.GPU.DrawFrame();
} else {
if (Playnewton.CLOCK.paused) {
Playnewton.CLOCK.Resume();
}
Playnewton.CLOCK.Update();
Playnewton.GPU.SetDrawLoadingOnly(true);
Playnewton.GPU.HUD.SetLoadingText(`Loading ${scene.progress}%`);
Playnewton.GPU.DrawFrame();
}
scene = scene.nextScene;
}
requestAnimationFrame(redraw);
};
requestAnimationFrame(redraw);
}
}
async function main() {
let game = new Capuchine();
game.Start();
}
main();
\ No newline at end of file
import * as Playnewton from "../playnewton.js"
import { Dialog } from "./dialog.js";
export default class Announcement {
/**
* @type string
*/
text;
/**
* @type Playnewton.GPU_Label
*/
label;
backgroundAlpha;
dialog = new Dialog();
constructor(text) {
this.text = text;
this.label = Playnewton.GPU.HUD.CreateLabel();
}
Start() {
Playnewton.GPU.HUD.SetLabelPosition(this.label, Playnewton.GPU.screenWidth / 2, Playnewton.GPU.screenHeight / 2);
Playnewton.GPU.HUD.EnableLabel(this.label);
Playnewton.GPU.HUD.SetLabelText(this.label, "");
this.backgroundAlpha = 128;
this.dx = 0;
this.dialog.keepLastLine = true;
this.dialog.Start([{text: this.text, align: "center"}]);
}
Stop() {
Playnewton.GPU.HUD.DisableLabel(this.label);
}
Update() {
if(this.label.enabled) {
this.dialog.Update(this.label);
let dx = this.dialog.done ? 4 : 0;
this.backgroundAlpha = Math.max(0, this.backgroundAlpha - dx);
Playnewton.GPU.HUD.SetLabelBackground(this.label, 0, this.label.y - 16, Playnewton.GPU.screenWidth, 24, `#000000${this.backgroundAlpha.toString(16).padStart(2, '0')}`);
Playnewton.GPU.HUD.SetLabelPosition(this.label, this.label.x + dx, this.label.y);
if(this.label.x > Playnewton.GPU.screenWidth) {
Playnewton.GPU.HUD.DisableLabel(this.label);
}
}
}
/**
* @type boolean
*/
get done() {
return !this.label.enabled;
}
}
\ No newline at end of file
import * as Playnewton from "../playnewton.js"
export class DialogLine {
/**
* @type String
*/
text;
/**
* @type string
*/
color;
/**
* Speed in millisecond per chararcter
* @type number
*/
speed;
/**
* Delay before showing next line
* @type number
*/
delay;
/**
* @type CanvasTextAlign
*/
align;
/**
* @type number
*/
x;
/**
* @type number
*/
y;
/**
* @type DOMHighResTimeStamp
*/
startTime;
/**
* @type DOMHighResTimeStamp
*/
endTime;
/**
* @type string
*/
get currentText() {
let text = this.text;
let nbCharacter = (Playnewton.CLOCK.now - this.startTime) / this.speed;
if (nbCharacter <= 0) {
return;
}
if (nbCharacter < text.length) {
text = text.slice(0, nbCharacter);
}
return text;
}
}
export class Dialog {
/**
* @type boolean
*/
skipped ;
/**
* @type boolean
*/
keepLastLine = false;
/**
* @type Array<DialogLine>
*/
lines = [];
/**
* @typedef DialogLineDescription
* @type {object}
* @property {string} text
* @property {string} [color]
* @property {number} [delay]
* @property {number} [speed]
* @property {number} [x]
* @property {number} [y]
* @property {CanvasTextAlign} [align]
*/
/**
* @param {Array<DialogLineDescription>} lines
*/
Start(lines) {
this.skipped = false;
let startTime = Playnewton.CLOCK.now;
this.lines = lines.map(desc => {
let line = new DialogLine();
line.text = desc.text;
line.color = desc.color || "#ffffff";
line.delay = desc.delay || 2000;
line.speed = desc.speed || 50;
line.align = desc.align || "left";
line.x = desc.x;
line.y = desc.y;
line.startTime = startTime;
line.endTime = startTime + line.text.length * line.speed + line.delay;
startTime = line.endTime;
return line;
});
}
Skip() {
this.skipped = true;
}
/**
* @param {Playnewton.GPU_Label} label
*/
Update(label) {
let line = this.currentLine;
if (line) {
Playnewton.GPU.HUD.SetLabelAlign(label, line.align);
Playnewton.GPU.HUD.SetLabelColor(label, line.color);
Playnewton.GPU.HUD.SetLabelPosition(label, Number.isFinite(line.x) ? line.x : label.x, Number.isFinite(line.y) ? line.y : label.y);
Playnewton.GPU.HUD.SetLabelText(label, line.currentText);
} else {
Playnewton.GPU.HUD.SetLabelText(label, "");
}
}
/**
* @type boolean
*/
get done() {
if(this.skipped) {
return true;
}
if (this.lines.length > 0) {
return this.lines[this.lines.length - 1].endTime < Playnewton.CLOCK.now;
} else {
return false;
}
}
get doneOrNotStarted() {
return this.lines.length === 0 || this.done;
}
/**
* @returns DialogLine
*/
get currentLine() {
if (!this.done) {
for (let i = this.lines.length - 1; i >= 0; --i) {
let line = this.lines[i];
if (Playnewton.CLOCK.now >= line.startTime) {
return line;
}
}
}
if(this.keepLastLine && this.lines.length > 0) {
return this.lines[this.lines.length - 1];
} else {
return null;
}
}
}
body {
background-color: black;
}
#game {
position: fixed;
top: 0px;
bottom: 0px;
left: 0px;
right: 0px;
margin: auto;
height: 56.25vw;
width: 100vw;
max-height: 100vh;
max-width: 177.78vh;
image-rendering: pixelated;
}
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>capuchine</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<canvas id="game" width="1024" height="576">
</canvas>
<script src="./capuchine.js" type="module" defer></script>
</body>
</html>
{
"compilerOptions": {
"target": "es2020",
"checkJs": true
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.6.0" orientation="orthogonal" renderorder="right-down" width="32" height="18" tilewidth="32" tileheight="32" infinite="0" nextlayerid="7" nextobjectid="72">
<tileset firstgid="1" source="../icons/icons.tsx"/>
<tileset firstgid="3" source="beach.tsx"/>
<layer id="4" name="bg1" width="32" height="18">
<data encoding="csv">
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
5,10,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
</data>
</layer>
</map>
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.6.0" name="beach" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="49" columns="7">
<image source="beach.png" width="256" height="256"/>
<tile id="2">
<animation>
<frame tileid="1" duration="300"/>
<frame tileid="8" duration="300"/>
<frame tileid="15" duration="300"/>
<frame tileid="8" duration="200"/>
</animation>
</tile>
</tileset>
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.5" tiledversion="1.6.0" name="icons" tilewidth="32" tileheight="32" tilecount="1" columns="0">
<grid orientation="orthogonal" width="1" height="1"/>
<properties>
<property name="doNotLoadBitmap" value="true"/>
</properties>
<tile id="1" type="capuchine">
<image width="32" height="32" source="capuchine-icon.png"/>
</tile>
</tileset>
{
"name": "capuchine",
"version": "1.0.0",
"keywords": ["game"],
"author": "devnewton",
"contributors": [],
"dependencies": {}
}
This diff is collapsed.
import * as Playnewton from "../playnewton.js"
export default class Scene {
/**
* @type Scene
*/
nextScene;
/**
* @type number
*/
progress = -1;
pausable = true;
/**
*
* @returns {boolean}
*/
get started() {
return this.progress >= 0;
}
/**
*
* @returns {boolean}
*/
get ready() {
return this.progress >= 100;
}
constructor() {
this.nextScene = this;
}
async Start() {
Playnewton.APU.Reset();
Playnewton.GPU.Reset();
Playnewton.PPU.Reset();
Playnewton.CTRL.Reset();
this.progress = 0;
}
Stop() {
Playnewton.APU.Reset();
Playnewton.GPU.Reset();
Playnewton.PPU.Reset();
Playnewton.CTRL.Reset();
Playnewton.DRIVE.Reset();
}
/**
*
* @param {number} progress
*/
Progress(progress) {
this.progress = progress;
}
UpdateBodies() {
}
UpdateSprites() {
}
}
\ No newline at end of file
import Scene from "./scene.js"
import * as Playnewton from "../playnewton.js"
import { MenuMapKeyboardEventToPadButton } from "../utils/keyboard_mappings.js";
class Adventure {
/**
* @type string
*/
name;
/**
* @type Playnewton.GPU_Label
*/
label;
constructor(name) {
this.name = name;
this.label = Playnewton.GPU.HUD.CreateLabel();
Playnewton.GPU.HUD.SetLabelPosition(this.label, 512, 288);
Playnewton.GPU.HUD.SetLabelFont(this.label, "bold 24px monospace");
Playnewton.GPU.HUD.SetLabelText(this.label, name);
Playnewton.GPU.HUD.SetLabelAlign(this.label, "right");
Playnewton.GPU.HUD.EnableLabel(this.label);
}
/**
*
* @param {Scene} nextScene
* @returns {Scene}
*/
build(nextScene) {
return nextScene;
}
};
class BeachAdventure extends Adventure {
constructor() {
super("Beach");
Playnewton.GPU.HUD.SetLabelPosition(this.label, 512, 288);
}
/**
*
* @param {Scene} nextScene
* @returns {Scene}
*/
build(nextScene) {
/**
* @type Scene
*/
let scene; //TODO = new BeachScene("maps/beach/beach.tmx", nextScene);
return scene;
}
}
export default class Title extends Scene {
/**
* @type Array<Adventure>
*/
adventures;
/**
* @type number
*/
adventureIndex;
/**
* @type ImageBitmap
*/
titleBitmap;
constructor() {
super();
this.pausable = false;