Browse Source

asdfasdfa

main
fluffy 7 months ago
commit
6c4e7045c4
9 changed files with 639 additions and 0 deletions
  1. +2
    -0
      .gitignore
  2. +21
    -0
      LICENSE
  3. +12
    -0
      Makefile
  4. +98
    -0
      html/Kubasta.css
  5. BIN
      html/Kubasta.ttf
  6. +28
    -0
      html/index.html
  7. +169
    -0
      html/sbh.css
  8. +309
    -0
      html/sbh.js
  9. BIN
      html/veggie-baggle.mp3

+ 2
- 0
.gitignore View File

@@ -0,0 +1,2 @@
build/
.DS_Store

+ 21
- 0
LICENSE View File

@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 fluffy

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.

+ 12
- 0
Makefile View File

@@ -0,0 +1,12 @@
all: upload

clean:
rm -rf build

build/sbh.zip: $(wildcard html/*)
mkdir -p build
cd html && zip -9 ../build/dongs.zip *

.PHONY: upload
upload: build/sbh.zip
butler push build/dongs.zip fluffy/dongs:html

+ 98
- 0
html/Kubasta.css View File

@@ -0,0 +1,98 @@
/*Copyright (c) 2018, Kai Kubasta
(https://fontstruct.com/fontstructors/1554550/kaikubasta)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.*/
@font-face {
font-family: 'Kubasta';
src: url('Kubasta.ttf') format('truetype');
}

BIN
html/Kubasta.ttf View File


+ 28
- 0
html/index.html View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dongs</title>
<link rel="stylesheet" href="sbh.css">
<link rel="me" href="https://beesbuzz.biz/">
<script src="sbh.js"></script>
</head>
<body>
<div id="arena">
<div id="score"></div>
<div id="enemies"></div>
<ul id="bullets"></ul>
</div>

<div id="title">
<div>
<h1>dongs</h1>
<h2>by <a href="https://beesbuzz.biz/">fluffy</a></h2>

<p>Click to play</p>
</div>
</div>

<div id="paused"><h1>Paused</h1></div>
</body>
</html>

+ 169
- 0
html/sbh.css View File

@@ -0,0 +1,169 @@
@import url('Kubasta.css');

html {
margin: 0;
padding: 0;
}

body {
background: black;
color: white;
overflow: hidden;
margin: 0;
padding: 0;
}

* {
cursor: crosshair;
}

#title {
display: block;
position: absolute;
width: 100%;
height: 100%;
}

#title * {
color: white;
text-align: center;
font-family: 'Kubasta', sans-serif;
}

#title div {
position: relative;
top: 50%;
transform: translate(0, -50%);
}

#title h1 {
color: yellow;
text-shadow: rgba(255,255,0,0.5) 0px 0px 5px;
}

#title h2 {
color: cyan;
text-shadow: rgba(0,255,255,0.5) 0px 0px 3px;
}

#title p {
color: magenta;
text-shadow: rgba(255,0,255,0.5) 0px 0px 2px;
}

#paused {
display: none;
position: absolute;
width: 100%;
height: 100%;
z-index: 1000;
}

#paused h1 {
position: relative;
top: 50%;
text-align: center;
transform: translate(0, -50%);
}

.healthBar {
position: absolute;
transition: background-color 1s;
transition: opacity 1s;
}

.healthBar.full {
background-color: #0f0;
}

.healthBar.medium {
background-color: #ff0;
}

.healthBar.low {
background-color: #f00;
}

.healthBar.empty {
background-color: #000;
}

#arena {
position: absolute;
width: 100%;
height: 100%;
z-index: 0;
}

#arena .healthBar {
height: 32px;
bottom: 0;
opacity: 100%;
}

#enemies div {
position: absolute;
z-index: 1;
transition: color 3s, font-size 3s, top 3s, left 3s;
color: white;
transform: translate(-50%, -50%);
}

#enemies .alive {
cursor: progress;
transition: text-shadow 1s;
text-shadow: black 0px 0px 10px;
}

#enemies .alive:hover {
text-shadow: #f00 0px 0px 1px;
}

#enemies .alive .healthBar {
display: block;
top: 0;
height: 10%;
z-index: -10;
transform: translate(0,-100%);

transition: opacity 1s;
opacity: 0;
}

#enemies .alive:hover .healthBar {
opacity: 100%;
}

#enemies .exploding {
color: rgba(0,0,0,0);
font-size: 500%;
z-index: -5;
}

#bullets li {
z-index: 100;
position: absolute;
cursor: zoom-out;
font-size: x-large;
}

#score {
position: absolute;
font-family: 'Kubasta', sans-serif;
top: 1ex;
left: 1ex;
color: yellow;
font-size: small;
text-shadow: yellow 0px 0px 5px;
z-index: -10;
font-size: large;
}

#hp {
position: absolute;
width: 100%;
height: 16px;
background-color: #0f0;
left: 0;
bottom: 0;
}

+ 309
- 0
html/sbh.js View File

@@ -0,0 +1,309 @@
window.addEventListener("load", () => {
"use strict";

var game;
var arena = document.getElementById("arena");
var enemies = document.getElementById("enemies");
var bullets = document.getElementById("bullets");
var score = document.getElementById("score");

var music = [];
var musicIdx = 0;

function flipMusic() {
console.log("Playing music track " + musicIdx);
music[musicIdx].currentTime = 0;
music[musicIdx].play();
musicIdx = 1 - musicIdx;
window.setTimeout(flipMusic, 72000);
}

document.getElementById("title").addEventListener("click", e => {
document.getElementById("title").style.setProperty("display", "none");
for (var i = 0; i < 2; i++) {
music[i] = new Audio("veggie-baggle.mp3");
}
flipMusic();
frame();
});

arena.addEventListener("mousemove", e => {
if (game) {
game.mx = e.clientX;
game.my = e.clientY;
}
});

function onKill() {
game.killed++;
game.spawns.push(new Enemy());
if (game.killed % 5 == 0) {
game.spawns.push(new Enemy());
}
if (game.killed % 9 == 0) {
game.spawns.push(new Bee());
}
}

class Actor {
constructor(element, container) {
this.element = document.createElement(element);
container.appendChild(this.element);
this.x = 0;
this.y = 0;
}

get content() {
return this.element.innerText;
}

set content(text) {
this.element.innerText = text;
}

get width() {
return this.element.clientWidth;
}

get height() {
return this.element.clientHeight;
}

update(dt) {
var style = this.element.style;
style.setProperty('left', Math.floor(this.x) + 'px');
style.setProperty('top', Math.floor(this.y) + 'px');

// despawn enemies as soon as they leave the screen
if (this.x > arena.clientWidth || this.x + this.width < 0 ||
this.y > arena.clientHeight || this.y + this.height < 0) {
this.die();
return false;
}

return true;
}

die() {
if (this.element.parentElement) {
this.element.parentElement.removeChild(this.element);
}
}
}

class HealthBar {
constructor(parent, maxVal) {
this.element = document.createElement("div");
this.element.setAttribute("class", "healthBar");
parent.appendChild(this.element);
this.maxVal = maxVal;
this.value = maxVal;
}

get value() {
return this._value;
}

set value(val) {
this._value = val;

var level = val*100.0/this.maxVal;

this.element.style.setProperty('width', level + '%');
if (level > 50) {
this.element.setAttribute("class", "healthBar full");
} else if (level > 25) {
this.element.setAttribute("class", "healthBar medium");
} else if (level > 0) {
this.element.setAttribute("class", "healthBar low");
} else {
this.element.setAttribute("class", "healthBar empty");
}
}
}

class Bullet extends Actor {
constructor(x, y, dx, dy, adjust) {
super("li", bullets);
this.x = x + dx*adjust;
this.y = y + dy*adjust;
this.dx = dx;
this.dy = dy;

this.element.addEventListener("mouseover", () => game.health.value--);
this.update(0);
}

update(dt) {
this.x += this.dx*dt;
this.y += this.dy*dt;
return super.update(dt);
}
}

class Enemy extends Actor {
constructor() {
super("div", enemies);
this.content = "🍆";
this.element.setAttribute("class", "alive");

this.size = (Math.random()*3 + 1)*100;
this.element.style.setProperty("font-size", this.size + '%')
this.healthBar = new HealthBar(this.element, this.size);

this.x = Math.random()*(arena.clientWidth - this.width) + this.width/2;
this.y = Math.random()*(arena.clientHeight/2 - this.height) + this.height/2;

this.hurting = false;
this.element.addEventListener("mouseover", () => this.hurting = true);
this.element.addEventListener("mouseout", () => this.hurting = false);

this.shootAngle = Math.random()*2*Math.PI;
this.shootAngleInc = Math.random()*2*Math.PI;
this.shootFreq = Math.random()*50 + 20;
this.shootVelocity = Math.random()*0.5 + 0.05;

this.nextShot = Math.random()*1000 + 100;
}

update(dt) {
this.x += (Math.random() - Math.random())*dt*this.size/1000;
this.y += (Math.random() - Math.random())*dt*this.size/1000;

if (this.hurting) {
game.score += Math.floor(dt*this.size);
this.healthBar.value -= dt/10;
if (this.healthBar.value <= 0) {
game.score += Math.floor(this.healthBar.maxVal*10);
this.content = "✨";
this.element.setAttribute("class", "exploding");
this.element.style.setProperty("font-size", (this.size*5) + '%');
this.element.addEventListener("transitionend", () => this.die());
onKill();
return false;
}
} else {
this.nextShot -= dt;
while (this.nextShot <= 0) {

var dx = this.shootVelocity*Math.sin(this.shootAngle);
var dy = this.shootVelocity*Math.cos(this.shootAngle);
game.spawns.push(new Bullet(
this.x,
this.y,
dx,
dy,
this.nextShot));
this.shootAngle += this.shootAngleInc;

this.nextShot += this.shootFreq;
}
}

return super.update(dt);
}
}

class Bee extends Actor {
constructor() {
super("div", enemies);
this.content = "🍑";
this.element.setAttribute("class", "alive");

this.size = (Math.random() + 1)*Math.min(arena.clientWidth/4, arena.clientHeight/8);
this.element.style.setProperty("font-size", this.size + 'px');
this.healthBar = new HealthBar(this.element, this.size*3);

this.x = this.cx = Math.random()*arena.clientWidth/10 + arena.clientWidth/2;
this.y = this.cy = Math.random()*arena.clientHeight/10 + arena.clientHeight/4;

this.hurting = false;
this.element.addEventListener("mouseover", () => this.hurting = true);
this.element.addEventListener("mouseout", () => this.hurting = false);

this.phase = Math.random()*Math.PI*2;
this.freqX = Math.random()*0.001 + 0.001;
this.freqY = Math.random()*0.001 + 0.001;
this.dx = Math.random()*Math.min(this.x, arena.clientWidth - this.cx) - this.size/3;
this.dy = Math.random()*Math.min(this.y, arena.clientHeight - this.cy) - this.size/3;

this.shootFreq = Math.random()*30 + 20;
this.shootVelocity = Math.random()*0.5 + 0.07;
this.nextShot = Math.random()*1000 + 100;
}

update(dt) {
this.phase += dt;
this.x = this.cx + Math.sin(this.phase*this.freqX)*this.dx;
this.y = this.cy + Math.sin(this.phase*this.freqY)*this.dy;

if (this.hurting) {
this.x += (Math.random() - Math.random())*20;
this.y += (Math.random() - Math.random())*20;
game.score += Math.floor(dt*this.size);
this.healthBar.value -= dt/10;
if (this.healthBar.value <= 0) {
game.score += Math.floor(this.healthBar.maxVal*10);
this.content = "✨";
this.element.setAttribute("class", "exploding");
this.element.style.setProperty("font-size", (this.size*5) + '%');
this.element.addEventListener("transitionend", () => this.die());
onKill();
return false;
}
} else {
this.nextShot -= dt;
while (this.nextShot <= 0) {
var ox = game.mx - this.x;
var oy = game.my - this.y;
var len = Math.sqrt(ox*ox + oy*oy);
game.spawns.push(new Bullet(
this.x,
this.y,
ox*this.shootVelocity/len,
oy*this.shootVelocity/len,
this.nextShot));
this.nextShot += this.shootFreq;
}
}

return super.update(dt);
}
}


game = {
score: 0,
health: new HealthBar(arena, 1000),
spawns: [],
actors: [],
killed: 0,
};

function update(dt) {
if (game.health.value <= 0) {
return;
}

game.spawns.forEach(spawn => game.actors.push(spawn));
game.spawns = []

if (game.actors.length < 1) {
game.actors.push(new Enemy());
}

game.actors = game.actors.filter(actor => actor.update(dt));
score.innerText = game.score;
}

var lastTime = new Date();
function frame() {
var now = new Date();
update(now - lastTime);

lastTime = now;
(window.requestAnimationFrame || window.setTimeout)(frame, 1000.0/30);
}

// frame();
});

BIN
html/veggie-baggle.mp3 View File


Loading…
Cancel
Save