From bead8e19a0c4b0150fee98c286883e3bbe9ec29f Mon Sep 17 00:00:00 2001 From: felix <60808107+ItsFelix5@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:28:49 +0100 Subject: [PATCH] A frogger-ish game (#2810) * Add files via upload * Add files via upload * Update frog.js --------- Co-authored-by: Mare Cosmin <147330889+Cosmin-Mare@users.noreply.github.com> --- games/frog.js | 193 +++++++++++++++++++++++++++++++++++++++++++++ games/img/frog.png | Bin 0 -> 2911 bytes 2 files changed, 193 insertions(+) create mode 100644 games/frog.js create mode 100644 games/img/frog.png diff --git a/games/frog.js b/games/frog.js new file mode 100644 index 0000000000..dad331dfe7 --- /dev/null +++ b/games/frog.js @@ -0,0 +1,193 @@ +/* +@title: Frog +@author: Felix +@tags: ['endless', 'retro', 'adventure', 'survival'] +@addedOn: 2025-01-22 +*/ + +const frog = "f" +const car = "c" +const road = "r" +const sidewalk = "s" +const house = "h" +setLegend( + [ frog, bitmap` +................ +........DD..DD.. +.......D44DD44D. +......D4404440D. +......D4444DD44D +.....D444444444D +....D444422224D. +...D444422224D.. +..D444422222D... +.D44444222DD.... +.D4D44D42D4D.... +.D44D4D44D44D... +D4444D4444D44D.. +................ +................ +................` ], + [ car, bitmap` +................ +................ +................ +................ +.......33333.... +......3373733... +.....33773773... +....3377737733.. +..3333333333333. +333333333333333. +6330003333300033 +3330103333301033 +...000.....000.. +................ +................ +................` ], + [ road, bitmap` +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +1111111111111111 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +0666006666006660 +0666006666006660 +0000000000000000 +0000000000000000 +0000000000000000 +0000000000000000 +1111111111111111 +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL` ], + [ sidewalk, bitmap` +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL +LLLLLLLLLLLLLLLL` ], + [ house, bitmap` +................ +................ +................ +................ +.....333333..... +....33333333.... +...3333333333... +..333333333333.. +...CCCCCCCCCC... +...CCCCCCCCCC... +...C777CCCCCC... +...C777CCCCCC... +...C777CC000C... +...CCCCCC000C... +...CCCCCC600C... +...CCCCCC000C...` ], +) + +setSolids([frog, house]) +setBackground(sidewalk) + +let dead; +let moved = true +let score = 0 +function spawn() { + dead = false; + clearText() + addText("0", {x:0, color: color`5`}) + setMap(map` +............. +............. +............. +............. +............. +............. +............. +............. +............. +......f......`) + for(let y = 0;y < height() - 1;y++)generateRow(y) + loop() +} +spawn() + +function loop() { + if(dead) return; + moved = false; + getAll(car).forEach(c=>{ + if(c.x == 0) c.remove() + else c.x-- + }) + if(tilesWith(frog, car).length > 0) { + addText("You died!", {color: color`3`}) + dead = true; + moved = true; + } + const newCar = ~~(Math.random() * height()) + const tile = getTile(width()-1, newCar); + if(tile.length == 1 && tile[0].type == road) addSprite(width() - 1, newCar, car) + setTimeout(loop, 250) +} + +function generateRow(y) { + if(Math.random() < 0.5) { + for(let x = 0;x < width();x++) addSprite(x, y, road) + } else if(Math.random() < 0.4) { + for(let x = 0;x < width();x++) { + if(Math.random() < 0.5) addSprite(x, y, house) + } + } +} + +onInput("w", () => { + if(moved) return; + if(--getFirst(frog).y < height() - 2) { + getAll().forEach(s=>{ + if(s.y == height() - 1) s.remove() + else s.y++ + }) + generateRow(0) + score++ + } +}) + +onInput("s", () => { + if(moved) return; + getFirst(frog).y++ + score-- +}) + +onInput("a", () => { + if(moved) return; + getFirst(frog).x-- +}) + +onInput("d", () => { + if(moved) return; + getFirst(frog).x++ +}) + +afterInput(() => { + if(dead == true) spawn() + moved = true; + if(tilesWith(frog, car).length > 0) { + addText("You died!", {color: color`3`}) + dead = true; + } else { + clearText() + addText(""+score, {x:0, color: color`5`}) + } +}) diff --git a/games/img/frog.png b/games/img/frog.png new file mode 100644 index 0000000000000000000000000000000000000000..fe88b13d90c6b8e2619d8430bd6ab0f118c9f63f GIT binary patch literal 2911 zcmeHJdr(tX9=<37OM%#}0~Q|$Tia4V$QX>}6%gc63Dbp^m_Z_7i6lV6ZXf|-z!fK2 zgrz&QJOxcDp#>X67Q(~uC`+9M0+BR=gd{60@+N=@5kh3oO<>yHv9Eu2W@q+~@7{aP zJ?Gqee&6@|e&^%&!-6c$ZOtJFvJ43h2!|je0RYj=1oW(r1bhi@MzrvtQxI?P;4Eku zU-ZNJK~O`%E1R)If-!FU=3Ss#UA6cYZ%GU$vYeQ-84fL@^!G9X#Be9Wua`<*aX^Q0^~nA9p{wJ;E>^Zb!44AQl;d%&&z6 z_MGf6OX~r2E_?T@UrD?n zH(c3a2zeF2Z$aXRIwZI}S?>_|~oLD*SO5N4Pd8mS} zKRnmrIh&mMfN^Y0@>y>O-Te-eyWfK^RM#_$;&KI&n?%R9X{*?xxbsY>MpgMU=U!23 z^x7b)C{FA}E32NVjA9TMB<1GQY#!k_ifWuj9$0T=` zO5{)})#XcJ#6@AX6$VwZSHD#xF z*o7HJ+%!4D270mJ{5bNSsusqDvrvEtCf+M+1J>S^pP6J~=Wk-rj&K52pdb8It||JT zI$6*nxlu|z-{cfy1MeB--9nVH8Oq*%dRnUL>3ZQ5O-InR4L^@T8$xofaCkW~ia?^( zxzrDpcz314YSb%os=ZK-zIX7KL}V>Zhd?O#bx!jH-a^M;s^>a5)h%k7rhnRBCkREJ zL8elQ1t5f@s3E;}A62~G&Zxx$WdS+9q8*D8!XaGROLSao;+IWq$RZhs+W5$U70vL) zTzoEv*1k|7cJAe7JVl*(=*?dm7!^baKL;D{5zgMtN%na!>HPRzt4Ww|kt)ViO*Lm_ z_a7j~M6g7u8V_5$BrX{1KhtgXUXN7u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