-
stage size
Hi, I recently had some trouble with re-sizing the stage for a game. It's a snake game, and when I re-sized the stage by modifying the document, my snake wouldn't go all the way to the other side of the stage, the borders stayed in the middle. How would I go about re-sizing it and making the snake go all away across the stage? Thank you very much!
snakeGame.fla
-
.
Hi,
Firstly you might want to change your publish settings to AS2 and higher the flah player settings.
Turn the yellow box into a movieclip and call it "board" no qoutes.
We are making this into a movieclip as the height and width are different to the stage height and width.
PHP Code:
var unit:Number = 15; var uwh:Number = 20; var canMove:Boolean = false; var dir:Number = 2; var score:Number = 0;
var maxX:Number = Math.round(board._width / unit); trace(maxX); var maxY:Number = Math.round(board._height / unit); trace(maxY);
var aPieceList:Array = new Array();
var mouseListener:Object = new Object(); mouseListener.onMouseDown = function() { if (!canMove) { canMove = true; startGame(); } }; Mouse.addListener(mouseListener);
var k:Object = new Object(); k.onKeyDown = function() { var k = Key.getCode(); if (k == Key.UP && dir != 2 && canMove) { dir = 0; canMove = false; } else if (k == Key.LEFT && dir != 3 && canMove) { dir = 1; canMove = false; } else if (k == Key.DOWN && dir != 0 && canMove) { dir = 2; canMove = false; } else if (k == Key.RIGHT && dir != 1 && canMove) { dir = 3; canMove = false; } }; Key.addListener(k);
function addPiece() { var p = this.attachMovie("piece", "piece" + aPieceList.length, aPieceList.length); p._x = aPieceList[aPieceList.length - 1]._x; p._y = aPieceList[aPieceList.length - 1]._y; aPieceList.push(p); }
function moveFood() { var moveIt:Boolean = true; while (moveIt) { food._x = Math.floor(Math.random() * uwh) * unit; food._y = Math.floor(Math.random() * uwh) * unit; moveIt = false; for (var i = 0; i < aPieceList.length; i++) { if (aPieceList[i]._x == food._x && aPieceList[i]._y == food._y) { moveIt = true; } } } }
function gameOver() { delete this.onEnterFrame; tScore.text = "You Lose. Score: " + score; canMove = false; }
function startGame() { for (var i:Number = aPieceList.length - 1; i >= 0; i--) { aPieceList[i].removeMovieClip(); aPieceList.pop(); } score = 0; var p:MovieClip = this.attachMovie("piece", "piece" + aPieceList.length, aPieceList.length); aPieceList.push(p);
p._x = 10 * unit; p._y = 10 * unit;
var food:MovieClip = this.attachMovie("food", "food", -1); var c:Number = 0;
moveFood();
var startingLength:Number = 3;
for (var i:Number = 1; i < startingLength; i++) { addPiece(); }
this.onEnterFrame = function() { canMove = true; tScore.text = score; for (var i = aPieceList.length - 1; i > 0; i--) { aPieceList[i]._x = aPieceList[i - 1]._x; aPieceList[i]._y = aPieceList[i - 1]._y; } if (dir == 0) { aPieceList[0]._y -= unit; } else if (dir == 1) { aPieceList[0]._x -= unit; } else if (dir == 2) { aPieceList[0]._y += unit; } else if (dir == 3) { aPieceList[0]._x += unit; } if (aPieceList[0]._y / unit == maxY) { aPieceList[0]._y = 0; } else if (aPieceList[0]._y / unit == -1) { aPieceList[0]._y = 19 * unit; } else if (aPieceList[0]._x / unit == -1) { aPieceList[0]._x = 19 * unit; } else if (aPieceList[0]._x / unit == maxX) { aPieceList[0]._x = 0; }
if (aPieceList[0]._x == food._x && aPieceList[0]._y == food._y) { score += 10 * aPieceList.length / 2; moveFood(); addPiece(); }
for (var i = 1; i < aPieceList.length; i++) { if (aPieceList[0]._x == aPieceList[i]._x && aPieceList[0]._y == aPieceList[i]._y) { gameOver(); } } }; }
-
When I did that, the borders stayed the same when the snake was moving across the screen, but when I moved up or down the snake just disappeared forever
-
.
Hi,
You must be doing something differently then, attach the newer version fla that you have done
-
.
Hi,
Width and height of board for best results should be divisible by unit var, which is 15 in this case.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|