Advertisement
Guest User

Untitled

a guest
May 12th, 2024
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. let gameStarted = false;
  2. let startButton;
  3. let characterX = 210; //starting position of aiden x
  4. let characterY = 200;
  5.  
  6. function setup() {
  7. createCanvas(700, 500);
  8. //start button
  9. startButton = createButton("Play");
  10. startButton.position(700, 500);
  11. startButton.mousePressed(startGame);
  12. }
  13. // start the game
  14. function startGame() {
  15. gameStarted = true;
  16. startButton.hide();
  17. }
  18. function draw() {
  19. background(0); // background menu
  20.  
  21. // If game is not started, display menu
  22. if (!gameStarted) {
  23. displayMenu();
  24. } else {
  25. // If game is started, display the game
  26. bedroomAiden();
  27. updateCharacterPosition();
  28. drawCharacter(characterX, characterY);
  29. checkCollisionsFloor();
  30. checkDoorInteraction();
  31. }
  32. }
  33.  
  34. // Function to display the menu
  35. function displayMenu() {
  36. textAlign(CENTER);
  37. fill(255);
  38. textSize(15);
  39. textFont("Courier");
  40. text("Aiden is a boy, whose beloved sister disapears one day,\n without saying last goodbye.\n The only sign is the letter left on the desk in his room.\n Aiden has to find out what happened and where is Ellie...", 350, 200);
  41. }
  42.  
  43. function bedroomAiden() {
  44. strokeWeight(0);
  45. // room block
  46. fill(134, 186, 104);
  47. rect(180, 100, 300);
  48. //floor
  49. fill(191, 137, 67);
  50. rect(180, 196, 300, 204);
  51. //door
  52. fill(94, 76, 38);
  53. rect(408, 136, 36, 60);
  54. fill(230);
  55. rect(412, 166, 3);
  56. //bed
  57. fill(230);
  58. rect(192, 172, 60, 24);
  59. fill(255);
  60. rect(204, 178, 36, 12);
  61. fill(210);
  62. rect(192, 190, 60, 6);
  63. fill(107, 166, 176);
  64. rect(192, 196, 60);
  65. fill(97, 156, 166);
  66. rect(192, 256, 60, 6);
  67. fill(94, 76, 38);
  68. rect(192, 262, 12);
  69. rect(240, 262, 12);
  70. //nightstand
  71. rect(258, 178, 24, 24);
  72. fill(124, 106, 68);
  73. rect(260, 180, 20, 6);
  74. rect(260, 188, 20, 12);
  75. fill(94, 76, 38);
  76. rect(268, 182, 4, 2);
  77. rect(268, 192, 4, 2);
  78. //rug
  79. fill(117, 46, 46);
  80. rect(300, 256, 72);
  81. rect(296, 256, 4, 72);
  82. rect(292, 268, 4, 48);
  83. rect(288, 280, 4, 24);
  84. rect(300, 328, 72, 4);
  85. rect(312, 332, 48, 4);
  86. rect(324, 336, 24, 4);
  87. rect(372, 256, 4, 72);
  88. rect(376, 268, 4, 48);
  89. rect(380, 280, 4, 24);
  90. rect(300, 252, 72, 4);
  91. rect(312, 248, 48, 4);
  92. rect(324, 244, 24, 4);
  93. //wardrobe
  94. fill(94, 76, 38);
  95. rect(300, 136, 88);
  96. fill(124, 106, 68);
  97. rect(304, 140, 38, 80);
  98. rect(346, 140, 38, 80);
  99. fill(94, 76, 38);
  100. rect(332, 180, 6, 4);
  101. rect(350, 180, 6, 4);
  102. //desk
  103. fill(50);
  104. rect(432, 268, 48, 72);
  105. rect(432, 340, 12, 24);
  106. rect(468, 340, 12, 24);
  107. fill(30);
  108. rect(432, 340, 48, 6);
  109. //desk-stuff
  110. fill(230);
  111. rect(428, 292, 4);
  112. rect(432, 288, 4, 12);
  113. rect(436, 284, 4, 20);
  114. rect(440, 280, 4, 20);
  115. rect(444, 284, 4, 12);
  116. rect(448, 288, 4);
  117. fill(148, 40, 40);
  118. rect(440, 316, 20, 12);
  119. fill(128, 20, 20);
  120. rect(440, 328, 20, 4);
  121. fill(39, 118, 10);
  122. rect(440, 332, 20, 4);
  123. //chair
  124. fill(50);
  125. rect(402, 312, 24);
  126. rect(398, 296, 4, 16);
  127. rect(398, 336, 4, 24);
  128. rect(422, 336, 4, 24);
  129. fill(30);
  130. rect(398, 312, 4, 24);
  131. rect(398, 336, 28, 4);
  132. //car
  133. fill(26, 36, 176);
  134. rect(208, 350, 24, 8);
  135. rect(200, 358, 40, 8);
  136. fill(235, 233, 127);
  137. rect(236, 358, 4);
  138. fill(0);
  139. rect(212, 354, 16, 4);
  140. rect(208, 362, 8);
  141. rect(224, 362, 8);
  142. //poster
  143. fill(0);
  144. rect(204, 112, 36, 48);
  145. fill(255, 0, 0);
  146. rect(220, 144, 4, 2);
  147. rect(218, 142, 8, 2);
  148. rect(216, 140, 12, 2);
  149. rect(214, 134, 16, 6);
  150. rect(214, 132, 7, 2);
  151. rect(223, 132, 7, 2);
  152. rect(215, 131, 1);
  153. rect(228, 131, 1);
  154. rect(217, 131, 2, 1);
  155. rect(224, 131, 2, 1);
  156. rect(216, 130, 2);
  157. rect(226, 130, 2);
  158. }
  159.  
  160. function drawCharacter(x, y) {
  161. //Aiden look
  162. fill(0); //tshirt actually
  163. strokeWeight(0);
  164. //body
  165. rect(x, y, 20, 14);
  166. //head
  167. fill(255, 228, 181); //skin
  168. rect(x, y - 15, 20, 15);
  169. //legs
  170. rect(x, y + 20, 5, 10);
  171. rect(x + 15, y + 20, 5, 10);
  172. //hands
  173. rect(x - 3, y + 5, 3, 10);
  174. rect(x + 20, y + 5, 3, 10);
  175. //shoes
  176. fill(0);
  177. rect(x, y + 26, 5, 5);
  178. rect(x + 15, y + 26, 5, 5);
  179. //pants
  180. fill(0, 102, 51);
  181. rect(x, y + 14, 20, 4);
  182. rect(x, y + 18, 9, 3);
  183. rect(x + 11, y + 18, 9, 3);
  184. //eyes
  185. fill(0);
  186. rect(x + 4, y - 10, 2, 2);
  187. rect(x + 14, y - 10, 2, 2);
  188. //hair
  189. rect(x - 1, y - 15, 3, 5);
  190. rect(x + 18, y - 15, 3, 5);
  191. rect(x + 14, y - 15, 4, 4);
  192. rect(x + 1, y - 15, 4, 4);
  193. //hat
  194. fill("red");
  195. rect(x, y - 20, 20, 4);
  196. rect(x - 1, y - 17, 10, 4);
  197. rect(x + 11, y - 17, 10, 4);
  198. //mouth
  199. fill(0);
  200. rect(x + 8, y - 5, 4, 1);
  201. //tshirt image
  202. fill("yellow");
  203. rect(x + 6, y + 4, 2, 2);
  204. rect(x + 7, y + 4, 2, 7);
  205. rect(x + 10, y + 4, 4, 2);
  206. rect(x + 10, y + 6, 2, 2);
  207. rect(x + 12, y + 7, 1, 1);
  208. rect(x + 12, y + 8, 1, 2);
  209. rect(x + 10, y + 9, 3, 2);
  210. //sleeves
  211. fill(0);
  212. rect(x + 20, y + 2, 3, 6);
  213. rect(x - 3, y + 2, 3, 6);
  214. }
  215.  
  216. //movement
  217. let moveSpeed = 2.3;
  218. let movingUp = false;
  219. let movingDown = false;
  220. let movingLeft = false;
  221. let movingRight = false;
  222. //movement WSAd
  223. function updateCharacterPosition() {
  224. if (movingUp) {
  225. characterY -= moveSpeed;
  226. }
  227. if (movingDown) {
  228. characterY += moveSpeed;
  229. }
  230. if (movingLeft) {
  231. characterX -= moveSpeed;
  232. }
  233. if (movingRight) {
  234. characterX += moveSpeed;
  235. }
  236. }
  237. function keyPressed() {
  238. if (key === "w") {
  239. movingUp = true;
  240. } else if (key === "s") {
  241. movingDown = true;
  242. } else if (key === "a") {
  243. movingLeft = true;
  244. } else if (key === "d") {
  245. movingRight = true;
  246. }
  247. }
  248. function keyReleased() {
  249. if (key === "w") {
  250. movingUp = false;
  251. } else if (key === "s") {
  252. movingDown = false;
  253. } else if (key === "a") {
  254. movingLeft = false;
  255. } else if (key === "d") {
  256. movingRight = false;
  257. }
  258. }
  259. //floor collision
  260. let floorX = 180;
  261. let floorY = 196;
  262. let floorWidth = 300;
  263. let floorHeight = 204;
  264.  
  265. function checkCollisionsFloor() {
  266. if (characterX < floorX) {
  267. characterX = floorX;
  268. } else if (characterX > floorX + floorWidth - 20) {
  269. characterX = floorX + floorWidth - 20;
  270. }
  271. if (characterY < floorY) {
  272. characterY = floorY;
  273. } else if (characterY > floorY + floorHeight - 36) {
  274. characterY = floorY + floorHeight - 36;
  275. }
  276. }
  277. let doorX = 408;
  278. let doorY = 136;
  279. let doorWidth = 36;
  280. let doorHeight = 60;
  281.  
  282. function checkDoorInteraction() {
  283. let distanceToDoor = dist(characterX, characterY, doorX + doorWidth / 2, doorY + doorHeight / 2);
  284. if (distanceToDoor < 10) {
  285. fill(255);
  286. textSize(15);
  287. text("Press 'R' to open the door", doorX + doorWidth / 2, doorY + doorHeight + 20);
  288. if (keyIsPressed && key === 'r') {
  289. console.log("Door interaction detected!"); // For debugging purposes
  290. // window.location.href = "hallway.html"; // Uncomment this line when ready to navigate to the hallway
  291. }
  292. }
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement