From 31d04e8581ba2fa1ab2de54f5c9167ad10faf337 Mon Sep 17 00:00:00 2001 From: Emre Guneyler Date: Wed, 23 Nov 2022 00:19:44 +0300 Subject: [PATCH] animator cards --- _pack.js | 2 +- content/out_0.json | 2 +- content/out_0.png | Bin 169 -> 2275 bytes content/sprites/card_bg.ase | Bin 0 -> 1084 bytes content/sprites/card_underline.ase | Bin 0 -> 763 bytes content/sprites/title_bg.ase | Bin 0 -> 665 bytes screens/palette.ase | Bin 0 -> 482 bytes src/components/animator.ts | 11 ++++- src/components/main_menu.ts | 70 +++++++++++++++++++++++++++++ src/game.ts | 3 ++ src/world.ts | 2 +- 11 files changed, 85 insertions(+), 5 deletions(-) create mode 100755 content/sprites/card_bg.ase create mode 100755 content/sprites/card_underline.ase create mode 100755 content/sprites/title_bg.ase create mode 100755 screens/palette.ase diff --git a/_pack.js b/_pack.js index 05b9f7a..69cf530 100644 --- a/_pack.js +++ b/_pack.js @@ -32,8 +32,8 @@ export default async function pack() { sprites } - fs.writeFileSync('./content/out_0.json', JSON.stringify(res)) fs.writeFileSync('./content/out_0.png', packer.pages[0].png_buffer) + fs.writeFileSync('./content/out_0.json', JSON.stringify(res)) console.log('content written.') diff --git a/content/out_0.json b/content/out_0.json index 1409242..f6aee40 100755 --- a/content/out_0.json +++ b/content/out_0.json @@ -1 +1 @@ -{"sprites":[{"name":"palette","tags":[{"from":0,"to":0,"name":"1"},{"from":1,"to":1,"name":"2"},{"from":2,"to":2,"name":"3"},{"from":3,"to":3,"name":"4"},{"from":4,"to":4,"name":"5"}],"packs":[{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":0,"y":0,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":8,"y":0,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":0,"y":8,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":16,"y":0,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":0,"y":16,"w":8,"h":8}}]}]} \ No newline at end of file +{"sprites":[{"name":"card_bg","tags":[{"from":0,"to":0,"name":"idle"}],"packs":[{"frame":{"x":-2,"y":-22,"w":140,"h":250},"packed":{"x":0,"y":0,"w":136,"h":226}}]},{"name":"card_underline","tags":[{"from":0,"to":0,"name":"idle"},{"from":1,"to":3,"name":"open"}],"packs":[{"frame":{"x":-13,"y":0,"w":20,"h":200},"packed":{"x":392,"y":0,"w":3,"h":80}},{"frame":{"x":-13,"y":0,"w":20,"h":200},"packed":{"x":389,"y":0,"w":3,"h":92}},{"frame":{"x":-11,"y":0,"w":20,"h":200},"packed":{"x":0,"y":226,"w":5,"h":163}},{"frame":{"x":-11,"y":0,"w":20,"h":200},"packed":{"x":384,"y":0,"w":5,"h":183}}]},{"name":"palette","tags":[{"from":0,"to":0,"name":"1"},{"from":1,"to":1,"name":"2"},{"from":2,"to":2,"name":"3"},{"from":3,"to":3,"name":"4"},{"from":4,"to":4,"name":"5"}],"packs":[{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":395,"y":0,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":0,"y":389,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":403,"y":0,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":0,"y":397,"w":8,"h":8}},{"frame":{"x":0,"y":0,"w":8,"h":8},"packed":{"x":411,"y":0,"w":8,"h":8}}]},{"name":"title_bg","tags":[{"from":0,"to":0,"name":"idle"}],"packs":[{"frame":{"x":0,"y":0,"w":248,"h":40},"packed":{"x":136,"y":0,"w":248,"h":40}}]}]} \ No newline at end of file diff --git a/content/out_0.png b/content/out_0.png index 6456990680b06052179bd3d4156a0392418aa88c..f8c9f38afd87cc4eeae2d53b528a70d5521abfed 100755 GIT binary patch literal 2275 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&zE~)R&4YzZe)eR(ZNOhEy=VJ-BgVHajEh zh2MHwE(gsPh;_)`ocLPd>G_1ZE@LIBf|Tux*vxMDwb-0U=6@Xdne&YM_c_H+(zhQt z-}h%%bi?w3-FH9Dx9U@V|MPNtf93i6|9(B+^Lz*Q{?)4-2`VtJm*86CPhbGkyna!}7}v48>9m z34Y8BXDnG6>TXXgulfDa`QGQZ$N3+AzJ!p>WN5JDWiVLI$neaB;lLa=h8ajYDUf_n z>kjg5W%XXRhUXW6_W3pXfB06#TjK|E_xyJvKXTpc%D8LXfQlIH?rMI>>|;3pNG#2i znvNjBZ@~-?9_~1O_^qDJT0|I}(`5Kiu$x;L7?2>QcHiy~TcCl86f|>~82FFJ&H#B5 zs<2@9>BEKM^TL3E4^p?B;Q)}UM%C~o!D|TrfKmgJ!|CB5HCg_|ASzp1%*AlIZ#VVR zEcsz72Tas8|L^iQg0d$tvoch~Ex$82Uhn70?eg|5xnPkz-=ZfE-+q<)aq{O=A%=Ou z#oxbG*@6lL`MrDNm=6?N=av67KOW1_u>2|wvZsB`=MU3&+td_`Gd#!~s7yAXDG^*2 z;!FL&+5igv)LVRl7AR`M2-3ktt_n zfR{6v<#^xc(@&?B@7WvI&%ofn6lWQ~eEbP0l+XkKRiEOE literal 169 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJ0#6smkP6152Nwz+a$sOM_*5c{l*y}+Pw@7%!i*y-YKEPjK1q*v=CKR^ z-p1#r0_F-$o^eEP{`c;gwb7Q7VQN5vP~}3unddujN3_2bG6ves;OXk;vd$@?2>@cb BJU9RV diff --git a/content/sprites/card_bg.ase b/content/sprites/card_bg.ase new file mode 100755 index 0000000000000000000000000000000000000000..9ef54e332b941a94fa4561e06a202bb7350a6a70 GIT binary patch literal 1084 zcmcCvVPJT$l#!u_;TMAf10w?iLkbWhfG7haNRUAQ2x$TKFf%ax`p5>hl?`Zt7!b27 zfUQKbZU&GosUQj!5kZmxGygL%D5w|$$>Q2(Ah~7V79jZ_2!QSua0HTup;LgQ*QT>T zviROTAbAZe+pPkU-D?vCB)?7V29p2J?FEsKt^vtswG2S=-Be8wxhV@se!I2?NdA9! z3rK>1ClIrMLJj0Jpc8=hgDn65A80MmPN0QA+kjR9?EzW>vH@uPqiaBefu;hD1ey2l z7ErG|$RGt^Sik|u26hIY#LCnn1w(ZpM*<^M;A%mR$V|ye&1Yg@U{zpXU;+l?e;^wI zIv5@?RLpsM#gMDnLBJufKWQR&#kMOeiwc~XPANUv&b6;G{7p!3P1&q(k%=45|B1M^ zp8L)bRvufQ$I;4vvJ-FH#^>j)`PaEQ|FP8<$BXQ)@*=eXql{r42$tIn?WfJ({Qgl* iH1~0{W3t~%GZHVcEk0bo@$Ad;LfL3}`MXok6axUbG*?al literal 0 HcmV?d00001 diff --git a/content/sprites/card_underline.ase b/content/sprites/card_underline.ase new file mode 100755 index 0000000000000000000000000000000000000000..c9529a1bdf3ac9abaf9e65e4208e1ba6043fd792 GIT binary patch literal 763 zcmey(#K7=iDGP%L!wCij21W)3h7=%108s`;kRXEq5Yhtl15N++kqvAs8_)tVAZAwp zTZv@d3?N%lK@=(?f+PcG{%2rNP%#9O#kI{qa?8FgK=MBj0NpL%2qXO=p2* z@x6OM@)}sSTLmP$*Cq-`ew*42B>$h=3nCv~1Cq~b8Gz)wshS{iQx=f?c5Mxi{QvG2 zkOTowAZ7uD8pvrtCjjjSS^ob&&|09KKnsDk0j&bs1GEHW1JL+K*MJ5CO$8bWGVk3j zpk8^9K?=-35(Ypvurv51R;Csy7}^0j5(>bm!Ub3uGE;I=85xjG0IFqS$S+9E(+09w z6&M(Jf%Jd4A9;J|F0M6X$mw5VPtUT-IM1GRPyU1BRD!hkzfqO*tEtVv^wM; za8Q!qd8c?xhQa^C52H9VBmAI7a06+C?W_!ofkwQ&pvcF-z;W2&-~X410vslh3#L9d z>(mn$ZA+ABE4_UpQ~%lg%i;I;%`f`3KANe$GL+97&2(!Vrf&zCeqtjh&~#>l|Mk1{ W_BskoG6ZrD^lE!V1`P%U21W)3h7=%108s`;kRXEq5Yhrj0`33xkqvAs8_)tVAZAwp zTZv@d3?N%lK@=(?f+PcG{%2rNP%#9O#kI{qa?8FgK=MBj0NpL%2qXO=p2* z@x6OM@)}sSTLmP$*Cq-`ew*42B>$h=3nCv~1Cq~b8Gz)wshS{iQx=f?c5Mxi{QvG2 zkOTowAZ7uD8pvrtCjjjSS^ob&&|09KKnsDk0j&bs1GEHW1JL+K*MJ5CO$8bWGVk3j zpk8^9K?=-35(Ypvurv51R;Csy7^(v~5*VQZQwpS67&23GQqKTctO^j}|G8w- literal 0 HcmV?d00001 diff --git a/screens/palette.ase b/screens/palette.ase new file mode 100755 index 0000000000000000000000000000000000000000..29d280a27970f7f11da75bc1af9f6f175dc8c00c GIT binary patch literal 482 zcmb`EF-yZx6h?1?LFv*UZN=>&U3BXxIH;TME>2AoD<~*f1eZ>ZT`f4cx;d4u^&jXW zWav<8v~>%(bm;OtH&xmn;Dvkg-n-;Gk0fzKhL4W;;>wD!k%*pGQ5-#F?#~bZaaALI z`t4;_kK7WyY%=A7<(~DrDgK@m7AD!!ikNZ*Hk!Av``m?=;@Xo}XS_USCAp>^(D^T6gx;-{Q*6Ls*S!_24A@ W8h$3@_tD3iUsx>#yCV55dHVssq;?Vj literal 0 HcmV?d00001 diff --git a/src/components/animator.ts b/src/components/animator.ts index 8264f84..5451fdc 100644 --- a/src/components/animator.ts +++ b/src/components/animator.ts @@ -21,6 +21,8 @@ export class Animator extends Component { _frame_index: number _frame_counter: number + _loop: boolean = true + scale = Vec2.one offset = Vec2.zero @@ -38,7 +40,8 @@ export class Animator extends Component { } - play(animation: string, restart: boolean = false) { + play(animation: string, loop: boolean, restart: boolean = false) { + this._loop = loop for (let i = 0; i < this._sprite.animations.length; i++) { if (this._sprite.animations[i].name === animation) { if (this._animation_index !== i || restart) { @@ -65,7 +68,11 @@ export class Animator extends Component { this._frame_index++; if (this._frame_index >= anim.frames.length) { - this._frame_index = 0 + if (this._loop) { + this._frame_index = 0 + } else { + this._frame_index = anim.frames.length - 1 + } } } } diff --git a/src/components/main_menu.ts b/src/components/main_menu.ts index 01c0734..f64e543 100644 --- a/src/components/main_menu.ts +++ b/src/components/main_menu.ts @@ -2,6 +2,71 @@ import { World, Component } from '../world' import { Vec2, Mat3x2 } from 'blah' import { Background } from './background' +import { Animator } from './animator' +import Game from '../game' + +class Title extends Component { + static make = (world: World, position: Vec2) => { + + let offset = Vec2.make(1, 1) + let en = world.add_entity(position.add(offset)) + + let anim = en.add(Animator.make('title_bg')) + anim.play('idle') + + en.add(new Background()) + + return en + + } +} + +class Card extends Component { + + static make = (world: World, position: Vec2) => { + let en = world.add_entity(position) + + let anim = en.add(Animator.make('card_bg')) + anim.play('idle') + + + let underline = world.add_entity(position.add(Vec2.make(0, 40))) + let under_anim = underline.add(Animator.make('card_underline')) + under_anim.play('idle') + + + + return en + } +} + +class Cards extends Component { + static make = (world: World, position: Vec2) => { + let en = world.add_entity(position) + + + let solitaire = Card.make(world, position), + freecell = Card.make(world, position.add(Vec2.make(Game.card_width, 0))), + spider = Card.make(world, position.add(Vec2.make(Game.card_width * 2, 0))) + + + en.add(new Cards()) + + return en + } + +} + +class TextButtons extends Component { + static make = (world: World, position: Vec2) => { + let en = world.add_entity(position) + + en.add(new TextButtons()) + + return en + } + +} export class MainMenu extends Component { @@ -12,6 +77,11 @@ export class MainMenu extends Component { en.add(new MainMenu()) Background.make(world, position) + Title.make(world, position) + + Cards.make(world, position.add(Vec2.make(Game.width * 0.05, Game.height * 0.2))) + TextButtons.make(world, position) + return en diff --git a/src/game.ts b/src/game.ts index 3c0fa21..6baa622 100644 --- a/src/game.ts +++ b/src/game.ts @@ -23,6 +23,9 @@ export default class Game { static width = 640 static height = 360 + + static card_width = 140 + buffer!: Target world!: World diff --git a/src/world.ts b/src/world.ts index 204d700..10d0006 100644 --- a/src/world.ts +++ b/src/world.ts @@ -91,7 +91,7 @@ export class World { for (let components of this.components.values()) { components.forEach(component => { if (component.active && component.entity.active) { - component.update + component.update() } }) }