Skip to content
Sign UpLog In
Profile icon

Keeg

@Keegooo
Repls
Community
Keegooo
Keegooo
shared a Post
4 years ago
Both buttons at once
How would I make it so I am able to move in both directions at the same time? Making me go diagonal https://repl.it/@Keegooo/ThoroughNumbDisks
ArchieMaclean
ArchieMaclean
On lines 52-60 the current code is: if (keysPressed[KEY_S]) { player1Y += 20; } else if (keysPressed[KEY_W]) { player1Y -= 20; } else if (keysPressed[KEY_A]) { player1X -= 20; } else if (keysPressed[KEY_D]) { player1X += 20; }; Basically that goes through each key and checks if it is pressed. However, if one of the earlier keys is pressed, then the later key will be ignored (because they are else if statements). To stop later ones being ignored, you can change the code 4 years ago
ArchieMaclean
ArchieMaclean
The link doesn't seem to be working...have you changed the filename?4 years ago
Keegooo
Keegooo
shared a Post
4 years ago
from my point of view everything seems right and it should be working but its not any clue why? https://repl.it/@Keegooo/ThoroughNumbDisks
ArchieMaclean
ArchieMaclean
Currently, the if statement is only running once. To run in continually, you need to put it in a function and have a setInterval, like this: function mainLoop() { if (keysPressed[KEY_S] === true) { console.log(player1X); player1X += 20; }; ctx.fillRect(player1X, player1Y, 75, 75); } setInterval(mainLoop,100); This will run it every 100 milliseconds (you can change that value if you want) Hope this helped. Please upvote if it did :)4 years ago
Keegooo
Keegooo
shared a Post
4 years ago
I'm making a pong game and i'm trying to make it so you can set your paddle color using an <INPUT TYPE="radio" in my HTML although it is not working.
abc3354
abc3354
Hi ! Your problem is quite simple, but if you don't have any idea about this problem, you can spend hours trying to resolve it. ;) In fact this line of code : var a = document.forms"player1Color".value; is at the beginning of your script, so it will be executed when your page is loaded, when the user didn't select anything. You have two basic solutions : Solution A Set a in myGameLoop : a = document.forms"player1Color".value || "blue"; The || "blue" is in case no value is selected Solutio4 years ago
ArchieMaclean
ArchieMaclean
Ok, here is my solution: In script.js add this at the start: var bat1colour = "#FFFFFF" var bat2colour = "#FFFFFF" function setBatColour(bat,colour) { if (bat==1) { bat1colour=colour; } else if (bat==2) { bat2colour = colour; }; }; Then in function myGameLoop() change: // Drawing Left Paddle ctx.fillStyle = bat1colour; ctx.fillRect(5, paddleYLeft, 10, 75); // Drawing Right Paddle ctx.fillStyle = bat2colour; ctx.fillRect(785, paddleYRight, 10, 75); Finally in the HTML, for each 4 years ago
TheDrone7
TheDrone7
As far as I've seen your repl, there was no changeBG function, also you will have to call it in every radio button's onclick event and you should call a function this way: onclick='changeBG() not onclick=changeBG.4 years ago
Keegooo
Keegooo
shared a Post
4 years ago
Every time I do the function it always results in a chickenCount = 0. I've tried multiple ways to fix this but can't pinpoint it. Help would be greatl
SPQR
SPQR
Essentially it's just going down the list, it doesn't actually associate your if statements with your chickenCount modifiers.4 years ago
SPQR
SPQR
I'm not entirely familiar with JS, but the problem that stands out to me is that you don't have the chickenCount = 0 inside curly braces {}. So, the program isn't actually doing chickenCount = 0 only if gamble < 0.5, it's multiplying it by 2 and then setting it to zero every time regardless of gamble's value.4 years ago
JackFly26
JackFly26
I think I fixed it at https://repl.it/@ThatSmart/click4 years ago
Keegooo
Keegooo
shared a Post
4 years ago
I keep getting this error and i've looked over my code multiple times but I can't seem to find an error in the code. Help would be greatly appreciated
Geocube101
Geocube101
Unbalanced Curly Brackets Function on line 39 was not closed4 years ago
Keegooo
Keegooo
shared a Post
4 years ago
I keep getting this error and i've looked over my code multiple times but I can't seem to find an error in the code. Help would be greatly appreciated
Vandesm14
Vandesm14
On line 14, there is an extra space between Eleme and ntById On line 19 and 20 there are missing semicolons Other than that everything should work :) > Please upvote this if it helped you out4 years ago