0% found this document useful (0 votes)
61 views5 pages

Principios para Juuegos en Flash

This document provides instructions for creating a character and game world in Flash. It discusses setting up character movement and collision detection with the game world boundaries using enterFrame events. Key listeners are added to control character movement based on arrow keys. The game involves a snake character that grows in length by eating food pieces that are randomly placed in the game world. The player loses if the snake runs into itself. Score is tracked based on the length of the snake.

Uploaded by

cesarsucari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views5 pages

Principios para Juuegos en Flash

This document provides instructions for creating a character and game world in Flash. It discusses setting up character movement and collision detection with the game world boundaries using enterFrame events. Key listeners are added to control character movement based on arrow keys. The game involves a snake character that grows in length by eating food pieces that are randomly placed in the game world. The player loses if the snake runs into itself. Score is tracked based on the length of the snake.

Uploaded by

cesarsucari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PRINCIPIOS PARA JUUEGOS EN FLASH CREAR UN UELO Y PERSONAJE

onClipEvent (load) { xvel = 6; yvel = 0; salto = -8; limite = 10; } onClipEvent (enterFrame) { if (_root.suelo.hitTest(_x, _y+_height/2, true)) { while (_root.suelo.hitTest(_x, -2+_y+_height/2, true)) { _y--; } yvel = 0; if (Key.isDown(Key.UP)) { yvel = salto; _y += yvel; } } else if (_root.suelo.hitTest(_x, _y-_height/2, true)) { yvel = yvel*-1; _y += yvel; while (_root.suelo.hitTest(_x, _y-_height/2, true)) { _y++; } } else { _y += yvel; if (yvelAAAAAAAAAAAA=limite) { yvel++; } } _x += (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT))*xvel; while (_root.suelo.hitTest(_x+_width/2, _y, true)) { _x--; } while (_root.suelo.hitTest(_x-_width/2, _y, true)) { _x++; } } onClipEvent (enterFrame) { if(Key.isDown(Key.LEFT)){ this._xscale = -100 }else if(Key.isDown(Key.RIGHT)){ this._xscale = 100

} }

http://www.youtube.com/watch?v=0H9QxSt8UNk CULEBRA var unit = 15; var uwh = 20; var canMove = false; var dir = 2; var score = 0; aPieceList = new Array(); mouseListener = new Object(); mouseListener.onMouseDown = function() { if (!canMove) { canMove = true; startGame(); } }; Mouse.addListener(mouseListener); k = 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 = 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 = aPieceList.length - 1; i >= 0; i--) { aPieceList[i].removeMovieClip(); aPieceList.pop(); } score = 0; var p = this.attachMovie("piece", "piece" + aPieceList.length, aPieceList.length); aPieceList.push(p); p._x = 10 * unit; p._y = 10 * unit; var food = this.attachMovie("food", "food", -1); var c = 0; moveFood(); var startingLength = 3; for (var i = 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 == 20) { 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 == 20) { 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(); } } }; }

You might also like