2011年10月17日星期一

Moncler Jackets UK Bears love to play and mushrooms ( 2 )

http://jacebook.co.uk/blog/2010/09/11/html5-writing-a-game/ --- Jason Croucher's blog html5 dedication Chinese net ---



expected to achieve the desired effect: http://www.html5china.com/html5games/mogu/index3.html

one to write a collision handler

JavaScript Code Copy to clipboard

function HasAnimalHitEdge () {/ / Bear hit the right border if (animal.x> screenWidth - animal.image.width) {if (horizontalSpeed> 0) / / if the right move horizontalSpeed ​​=- horizontalSpeed ; / / change the direction of the horizontal velocity} / / Bear left across the border if (animal.x <-10) {if (horizontalSpeed ​​<0) / / if left horizontalSpeed ​​=-horizontalSpeed; / / change the direction of the horizontal velocity} / / Bear get the following boundary if (animal.y> screenHeight - animal.image.height) {/ / 2 seconds and start again setTimeout (function () {horizontalSpeed ​​= speed; verticalSpeed ​​=-speed; animal.x = parseInt (screenWidth / 2); animal.y = parseInt (screenHeight / 2); gameLoop ();}, 2000);} / / Bear hit above the border if (animal.y <0) {verticalSpeed ​​=-verticalSpeed;}} Second, the game loop GameLoop () to add the rear boundary function testing, as

JavaScript Code Copy to clipboard

function GameLoop () {/ / clear the screen ctx.clearRect (0,Moncler Jackets UK, 0, screenWidth, screenHeight); ctx.save (); / / draw the background ctx.drawImage (backgroundForestImg,Moncler Jackets UK, 0,Moncler Jackets UK, 0); / / draw mushrooms ctx.drawImage (mushroom.image, mushroom.x, mushroom.y); / / draw the Bear / / change the X and Y position of the mobile animals animal.x + = horizontalSpeed; animal.y + = verticalSpeed; / / change roll angle animal.angle + = bearAngle; / / center of the current bear as the base ctx.translate (animal.x + (animal.image.width / 2), animal.y + (animal.image.height / 2) ); / / the angle of rotation according to the current bear ctx.rotate (animal.angle * Math.PI/180); / / description Bear ctx.drawImage (animal.image, - (animal.image.width / 2), - ( animal.image.height / 2)); ctx.restore (); / / test whether the encounter boundary HasAnimalHitEdge ();} The complete code for this fourth round is as follows:

folding XML / HTML Code Copy to clipboard

Chinese mushrooms moving-html5 Network < ; body>
support html5 browser to watch
talked about this on the fourth round, the fifth round of the event about bears collision mushrooms

fifth round of the major stresses encountered mushrooms bear up a rebound effect after

1 条评论:

  1. Moncler Vest are moncler jackets uk respected garment of men. People prefer to clothes these kind of vests with cracking open interlude associated with winters but additionally these types of go moncler uk within mid winter seasons. Differing people have got release feelings to erosion the actual vests. Even so prior to buying any

    回复删除