Worms source code game




















EMBED for wordpress. Want more? Advanced embedding details, examples, and help! The game was published by Electronic Arts in , but the printout seems to be from Maynard retained copyright to the code and has allowed me to share it here. There seem to be several versions in the printout stacks. I have bundled the files in the same manner that David provided the printouts. That is, each unbroken stack of sheetfed paper is in its own file. David has donated the original printouts to The Strong Museum of Play.

We start right at the basics and teach you everything you need to know to get started with Linux. The largest compilation of the best free and open source software in the universe. Each article is supplied with a legendary ratings chart helping you make informed decisions. Hundreds of in-depth reviews offering our unbiased and expert opinion on software. We offer helpful and impartial information. Alternatives to Google's Products and Services examines your options to migrate from the Google ecosystem with open source Linux alternatives.

Alternatives to Microsoft's Products and Services recommends open source Linux software. Alternatives to Adobe Cloud looks at free and open source alternatives to products available from Adobe Cloud's subscription service.

Alternatives to Apple recommends free and open source alternatives to Apple's proprietary world. Alternatives to Corel surveys alternatives to Corel's range of graphics processing products and other software applications. Getting Started with Docker helps you master Docker, a set of platform as a service products that delivers software in packages called containers.

Essential Linux system tools focuses on small, indispensable utilities, useful for system administrators as well as regular users. Rotating degrees is rotating the image all the way around, which means you end up with the same image as if you rotated it 0 degrees. In fact, if the rotation argument you pass to pygame. This image shows several examples of different rotation amounts:. This animation loop will keep looping until checkForKeyPress returns a value that is not None , which happens if the player presses a key.

Before returning, pygame. You may wonder why we store the rotated Surface in a separate variable, rather than just overwrite the titleSurf1 and titleSurf2 variables. There are two reasons. First, rotating a 2D image is never completely perfect.

The rotated image is always approximate. If you rotate an image by 10 degrees counterclockwise, and then rotate it back 10 degrees clockwise, the image you have will not be the exact same image you started with. Think of it as making a photocopy, and then a photocopy of the first photocopy, and the another photocopy of that photocopy. If you keep doing this, the image gets worse and worse as the slight distortions add up.

The only exception to this is if you rotate an image by a multiple of 90 degrees, such as 0, 90, , , or degrees. In that case, the pixels can be rotated without any distortion. Second, if you rotate a 2D image then the rotated image will be slightly larger than the original image. If you rotate that rotated image, then the next rotated image will be slightly larger again. If you keep doing this, eventually the image will become too large for Pygame to handle, and your program will crash with the error message, pygame.

On each iteration through the animation loop, we increase the number stored in degrees1 by 3 and degrees2 by 7. This is why the one of the Surface objects rotates slower than the other. The terminate function calls pygame. It is identical to the terminate functions in the previous game programs. The getRandomLocation function is called whenever new coordinates for the apple are needed. This function returns a dictionary with keys 'x' and 'y' , with the values set to random XY coordinates.

The Game Over text will stay on the screen until the player pushes a key. The argument stands for a millisecond pause, which is half of one second.

Then, checkForKeyPress is called so that any key events that were made since the showGameOverScreen function started are ignored.

This pause and dropping of the key events is to prevent the following situation: Say the player was trying to turn away from the edge of the screen at the last minute, but pressed the key too late and crashed into the edge of the board.

If this happens, then the key press would have happened after the showGameOverScreen was called, and that key press would cause the game over screen to disappear almost instantly. The next game would start immediately after that, and might take the player by surprise. The code to draw the score, worm, apple, and grid are all put into separate functions.

The drawScore function simply renders and draws the text of the score that was passed in its score parameter on the display Surface object.

The segments are passed in the wormCoords parameter, which is a list of dictionaries each with an 'x' key and a 'y' key. The for loop on line loops through each of the dictionary values in wormCoords. Because the grid coordinates take up the entire window and also begin a 0, 0 pixel, it is fairly easy to convert from grid coordinates to pixel coordinates. Line creates a Rect object for the worm segment that will be passed to the pygame.

Line draws a dark green rectangle for the segment. Then on top of this, a smaller bright green rectangle is drawn. This makes the worm look a little nicer. The inner bright green rectangle starts 4 pixels to the right and 4 pixels below the topleft corner of the cell. The width and height of this rectangle are 8 pixels less than the cell size, so there will be a 4 pixel margin on the right and bottom sides as well.

The drawApple function is very similar to drawWorm , except since the red apple is just a single rectangle that fills up the cell, all the function needs to do is convert to pixel coordinates which is what lines and do , create the Rect object with the location and size of the apple line , and then pass this Rect object to the pygame.

Just to make it easier to visualize the grid of cells, we call pygame. Normally, to draw the 32 vertical lines needed, we would need 32 calls to pygame.

Instead of typing out all these lines of code, we can just have one line of code inside a for loop. Notice that the pattern for the vertical lines is that the X coordinate of the start and end point starts at 0 and goes up to , increasing by 20 each time.

That means the for loop should iterate over range 0, , The Y coordinate ranges from 0 to , increasing by 20 each time. Noticing regular patterns needed by the calls and using loops is a clever programmer trick to save us from a lot of typing.

We could have typed out all 56 pygame. But by being a little bit clever, we can save ourselves a lot of work. After all the functions and constants and global variables have been defined and created, the main function is called to start the game.

Take a look at a few lines of code from the drawWorm function again:.



0コメント

  • 1000 / 1000