From: John Benediktsson Date: Sun, 31 Jul 2022 21:16:08 +0000 (-0700) Subject: Squashed commit of the following: X-Git-Tag: 0.99~1262 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=3c1dfa28b7d4afeba2071183d89aaa20585a021a Squashed commit of the following: commit 1f2c601bf9f3457d7233d077972a101e363f0175 Author: Catherine W Date: Mon Apr 25 23:08:57 2022 -0700 game_lib.ui: use cartesian-product for all-combinations last fixes changed add-to-cell so it's not the same as add-copy-to-cell Update README.txt remove .vs files ui.gadgets.scrollers: restore original code audio.engine.test: restore old test remove key-log.txt commit 17562472d26ca2f52416a0e07a79720499cc4c21 Author: Catherine W Date: Mon Apr 25 22:27:17 2022 -0700 multiple board demo commit 322a5b43faa0ed927574e9ed90fa12b1376760c8 Author: Catherine W Date: Mon Apr 25 22:11:46 2022 -0700 deleted test folder commit afdc2a39a19ddd095b3afd6dd9ac12922f4d899d Author: Loaner Date: Sun Apr 24 10:48:10 2022 -0700 used call( to fix error with running quote in crate-cell call-parent* commit 498aae916b44ecca61ac20b5dd5ae74fee45d3af Author: Loaner Date: Sun Apr 24 10:40:51 2022 -0700 used parent function in call-parent commit c10cf44a627e63d5a0c198d3492a2676cce30c6d Author: Jason Chen Date: Sat Apr 23 13:15:32 2022 -0700 Changed flow-demo speeds to shorten demo video commit 6f34d6a7b0a3711d6cee43b52b55e8b2153cfab0 Author: Jason Chen Date: Sat Apr 23 12:58:39 2022 -0700 Made cell object and flow cell separate files commit 4de6a37e058d72de6ad3f733a938572d22a019f9 Author: Catherine W Date: Fri Apr 22 21:31:19 2022 -0700 added levels to sokoban2 commit 49f6a8a3c5038d316df9a11bc6d187c8e440cedf Author: Loaner Date: Fri Apr 22 16:25:49 2022 -0700 new parent piece demo + call-parent* used commit 70c12a395e296f0985208e4660b7e4b29aa1412f Author: Loaner Date: Thu Apr 21 19:33:12 2022 -0700 removed parent.factor and added its useful stuff to cell.factor commit f09fc5dcd310e0a4ec8db79dbccbb03c3e565b24 Author: Catherine W Date: Thu Apr 21 16:33:11 2022 -0700 finished third game commit 8d69265a05c61cdecd20726d2993e7f014848577 Author: Loaner Date: Thu Apr 21 12:21:07 2022 -0700 parent-demo has parent pieces with several bugs, delete-object is unchanged commit 45fb103ec56028bccad4320d3f385ccb22c6080f Author: Catherine W Date: Wed Apr 20 14:37:46 2022 -0700 removed sokoban from flow demo commit e4a92b19887693d0b4a4f79203a410b48924c442 Author: cherrymar Date: Wed Apr 20 13:59:55 2022 -0700 changed naming for flow-demo file/folder commit e44de9ed4234333f25a7ac362c09da305e855358 Author: cherrymar Date: Wed Apr 20 13:50:03 2022 -0700 remove blue boxxes commit 7e59dd9b00a23db375c89182f3f3113dfe28144b Author: Catherine W Date: Wed Apr 20 13:01:52 2022 -0700 new game commit eb7a5078c335e338525cbd7e328c6bb3cd91a909 Author: Loaner Date: Sun Apr 17 15:30:20 2022 -0700 parent piece move demo no graphics rough draft commit 2763314ed4adcf9894b3ca5927617f4cdff7eb64 Author: cherrymar Date: Sat Apr 16 18:49:15 2022 -0700 cleaned up code for flow commit a38188cb9a2d06f2515d640f4c11be00f9936bb5 Author: cherrymar Date: Sat Apr 16 16:32:40 2022 -0700 flow is moving commit 069c032ca6ae5881cc4adc2064b5e9c993beba43 Author: Catherine W Date: Mon Apr 11 22:06:10 2022 -0700 changed board into a gadget commit b5c91f2c25905b78eb2281e72ef30490fd2cc009 Author: cherrymar Date: Sat Apr 9 23:20:49 2022 -0700 flow logic implemented but working through bugs commit 133f303eab312a91a76bac118ac346f8ca78b102 Author: Catherine W Date: Thu Apr 7 20:51:14 2022 -0700 make board gadget commit 00ed028c5ec784f2ff3ce1a202d60f5b53c37306 Author: Catherine W Date: Wed Apr 6 19:31:23 2022 -0700 added bounds checking commit 409080214855c1dc7806fae6f4cf26bbb43c0fd9 Author: Catherine W Date: Tue Apr 5 23:57:25 2022 -0700 fixed tic-tac-toe commit 95690e189cd8982dfe6f650683959eeaa23223dd Author: Catherine W Date: Tue Apr 5 23:37:32 2022 -0700 forgot a space commit 45032a96b75cd2200879fb8d4320d8ae7bebb8b8 Author: cherrymar Date: Tue Apr 5 23:31:42 2022 -0700 fixed bug with gravity in board commit 502d760329ecda90eefc24ba763e4904a0b2c29a Author: Catherine W Date: Tue Apr 5 23:30:42 2022 -0700 added game loop to sokoban2 commit a23d47c64e8f9990c8077ab36349b3ce0c94b3a3 Author: cherrymar Date: Tue Apr 5 22:36:07 2022 -0700 added gravity to board, add gravity to game logic commit 022bffd84b8e953566d5ac2c22bdd12b2d99c469 Author: Catherine W Date: Tue Apr 5 19:41:18 2022 -0700 trying win con commit df70937d72d0aebd83b5f1d8594cfffae3f7ce67 Author: cherrymar Date: Tue Apr 5 15:32:34 2022 -0700 added gravity to board, add gravity to game logic commit 04ae83a8bae2bfe7f12eb301ec728fe5a0f94531 Author: cherrymar Date: Sat Apr 2 00:48:20 2022 -0700 notes on gravity commit 71e23e938f5f4094ee85cceae92cc6d8653e5886 Author: cherrymar Date: Sat Apr 2 00:47:30 2022 -0700 undo accidental push commit 814163721b2d00f9c12f5b6848388aef9ce696db Author: cherrymar Date: Sat Apr 2 00:44:50 2022 -0700 brainstorm notes commit 1702be19578cbf528ebfc8375dbd27e30611dd9f Author: cherrymar Date: Fri Apr 1 23:46:28 2022 -0700 Finished board and fixed remaining bugs commit e86414d4123d40552200bd2e35898ddb6534698f Author: Catherine W Date: Wed Mar 30 22:58:08 2022 -0700 fixed libraries commit e4fe09ca38c73a88de7c979cf5aa8f304cafa0a0 Author: Samuel Freisem-Kirov Date: Wed Mar 30 21:14:35 2022 -0700 fixes some rebase issues commit ee0e71406a91c08902233540c4277ab992566967 Author: Catherine W Date: Tue Mar 29 22:20:51 2022 -0700 merged board implementations for supporting multiple objects in a cell commit 3848ef87c77430b335c596ee1db0d1d795fc2298 Author: Catherine W Date: Tue Mar 29 11:52:12 2022 -0700 fixed tic tac toe commit 5e0ac3c3306c62f41e1c9bcb17f1a627ff601318 Author: Catherine W Date: Fri Mar 25 20:04:40 2022 -0700 added stackable boards commit b43f02ee64d6ba083cded3661e60896af70dcb69 Author: Catherine W Date: Tue Mar 29 11:48:19 2022 -0700 updated libraries commit 2ab65a82d4c8752afa1a63a90ba065f6bd9d46e5 Author: Catherine W Date: Wed Mar 23 21:20:38 2022 -0700 allows for user defined draw methods commit c79a1617d62098ba3bf4c504bc514d94efdfc3dd Author: Catherine W Date: Tue Mar 29 19:24:59 2022 -0700 fixed tic-tac-toe commit d29a4f2af04fb5da80cfc0798506c22588e1d2fe Author: Catherine W Date: Tue Mar 29 16:41:21 2022 -0700 cleaned up code commit 33c844a5ef8bc070f98d858949d09c12e94dd090 Author: Catherine W Date: Tue Mar 29 15:18:06 2022 -0700 fixed sokoban2 commit 33cb107bf5d291e15abe5d40d98a0fdb67319b1c Author: cherrymar Date: Sun Mar 27 00:24:30 2022 -0700 Change sokoban2 to compile and display properly with new board commit 5da9fe91fc9820642b233d857160d8d60e5bdbc6 Author: cherrymar Date: Sun Mar 27 00:24:05 2022 -0700 Fix label-cell and find-all cells to have the coordinates in order commit 809383fb48c38ac67b071f6892434101cf5464ec Author: Samuel Freisem-Kirov Date: Wed Mar 23 21:43:55 2022 -0700 starts changing sokoban2 to use the new board changes. TODO: make sure that the rest of sokoban2 and tic-tac-toe work with the new changes. commit 9e27f410c7546952d996e78346ce7adb66464d9e Author: cherrymar Date: Wed Mar 23 00:13:33 2022 -0700 changed default cell to empty sequence, added corresponding added corresponding functionality commit 3e0c6eb77a039fc15f8cf45badf07a6369423089 Author: cherrymar Date: Tue Mar 22 22:18:37 2022 -0700 made loop library for game loop stuffs commit 54e02e94972ec04d4954065c49d5611bd2abe6eb Author: Catherine W Date: Sun Mar 20 11:57:15 2022 -0700 added some ideas in comments commit 6f196b71a3b808329810858c05a6b03ed360b1ee Author: Catherine W Date: Sat Mar 19 17:33:55 2022 -0700 comments commit 2c9360db86241bb67b95f4d209720b0e891ba888 Author: Catherine W Date: Sat Mar 19 17:22:51 2022 -0700 updated gestures and added some logic to sokoban2 commit 27646aade7d111b89cafe8048222eb69c64cc72d Author: Loaner Date: Thu Mar 10 11:51:37 2022 -0800 Collision detection added to tic tac toe commit a143d4f797dd2afc2f0f9cd9fe5aa1c321b27c2c Author: Catherine W Date: Thu Mar 10 10:46:26 2022 -0800 minor updates commit cc3602bd5a89275855c68672f7507b9002b86c83 Author: Catherine W Date: Wed Mar 9 18:41:20 2022 -0800 added game over text to tic tac toe commit e05e7b861c48a54635f433d748c73750ea14a520 Author: cherrymar Date: Tue Mar 8 23:20:09 2022 -0800 added game-loops to tic-tac-toe commit be1cec642b79c2ff33472d73824d7b99c8a3c025 Author: Catherine W Date: Wed Mar 9 18:17:05 2022 -0800 added more drawing functionality commit 7d021d649ee95088e051b7961c4bb8c172580851 Author: Catherine W Date: Tue Mar 8 22:53:21 2022 -0800 fixed drawing order commit dfbb101cfa513786fbcb8564951feaa3b334d166 Author: Catherine W Date: Mon Mar 7 16:47:00 2022 -0800 minor updates commit 36de99b84c4cdd79f7767fb3ddf758469f4ad61d Author: cherrymar Date: Fri Feb 25 20:51:51 2022 -0800 added code to draw color rectangle sprites commit 97f0a9856a6e9f0087810d31ddbb8fd0cd2bc073 Author: Catherine W Date: Fri Feb 25 01:31:53 2022 -0800 comments commit e2fd16279284aab54e35634887b6914bd546031f Author: Catherine W Date: Fri Feb 25 01:25:51 2022 -0800 added second board to sokoban2 commit 26f96d27bf38dceb89a300434d1d62e30c2267f1 Author: Catherine W Date: Thu Feb 24 23:44:52 2022 -0800 fixed win condition commit 8b567699d120390212ee29ec6d3c654fcd76a956 Author: Catherine W Date: Wed Feb 23 22:57:31 2022 -0800 win condition progress commit 4122d73b03ea4e644efe1b5f5e9ff8c5c2b6ef43 Author: Catherine W Date: Wed Feb 23 19:46:08 2022 -0800 added some functions to board library commit 8d7444ef0472e6bd8d0ff82f219e3f955524338c Author: Catherine W Date: Wed Feb 23 16:15:57 2022 -0800 added sokoban2 and renamed game_lib files commit 2ebc7c14e57eef1a3bea2c88b90e764252372e2d Author: Sfreisem-Kirov Date: Thu Feb 17 06:05:32 2022 -0800 adds a game rule to switch between x and o on-click commit 75f83c33d7e9de6f7f81bca5ed3e7285ad67e4ce Author: Catherine W Date: Sun Feb 20 17:16:57 2022 -0800 minor changes commit 8754ab70b1958ecae2c1d2a4719eb4d7575dc43c Author: Catherine W Date: Wed Feb 16 23:43:02 2022 -0800 tried to handle collisions commit a1c0f37bb8c5f8df991c5a5cf394c1f856ef6c43 Author: Catherine W Date: Wed Feb 16 14:27:43 2022 -0800 small generalizations on gestures commit 7cd5c4d93c672b6c4008e12e48589cb8659527a2 Author: Sfreisem-Kirov Date: Mon Feb 14 21:07:16 2022 -0800 adds interactivity with board. TODO abstract this to the user... had dificulty doing so commit 421928e84184a78e0260eefce9ea26dd1461a4b5 Author: Catherine W Date: Wed Feb 9 21:45:08 2022 -0800 cleaned up board display functions commit 944c877370a1a110ebe1096e04fdff060475c082 Author: Catherine W Date: Tue Feb 8 12:20:59 2022 -0800 draw things by storing a sequence of quotes commit 31afba2374b8604c229775c154f8269bdf976084 Author: Catherine W Date: Mon Feb 7 21:37:19 2022 -0800 Displays the board commit 14423d3b9a85ec4f04aeba1c0a1becc38e3308ec Author: cherrymar Date: Sun Feb 6 21:59:47 2022 -0800 fixed syntax so that code compiles and runs as expected for demo ui commit 079a4190aabdaf4cac8561ad70f3c38252c5b82b Author: Sfreisem-Kirov Date: Sat Feb 5 22:45:42 2022 -0800 mesh grid function for generating initial locations of cells commit 2eef5c892afafa7248c2c010eb8d0b72b25e38e7 Author: Catherine W Date: Mon Jan 31 13:25:23 2022 -0800 rearranged some functions commit 0d7ddf082e95231087a43530d173f8310ccc600f Author: Catherine W Date: Mon Jan 31 13:16:12 2022 -0800 added sprite drawing functionality commit ba97424700e1ee99159270ae87f5240063e07cf7 Author: Catherine W Date: Mon Jan 31 00:39:16 2022 -0800 added rectangle drawing capabilites commit f0a2cf1c44d3124a070ae97e99eec26c4527393b Author: Catherine W Date: Sun Jan 30 19:55:54 2022 -0800 preliminary window library commit bdbc07ca392b4b8dd3bf1fa9ff24f75acac99c29 Author: cherrymar Date: Mon Dec 6 16:57:25 2021 -0800 added 'find-all-cells' which finds all cells on the board that satisfy the given condition commit e51842a6415421af3fa72328e2015ef368909041 Author: Jason Chen Date: Mon Nov 29 16:38:07 2021 -0800 Add comments commit e5d5c548c73ea6be1e9d28315cf1d450bce26c4e Author: Jason Chen Date: Mon Nov 29 16:34:22 2021 -0800 Add find-cell commit 0a17df7fa9f21479b4b37831e0e667e6ca6de86e Author: Jason Chen Date: Mon Nov 29 16:34:05 2021 -0800 Add find-cell commit 42635901334a7415c9a693e4d63ea47e7b37e730 Author: Jason Chen Date: Mon Nov 29 16:00:29 2021 -0800 Add reset-board and find-row, and reorder some arguments commit d55d68d7ef3f4b7e608849d22c477413ff208070 Author: Jason Chen Date: Sun Nov 21 15:58:40 2021 -0800 Add change-cell commit e9406a69040a00d985fbdcfb68a2df0a9f8f0f84 Author: Jason Chen Date: Fri Nov 19 00:19:55 2021 -0800 Fix get-cell to multi-bind location to x and y commit 918f7d8022099907c63f61b5170338111419c2fe Author: Jason Chen Date: Fri Nov 19 00:08:56 2021 -0800 Add move-cell commit 6c4fa81eb0ab9239c0b104cb70dad3fadccfa5b0 Author: Jason Chen Date: Wed Nov 17 17:15:09 2021 -0800 Add is-empty?, swap order of inputs on words commit 37c365ec5e1be484383d365373b3906a9a90fa11 Author: cherrymar Date: Wed Nov 17 16:24:47 2021 -0800 add swap-cells word and refactor make-board commit 62c82fa707e360cd689528cb02e3e7fab4dcb1f2 Author: Jason Chen Date: Wed Nov 17 16:16:28 2021 -0800 Add delete-cell, duplicate-cell, make words leave a board on the stack commit b8b37df13bd85a2ebc12ac51362a6d86fbd614d2 Author: Jason Chen Date: Wed Nov 10 16:55:38 2021 -0800 Delete modify-cell commit 60598655564af8551ca81c305fa8baba3ace987a Author: Sfreisem-Kirov Date: Fri Dec 3 20:38:09 2021 -0800 fixes sound bugs and optimizes run time calls commit b7237367f65779fcac42d920b1b532081231a897 Author: Catherine W Date: Fri Dec 3 19:43:45 2021 -0800 sound stops when window is closed commit b760c30dc58577d6c03c4a8180dca5d39879f714 Author: Catherine W Date: Thu Dec 2 13:59:04 2021 -0800 allow for beep and background music to play at the same time commit d4e1e499d242f84f23d2bb361eb6e5a046c755b4 Author: Sfreisem-Kirov Date: Tue Nov 30 21:09:12 2021 -0800 adds tetris music as background to demonstrate background loop capabilities commit 458f1ce3b217878a4421c515a7bbdb84a08c8ec6 Author: Sfreisem-Kirov Date: Tue Nov 30 20:38:21 2021 -0800 adds a beep for when boxes are placed on a goal. commit c48eaf36855692cfb05eb931184a58793a89c42b Author: Catherine W Date: Thu Nov 18 00:53:27 2021 -0800 boxes change sprites when moved onto a goal point. Still uses color representations, need to get rid of those commit e240361a9a74b938d252744d4bd3db4bd32d9316 Author: Sfreisem-Kirov Date: Wed Nov 17 21:08:00 2021 -0800 adds texture functionality, needs to be able to specify which sprite for which object commit 054d7cf25924705aebdcb5c9264a0b4531d2c387 Author: Sfreisem-Kirov Date: Mon Nov 15 17:20:16 2021 -0800 fixes goal bug on non-first levels commit 328cacad8dee8f8d6a953d620dd17ee303d6d743 Author: Sfreisem-Kirov Date: Mon Nov 15 16:46:38 2021 -0800 changes the window dimentions based on the level dimentions commit b58e5e7d7d1a64ba51ac18570650451f70578dd7 Author: Sfreisem-Kirov Date: Fri Nov 12 11:51:08 2021 -0800 fixes new level to adjust goals as well commit d84e684a09336e1bcc61943f07d92e48618e93f9 Author: Jason Chen Date: Wed Nov 10 16:36:39 2021 -0800 Reorder word inputs in gamedev, add set-cell and change-cell commit a37511e95a9941551d2f1b9abafec8617f795034 Author: Catherine W Date: Sat Nov 6 15:30:46 2021 -0700 deleted even more unused functions commit d95143b95f055adf24ddd6ee03b848193060f8e0 Author: Catherine W Date: Sat Nov 6 15:21:56 2021 -0700 deleted and revised functions to clean up code further commit d32a9da513dc8a65d8ccfbc22dbacfd7fbcaa5e5 Author: Catherine W Date: Sat Nov 6 13:35:37 2021 -0700 cleaned up code commit 8f1e89f8f27c1958b5556ff0b6f683c035630538 Author: Catherine W Date: Sat Nov 6 12:25:22 2021 -0700 board is now mutable commit 013858b3b8acee7d330bb3b0ff0a34125f014729 Author: Jason Chen Date: Wed Nov 10 16:14:34 2021 -0800 Create gamedev folder with board and gl files commit 31055a98f70fe80e6d420b0e24dd0579cf89e1ff Author: Jason Chen Date: Sat Nov 6 14:19:30 2021 -0700 Remove unnecessary input to set-player-location commit 631a7f67801add63eb20f457030d64f6b9fc47ff Author: Sfreisem-Kirov Date: Fri Nov 5 20:22:50 2021 -0700 fixes level update, now working. TODO: dynamic width and height. commit 74084c3f164d19a59650dd9b7f680a1758c62d2c Author: Catherine W Date: Fri Nov 5 09:49:16 2021 -0700 trying to fix levels commit b90c06df11647a3aa4a36fd0a3cb5ca6a36de6aa Author: Jason Chen Date: Wed Nov 3 18:46:28 2021 -0700 Update next level with new board size, still needs bugfixes commit 35d8a24381ebfb731aec69ffde434f6c00a97b97 Author: Jason Chen Date: Mon Nov 1 23:38:54 2021 -0700 Draw boxes on top of goals, add second implementation of get-adj-box commit cbf134bded9ca71be139ff492b2839da5c70ece3 Author: Catherine W Date: Tue Nov 2 20:37:28 2021 -0700 added level updater commit b689a4711b22660ed7cf1033108d4328753473e1 Author: Jason Chen Date: Fri Oct 29 10:40:38 2021 -0700 Center the goal points commit 320fa923b44edd45bb390f4a9f92f9d3c99b25ae Author: Catherine W Date: Thu Oct 28 23:32:18 2021 -0700 boxes turn blue for multiple goal points commit 1481884662c917ba726f79eeb2530f70e7009798 Author: Sfreisem-Kirov Date: Thu Oct 28 19:54:56 2021 -0700 changes in progress commit bc80ff0a007e5c7d985f1d1bcc481e0e5e64ee6c Author: Sfreisem-Kirov Date: Thu Oct 28 17:42:34 2021 -0700 added box collision logic with other boxes commit dc55cdcf21d5708a4ac846240e19dbfa078d2458 Author: Sfreisem-Kirov Date: Thu Oct 28 17:09:07 2021 -0700 fixes movement bug commit db3aaa65bb11d40912991b333414679805689994 Author: cherrymar Date: Thu Oct 28 12:02:16 2021 -0700 Reshaped second level commit 3c6463cbc47d85bef612bc19b28a2988625297ff Author: cherrymar Date: Thu Oct 28 11:59:07 2021 -0700 Made it so that all boxes can be moved, still needs box-box collision commit df594485702b4c56b9724dfcb5ed8df50cc4de33 Author: cherrymar Date: Thu Oct 28 00:04:06 2021 -0700 Change name of moved_box to box2move commit d7accc3a51ff77220213e85cd7bb195fd8c97245 Author: cherrymar Date: Thu Oct 28 00:01:30 2021 -0700 Fix comment wording commit 7a60eabd1f51c372f20733fd57bdc6c8cb39e190 Author: cherrymar Date: Wed Oct 27 23:17:08 2021 -0700 Add specific box checking commit e2b1a4bd1d47015c6eee78bebb397a7ec4957388 Author: cherrymar Date: Wed Oct 27 21:56:57 2021 -0700 Change all instances of "rotation" to "level_num" commit 44fdf0520810ac3bf57474aae50ca31879e5f570 Author: cherrymar Date: Wed Oct 27 21:56:13 2021 -0700 Change first level to match Sokoban's first level commit 2032ad6da1a7114c6caf21dcd5159d8c57c748c1 Author: Sfreisem-Kirov Date: Wed Oct 27 05:03:36 2021 -0700 places boxes on first level commit 1ef9501cc91854449489b2869f15b26401950176 Author: Sfreisem-Kirov Date: Wed Oct 27 04:55:59 2021 -0700 fixes reset errors, starting locations no longer necessary commit a7c2f5cac4abcb6656d88b4ff4ef41d68d2c9e91 Author: Sfreisem-Kirov Date: Wed Oct 27 04:10:08 2021 -0700 adds functionality to create and draw multiple boxes. TODO: fix starting location for boxes, change is-box? to handle multiple boxes commit becc34fdd9d7b8303b71073128a95516d7267ff1 Author: Jason Chen Date: Mon Oct 25 19:10:39 2021 -0700 Move is-goal? to sokoban.piece, fix problems with start goal check commit bebf9cbca5de4bdbc122f0e278e11bb149c1e0f7 Author: Jason Chen Date: Mon Oct 25 16:56:48 2021 -0700 Check if box starts on goal, change is-goal? input commit 68a57b7b18d050955ba1ff79ea7a2b1baa8e998e Author: Jason Chen Date: Mon Oct 25 15:43:06 2021 -0700 Changed "colour" to "color" commit f7a4a22112521640c23b580f5988700409bbc2d5 Author: Catherine W Date: Thu Oct 21 20:39:04 2021 -0700 Used startinglocs symbol to reset the box position, reset box color commit 4889d356f5541cb9017d5f882fb437e3097ab7f7 Author: Sfreisem-Kirov Date: Thu Oct 14 17:49:21 2021 -0700 fixes box location to not use starting-locs commit 9affb5f8587bcfa0f1d03188dbf5e3c1960fd379 Author: Sfreisem-Kirov Date: Thu Oct 14 13:33:15 2021 -0700 in progress commit 4cbb5cdad1e072e3658d0f1790b62c6742926f0c Author: Jason Chen Date: Thu Oct 21 11:45:15 2021 -0700 Changed all instances of "colour" to "color" commit c816c816ec6833b916733a75121860da42234bd9 Author: Jason Chen Date: Wed Oct 20 22:09:32 2021 -0700 Added color change functionality to goal points commit a99d839446d8c10b968b6137febdd57b47e01811 Author: Catherine W Date: Wed Oct 13 19:22:24 2021 -0700 added one goal point; box changes color when pushed onto goal point commit 69758603493148aea57e4de30274148b3e4f9c37 Author: Jason Chen Date: Wed Oct 20 21:35:58 2021 -0700 Refactored sokoban-move to be intuitive/efficient commit 5e6385b48722565412481dcae6b885d26715a664 Author: Jason Chen Date: Wed Oct 13 17:57:57 2021 -0700 Fixed coordinate system mismatch (hardcoded levelnum) commit ea203eb08db8d56114574273626d99761d2ed485 Author: Catherine W Date: Tue Oct 12 23:45:50 2021 -0700 added collision between walls and boxes commit 5efd52fc4df15c1ea8f8092c21d219b191fac4c4 Author: Sfreisem-Kirov Date: Fri Oct 8 18:10:32 2021 -0700 Revert "adds the box to the board, makes the box pushable, moves the boxes into their own category of item" This reverts commit ea0ef4840dd10b1e9b79c0851558d33064d840db. commit e9ddd943258c0fdeb3d50d19785ed8a9c4464a15 Author: Sfreisem-Kirov Date: Fri Oct 8 05:32:17 2021 -0700 adds the box to the board, makes the box pushable, moves the boxes into their own category of item commit e28ec22dbe21ef1a0da45f58c8b70a7e20dc32bf Author: Catherine W Date: Mon Oct 11 17:08:37 2021 -0700 added box logic, not accounting for box collision with walls. coordinates need to be fixed. commit 2f2a90728250d5a0e78a550918c9f1a7219a0b57 Author: Catherine W Date: Fri Oct 8 18:50:03 2021 -0700 Player can successfully push boxes upon contact, although the coordinate system is not correct and needs to be fixed. In addition, collision between box and wall has not been implemented. commit 8f0b444d9b27d15cfe41dab09952a5f840f08f39 Author: Catherine W Date: Wed Oct 6 21:22:31 2021 -0700 made it so that there is a level property in sokoban which sets the correct wall layout commit 5d39e8e79aaa3ca601b6516cd4fdfce35214d80c Author: Jason Chen Date: Wed Oct 6 19:46:42 2021 -0700 Moved walls, player, and boxes into one symbol commit 4e27fe8cc1197bdc086fb0705cb2cefae8320bd8 Author: Santiago Date: Wed Oct 6 16:52:04 2021 -0700 Added box visually on the game. Need collision logic still commit 948112d19374197e3e4af5d443a65551716bac5c Author: Catherine W Date: Tue Oct 5 23:42:23 2021 -0700 created box object but need to load it in correctly. The code is incomplete and does not run yet. commit c77ae119cbe77fb3e7f2c8893926dce43dcd2489 Author: Sfreisem-Kirov Date: Fri Oct 1 04:38:15 2021 -0700 creates first sokoban level and generates walls on load in commit de6fa19b18e413ad9bc9c1efaadb564245c66648 Author: Sfreisem-Kirov Date: Fri Oct 1 04:04:42 2021 -0700 add walls with space key. TODO: add walls at the beginning commit 0de39741edc59d97c757f61659798d62d18c1176 Author: Catherine W Date: Thu Sep 30 18:24:17 2021 -0700 Sokoban game using tetris as a template commit a59bfd93a13495fed7d5adb8eff8a54e4579f1dd Author: Catherine W Date: Tue Mar 29 22:20:51 2022 -0700 merged board implementations for supporting multiple objects in a cell commit 36cdbfed35ae0cf6fca3a27989acec4d9aa6e37d Author: Catherine W Date: Tue Mar 29 19:24:59 2022 -0700 fixed tic-tac-toe commit 2c81db3d3d884ae57edad8d30394303db2576618 Author: Catherine W Date: Tue Mar 29 16:41:21 2022 -0700 cleaned up code commit dd9c385f4a3b4728f089b77e453a8261293adec4 Author: Catherine W Date: Tue Mar 29 15:18:06 2022 -0700 fixed sokoban2 commit 6d93f1fbbc0452f61760133daa59b0b18dbb95ed Author: Catherine W Date: Tue Mar 29 11:52:12 2022 -0700 fixed tic tac toe commit 8b81d3cd3557b28a75c82a444bbad886a7793cdd Author: Catherine W Date: Tue Mar 29 11:48:19 2022 -0700 updated libraries --- diff --git a/extra/gamelib/board/board.factor b/extra/gamelib/board/board.factor new file mode 100644 index 0000000000..03f2521bd3 --- /dev/null +++ b/extra/gamelib/board/board.factor @@ -0,0 +1,260 @@ +USING: assocs classes sequences sequences.generalizations math +timers sets kernel accessors sequences.extras ranges +math.vectors generalizations strings prettyprint gamelib.loop +ui.gadgets ; + +IN: gamelib.board + +TUPLE: board width height cells ; + + +CONSTANT: UP { 0 -1 } +CONSTANT: DOWN { 0 1 } +CONSTANT: RIGHT { 1 0 } +CONSTANT: LEFT { -1 0 } + +! Make cells, with an empty sequence as the default cell +:: make-cells ( width height -- cells ) + height [ width [ { } clone ] replicate ] replicate ; + +:: make-board ( width height -- board ) + width height make-cells :> cells + width height cells board boa ; + +! Sets all cells to an empty sequence +:: reset-board ( board -- board ) + board width>> board height>> make-board ; + +:: get-cell ( board location -- cell ) + location first2 :> ( x y ) + board cells>> :> cells + x y cells nth nth ; + +! Gets all cells in locations array and return as a sequence +:: get-cells ( board locations -- seq ) + locations [ board swap get-cell ] map ; + +:: get-instance-from-cell ( cell class -- object ) + cell [ class instance? ] find swap drop ; + +! returns all elements of a specified row as a seq +:: get-row ( board index -- seq ) + index board cells>> nth ; + +! returns all elements of a specified column as a seq +:: get-col ( board index -- seq ) + board + board height>> [ index ] replicate + board height>> [0..b) zip + get-cells ; + +! For a board, set the cell at the given location to new-cell (should be a sequence) +:: set-cell ( board location new-cell -- board ) + location first2 :> ( x y ) + board cells>> :> cells + new-cell sequence? new-cell string? not and + [ + new-cell x y cells nth set-nth + ] + [ "New cell is not a sequence! No changes made." . ] if + board ; + +! For a board, set all the given locations to a new cell (should be a sequence) +:: set-cells ( board locations new-cell -- board ) + locations [ board swap new-cell set-cell drop ] each + board ; + +! Applies a quotation to a specific cell +:: change-cell ( board location quot -- board ) + location first2 :> ( x y ) + board cells>> :> cells + x y cells nth quot change-nth + board ; inline + +! Adds an object to the cell at the specified location in a board +:: add-to-cell ( board location obj -- board ) + board cells>> :> cells + board location get-cell :> old-cell + old-cell { obj } append :> new-cell + board location new-cell set-cell ; + +! Adds an object to all the given locations to new-cell +:: add-to-cells ( board locations obj -- board ) + locations [ board swap obj add-to-cell drop ] each + board ; + +! Adds a copy of an object to all the given locations to new-cell +:: add-copy-to-cells ( board locations obj -- board ) + locations [ board swap obj clone add-to-cell drop ] each + board ; + +! Sets a cell back to the default cell +:: delete-cell ( board location -- board ) + board location { } set-cell ; + +! Delete the first instance of obj in the cell at the specified location in the board (if found) +:: delete-from-cell ( board location obj -- board ) + board location get-cell :> cell + cell [ obj = ] find drop :> obj-index + obj-index + [ + obj-index cell remove-nth :> new-cell + board location new-cell set-cell + ] [ + board + ] if ; + +! Delete the first instance of obj from all cells at the specified locations in the board (if found) +:: delete-from-cells ( board locations obj -- board ) + locations [ board swap obj delete-from-cell drop ] each + board ; + +! Like delete-from-cell, but delete all instances of obj (if found) +:: delete-all-from-cell ( board location obj -- board ) + board location [ obj swap remove ] change-cell ; + +! Like delete-all-from-cell, but deletes from all specified locations in the board (if found) +:: delete-all-from-cells ( board locations obj -- board ) + locations [ board swap obj delete-all-from-cell drop ] each + board ; + +! Helper word that creates a sequence of n k's +:: make-n-k ( n k -- seq ) + n [ k ] replicate ; + +! Helper word that creates a list of all cell locations in the board +:: location-matrix ( board -- loclist ) + board width>> :> w + board height>> :> h + w [0..b) :> single-row + h [0..b) :> single-col + h [ single-row ] replicate concat :> x-vals + h [ w ] replicate :> w-list + w-list single-col [ make-n-k ] 2map concat :> y-vals + x-vals y-vals zip ; + +! Sets all cells to a given sequence +:: set-all ( board seq -- board ) + board location-matrix :> loclist + board loclist seq set-cells ; + +! Deletes all instances of obj from all cells (if found) +:: delete-from-all ( board obj -- board ) + board location-matrix :> loclist + board loclist obj delete-all-from-cells ; + +:: duplicate-cell ( board start dest -- board ) + board dup start get-cell dest swap set-cell ; + +! Moves an entire cell if it can be moved to a new destination, leaving the original cell empty +:: move-entire-cell ( board start dest -- board ) + ! bound checking + { start dest } [ first board width>> < ] all? + { start dest } [ second board height>> < ] all? and + start [ 0 >= ] all? and + dest [ 0 >= ] all? and + ! move cell + [ board start dest duplicate-cell + start delete-cell drop ] when + board ; + +! Move an object from a cell, relative to its original cell +:: move-object ( board object-pos move object -- board ) + object-pos move v+ :> dest + { object-pos dest } [ first board width>> < ] all? + { object-pos dest } [ second board height>> < ] all? and + object-pos [ 0 >= ] all? and + dest [ 0 >= ] all? and + [ board object-pos object delete-from-cell + dest object add-to-cell drop ] when + board ; + +! Move a specified object in many cells to different locations +:: move-objects ( board start dest object -- board ) + board start object delete-from-cells + dest object add-to-cells ; + +:: move-many-objects ( board start dest objects -- board ) + board objects [ start swap dest swap move-objects ] each ; + +! move a cell with a move relative to its start +:: move-entire-cell-rel ( board start move -- board ) + board start start move v+ move-entire-cell ; + +! move cells of a parent (only works when cells are all the same) +:: move-cells ( board start dest -- board ) + board start first get-cell :> cell + board start [ delete-cell ] each + dest cell set-cells ; + +:: swap-cells ( board loc1 loc2 -- board ) + board loc1 get-cell :> cell1 + board loc2 get-cell :> cell2 + board loc2 cell1 set-cell + loc1 cell2 set-cell ; + +! Returns true if cell at location is the default cell +:: is-cell-empty? ( board location -- ? ) + board location get-cell { } = ; + +:: is-board-empty? ( board -- ? ) + board cells>> [ [ { } = ] all? ] all? ; + +! Return index and row that contains the first cell that satisfies the quot +:: find-row ( board quot -- index row ) + board cells>> [ [ quot find drop ] find drop ] find ; inline + +! Return first location and cell that satisfies the quot +:: find-cell ( board quot -- seq cell ) + board quot find-row swap :> y + [ quot find drop ] find swap :> x + { x y } swap ; inline + +! Return first cell that satisfies the quot +:: find-cell-nopos ( board quot -- cell ) + board cells>> [ quot find swap drop ] map-find drop ; inline + +: find-cell-pos ( board quot -- seq ) + find-cell drop ; inline + +! Returns a vector containing index row pairs +:: find-all-rows ( board quot -- index row ) + board cells>> [ quot find swap drop ] find-all ; inline + +: is-empty? ( cell -- ? ) + { } = ; + +: cell-contains? ( cell object -- ? ) + swap in? ; + +:: cell-only-contains? ( cell object -- ? ) + cell length 1 = + cell object cell-contains? and ; + +:: cell-contains-instance? ( cell class -- ? ) + cell [ class instance? ] any? ; + +:: cell-only-contains-instance? ( cell class -- ? ) + cell length 1 = + cell class cell-contains-instance? and ; + +! Helper function that formats a position cell pair +:: label-cell ( x cell y -- seq ) + { { x y } cell } ; + +! Helper function that finds all cells in an given row that satisfy the quot +:: row-to-cells ( seq quot -- cells ) + seq first2 :> ( y row ) + row quot find-all :> indexed-cells + indexed-cells [ first2 y label-cell ] map ; inline + +! Return a vector of position cell pairs of all cells in the board that satisfy the quot +:: find-all-cells ( board quot -- assoc ) + board quot find-all-rows :> row-list ! find-all - returns vector w/ index/elt + row-list [ quot row-to-cells ] map concat ; inline + +:: find-all-cells-nopos ( board quot -- assoc ) + board quot find-all-cells [ second ] map ; inline + +:: all-equal-value? ( value seq -- ? ) + seq [ value = ] all? ; diff --git a/extra/gamelib/cell-object/cell-object.factor b/extra/gamelib/cell-object/cell-object.factor new file mode 100644 index 0000000000..98472dc3ab --- /dev/null +++ b/extra/gamelib/cell-object/cell-object.factor @@ -0,0 +1,61 @@ +USING: accessors math kernel sequences math.vectors gamelib.board ; + +IN: gamelib.cell-object + +TUPLE: cell-object draw-cell-delegate ; + +GENERIC: draw-cell-object* ( loc dim delegate -- ) + +: ( draw-delegate -- cell ) + cell-object boa ; + +: ( delegate -- cell ) + ; inline + + +TUPLE: flowcell-object < cell-object flow ; + +! the flowcell-object will move every target frames +! counter keeps track of how many frames have passed since the flowcell-object has last moved +TUPLE: flow is-on direction target counter ; + +! -------------------- Helper methods ---------------------------------------- +! Checks if the flow constant is at the specified location on the board +:: flow-on? ( flowcell-object -- ? ) + flowcell-object flow>> is-on>> ; + +! Add flow information to the cell +:: set-flow ( flowcell-object direction target -- flowcell-object ) + t direction target 0 flow boa :> flow-obj + flowcell-object flow-obj >>flow + ; + +:: turn-off-flow ( cell -- cell ) + f f f f flow boa :> flow-obj + flowcell-object flow-obj >>flow + ; + + +TUPLE: child-cell < cell-object parent ; + + +GENERIC: call-parent* ( resources instruction delegate -- ) + +TUPLE: parent children function ; + +: ( children function -- parent ) + parent boa ; + +: ( children function -- parent ) + ; inline + +:: new-child ( child-pos parent -- ) + parent parent children>> { child-pos } append >>children drop ; + +:: fill-board-parent ( board parent -- board ) + board parent children>> { parent } set-cells ; + +:: move-children ( board move parent -- board ) + parent children>> :> children + parent children [ move v+ ] map >>children drop + board children children [ move v+ ] map board children first get-cell move-many-objects ; diff --git a/extra/gamelib/demos/flow-demo/flow-demo.factor b/extra/gamelib/demos/flow-demo/flow-demo.factor new file mode 100644 index 0000000000..22c0e2d9a7 --- /dev/null +++ b/extra/gamelib/demos/flow-demo/flow-demo.factor @@ -0,0 +1,93 @@ + +USING: literals kernel namespaces accessors sequences +combinators math.vectors colors gamelib.ui gamelib.board +gamelib.cell-object gamelib.loop game.loop ui.gestures +ui.gadgets opengl opengl.textures images.loader prettyprint +classes math ; + +IN: gamelib.demos.flow-demo + +CONSTANT: light-crate "vocab:gamelib/demos/sokoban/resources/Crate_Yellow.png" + +TUPLE: crate-cell < flowcell-object image-path ; + +! Note -- probably need to cache larger images +M: crate-cell draw-cell-object* + rot [ image-path>> load-image ] dip draw-scaled-texture ; + +:: make-crate ( image-path -- crate ) + crate-cell new + f image-path crate-cell boa ; + +: board-one ( gadget -- gadget ) + 8 9 make-board + + { { 1 1 } } light-crate make-crate RIGHT 220 set-flow add-to-cells + { { 3 1 } } light-crate make-crate DOWN 75 set-flow add-to-cells + { { 5 1 } } light-crate make-crate DOWN 20 set-flow add-to-cells + { } 1sequence add-board ; + +! -------------------- Game loop -------------------------------------------------- + +TUPLE: game-state gadget ; + +:: ( gadget -- gadget game-state ) + gadget + game-state new + gadget >>gadget ; + +: create-loop ( game-state -- ) + 10000000 swap new-game-loop start-loop ; + +! Updates a crate-cell's location if a target number of frames have passed, otherwise it updates the counter +:: update-location ( board loc flowcell-object -- ) + flowcell-object flow-on? + [ + flowcell-object flow>> :> flow-obj + flow-obj target>> :> target + flow-obj counter>> 1 + :> counter + counter target = + [ + flow-obj direction>> :> direction + board loc direction flowcell-object move-object drop + flow-obj 0 >>counter drop + + ] + [ + flow-obj counter >>counter drop + ] + if + flowcell-object flow-obj >>flow drop + ] when ; + +! Takes in a cell object and updates its location based on its flow if the cell object is a crate-cell +:: update-all-flowcells ( board loc obj -- ) + obj crate-cell instance? + [ + board loc obj update-location + ] when ; + +! Takes a board, a location, and the corresponding cell and updates all crate-cell objects in the cell +:: update-all-cells-with-flowcells ( board pair -- ) + pair first2 :> ( loc cell ) + board loc cell [ update-all-flowcells ] 2with each ; + +:: tick-update ( game-state -- ) + game-state gadget>> :> g + g board>> :> boards + boards first [ crate-cell cell-contains-instance? ] find-all-cells :> all-cells + boards first all-cells [ update-all-cells-with-flowcells ] with each + g relayout ; + +M: game-state tick* tick-update ; + +M: game-state draw* drop drop ; + + +: main ( -- ) + { 700 800 } init-board-gadget + board-one + create-loop + display ; + +MAIN: main diff --git a/extra/gamelib/demos/maze-game/maze-game.factor b/extra/gamelib/demos/maze-game/maze-game.factor new file mode 100644 index 0000000000..4903aa239c --- /dev/null +++ b/extra/gamelib/demos/maze-game/maze-game.factor @@ -0,0 +1,84 @@ +USING: accessors colors combinators gamelib.board gamelib.ui +kernel math math.vectors prettyprint sequences ui ui.gadgets +ui.gadgets.scrollers ui.gadgets.sliders ui.gadgets.tracks +ui.gestures ; + +IN: gamelib.demos.maze-game + +TUPLE: maze-gadget < track maze-scroller board-gadget ; + +: board ( gadget -- gadget ) + 17 17 make-board + { + { 0 0 } { 1 0 } { 2 0 } { 3 0 } { 4 0 } { 5 0 } { 6 0 } { 7 0 } { 8 0 } { 9 0 } { 10 0 } { 11 0 } { 12 0 } { 13 0 } { 14 0 } { 15 0 } { 16 0 } + { 8 1 } { 16 1 } + { 0 2 } { 1 2 } { 2 2 } { 3 2 } { 4 2 } { 6 2 } { 8 2 } { 9 2 } { 10 2 } { 11 2 } { 12 2 } { 14 2 } { 16 2 } + { 0 3 } { 6 3 } { 12 3 } { 14 3 } { 16 3 } + { 0 4 } { 2 4 } { 3 4 } { 4 4 } { 5 4 } { 6 4 } { 7 4 } { 8 4 } { 9 4 } { 10 4 } { 12 4 } { 14 4 } { 15 4 } { 16 4 } + { 0 5 } { 4 5 } { 8 5 } { 12 5 } { 16 5 } + { 0 6 } { 1 6 } { 2 6 } { 4 6 } { 6 6 } { 8 6 } { 10 6 } { 11 6 } { 12 6 } { 13 6 } { 14 6 } { 16 6 } + { 0 7 } { 4 7 } { 6 7 } { 8 7 } { 12 7 } { 16 7 } + { 0 8 } { 2 8 } { 3 8 } { 4 8 } { 5 8 } { 6 8 } { 8 8 } { 9 8 } { 10 8 } { 12 8 } { 14 8 } { 16 8 } + { 0 9 } { 6 9 } { 10 9 } { 14 9 } { 16 9 } + { 0 10 } { 1 10 } { 2 10 } { 3 10 } { 4 10 } { 6 10 } { 8 10 } { 10 10 } { 11 10 } { 12 10 } { 13 10 } { 14 10 } { 16 10 } + { 0 11 } { 2 11 } { 6 11 } { 8 11 } { 14 11 } { 16 11 } + { 0 12 } { 2 12 } { 3 12 } { 4 12 } { 5 12 } { 6 12 } { 8 12 } { 10 12 } { 11 12 } { 12 12 } { 13 12 } { 14 12 } { 16 12 } + { 0 13 } { 6 13 } { 8 13 } { 16 13 } + { 0 14 } { 2 14 } { 3 14 } { 4 14 } { 5 14 } { 6 14 } { 8 14 } { 9 14 } { 10 14 } { 11 14 } { 12 14 } { 13 14 } { 14 14 } { 15 14 } { 16 14 } + { 0 15 } + { 0 16 } { 1 16 } { 2 16 } { 3 16 } { 4 16 } { 5 16 } { 6 16 } { 7 16 } { 8 16 } { 9 16 } { 10 16 } { 11 16 } { 12 16 } { 13 16 } { 14 16 } { 15 16 } { 16 16 } + } COLOR: black add-to-cells + + { 1 1 } COLOR: blue add-to-cell + + { } 1sequence add-board ; + +:: bound-check ( new-pos -- ? ) + new-pos [ 0 >= ] all? + new-pos [ 17 < ] all? and ; + +: can-move? ( board new-pos -- ? ) + get-cell is-empty? ; + +:: move-window ( scroller move -- ) + { + { [ move LEFT = ] [ scroller x>> -100 swap slide-by ] } + { [ move RIGHT = ] [ scroller x>> 100 swap slide-by ] } + { [ move DOWN = ] [ scroller y>> 100 swap slide-by ] } + { [ move UP = ] [ scroller y>> -100 swap slide-by ] } + } cond ; + +:: move ( maze-gadget move -- ) + maze-gadget board-gadget>> board>> first :> board + maze-gadget maze-scroller>> :> scroller + board [ COLOR: blue = ] find-cell-pos :> player-pos + player-pos move v+ :> new-pos + + new-pos bound-check ! check new pos is still inside of board + [ + board new-pos can-move? ! check if new pos is an empty space + [ + player-pos { 0 1 } = not player-pos { 16 15 } = not and ! check player isn't at edge of board + [ + scroller move move-window + ] when + board player-pos new-pos move-entire-cell drop + ] when + ] when + maze-gadget relayout-1 ; + +maze-gadget H{ + { T{ key-down f f "RIGHT" } [ RIGHT move ] } + { T{ key-down f f "LEFT" } [ LEFT move ] } + { T{ key-down f f "UP" } [ UP move ] } + { T{ key-down f f "DOWN" } [ DOWN move ] } +} set-gestures + +: main ( -- gadget ) + vertical maze-gadget new-track + { 1700 1700 } init-board-gadget + board [ >>board-gadget ] keep + [ >>maze-scroller ] keep + 1 track-add ; + +MAIN-WINDOW: maze-game-demo { { title "maze" } { pref-dim { 400 400 } } } main >>gadgets ; diff --git a/extra/gamelib/demos/multiple-board-demo/multiple-board-demo.factor b/extra/gamelib/demos/multiple-board-demo/multiple-board-demo.factor new file mode 100644 index 0000000000..798b5d6f91 --- /dev/null +++ b/extra/gamelib/demos/multiple-board-demo/multiple-board-demo.factor @@ -0,0 +1,35 @@ +USING: accessors sequences kernel opengl gamelib.ui colors math +math.vectors ui.gadgets.tracks ui.gestures ui.gadgets +gamelib.board assocs calendar timers ; + +IN: multiple-board-demo + +: board-init ( -- board ) + 10 10 make-board + { 0 0 } COLOR: blue add-to-cell + { } 1sequence ; + +:: move ( board mov -- ) + board [ COLOR: blue = ] find-cell-pos :> player-pos + player-pos mov v+ :> new-pos + new-pos first 0 >= + new-pos first 10 < and + [ board player-pos new-pos move-entire-cell drop ] when ; + +:: first-gadget ( -- gadget ) + { 400 400 } init-board-gadget + T{ key-down f f "RIGHT" } [ dup board>> first RIGHT move relayout ] new-gesture + T{ key-down f f "LEFT" } [ dup board>> first LEFT move relayout ] new-gesture + board-init add-board ; + +:: second-gadget ( -- gadget ) + { 500 400 } init-board-gadget + board-init add-board ; + + :: display-window ( -- ) + first-gadget :> g1 + second-gadget :> g2 + { g1 g2 } horizontal 0 f ! initalize two boards + display ; + +MAIN: display-window diff --git a/extra/gamelib/demos/parent-demo/parent-demo.factor b/extra/gamelib/demos/parent-demo/parent-demo.factor new file mode 100644 index 0000000000..91b4dc5ae9 --- /dev/null +++ b/extra/gamelib/demos/parent-demo/parent-demo.factor @@ -0,0 +1,134 @@ + +USING: literals kernel namespaces accessors sequences +combinators math.vectors colors gamelib.ui gamelib.board +gamelib.cell-object gamelib.loop game.loop ui.gestures +ui.gadgets opengl opengl.textures images.loader prettyprint +strings classes ; + +IN: gamelib.demos.parent-demo + +CONSTANT: player "vocab:gamelib/demos/parent-demo/resources/CharR.png" +CONSTANT: wall "vocab:gamelib/demos/parent-demo/resources/Wall_Brown.png" +CONSTANT: goal "vocab:gamelib/demos/parent-demo/resources/Goal.png" +CONSTANT: light-crate "vocab:gamelib/demos/parent-demo/resources/Crate_Yellow.png" +CONSTANT: dark-crate "vocab:gamelib/demos/parent-demo/resources/CrateDark_Yellow.png" + +TUPLE: crate-cell < child-cell image-path ; +M: crate-cell draw-cell-object* + rot [ image-path>> load-image ] dip draw-scaled-texture ; + +M: crate-cell call-parent* + parent>> dup function>> call( board move parent -- board ) drop ; inline + +SYMBOL: level +0 level set-global + +: ( -- parent ) + { } [ move-children ] ; + +:: make-crate ( image-path parent -- crate ) + crate-cell new + parent image-path crate-cell boa ; + +:: board-one-bg ( parent -- board ) + 8 9 make-board + + { 2 2 } player add-to-cell + + { + { 0 0 } { 1 0 } { 2 0 } { 3 0 } { 4 0 } { 5 0 } { 6 0 } { 7 0 } + { 0 1 } { 7 1 } + { 0 2 } { 7 2 } + { 0 3 } { 7 3 } + { 0 4 } { 7 4 } + { 0 5 } { 7 5 } + { 0 6 } { 7 6 } + { 0 7 } { 7 7 } + { 0 8 } { 1 8 } { 2 8 } { 3 8 } { 4 8 } { 5 8 } { 6 8 } { 7 8 } + + } $ wall add-to-cells + + { + + { 3 4 } { 4 4 } { 5 4 } { 4 3 } + } dup parent swap >>children drop light-crate parent make-crate add-copy-to-cells ; + +: board-one ( gadget parent -- gadget ) + board-one-bg { } 1sequence add-board ; + +:: get-pos ( board object -- seq ) + board [ object = ] find-cell-pos ; + +:: move-crate ( board player-pos move crate -- ) + player-pos move v+ :> crate-pos + board crate-pos move v+ get-cell :> next-cell + ! Move both the player and crate if possible, otherwise do nothing + { + { + [ next-cell class-of wall class-of = not ] ! crate can be moved to free space + [ crate light-crate >>image-path drop + ! board crate parent>> move move-children + board move crate call-parent* + board player-pos move player move-object drop ] + } + { + [ next-cell goal cell-only-contains? ] ! crate can be moved to goal + [ crate dark-crate >>image-path drop + board crate-pos move crate move-object + player-pos move player move-object drop ] + } + [ ] ! Else do nothing + } cond ; + +:: sokoban-move ( board move -- ) + board player get-pos :> player-pos + player-pos move v+ :> new-pos + board new-pos get-cell :> adjacent-cell + ! Move player to free space or have player push crate if possible, otherwise do nothing + { + { + [ adjacent-cell crate-cell cell-contains-instance? ] ! player is moving into a crate + [ adjacent-cell crate-cell get-instance-from-cell :> crate + board player-pos move crate move-crate ] + } + { + [ adjacent-cell is-empty? adjacent-cell goal cell-contains? or ] ! player can be moved to free space or goal + [ board player-pos move player move-object drop ] + } + [ ] ! Else do nothing + } cond ; + +: game-logic ( gadget -- gadget ) + ! Move pieces according to user input + T{ key-down f f "UP" } [ board>> first UP sokoban-move ] new-gesture + T{ key-down f f "DOWN" } [ board>> first DOWN sokoban-move ] new-gesture + T{ key-down f f "RIGHT" } [ board>> first RIGHT sokoban-move ] new-gesture + T{ key-down f f "LEFT" } [ board>> first LEFT sokoban-move ] new-gesture ; + +TUPLE: game-state gadget ; + +:: ( gadget -- gadget game-state ) + gadget + game-state new + gadget >>gadget ; + +: create-loop ( game-state -- ) + 10000000 swap new-game-loop start-loop ; + +:: tick-update ( game-state -- ) + game-state gadget>> relayout ; + +M: game-state tick* tick-update ; + +M: game-state draw* drop drop ; + + +: main ( -- ) + { 700 800 } init-board-gadget + + board-one + create-loop + game-logic + display ; + +MAIN: main diff --git a/extra/gamelib/demos/parent-demo/resources/CharB.png b/extra/gamelib/demos/parent-demo/resources/CharB.png new file mode 100644 index 0000000000..7f94ffa295 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharB.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharF.png b/extra/gamelib/demos/parent-demo/resources/CharF.png new file mode 100644 index 0000000000..0315373306 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharF.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharL.png b/extra/gamelib/demos/parent-demo/resources/CharL.png new file mode 100644 index 0000000000..cbf68570e6 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharL.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharR.png b/extra/gamelib/demos/parent-demo/resources/CharR.png new file mode 100644 index 0000000000..6e21bb3b51 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharR.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharWalkB.png b/extra/gamelib/demos/parent-demo/resources/CharWalkB.png new file mode 100644 index 0000000000..74d981939f Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharWalkB.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharWalkF.png b/extra/gamelib/demos/parent-demo/resources/CharWalkF.png new file mode 100644 index 0000000000..03d27e184a Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharWalkF.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharWalkL.png b/extra/gamelib/demos/parent-demo/resources/CharWalkL.png new file mode 100644 index 0000000000..465e48b412 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharWalkL.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CharWalkR.png b/extra/gamelib/demos/parent-demo/resources/CharWalkR.png new file mode 100644 index 0000000000..13e717f343 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CharWalkR.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/CrateDark_Yellow.png b/extra/gamelib/demos/parent-demo/resources/CrateDark_Yellow.png new file mode 100644 index 0000000000..3de69773b7 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/CrateDark_Yellow.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/Crate_Yellow.png b/extra/gamelib/demos/parent-demo/resources/Crate_Yellow.png new file mode 100644 index 0000000000..06c7b993c6 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/Crate_Yellow.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/Goal.png b/extra/gamelib/demos/parent-demo/resources/Goal.png new file mode 100644 index 0000000000..5be73abe92 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/Goal.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/Tetris.wav b/extra/gamelib/demos/parent-demo/resources/Tetris.wav new file mode 100644 index 0000000000..705f847a4f Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/Tetris.wav differ diff --git a/extra/gamelib/demos/parent-demo/resources/Wall_Brown.png b/extra/gamelib/demos/parent-demo/resources/Wall_Brown.png new file mode 100644 index 0000000000..44fff22e0d Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/Wall_Brown.png differ diff --git a/extra/gamelib/demos/parent-demo/resources/once.wav b/extra/gamelib/demos/parent-demo/resources/once.wav new file mode 100644 index 0000000000..3fc85b03d3 Binary files /dev/null and b/extra/gamelib/demos/parent-demo/resources/once.wav differ diff --git a/extra/gamelib/demos/sokoban/layouts/layouts.factor b/extra/gamelib/demos/sokoban/layouts/layouts.factor new file mode 100644 index 0000000000..198919b64a --- /dev/null +++ b/extra/gamelib/demos/sokoban/layouts/layouts.factor @@ -0,0 +1,107 @@ +USING: accessors colors gamelib.board gamelib.cell-object +gamelib.ui images.loader kernel literals opengl.textures +sequences namespaces ; + +IN: gamelib.demos.sokoban.layouts + +CONSTANT: player "vocab:gamelib/demos/sokoban/resources/CharR.png" +CONSTANT: wall "vocab:gamelib/demos/sokoban/resources/Wall_Brown.png" +CONSTANT: goal "vocab:gamelib/demos/sokoban/resources/Goal.png" +CONSTANT: light-crate "vocab:gamelib/demos/sokoban/resources/Crate_Yellow.png" +CONSTANT: dark-crate "vocab:gamelib/demos/sokoban/resources/CrateDark_Yellow.png" + +TUPLE: crate-cell < cell-object image-path ; +M: crate-cell draw-cell-object* + rot [ image-path>> load-image ] dip draw-scaled-texture ; + +:: make-crate ( image-path -- crate ) + crate-cell new + image-path crate-cell boa ; + +: board-one ( gadget -- gadget ) + 8 9 make-board + + { 2 2 } player add-to-cell + + { + { 2 0 } { 3 0 } { 4 0 } { 5 0 } { 6 0 } + { 0 1 } { 1 1 } { 2 1 } { 6 1 } + { 0 2 } { 6 2 } + { 0 3 } { 1 3 } { 2 3 } { 6 3 } + { 0 4 } { 2 4 } { 3 4 } { 6 4 } + { 0 5 } { 2 5 } { 6 5 } { 7 5 } + { 0 6 } { 7 6 } + { 0 7 } { 7 7 } + { 0 8 } { 1 8 } { 2 8 } { 3 8 } { 4 8 } { 5 8 } { 6 8 } { 7 8 } + + } $ wall add-to-cells + + { + + { 1 6 } { 3 2 } { 4 3 } { 4 4 } { 4 6 } { 3 6 } { 5 6 } + } $ light-crate make-crate add-copy-to-cells + + { + { 1 2 } { 5 3 } { 1 4 } { 4 5 } { 3 6 } { 6 6 } { 4 7 } + } $ goal add-to-cells + + { } 1sequence add-board ; + + +: board-two ( gadget -- gadget ) + 22 11 make-board + + { 11 8 } player add-to-cell + + { + { 4 0 } { 5 0 } { 6 0 } { 7 0 } { 8 0 } + { 4 1 } { 8 1 } + { 4 2 } { 8 2 } + { 2 3 } { 3 3 } { 4 3 } { 8 3 } { 9 3 } { 10 3 } + { 2 4 } { 10 4 } + { 0 5 } { 1 5 } { 2 5 } { 4 5 } { 6 5 } { 7 5 } { 8 5 } { 10 5 } { 16 5 } { 17 5 } { 18 5 } { 19 5 } { 20 5 } { 21 5 } + { 0 6 } { 4 6 } { 6 6 } { 7 6 } { 8 6 } { 10 6 } { 11 6 } { 12 6 } { 13 6 } { 14 6 } { 15 6 } { 16 6 } { 21 6 } + { 0 7 } { 21 7 } + { 0 8 } { 1 8 } { 2 8 } { 3 8 } { 4 8 } { 6 8 } { 7 8 } { 8 8 } { 10 8 } { 12 8 } { 13 8 } { 14 8 } { 15 8 } { 16 8 } { 21 8 } + { 4 9 } { 10 9 } { 11 9 } { 12 9 } { 16 9 } { 17 9 } { 18 9 } { 19 9 } { 20 9 } { 21 9 } + { 4 10 } { 5 10 } { 6 10 } { 7 10 } { 8 10 } { 9 10 } { 10 10 } + } $ wall add-to-cells + + { + { 19 6 } { 20 6 } + { 19 7 } { 20 7 } + { 19 8 } { 20 8 } + } $ goal add-to-cells + + { + { 5 2 } { 7 3 } { 5 4 } { 8 4 } { 5 7 } { 2 7 } + } $ light-crate make-crate add-copy-to-cells + + { } 1sequence + + add-board ; + + +: board-three ( gadget -- gadget ) + 8 8 make-board + + { 1 1 } player add-to-cell + + { + { 0 0 } { 1 0 } { 2 0 } { 3 0 } { 4 0 } { 5 0 } { 6 0 } { 7 0 } + { 0 1 } { 7 1 } + { 0 2 } { 7 2 } + { 0 3 } { 7 3 } + { 0 4 } { 7 4 } + { 0 5 } { 7 5 } + { 0 6 } { 7 6 } + { 0 7 } { 1 7 } { 2 7 } { 3 7 } { 4 7 } { 5 7 } { 6 7 } { 7 7 } + } $ wall add-to-cells + + { 2 1 } $ light-crate make-crate add-to-cell + + { 3 1 } $ goal add-to-cell + + { } 1sequence + + add-board ; diff --git a/extra/gamelib/demos/sokoban/loop/loop.factor b/extra/gamelib/demos/sokoban/loop/loop.factor new file mode 100644 index 0000000000..77cd9660c2 --- /dev/null +++ b/extra/gamelib/demos/sokoban/loop/loop.factor @@ -0,0 +1,42 @@ + +USING: accessors colors fonts game.loop gamelib.board +gamelib.loop gamelib.ui kernel math namespaces opengl +prettyprint sequences gamelib.demos.sokoban.layouts ui ui.gadgets ui.text +combinators ; + +IN: gamelib.demos.sokoban.loop + +SYMBOL: level + +TUPLE: game-state gadget ; + +:: check-win ( board -- ? ) + board [ crate-cell cell-contains-instance? ] find-all-cells-nopos :> seq + seq length 0 = not seq [ dark-crate make-crate cell-contains? ] all? and ; + +:: ( gadget -- gadget game-state ) + gadget + game-state new + gadget >>gadget ; + +: create-loop ( game-state -- ) + 10000000 swap new-game-loop start-loop ; + +: game-over ( gadget -- gadget ) + [ { 200 200 } [ monospace-font t >>bold? 50 >>size COLOR: red >>foreground "YOU WIN!" draw-text ] with-translation ] draw-quote ; + +:: tick-update ( game-state -- ) + game-state gadget>> :> g + g relayout-window + g board>> first check-win + [ + { + { [ level get-global 0 = ] [ level [ 1 + ] change-global game-state g { } >>board { } >>draw-quotes board-two >>gadget drop g { 1500 750 } set-dim relayout ] } + { [ level get-global 1 = ] [ level [ 1 + ] change-global game-state g { } >>board { } >>draw-quotes board-three >>gadget drop g { 600 600 } set-dim relayout ] } + { [ level get-global 2 = ] [ g game-over relayout-1 stop-game ] } + } cond + ] when ; + +M: game-state tick* tick-update ; + +M: game-state draw* drop drop ; diff --git a/extra/gamelib/demos/sokoban/resources/CharB.png b/extra/gamelib/demos/sokoban/resources/CharB.png new file mode 100644 index 0000000000..7f94ffa295 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharB.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharF.png b/extra/gamelib/demos/sokoban/resources/CharF.png new file mode 100644 index 0000000000..0315373306 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharF.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharL.png b/extra/gamelib/demos/sokoban/resources/CharL.png new file mode 100644 index 0000000000..cbf68570e6 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharL.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharR.png b/extra/gamelib/demos/sokoban/resources/CharR.png new file mode 100644 index 0000000000..6e21bb3b51 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharR.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharWalkB.png b/extra/gamelib/demos/sokoban/resources/CharWalkB.png new file mode 100644 index 0000000000..74d981939f Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharWalkB.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharWalkF.png b/extra/gamelib/demos/sokoban/resources/CharWalkF.png new file mode 100644 index 0000000000..03d27e184a Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharWalkF.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharWalkL.png b/extra/gamelib/demos/sokoban/resources/CharWalkL.png new file mode 100644 index 0000000000..465e48b412 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharWalkL.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CharWalkR.png b/extra/gamelib/demos/sokoban/resources/CharWalkR.png new file mode 100644 index 0000000000..13e717f343 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CharWalkR.png differ diff --git a/extra/gamelib/demos/sokoban/resources/CrateDark_Yellow.png b/extra/gamelib/demos/sokoban/resources/CrateDark_Yellow.png new file mode 100644 index 0000000000..3de69773b7 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/CrateDark_Yellow.png differ diff --git a/extra/gamelib/demos/sokoban/resources/Crate_Yellow.png b/extra/gamelib/demos/sokoban/resources/Crate_Yellow.png new file mode 100644 index 0000000000..06c7b993c6 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/Crate_Yellow.png differ diff --git a/extra/gamelib/demos/sokoban/resources/Goal.png b/extra/gamelib/demos/sokoban/resources/Goal.png new file mode 100644 index 0000000000..5be73abe92 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/Goal.png differ diff --git a/extra/gamelib/demos/sokoban/resources/Tetris.wav b/extra/gamelib/demos/sokoban/resources/Tetris.wav new file mode 100644 index 0000000000..705f847a4f Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/Tetris.wav differ diff --git a/extra/gamelib/demos/sokoban/resources/Wall_Brown.png b/extra/gamelib/demos/sokoban/resources/Wall_Brown.png new file mode 100644 index 0000000000..44fff22e0d Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/Wall_Brown.png differ diff --git a/extra/gamelib/demos/sokoban/resources/hardwood-tree.jpg b/extra/gamelib/demos/sokoban/resources/hardwood-tree.jpg new file mode 100644 index 0000000000..617d9690cc Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/hardwood-tree.jpg differ diff --git a/extra/gamelib/demos/sokoban/resources/large-tree.jpg b/extra/gamelib/demos/sokoban/resources/large-tree.jpg new file mode 100644 index 0000000000..62a8716fae Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/large-tree.jpg differ diff --git a/extra/gamelib/demos/sokoban/resources/once.wav b/extra/gamelib/demos/sokoban/resources/once.wav new file mode 100644 index 0000000000..3fc85b03d3 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/once.wav differ diff --git a/extra/gamelib/demos/sokoban/resources/tree.png b/extra/gamelib/demos/sokoban/resources/tree.png new file mode 100644 index 0000000000..b9f0285970 Binary files /dev/null and b/extra/gamelib/demos/sokoban/resources/tree.png differ diff --git a/extra/gamelib/demos/sokoban/sokoban.factor b/extra/gamelib/demos/sokoban/sokoban.factor new file mode 100644 index 0000000000..8b7b71f47e --- /dev/null +++ b/extra/gamelib/demos/sokoban/sokoban.factor @@ -0,0 +1,68 @@ +USING: literals kernel namespaces accessors sequences +combinators math.vectors colors gamelib.ui gamelib.board +gamelib.cell-object gamelib.loop game.loop ui.gestures +ui.gadgets opengl opengl.textures images.loader prettyprint +layouts gamelib.demos.sokoban.layouts gamelib.demos.sokoban.loop ; + +IN: gamelib.demos.sokoban + +CONSTANT: player "vocab:gamelib/demos/sokoban/resources/CharR.png" +CONSTANT: wall "vocab:gamelib/demos/sokoban/resources/Wall_Brown.png" +CONSTANT: goal "vocab:gamelib/demos/sokoban/resources/Goal.png" +CONSTANT: light-crate "vocab:gamelib/demos/sokoban/resources/Crate_Yellow.png" +CONSTANT: dark-crate "vocab:gamelib/demos/sokoban/resources/CrateDark_Yellow.png" + +:: move-crate ( board player-pos move crate -- ) + player-pos move v+ :> crate-pos + board crate-pos move v+ get-cell :> next-cell + ! Move both the player and crate if possible, otherwise do nothing + { + { + [ next-cell is-empty? ] ! crate can be moved to free space + [ crate light-crate >>image-path drop + board crate-pos move crate move-object + player-pos move player move-object drop ] + } + { + [ next-cell goal cell-only-contains? ] ! crate can be moved to goal + [ crate dark-crate >>image-path drop + board crate-pos move crate move-object + player-pos move player move-object drop ] + } + [ ] ! Else do nothing + } cond ; + +:: sokoban-move ( board move -- ) + board [ player = ] find-cell-pos :> player-pos + player-pos move v+ :> new-pos + board new-pos get-cell :> adjacent-cell + ! Move player to free space or have player push crate if possible, otherwise do nothing + { + { + [ adjacent-cell crate-cell cell-contains-instance? ] ! player is moving into a crate + [ adjacent-cell crate-cell get-instance-from-cell :> crate + board player-pos move crate move-crate ] + } + { + [ adjacent-cell is-empty? adjacent-cell goal cell-contains? or ] ! player can be moved to free space or goal + [ board player-pos move player move-object drop ] + } + [ ] ! Else do nothing + } cond ; + +: game-logic ( gadget -- gadget ) + ! Move pieces according to user input + T{ key-down f f "UP" } [ board>> first UP sokoban-move ] new-gesture + T{ key-down f f "DOWN" } [ board>> first DOWN sokoban-move ] new-gesture + T{ key-down f f "RIGHT" } [ board>> first RIGHT sokoban-move ] new-gesture + T{ key-down f f "LEFT" } [ board>> first LEFT sokoban-move ] new-gesture ; + +: main ( -- ) + [ 0 level set-global ] with-global ! set global level variable to 0 + { 600 675 } init-board-gadget + board-one + create-loop + game-logic + display ; + +MAIN: main diff --git a/extra/gamelib/demos/tic-tac-toe/resources/O.png b/extra/gamelib/demos/tic-tac-toe/resources/O.png new file mode 100644 index 0000000000..2c45370e5d Binary files /dev/null and b/extra/gamelib/demos/tic-tac-toe/resources/O.png differ diff --git a/extra/gamelib/demos/tic-tac-toe/resources/X.png b/extra/gamelib/demos/tic-tac-toe/resources/X.png new file mode 100644 index 0000000000..c1fc7a8c8f Binary files /dev/null and b/extra/gamelib/demos/tic-tac-toe/resources/X.png differ diff --git a/extra/gamelib/demos/tic-tac-toe/tic-tac-toe.factor b/extra/gamelib/demos/tic-tac-toe/tic-tac-toe.factor new file mode 100644 index 0000000000..c80b7e4df6 --- /dev/null +++ b/extra/gamelib/demos/tic-tac-toe/tic-tac-toe.factor @@ -0,0 +1,105 @@ +USING: kernel namespaces accessors fonts literals ui.text +sequences math gamelib.ui gamelib.board colors ui.gestures +ui.gadgets opengl gamelib.loop game.loop ; + +IN: gamelib.demos.tic-tac-toe + +CONSTANT: X "vocab:gamelib/demos/tic-tac-toe/resources/X.png" +CONSTANT: O "vocab:gamelib/demos/tic-tac-toe/resources/O.png" + +SYMBOL: player +X player set-global + +: background ( gadget -- gadget ) + COLOR: pink set-background-color + X { 80 80 } { 30 30 } draw-image + X { 10 10 } { 40 40 } draw-image ; + +: foreground ( gadget -- gadget ) + COLOR: black { 123 0 } { 10 400 } draw-filled-rectangle + COLOR: black { 256 0 } { 10 400 } draw-filled-rectangle + COLOR: black { 0 123 } { 400 10 } draw-filled-rectangle + COLOR: black { 0 256 } { 400 10 } draw-filled-rectangle ; + +: board ( gadget -- gadget ) + 3 3 make-board { } 1sequence + add-board ; + +: set-player ( -- ) + player get-global X = + [ O player set-global ] + [ X player set-global ] + if ; + +:: set-board ( board cell-pos cell -- ) + board cell-pos is-cell-empty? + [ + board cell-pos cell add-to-cell drop + set-player + ] when ; + +:: on-click ( -- quot ) + [ dup board>> first swap hand-rel-cell player get-global set-board ] ; + +:: row-win ( board -- ? ) + ! Returns true if either X or O has a row win + ! For each row, check if every element in specified row equals X, returning true if any row meets the condition + { 0 1 2 } [ { $ X } swap board swap get-row all-equal-value? ] any? + ! Same check but with O + { 0 1 2 } [ { $ O } swap board swap get-row all-equal-value? ] any? or ; + +:: col-win ( board -- ? ) + ! Same as row win except checks column wins + { 0 1 2 } [ { $ X } swap board swap get-col all-equal-value? ] any? + { 0 1 2 } [ { $ O } swap board swap get-col all-equal-value? ] any? or ; + +:: diag-win ( board -- ? ) + ! Same as row win except checks diagonal wins + { $ X } board { { 0 0 } { 1 1 } { 2 2 } } get-cells all-equal-value? + { $ X } board { { 2 0 } { 1 1 } { 0 2 } } get-cells all-equal-value? or + { $ O } board { { 0 0 } { 1 1 } { 2 2 } } get-cells all-equal-value? or + { $ O } board { { 2 0 } { 1 1 } { 0 2 } } get-cells all-equal-value? or ; + +:: check-win ( board -- ? ) + ! Returns true if any win condition is met + board row-win board col-win or board diag-win or ; + +: game-logic ( gadget -- gadget ) + T{ button-down { # 1 } } on-click new-gesture + T{ button-down { # 3 } } on-click new-gesture ; + +TUPLE: game-state gadget ; + + +: game-over ( gadget -- gadget ) + [ { 75 75 } [ monospace-font t >>bold? 50 >>size COLOR: red >>foreground "GAME OVER" draw-text ] with-translation ] draw-quote ; + +:: ( gadget -- gadget game-state ) + gadget + game-state new + gadget >>gadget ; + + +: create-loop ( game-state -- ) + 1000 swap new-game-loop start-loop ; + + +: tick-update ( game-state -- ) + dup gadget>> board>> first check-win + [ gadget>> game-over relayout-1 stop-game ] + [ gadget>> relayout-1 ] if ; + + +M: game-state tick* tick-update ; + +M: game-state draw* drop drop ; + + +: main ( -- ) + { 400 400 } init-board-gadget + background board foreground + game-logic + create-loop + display ; + +MAIN: main diff --git a/extra/gamelib/loop/loop.factor b/extra/gamelib/loop/loop.factor new file mode 100644 index 0000000000..03f7c21527 --- /dev/null +++ b/extra/gamelib/loop/loop.factor @@ -0,0 +1,15 @@ +USING: accessors sequences kernel opengl grouping words game.loop delegate namespaces ; + +IN: gamelib.loop + + +SYMBOL: game-loop + + +: new-game-loop ( interval game-state -- game-loop ) + dup game-loop set-global ; + +:: stop-game ( -- ) + game-loop get-global :> loop + loop + [ loop stop-loop ] when ; diff --git a/extra/gamelib/ui/ui.factor b/extra/gamelib/ui/ui.factor new file mode 100644 index 0000000000..74e8ce06b0 --- /dev/null +++ b/extra/gamelib/ui/ui.factor @@ -0,0 +1,146 @@ +USING: accessors arrays classes quotations ui.gadgets kernel +ui.gadgets.status-bar ui ui.render opengl locals.types strings +sequences combinators peg images.loader opengl.textures assocs +math ranges gamelib.board gamelib.cell-object ui.gestures +ui.gadgets.tracks ui.gadgets.worlds colors destructors +gamelib.loop ; + +IN: gamelib.ui + +TUPLE: board-gadget < gadget dimension bg-color draw-quotes board gests textures ; + +:: get-cell-dimension ( n gadget -- celldims ) + ! Calculates cell height and width based on gadget height and width + gadget dimension>> first2 :> ( wdt hgt ) + n gadget board>> nth dup width>> swap height>> :> ( cols rows ) + + wdt cols /i :> cellwidth + hgt rows /i :> cellheight + + cellwidth cellheight { } 2sequence ; + +:: get-dimension-matrix ( n gadget -- matrix ) + ! gets a matrix of all starting locations of cells + n gadget get-cell-dimension :> celldims + ! applies appropriate offset to starting locations based on the cell heigh/width + n gadget board>> nth width>> [0..b) [ celldims first * ] map :> widths + n gadget board>> nth height>> [0..b) [ celldims second * ] map :> heights + + widths heights cartesian-product flip ; + +:: draw-append ( gadget quot -- gadget ) + gadget + gadget draw-quotes>> + quot { } 1sequence append + >>draw-quotes ; + +:: draw-background-color ( gadget -- ) + ! if given a background color, draw the background color + gadget bg-color>> + [ gadget bg-color>> gl-color { 0 0 } gadget dimension>> gl-fill-rect ] + [ ] if ; + +:: draw-filled-rectangle ( gadget color loc dim -- gadget ) + ! appends instruction to draw a rectangle to current set of instructions in draw-quotes attribute + gadget [ color gl-color loc dim gl-fill-rect ] draw-append ; + +:: draw-image ( gadget path loc dim -- gadget ) + ! appends instructions to draw a sprite to current set of instructions in draw-quotes attributes + gadget [ dim { path loc } gadget textures>> [ first load-image loc ] cache draw-scaled-texture ] draw-append ; + ! gadget [ dim path load-image loc draw-scaled-texture ] draw-append ; + +:: draw-quote ( gadget quote -- gadget ) + gadget quote draw-append ; + +:: draw-single ( display-cell loc dim gadget -- ) + ! Executes instructions based on content of the cell, does nothing if cell isn't a + ! string, color or quote. + { + { [ display-cell cell-object instance? ] [ loc dim display-cell draw-cell-object* ] } + { [ display-cell string? ] [ dim { display-cell loc } gadget textures>> [ first load-image loc ] cache draw-scaled-texture ] } + { [ display-cell color? ] [ display-cell gl-color loc dim gl-fill-rect ] } + { [ display-cell quotation? ] [ loc dim display-cell 2curry call( -- ) ] } + { [ display-cell array? ] [ display-cell [ loc dim gadget draw-single ] each ] } + [ ] + } cond ; + +:: draw-cells ( n gadget -- ) + ! board is always valid since this instruction gets added on creation of board + n gadget board>> nth cells>> :> cell + n gadget get-cell-dimension :> celldims + n gadget get-dimension-matrix :> dim-matrix + cell dim-matrix [ [ celldims gadget draw-single ] 2each ] 2each ; + +: draw-all ( gadget -- ) + ! draws everything in draw-quotes (which we added to using draw-filled-rectangle and draw-image) + draw-quotes>> [ call( -- ) ] each ; + +! TODO: change to have a board +: init-board-gadget ( dim -- gadget ) + ! makes a window gadget with given dimensions + board-gadget new + swap >>dimension + H{ } >>gests + H{ } clone >>textures ; + +:: add-board ( gadget board -- gadget ) + ! board should be a seq + gadget board >>board + [ board length [0..b) [ gadget draw-cells ] each ] draw-append ; + +:: display ( gadget -- ) + [ + gadget + "Display window" + open-status-window + ] with-ui ; + +: set-background-color ( gadget color -- gadget ) + >>bg-color ; + +: set-dim ( gadget dim -- gadget ) + >>dimension ; + +: get-dim ( gadget -- dim ) + dimension>> ; + +:: hand-rel-cell ( gadget -- cellpos ) + gadget hand-rel first2 :> ( w h ) + 0 gadget get-cell-dimension first2 :> ( cw ch ) + w cw /i :> row + h ch /i :> col + row col { } 2sequence ; + +:: new-gesture ( gadget key value -- gadget ) + value key gadget gests>> set-at gadget ; + + +! SECTION: gadget methods +M: board-gadget pref-dim* + dimension>> ; + +M: board-gadget handle-gesture + swap over gests>> ?at + [ + 2dup call( gadget -- ) + ] when 2drop f ; + +M: board-gadget draw-gadget* + { + [ draw-background-color ] + [ draw-all ] + } cleave ; + +M: board-gadget ungraft* + [ dup find-gl-context [ values dispose-each H{ } clone ] change-textures drop + stop-game + ] [ call-next-method ] bi ; + +TUPLE: window-gadget < track focusable-child-number ; + +:: ( board-gadgets orientation fsn constraint -- gadget ) + orientation window-gadget new-track + fsn >>focusable-child-number + board-gadgets [ constraint track-add ] each ; + +M: window-gadget focusable-child* dup children>> swap focusable-child-number>> swap nth ; diff --git a/extra/sokoban/README.txt b/extra/sokoban/README.txt new file mode 100644 index 0000000000..a3bdf792ef --- /dev/null +++ b/extra/sokoban/README.txt @@ -0,0 +1,7 @@ +This is a simple sokoban game. To play, open factor (in GUI mode), and run: + +"sokoban" run + +This should open a new window with a running sokoban game. The commands are: + +left,right,up,down arrows -- moves the player in the given direction diff --git a/extra/sokoban/authors.txt b/extra/sokoban/authors.txt new file mode 100644 index 0000000000..36ce64f6f0 --- /dev/null +++ b/extra/sokoban/authors.txt @@ -0,0 +1 @@ +Factor Clinic Team 2021-2022 diff --git a/extra/sokoban/board/board-tests.factor b/extra/sokoban/board/board-tests.factor new file mode 100644 index 0000000000..bbcff3c955 --- /dev/null +++ b/extra/sokoban/board/board-tests.factor @@ -0,0 +1,23 @@ +USING: accessors arrays colors colors.constants kernel sokoban.board sokoban.piece tools.test ; + +{ { { f f } { f f } { f f } } } [ 2 3 make-rows ] unit-test +{ { { f f } { f f } { f f } } } [ 2 3 rows>> ] unit-test +{ 1 { f f } } [ 2 3 { 1 1 } board@block ] unit-test +{ f } [ 2 3 { 1 1 } block ] unit-test +[ 2 3 { 2 3 } block ] must-fail +{ COLOR: red } [ 2 3 dup { 1 1 } COLOR: red set-block { 1 1 } block ] unit-test +{ t } [ 2 3 { 1 1 } block-free? ] unit-test +{ f } [ 2 3 dup { 1 1 } COLOR: red set-block { 1 1 } block-free? ] unit-test +{ t } [ 2 3 dup { 1 1 } COLOR: red set-block { 1 2 } block-free? ] unit-test +{ t } [ 2 3 dup { 1 1 } COLOR: red set-block { 0 1 } block-free? ] unit-test +{ t } [ 2 3 { 0 0 } block-in-bounds? ] unit-test +{ f } [ 2 3 { -1 0 } block-in-bounds? ] unit-test +{ t } [ 2 3 { 1 2 } block-in-bounds? ] unit-test +{ f } [ 2 3 { 2 2 } block-in-bounds? ] unit-test +{ t } [ 2 3 { 1 1 } location-valid? ] unit-test +{ f } [ 2 3 dup { 1 1 } COLOR: red set-block { 1 1 } location-valid? ] unit-test +! { t } [ 10 10 10 piece-valid? ] unit-test +! { f } [ 2 3 10 { 1 2 } >>location piece-valid? ] unit-test +{ { { f } { f } } } [ 1 1 add-row rows>> ] unit-test +{ { { f } } } [ 1 2 dup { 0 1 } COLOR: red set-block remove-full-rows rows>> ] unit-test +{ { { f } { f } } } [ 1 2 dup { 0 1 } COLOR: red set-block dup check-rows drop rows>> ] unit-test diff --git a/extra/sokoban/board/board.factor b/extra/sokoban/board/board.factor new file mode 100644 index 0000000000..800bf8416e --- /dev/null +++ b/extra/sokoban/board/board.factor @@ -0,0 +1,39 @@ +! Copyright (C) 2006, 2007, 2008 Alex Chapman +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays combinators.short-circuit fry kernel +math sequences sokoban.piece sokoban.layout ; +IN: sokoban.board + +TUPLE: board + { width integer } + { height integer } + { rows array } ; + +: make-rows ( width height -- rows ) + swap '[ _ f ] replicate ; + +: ( width height -- board ) + 2dup make-rows board boa ; + +! A block is simply an array of form { x y } where { 0 0 } is +! the top-left of the sokoban board, and { 9 19 } is the bottom +! right on a 10x20 board. + +: board@block ( board block -- n row ) + [ second swap rows>> nth ] keep first swap ; + +: set-block ( board block color -- ) -rot board@block set-nth ; + +: block ( board block -- color ) board@block nth ; + +: block-free? ( board block -- ? ) block not ; + +: block-in-bounds? ( board block -- ? ) + [ first swap width>> bounds-check? ] + [ second swap height>> bounds-check? ] 2bi and ; + +: location-valid? ( board block -- ? ) + { [ block-in-bounds? ] [ block-free? ] } 2&& ; + +: piece-valid? ( board piece -- ? ) + piece-blocks [ location-valid? ] with all? ; diff --git a/extra/sokoban/deploy.factor b/extra/sokoban/deploy.factor new file mode 100644 index 0000000000..ea8750f6d1 --- /dev/null +++ b/extra/sokoban/deploy.factor @@ -0,0 +1,13 @@ +USING: tools.deploy.config ; +H{ + { deploy-ui? t } + { deploy-threads? t } + { deploy-word-props? f } + { deploy-reflection 1 } + { "stop-after-last-window?" t } + { deploy-io 3 } + { deploy-math? t } + { deploy-word-defs? f } + { deploy-c-types? f } + { deploy-name "sokoban" } +} diff --git a/extra/sokoban/game/game-tests.factor b/extra/sokoban/game/game-tests.factor new file mode 100644 index 0000000000..b5e9736608 --- /dev/null +++ b/extra/sokoban/game/game-tests.factor @@ -0,0 +1,15 @@ +USING: accessors kernel sokoban.game sokoban.board sokoban.piece tools.test +sequences ; + +{ t } [ [ current-piece ] [ next-piece ] bi and t f ? ] unit-test +{ t } [ { 1 1 } can-move? ] unit-test +{ t } [ { 1 1 } sokoban-move ] unit-test +{ 1 } [ dup { 1 1 } sokoban-move drop current-piece location>> second ] unit-test +{ 1 } [ level ] unit-test +{ 1 } [ 9 >>rows level ] unit-test +{ 2 } [ 10 >>rows level ] unit-test +{ 0 } [ 3 0 rows-score ] unit-test +{ 80 } [ 1 1 rows-score ] unit-test +{ 4800 } [ 3 4 rows-score ] unit-test +{ 1 } [ dup 3 score-rows dup 3 score-rows dup 3 score-rows level ] unit-test +{ 2 } [ dup 4 score-rows dup 4 score-rows dup 2 score-rows level ] unit-test diff --git a/extra/sokoban/game/game.factor b/extra/sokoban/game/game.factor new file mode 100644 index 0000000000..fa4cfd1ab2 --- /dev/null +++ b/extra/sokoban/game/game.factor @@ -0,0 +1,119 @@ +! Copyright (C) 2006, 2007, 2008 Alex Chapman +! See http://factorcode.org/license.txt for BSD license. + +USING: accessors combinators kernel lists math math.functions math.vectors +sequences system sokoban.board sokoban.piece sokoban.layout sokoban.sound colors +namespaces locals ; + +IN: sokoban.game + +TUPLE: sokoban + { board } + { player } + { boxes } + { goals } + { engine } + { last-update integer initial: 0 } + { level integer initial: 0 } + { paused? initial: f } + { running? initial: t } ; + +: add-wall-block ( sokoban block -- ) + over [ board>> ] 2dip swap level>> rotate-piece layout>> color>> set-block ; + +: add-walls ( sokoban -- ) + dup swap level>> rotate-piece wall-blocks [ add-wall-block ] with each ; + +:: ( lev w h -- sokoban ) + ! make components + w h :> board + lev :> player + lev :> goals + + ! put components into sokoban instance + sokoban new :> soko + soko player >>player + lev >>level + board >>board + goals >>goals + goals lev >>boxes + soko add-walls ; ! draw walls + + +: ( -- sokoban ) + ! Level 0 sokoban + 0 8 9 ; + +: toggle-pause ( sokoban -- ) + [ not ] change-paused? drop ; + +: can-player-move? ( sokoban move -- ? ) + [ drop board>> ] [ [ player>> clone ] dip move-piece ] 2bi piece-valid? ; + +:: get-adj-box ( soko piece mov -- box ) + ! If the input piece (either a player or another box) has a box at its move location, + ! return the box at the move location. Otherwise, return false + piece location>> :> player_loc + player_loc mov v+ :> next_loc + soko boxes>> :> box_list + box_list [ location>> next_loc = ] find swap drop ; + +:: can-box-move? ( soko box mov -- ? ) + soko box mov get-adj-box :> box2move ! Checks if input box has a box at its move location + box2move + [ ! If there is another box at the move location, the current box is unable to move + f + ] + [ ! Otherwise, we check if there is a wall blocking the box + soko board>> box clone mov move-piece piece-valid? + ] if ; + +:: sokoban-move ( soko mov -- ? ) + ! Collision logic -- checks if player can move and moves the player accordingly + soko mov can-player-move? + [ ! Player can move + soko dup player>> mov get-adj-box :> box2move + box2move + [ ! Next location of player is a box + soko box2move mov can-box-move? + [ ! Next location of player is a box and box is able to move + soko goals>> box2move location>> mov is-goal? + [ ! Next location of box is a goal point + soko player>> mov move-piece drop + box2move mov move-piece + soko engine>> play-beep + "vocab:sokoban/resources/CrateDark_Yellow.png" >>path + layout>> COLOR: blue >>color drop t ! change color once box is on goal + ] + [ ! Next location of box is a free space + soko player>> mov move-piece drop + box2move mov move-piece + layout>> COLOR: orange >>color drop t + ] if + ] + [ ! Next location of player is a box but box cannot move + f + ] if + ] + [ ! Next location of player is a free space, move the player onto the free space + soko player>> mov move-piece drop t + ] if + ] + [ ! Player cannot move + f + ] if ; + +: move-left ( sokoban -- ) dup player>> "vocab:sokoban/resources/CharL.png" >>path drop { -1 0 } sokoban-move drop ; + +: move-right ( sokoban -- ) dup player>> "vocab:sokoban/resources/CharR.png" >>path drop { 1 0 } sokoban-move drop ; + +: move-down ( sokoban -- ) dup player>> "vocab:sokoban/resources/CharF.png" >>path drop { 0 1 } sokoban-move drop ; + +: move-up ( sokoban -- ) dup player>> "vocab:sokoban/resources/CharB.png" >>path drop { 0 -1 } sokoban-move drop ; + +: update-level? ( sokoban -- ? ) + ! Get color color of each box + boxes>> [ layout>> ] map [ color>> ] map + ! All boxes are on correct spots if there are no orange boxes left and level should be updated + [ COLOR: orange ] first swap member? not ; + diff --git a/extra/sokoban/gl/gl.factor b/extra/sokoban/gl/gl.factor new file mode 100644 index 0000000000..b8fe358b9c --- /dev/null +++ b/extra/sokoban/gl/gl.factor @@ -0,0 +1,66 @@ +! Copyright (C) 2006, 2007, 2008 Alex Chapman +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays colors combinators math.vectors +kernel math opengl opengl.gl opengl.textures sequences sokoban.game sokoban.piece images.loader +; + +IN: sokoban.gl + +! OpenGL rendering for sokoban ; + +: draw-block ( block -- ) + { 1 1 } gl-fill-rect ; + +: draw-sprite ( block path -- ) + load-image swap { 1 1 } swap draw-scaled-texture ; + +:: draw-piece-blocks ( piece -- ) + piece piece-blocks [ piece path>> draw-sprite ] each ; + +: draw-piece ( piece -- ) + dup layout>> color>> gl-color draw-piece-blocks ; + +: draw-goal ( block -- ) + { 0.38 0.38 } v+ { 0.24 0.24 } gl-fill-rect ; + +: draw-goal-blocks ( piece -- ) + ! implement goals the same way we do as walls + wall-blocks [ draw-goal ] each ; + +: draw-goal-piece ( piece -- ) + dup layout>> color>> gl-color draw-goal-blocks ; + +! TODO: move implementation specific stuff into sokoban-board +: (draw-row) ( x y row -- ) + overd nth [ gl-color 2array draw-block ] [ 2drop ] if* ; + +: draw-row ( y row -- ) + [ length swap ] keep [ (draw-row) ] 2curry each ; + +: draw-board ( board -- ) + rows>> [ swap draw-row ] each-index ; + +: scale-board ( width height board -- ) + [ width>> ] [ height>> ] bi swapd [ / ] dup 2bi* 1 glScalef ; + +: set-background-color ( sokoban -- ) + dup running?>> [ + paused?>> COLOR: light-gray COLOR: white ? + ] [ drop COLOR: black ] if gl-color ; + +: draw-background ( board -- ) + [ 0 0 ] dip [ width>> ] [ height>> ] bi glRectf ; + +: draw-sokoban ( width height sokoban -- ) + ! width and height are in pixels + [ + { + [ board>> scale-board ] + [ set-background-color ] + [ board>> draw-background ] + [ board>> draw-board ] + [ player>> draw-piece ] + [ goals>> draw-goal-piece ] + [ boxes>> [ draw-piece ] each ] + } cleave + ] do-matrix ; diff --git a/extra/sokoban/layout/layout.factor b/extra/sokoban/layout/layout.factor new file mode 100644 index 0000000000..aaf70b48e9 --- /dev/null +++ b/extra/sokoban/layout/layout.factor @@ -0,0 +1,171 @@ +! Copyright (C) 2006, 2007, 2008 Alex Chapman +! See http://factorcode.org/license.txt for BSD license. +USING: kernel arrays namespaces sequences math math.order +math.vectors colors random ; +IN: gamelib.demos.sokoban.layout + +TUPLE: layout states color ; + +C: layout + +SYMBOL: component + +{ + [ ! walls on each level + { + { + { 2 0 } { 3 0 } { 4 0 } { 5 0 } { 6 0 } + { 0 1 } { 1 1 } { 2 1 } { 6 1 } + { 0 2 } { 6 2 } + { 0 3 } { 1 3 } { 2 3 } { 6 3 } + { 0 4 } { 2 4 } { 3 4 } { 6 4 } + { 0 5 } { 2 5 } { 6 5 } { 7 5 } + { 0 6 } { 7 6 } + { 0 7 } { 7 7 } + { 0 8 } { 1 8 } { 2 8 } { 3 8 } { 4 8 } { 5 8 } { 6 8 } { 7 8 } + } + { ! new level (access it by rotating the level piece) + { 4 0 } { 5 0 } { 6 0 } { 7 0 } { 8 0 } + { 4 1 } { 8 1 } + { 4 2 } { 8 2 } + { 2 3 } { 3 3 } { 4 3 } { 8 3 } { 9 3 } { 10 3 } + { 2 4 } { 10 4 } + { 0 5 } { 1 5 } { 2 5 } { 4 5 } { 6 5 } { 7 5 } { 8 5 } { 10 5 } { 16 5 } { 17 5 } { 18 5 } { 19 5 } { 20 5 } { 21 5 } + { 0 6 } { 4 6 } { 6 6 } { 7 6 } { 8 6 } { 10 6 } { 11 6 } { 12 6 } { 13 6 } { 14 6 } { 15 6 } { 16 6 } { 21 6 } + { 0 7 } { 21 7 } + { 0 8 } { 1 8 } { 2 8 } { 3 8 } { 4 8 } { 6 8 } { 7 8 } { 8 8 } { 10 8 } { 12 8 } { 13 8 } { 14 8 } { 15 8 } { 16 8 } { 21 8 } + { 4 9 } { 10 9 } { 11 9 } { 12 9 } { 16 9 } { 17 9 } { 18 9 } { 19 9 } { 20 9 } { 21 9 } + { 4 10 } { 5 10 } { 6 10 } { 7 10 } { 8 10 } { 9 10 } { 10 10 } + + } + } COLOR: gray + ] + [ ! player position on each level + { + { + { 2 2 } + } + { + { 11 8 } + } + } COLOR: green + ] + [ + { + { + { 1 2 } { 5 3 } { 1 4 } { 4 5 } { 3 6 } { 6 6 } { 4 7 } + } + { + { 19 6 } { 20 6 } + { 19 7 } { 20 7 } + { 19 8 } { 20 8 } + } + } COLOR: pink + ] +} [ first2 ] map component set-global + +SYMBOL: boxes +{ + { ! first box on each level + { + { ! level 0 + { 3 2 } + } + + { ! level 1 + { 5 2 } + } + } COLOR: orange + } + + { ! second box on each level + { + { ! level 0 + { 4 3 } + } + + { ! level 1 + { 7 3 } + } + } COLOR: orange + } + + { ! third box on each level + { + { ! level 0 + { 4 4 } + } + { ! level 1 + { 5 4 } + } + } COLOR: orange + } + + { ! fourth box on each level + { + { ! level 0 + { 4 6 } + } + { ! level 1 + { 8 4 } + } + } COLOR: orange + } + + { ! fifth box on each level + { + { ! level 0 + { 3 6 } + } + { ! level 1 + { 5 7 } + } + } COLOR: orange + } + + { ! sixth box on each level + { + { ! level 0 + { 5 6 } + } + { ! level 1 + { 2 7 } + } + } COLOR: orange + } + + { ! seventh box on each level + { + { ! level 0 + { 1 6 } + } + } COLOR: orange + } + + ! etc +} [ first2 ] map boxes set-global + + +SYMBOL: num-boxes +{ + ! number of boxes -1 of each level + 6 + 5 +} num-boxes set-global + +: get-board ( -- layout ) + component get first ; + +: get-player ( -- layout ) + component get second ; + +: get-box ( n -- layout ) + boxes get nth ; + ! TODO add an n argument and get (n + 1)th + +: get-goal ( -- layout ) + component get third ; + +: get-num-boxes ( n -- m ) + ! outputs how many boxes are on each level, allows for different numbers of boxes per level + num-boxes get nth ; diff --git a/extra/sokoban/piece/piece-tests.factor b/extra/sokoban/piece/piece-tests.factor new file mode 100644 index 0000000000..aff8ba1dba --- /dev/null +++ b/extra/sokoban/piece/piece-tests.factor @@ -0,0 +1,23 @@ +USING: accessors kernel sokoban.tetromino sokoban.piece tools.test sequences arrays namespaces ; + +! Tests for sokoban.tetromino and sokoban.piece, since there's not much to test in sokoban.tetromino + +! these two tests rely on the first level_num of the first tetromino being the +! 'I' tetromino in its vertical orientation. +{ 4 } [ tetrominoes get first states>> first blocks-width ] unit-test +{ 1 } [ tetrominoes get first states>> first blocks-height ] unit-test + +! { { 0 0 } } [ random-tetromino location>> ] unit-test +! { 0 } [ 10 level_num>> ] unit-test + +{ { { 0 0 } { 1 0 } { 2 0 } { 3 0 } } } +[ tetrominoes get first piece-blocks ] unit-test + +{ { { 0 0 } { 0 1 } { 0 2 } { 0 3 } } } +[ tetrominoes get first 1 rotate-piece piece-blocks ] unit-test + +{ { { 1 1 } { 2 1 } { 3 1 } { 4 1 } } } +[ tetrominoes get first { 1 1 } move-piece piece-blocks ] unit-test + +{ 3 } [ tetrominoes get second piece-width ] unit-test +{ 2 } [ tetrominoes get second 1 rotate-piece piece-width ] unit-test diff --git a/extra/sokoban/piece/piece.factor b/extra/sokoban/piece/piece.factor new file mode 100644 index 0000000000..01aca87e0b --- /dev/null +++ b/extra/sokoban/piece/piece.factor @@ -0,0 +1,75 @@ +! Copyright (C) 2006, 2007, 2008 Alex Chapman +! See http://factorcode.org/license.txt for BSD license. +USING: accessors arrays kernel math math.vectors sequences +sokoban.layout lists.lazy namespaces colors +ranges random ; +IN: sokoban.piece + +! The level_num is an index into the layout's states array, +! and the position is added to the layout's blocks to give +! them their location on the sokoban board. If the location is f +! then the piece is not yet on the board. + +TUPLE: piece + { layout layout } + { level_num integer initial: 0 } + { location array initial: { 0 0 } } + { path } ; + +: ( layout -- piece ) + piece new swap >>layout ; + +: (piece-blocks) ( piece -- blocks ) + ! rotates the piece + [ level_num>> ] [ layout>> states>> ] bi nth ; + +: wall-blocks ( piece -- blocks ) + [ (piece-blocks) ] [ location>> ] bi [ v+ ] curry map ; + +: piece-blocks ( piece -- blocks ) + location>> { } 1sequence ; ! literally just returns the location in a sequence + +: set-location ( piece level -- piece ) + ! sets the location of piece to where they are defined in layout + over layout>> states>> nth first >>location ; + +: is-goal? ( goal-piece location move -- ? ) + ! check if next move is a goal or not + v+ swap [ level_num>> ] [ layout>> ] bi states>> nth member? ; + +: ( -- piece ) + get-board ; + +: ( level -- piece ) + get-player swap set-location "vocab:sokoban/resources/CharR.png" >>path ; + + +:: ( box-number goal-piece level -- piece ) + box-number get-box level set-location "vocab:sokoban/resources/Crate_Yellow.png" >>path dup [ layout>> ] [ location>> ] bi + goal-piece swap { 0 0 } is-goal? + [ + COLOR: blue + ] + [ + COLOR: orange + ] if + >>color drop ; + +:: ( goal-piece level -- seq ) + ! get list of boxes on corresponding level + level get-num-boxes [0..b] [ goal-piece level ] map ; + +: (rotate-piece) ( level_num inc n-states -- level_num' ) + [ + ] dip rem ; + +: rotate-piece ( piece inc -- piece ) + over layout>> states>> length + [ (rotate-piece) ] 2curry change-level_num ; + +: ( level -- piece ) + ! rotate goal according to level + get-goal swap rotate-piece ; + + +: move-piece ( piece move -- piece ) + [ v+ ] curry change-location ; diff --git a/extra/sokoban/resources/CharB.png b/extra/sokoban/resources/CharB.png new file mode 100644 index 0000000000..7f94ffa295 Binary files /dev/null and b/extra/sokoban/resources/CharB.png differ diff --git a/extra/sokoban/resources/CharF.png b/extra/sokoban/resources/CharF.png new file mode 100644 index 0000000000..0315373306 Binary files /dev/null and b/extra/sokoban/resources/CharF.png differ diff --git a/extra/sokoban/resources/CharL.png b/extra/sokoban/resources/CharL.png new file mode 100644 index 0000000000..cbf68570e6 Binary files /dev/null and b/extra/sokoban/resources/CharL.png differ diff --git a/extra/sokoban/resources/CharR.png b/extra/sokoban/resources/CharR.png new file mode 100644 index 0000000000..6e21bb3b51 Binary files /dev/null and b/extra/sokoban/resources/CharR.png differ diff --git a/extra/sokoban/resources/CharWalkB.png b/extra/sokoban/resources/CharWalkB.png new file mode 100644 index 0000000000..74d981939f Binary files /dev/null and b/extra/sokoban/resources/CharWalkB.png differ diff --git a/extra/sokoban/resources/CharWalkF.png b/extra/sokoban/resources/CharWalkF.png new file mode 100644 index 0000000000..03d27e184a Binary files /dev/null and b/extra/sokoban/resources/CharWalkF.png differ diff --git a/extra/sokoban/resources/CharWalkL.png b/extra/sokoban/resources/CharWalkL.png new file mode 100644 index 0000000000..465e48b412 Binary files /dev/null and b/extra/sokoban/resources/CharWalkL.png differ diff --git a/extra/sokoban/resources/CharWalkR.png b/extra/sokoban/resources/CharWalkR.png new file mode 100644 index 0000000000..13e717f343 Binary files /dev/null and b/extra/sokoban/resources/CharWalkR.png differ diff --git a/extra/sokoban/resources/CrateDark_Yellow.png b/extra/sokoban/resources/CrateDark_Yellow.png new file mode 100644 index 0000000000..3de69773b7 Binary files /dev/null and b/extra/sokoban/resources/CrateDark_Yellow.png differ diff --git a/extra/sokoban/resources/Crate_Yellow.png b/extra/sokoban/resources/Crate_Yellow.png new file mode 100644 index 0000000000..06c7b993c6 Binary files /dev/null and b/extra/sokoban/resources/Crate_Yellow.png differ diff --git a/extra/sokoban/resources/music.wav b/extra/sokoban/resources/music.wav new file mode 100644 index 0000000000..b0ee9366a1 Binary files /dev/null and b/extra/sokoban/resources/music.wav differ diff --git a/extra/sokoban/resources/once.wav b/extra/sokoban/resources/once.wav new file mode 100644 index 0000000000..3fc85b03d3 Binary files /dev/null and b/extra/sokoban/resources/once.wav differ diff --git a/extra/sokoban/sokoban.factor b/extra/sokoban/sokoban.factor new file mode 100644 index 0000000000..efe91c3ea7 --- /dev/null +++ b/extra/sokoban/sokoban.factor @@ -0,0 +1,98 @@ +! Copyright (C) 2006, 2007, 2008 Alex Chapman +! See http://factorcode.org/license.txt for BSD license. +USING: accessors timers arrays calendar destructors kernel make math math.rectangles +math.parser namespaces sequences system sokoban.game sokoban.layout sokoban.gl sokoban.sound ui.gadgets +ui.gadgets.labels ui.gadgets.worlds ui.gadgets.status-bar ui.gestures +ui.render ui ; +IN: sokoban + +TUPLE: sokoban-gadget < gadget { sokoban sokoban } { timer } { window-dims array initial: { 700 800 } } ; + +: ( sokoban -- gadget ) + create-engine >>engine + sokoban-gadget new swap >>sokoban ; + +:: get-dim ( sokoban level -- level w h ) + ! Look for maximum height and width of wall layout to determine size of board + level component get first states>> nth :> new_board + level + new_board [ first ] map supremum 1 + + new_board [ second ] map supremum 1 + ; + +: new-sokoban ( gadget -- gadget ) + ! Restarts sokoban without changing levels + dup sokoban>> engine>> swap + [ dup level>> get-dim ] change-sokoban + swap over sokoban>> swap >>engine >>sokoban ; + +:: window-size ( sokoban -- window-size ) + sokoban level>> :> level + sokoban level get-dim :> ( lev w h ) + 100 w * :> xpix + 100 h * :> ypix + { xpix ypix } ; + + +: update-sokoban ( gadget -- gadget ) + ! Changes to the next level of sokoban + dup sokoban>> engine>> swap + [ dup level>> 1 + get-dim ] change-sokoban + dup sokoban>> window-size >>window-dims + swap over sokoban>> swap >>engine >>sokoban ; + +M: sokoban-gadget pref-dim* ( gadget -- dim ) + sokoban>> window-size ; + ! drop { 700 800 } ; ! needs to be changed as well + +: update-status ( gadget -- ) + dup sokoban>> [ + [ "Level: " % level>> # ] + [ paused?>> [ " (Paused)" % ] when ] bi + ] "" make swap show-status ; + +M: sokoban-gadget draw-gadget* ( gadget -- ) + [ + [ dim>> first2 ] [ sokoban>> ] bi draw-sokoban + ] keep update-status ; + +: unless-paused ( sokoban quot -- ) + over sokoban>> paused?>> [ + 2drop + ] [ + call + ] if ; inline + +sokoban-gadget H{ + { T{ button-down f f 1 } [ request-focus ] } + { T{ key-down f f "UP" } [ [ sokoban>> move-up ] unless-paused ] } + { T{ key-down f f "LEFT" } [ [ sokoban>> move-left ] unless-paused ] } + { T{ key-down f f "RIGHT" } [ [ sokoban>> move-right ] unless-paused ] } + { T{ key-down f f "DOWN" } [ [ sokoban>> move-down ] unless-paused ] } + { T{ key-down f f "p" } [ sokoban>> toggle-pause ] } + { T{ key-down f f "n" } [ new-sokoban drop ] } +} set-gestures + +: tick ( gadget -- ) + dup sokoban>> update-level? [ + update-sokoban + relayout-window + ] [ + relayout-1 + ] if + ; + +M: sokoban-gadget graft* ( gadget -- ) + dup sokoban>> engine>> play-music + [ [ tick ] curry 100 milliseconds every ] keep timer<< ; + +M: sokoban-gadget ungraft* ( gadget -- ) + dup sokoban>> engine>> dispose + [ stop-timer f ] change-timer drop ; + +: sokoban-window ( -- ) + [ + + "sokoban" open-status-window + ] with-ui ; + +MAIN: sokoban-window \ No newline at end of file diff --git a/extra/sokoban/sound/sound.factor b/extra/sokoban/sound/sound.factor new file mode 100644 index 0000000000..c1b308bd5f --- /dev/null +++ b/extra/sokoban/sound/sound.factor @@ -0,0 +1,27 @@ +! Copyright (C) 2009 Joe Groff. +! See http://factorcode.org/license.txt for BSD license. +USING: accessors timers audio audio.engine audio.loader calendar +destructors io kernel locals math math.functions ranges specialized-arrays +sequences random math.vectors literals ; + + +IN: sokoban.sound + +: create-engine ( -- engine ) + f 10 ; + +:: play-beep ( engine -- ) + $[ "vocab:sokoban/resources/once.wav" read-audio ] :> once-sound + engine start-audio* + + engine T{ audio-source f { 0.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } once-sound f + play-static-audio-clip drop ; + +:: play-music ( engine -- ) + $[ "vocab:sokoban/resources/music.wav" read-audio ] :> loop-sound + engine start-audio* + + engine T{ audio-source f { 0.0 0.0 0.0 } 1.0 { 0.0 0.0 0.0 } f } loop-sound t + play-static-audio-clip drop ; + + diff --git a/extra/sokoban/summary.txt b/extra/sokoban/summary.txt new file mode 100644 index 0000000000..f5e5143269 --- /dev/null +++ b/extra/sokoban/summary.txt @@ -0,0 +1 @@ +Graphical sokoban game diff --git a/extra/sokoban/tags.txt b/extra/sokoban/tags.txt new file mode 100644 index 0000000000..09934571b3 --- /dev/null +++ b/extra/sokoban/tags.txt @@ -0,0 +1,3 @@ +demos +applications +games