Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. Actually, that's supposed to be a function declaration. It's a mistake in the code I gave, but you seemed to have a removed a parenthesis anyway. It should be this: Game.hitTest = function(a, {
  2. I cannot see the issue on your page, but a blue border will appear around images inside links. This will fix that: a img { border: 0; }
  3. You don't need a function, just take the invariants out of the if() statement: // Before the ondition var row = document.createElement("tr"); // Check the condition if (x%2 == 0) { row.setAttribute("class","even"); } // After the condition for (var y in obj) { var column = document.createElement("td"); var data = document.createTextNode(obj[y]); column.appendChild(data); row.appendChild(column); table.appendChild(row); }
  4. What's does "focus" mean in this context? You shouldn't need a string reference when you can reference the object itself. Each object should be self contained and should not reference global variables or objects. Everything that it interacts with should either be a property of that object or a value passed in through one of its methods. The Game object is the only object that's has both the Cowpie and the Target as properties, so it should be the one to take care of checking for collisions between the two. If you actually want the Target to detect its own collisions then you will have to make the array of cowpies a property of the target. Semantically that means that the target owns the cowpies, which I don't believe is correct.
  5. You need CSS. This is a very general rule, but it will work: table, th, td { text-align: center; } The align attribute is deprecated and shouldn't be used.
  6. You should properly indent your code, it's already starting to get messy. What is the purpose of the idTag, directionX and directionY properties? If I were you I would not put the collision detection in the target's update function. Instead I would put it in the main game loop. Do not create any global variables, global variables make code messy. Please read and analyze the code I provided previously and try to learn how to structure your code.
  7. You're still using implementation terms in your requirements. It doesn't really matter if your game uses a <canvas> or not from a user perspective. That's just how it's implemented, it could be done in other ways. How would you describe your game to somebody who knows nothing about programming? That's requirements. Here's an example: I think you misinterpreted the word "object" to mean "objective". By "object" I'm referring to elements of the game, like cowpie and thrower. Your game has four objects: Game, Thrower, Cowpie and Target. We need to define what properties and methods these objects should have and how they interact with each other. I've already started you off with a template of how your game should be designed, I'd like you to start filling in the blanks.
  8. You forgot a closing quote here: "index,follow/>
  9. Google should index all the pages on your site as long as there are links to them (which possibly is not happening currently). Hundreds of thousands is quite a lot, though. If you actually have such a large amount of items in the database I would recommend structuring your data and building your own search feature. Databases are intended to be searched. Having your website built in a tree structure would be easier. Each branch of the tree would be slightly more specific than the last, this is data architecture. Trees are much faster to navigate than lists. Take Canada Computers, for example: www.canadacomputers.com/ Under "Shop Products" they have a set of options, under each of those options they have subcategories. Clicking on a subcategory will take you to a page where products are shown and on the left of the page the category is further divided into more options. An example of one of the paths you can take down the tree is "Laptops, Dektops and Tablets" > "Laptops & Ultrabooks" > "Notebooks" After that, they give you dropdown to filter by "All" or "Best Selling" When you have such a large amount of data, data architecture is important.
  10. It seems you've put most of your requirements under the software design section, while you put part of the description of your current implementation in the requirements section. The requirements should be what somebody who knows nothing about programming would ask you to make. This is going to take a lot of work. You need to reprogram the game with a proper structure. I'm going to go through your descriptions and help you with the design. > Game starts with playing "cheeringCrowd.mp3" . This sounds like you need an object called "Game" with a start() method. That start() method would play a sound. > Soundfiles are loaded into an array here: This could be an array belonging to the Game object > And souds are played here: You haven't described where the playThis parameter comes from, in your sounds array all you have are strings. You can either change the playAudio() method to accept strings a parameter or you can make the sounds array contain Audio objects. > Sprites are loaded into an array here: > cowpies.png are updated in an array here: These arrays can also be a property of the Game object. > Cowpies are created here: > Cowpies are removed here: createCowpie() can and destroyCowpie() can be methods of the Game object > Collision detection occurs here: A collision method could be made here. There are still a lot of requirements missing: You haven't described what the thrower and target are and what they do, I will need you to describe that. You forgot to mention that some objects in the game are moving and haven't described how they move. For this current iteration I will give all objects that can move an update() method. The game needs a game loop, there are two ways to do that: Fixed time loops are done with setInterval() and variable time loops are with requestAnimationFrame. With fixed time loops, you calculate physics based on frames, in variable-time loops you have to calculate the physics based on the time that has passed since the previous loop. You're going to have to decide which one you want to use, until then I can't show you the code for the game loop. In the game loop you should call the update() method of all the objects in the game, so we should add an array of movable objects to the game. From my understanding you have a Cowpie object, a Thrower object and a Target. I will assume these have a position and a size, so at minimum they need x, y, width and height properties. Since they all can move I'll give them an update() method. With your description so far I have created this structure. We can add more once you have refined the requirements: /*****************/ /** Game object **/ /*****************/ var Game = {} /* Properties */ // For drawing Game.canvas = document.getElementById("canvas"); Game.graphics = Game.canvas.getContext("2d"); // Sounds Game.sounds = { splat : new Audio("sounds/CowMooSplat.mp3"), goodbye : new Audio("sounds/GoodBye-Female.mp3"), cheering : new Audio("sounds/cheeringCrowd.mp3"), oops : new Audio("sounds/oops.mp3") }; // Movable objects Game.cowpies = []; Game.thrower = new Thrower(document.getElementById("thrower"), 0, 0); Game.target = new Target(document.getElementById("lie02"), 128, 24) /* Methods */ // Play a sound Game.playSound = function(sound) { sound.play(); } // Detect a rectangular collision between two objects Game.hitTest(a, { return a.x <= b.x + b.width && a.x + a.width >= b.x && a.y <= b.y + b.height && a.y + a.height >= b.y; } // Create or detroy cowpies Game.createCowpie = function() { cowpies.push(new Cowpie()); } Game.destroyCowpie = function(cowpie) { // Play sound Game.playSound(Game.sounds.splat); // Remove from cowpies var count = Game.cowpies.length; var destroyed = false; for(var i = 0; i < count && !destroyed; i++) { if(Game.cowpies[i] == cowpie) { destroyed = true; Game.cowpies.splice(i, 1); } } } // Starts up the game Game.start = function() { // Start by playing the cheering sound playSound(Game.sounds.cheering); // Then begin the game loop, this code depends on what kind of loop you're using } // Ends the game Game.end() { // Stop the game loop, this code depends on what kind of loop you're using. } // This is the game loop Game.gameLoop = function() { // Loop through objects and update them var amount = Game.cowpies.length; var cowpie; for(var i = 0; i < amount; i++) { cowpie = Game.cowpies[i]; cowpie.update(); } thrower.update(); target.update(); // Detect collisions and do something // // // Draw everything context.clearRect(0, 0, Game.canvas.width, Game.canvas.height); for(var i = 0; i < amount; i++) { cowpie = Game.cowpies[i]; cowpie.draw(); } thrower.draw(); target.draw(); } /*********************/ /** Movable objects **/ /*********************/ /* Cowpie */ function Cowpie(sprite, x, y) { this.sprite = sprite; this.x = x; this.y = y; this.width = sprite.width; this.height = sprite.height; // Update position based on requirements this.update = function() { } // Draw the sprite this.draw = function() { Game.context.drawImage(this.sprite, this.x, this.y, this.width, this.height); } } /* Thrower */ function Thrower(sprite, x, y) { this.sprite = sprite; this.x = x; this.y = y; this.width = sprite.width; this.height = sprite.height; // Update position based on requirements this.update = function() { } // Draw the sprite this.draw = function() { Game.context.drawImage(this.sprite, this.x, this.y, this.width, this.height); } } /* Target */ function Target(x, y) { this.x = x; this.y = y; this.width = sprite.width; this.height = sprite.height; // Update position based on requirements this.update = function() { } // Draw the sprite this.draw = function() { Game.context.drawImage(this.sprite, this.x, this.y, this.width, this.height); } }
  11. $(form) is not defined, because you defined it inside an anonymous function, so it's not available outside You should put the event listener inside the anonymous function.
  12. You have to target that element rather than one of its ancestors. In your case, since they're both <p> elements .aaa p would work as a selector.
  13. There are two things you need to start off: 1. The requirements 2. The software design The requirements would be a description of exactly how the game is supposed to look from a user's perspective, with all the details. For the software design, it would be good enough to make a diagram of all the objects in the game, their properties and how they interact with each other.
  14. Did you spend any time designing this software before beginning the implementation phase? I'd like to see the structure of your program, because it's really hard to tell what it's supposed to be from just the source code.
  15. Forget the min-height property, you don't need it and it's going to mess things up.
  16. Remove this line: height: 700px !important; It's forcing the image to be 700px tall no matter what the width is. Also, setting min-height to 700px and width to 100% will probably force some of the flatter images to distort in order to meet your requirements. What you should do is open all these images in an image editor and crop them all to be the exactly same size.
  17. That's because you've set the width to 100%. It's forcing the image to be 100% wide while also being 700px tall, which will change the aspect ratio.
  18. Style the span and a elements, not the list items. .pagination li span, .pagination li a { display: block; width: 1.5em; height: 1.5em; line-height: 1.5em; text-align: center; border-radius: 0.75em; color: white; background-color: blue; } .pagination .active span { background-color: red; }
  19. But on the server-side, PHP would not be able to access all the values of n. I would recommend using n[] instead so that it would be accessible as an array. Anyways, here's what you have to do: 1. When the button is clicked, check all of the checkboxes to see which ones are active and which ones are not, keep a count and store their values. 2. Generate the URL with the data you have collected. Using jQuery for this is overkill. A whole library for just a few lines of basic code is inefficient. document.getElementById("btnSearch").addEventListener("click", generateURL, false); function generateURL(e) { // var urls = []; urls[1] = "http://example.com/results?choice="; urls[2] = "http://domain.com/results?choice="; urls[3] = "http://url.com/results?choice="; // Get all the checkboxes var checkboxes = document.getElementsByName("n"); // Compile information var count = 0; var values = []; var checkbox; for(var i = 0; i < checkboxes.length; i++) { checkbox = checkboxes[i]; if(checkbox.checked) { count++; values.push(checkbox.value); } } // Generate the URL if(count > 0 && count < urls.length) { // Get base URL var url = urls[count]; url += String(count); // Add Ns for(var j = 0; j < values.length; j++) { url += "&n[]=" + values[j]; } // Display the URL alert(url); } }
  20. Why is n 3 rather than 2 when the values of the boxes are 2 and 3? Does it always select the highest value?
  21. The ::before and ::after pseudo-elements need to have the content property set selector::before { content: ""; }
  22. Set the <span> and <a> elements in the list to be blocks. Give them a fixed width and height that are both the same then set the border-radius to half that width. Give them a background color or a border, whichever you prefer. Use the .active span selector to set the span to be red.
  23. That line of code creates the variable (reserves space in the computer's memory) and tells it to be a string with no content in it. As dsonsuk said, try removing that line and see what shows up in the browser's Javascript console (most browsers let you access the console by pressing F12)
  24. You should test your PHP without AJAX first, or at least check the developer console to see exactly what's being returned in the AJAX request.
  25. It says you're not using a password, so $password must be empty. Put var_dump() right before the connection to see if the variables have the value you expected them to. var_dump($servername, $username, $password, $dbname); $db_con = new mysqli($servername,$username,$password,$dbname);
×
×
  • Create New...