penger family

This commit is contained in:
nemo 2024-11-15 12:29:27 +01:00
parent a6a8792905
commit 4e972cac7e
155 changed files with 142 additions and 54 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ app.wat
png2c
penger.c
hand.c
index.html
museum.c
pengers.h

34
app.c
View File

@ -1,4 +1,4 @@
#include "penger.c"
#include "pengers.h"
#include "hand.c"
#define GREEN 0xff00ff00
@ -11,6 +11,7 @@
const unsigned int width = 800;
const unsigned int height = 600;
unsigned int BUFFER[width * height];
int id = 0;
// importer depuis js
int get_scale(void);
@ -97,20 +98,20 @@ int rand(int min, int max)
void rebondi(v2 *pos, int scale)
{
float div = -1.5;
if (pos->x - penger_width*scale/2 < 0) {
pos->x = penger_width*scale/2;
if (pos->x - pengers_width[id]*scale/2 < 0) {
pos->x = pengers_width[id]*scale/2;
velocity.x /= div;
}
if (pos->y - penger_height*scale/2 < 0) {
pos->y = penger_height*scale/2;
if (pos->y - pengers_height[id]*scale/2 < 0) {
pos->y = pengers_height[id]*scale/2;
velocity.y /= div;
}
if (pos->x + penger_width*scale/2 >= width) {
pos->x = width - penger_width*scale/2;
if (pos->x + pengers_width[id]*scale/2 >= width) {
pos->x = width - pengers_width[id]*scale/2;
velocity.x /= div;
}
if (pos->y + penger_height*scale/2 >= height) {
pos->y = height - penger_height*scale/2;
if (pos->y + pengers_height[id]*scale/2 >= height) {
pos->y = height - pengers_height[id]*scale/2;
velocity.y /= div;
}
}
@ -123,6 +124,7 @@ int collision(v2 point, int x, int y, int w, int h)
void init()
{
pengers_init();
}
void draw(float dt)
@ -131,8 +133,8 @@ void draw(float dt)
// position du penger en haut a gauche de l'image
v2 penger_origin = {0};
penger_origin.x = penger_pos.x - penger_width*scale/2;
penger_origin.y = penger_pos.y - penger_height*scale/2;
penger_origin.x = penger_pos.x - pengers_width[id]*scale/2;
penger_origin.y = penger_pos.y - pengers_height[id]*scale/2;
// jump
if (keys[SPACE]) {
@ -141,7 +143,7 @@ void draw(float dt)
}
// mouse push
if (collision(mouse, penger_origin.x, penger_origin.y, penger_width*scale, penger_height*scale)) {
if (collision(mouse, penger_origin.x, penger_origin.y, pengers_width[id]*scale, pengers_height[id]*scale)) {
v2 force = v2_diff(penger_pos, mouse);
force = v2_normalize(force);
force = v2_scale(force, 5);
@ -185,9 +187,9 @@ void draw(float dt)
rebondi(&penger_pos, scale);
// dessine le penger sur le canva
for (int y = 0; y < penger_height; y++) {
for (int i = 0; i < penger_width; i++) {
if (penger_img[y][i] <= 0x00FFFFFF) // pixel transparant
for (int y = 0; y < pengers_height[id]; y++) {
for (int i = 0; i < pengers_width[id]; i++) {
if (pengers_img[id][y*pengers_width[id] + i] <= 0x00FFFFFF) // pixel transparant
continue;
for (int s1 = 0; s1 < scale; s1++) {
for (int s2 = 0; s2 < scale; s2++) {
@ -195,7 +197,7 @@ void draw(float dt)
int idx_y = penger_origin.y + y*scale+s2;
if (idx_x < 0 || idx_x >= width || idx_y < 0 || idx_y >= height)
continue;
BUFFER[idx_y*width + idx_x] = penger_img[y][i];
BUFFER[idx_y*width + idx_x] = pengers_img[id][y*pengers_width[id] + i];
}
}
}

View File

@ -1,6 +1,6 @@
#!/bin/bash
export_sym="init draw key_pressed key_released set_velocity set_mouse BUFFER width height"
export_sym="init draw key_pressed key_released set_velocity set_mouse BUFFER width height id"
export_cmd=""
for e in $export_sym; do
export_cmd="$export_cmd -Wl,--export=$e";
@ -14,10 +14,38 @@ else
a=$1
fi
set -xe
#set -xe
clang png2c.c -o png2c -lm
./png2c "penger.png" > penger.c
mkdir -p museum.c
rm -f museum.c/*
pengers_html=$'\n'
pengers_include=$'\n'
id=0
for p in $(ls museum); do
file=$(echo $p | sed "s/\.png$//g")
./png2c "museum/"$p $id > museum.c/$file.c
pengers_html+=$' <img src="museum/'$p'" class="penger-img" penger-id="'$id'"></img>\n'
pengers_include+='#include "museum.c/'$file$'.c"\n'
((id=id+1))
done
echo "int pengers_height[$id];" > pengers.h
echo "int pengers_width[$id];" >> pengers.h
echo "unsigned int *pengers_img[$id];" >> pengers.h
echo "$pengers_include" >> pengers.h
echo "void pengers_init(void) {" >> pengers.h
((id=id-1))
for i in $(seq 0 $id); do
echo " penger_init_$i();" >> pengers.h;
done
echo "}" >> pengers.h
echo -e "$pengers_html" > pengers_image.html.temp
sed -e '/Choose your penger:/rpengers_image.html.temp' index.html.template > index.html
rm pengers_image.html.temp
./png2c "hand.png" > hand.c
clang -O2 --target=wasm32 -fno-builtin -nostdlib --no-standard-libraries -Wl,--no-entry $export_cmd -Wl,--allow-undefined -o $f.wasm $a

View File

@ -1,23 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<script src="load.js"></script>
<style>
#demo-canvas:hover {
cursor: none
};
</style>
</head>
<body>
<canvas id="demo-canvas"></canvas>
<br>
<p id='scale'></p>
<button id='descaling'>scale - 1</button>
<button id='scaling'>scale + 1</button>
<button id='reset'>reset velocity</button>
<br>
<p>Press arrow key to move</p>
<p>Press space key to jump</p>
<p>Penger is afraid of your stinky hand</p>
</body>
</html>

47
index.html.template Normal file
View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<script src="load.js"></script>
<style>
#demo-canvas:hover {
cursor: none
}
.penger-img {
width: 64px;
image-rendering: pixelated;
}
@media screen and (min-width: 1620px) {
body {
content: "";
display: table;
clear: both;
}
#left {
float: left;
width: 50%;
}
#right {
float: right;
width: 50%;
}
}
</style>
</head>
<body>
<div id="left">
<canvas id="demo-canvas"></canvas>
<br>
<button id='descaling'>scale - 1</button>
<button id='scaling'>scale + 1</button>
<button id='reset'>reset velocity</button>
<br>
<p id='scale'></p>
<p>Press arrow key to move</p>
<p>Press space key to jump</p>
<p>Penger is afraid of your stinky hand</p>
</div>
<div id="right">
<h3>Choose your penger:</h3>
</div>
</body>
</html>

View File

@ -7,6 +7,10 @@ function wasm_variable(name)
{
return global_memory[global_instance.exports[name].value / 4];
}
function wasm_set_variable(name, val)
{
return global_memory[global_instance.exports[name].value / 4] = val;
}
function wasm_function(name)
{
return global_instance.exports[name];
@ -18,6 +22,7 @@ window.onload = () => {
var scale_p = document.getElementById("scale");
var reset_but = document.getElementById("reset");
var canvas = document.getElementById("demo-canvas");
var pengers_img = document.getElementsByClassName('penger-img');
scale_p.innerText = "scale: " + scale;
scale_but.onclick = () => {
scale++;
@ -34,6 +39,9 @@ window.onload = () => {
var r = canvas.getBoundingClientRect();
wasm_function('set_mouse')(e.clientX - r.x, e.clientY - r.y);
}
for (var i = 0; i < pengers_img.length; i++) {
pengers_img[i].onclick = (e) => {wasm_set_variable('id', e.target.getAttribute('penger-id'))}
}
};
(async() => {
@ -90,6 +98,7 @@ wasm_function('init')();
let prev = null;
function first(timestamp) {
wasm_set_variable('id', Math.random() * document.getElementsByClassName('penger-img').length);
prev = timestamp;
wasm_function('draw')(0.16);
window.requestAnimationFrame(loop);

BIN
museum/18Plusger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Adelieger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Baldger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Blenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
museum/BlueWolologer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
museum/Camelger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Camellow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Capger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/CephonPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B

BIN
museum/Clipenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Clownger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Coffeeger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Cookger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
museum/Copeger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
museum/Criminalger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Cryger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/CrygerBlood.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/CrygerChernobyl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Cyberger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/DarthPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Deadger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
museum/Demureger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
museum/Disger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/DoctorPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Doomger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
museum/EvilCyberger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Factoryger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
museum/Fatger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Ferrisger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
museum/Fesh.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Feshger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Frankenpenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/FullCookger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
museum/GNUPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Geniusger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Ghostger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
museum/Ghostyger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Githubger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
museum/Goldger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
museum/Gonger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

BIN
museum/Gopnikger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Grubenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
museum/Gunger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/HDPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
museum/Hackger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
museum/Heisenberger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/HolyCPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 550 B

BIN
museum/Holyger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Hoodger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Howdyger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Ideager.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/JPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 535 B

BIN
museum/Jonkger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Kidger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Knightger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
museum/Laptopger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Luigiger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Macger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Madger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Malger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
museum/Marioger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Michaelger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Millhouseger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Mineger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Momger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/Moustacheger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Nerdger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/NinjaPenger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
museum/Oldger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/P_.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
museum/Paintger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Partyger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/Pe.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
museum/Peng.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
museum/PengKisser.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Pengachu.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/Penganger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
museum/Pengcoder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 500 B

BIN
museum/Penger.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
museum/PengerClose.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

BIN
museum/PengerCoin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 391 B

BIN
museum/PengerFront.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
museum/PengerGiga.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/PengerH.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/PengerHeart.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/PengerNote.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/PengerNumberOne.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/PengerSeller.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

BIN
museum/PengerSilverfoot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
museum/PengerStatue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/PengerStream.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

BIN
museum/PengerTPose.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Some files were not shown because too many files have changed in this diff Show More