Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Globals
- var width = 900;
- var height = 700;
- var renderer = PIXI.autoDetectRenderer(width,height,{backgroundColor : 0x1099bb});
- var stage = new PIXI.Container();
- var animationStages = {menu:0, highscores:1, shop:2, options:3,exit:4,play:5};
- var animationStage = animationStages.menu;
- var entArray = [];
- function start(){
- document.body.appendChild(renderer.view);
- showMenu(stage);
- requestAnimationFrame(animate);
- }
- function animate(){
- if(animationStage == animationStages.menu){
- //TODO: load player information
- }else if(animationStage == animationStages.highscores){
- //TODO: highscores display/refresh every x seconds
- }else if(animationStage == animationStages.shop){
- //TODO: modify player data securely
- }else if(animationStage == animationStages.options){
- //TODO: modify config file
- }else if(animationStage == animationStage.play){
- animateMainLoop();
- }
- renderer.render(stage);
- requestAnimationFrame(animate);
- }
- function startPress(eventData){
- console.log("starting game");
- animationStage = animationStages.play;
- cleanMenu();
- test();
- }
- function test(){
- for(var i = 0; i < 50; i++){
- var ballEnt = new PIXI.Sprite.fromImage("assets/mettalic_ball.png");
- ballEnt.tint = Math.random() * 0xFFFFFF;
- ballEnt.anchor.set(0.5);
- ballEnt.position.x = Math.random() * renderer.width;
- ballEnt.position.y = Math.random() * renderer.height;
- ballEnt.direction = Math.random() * Math.PI * 2;
- ballEnt.speed = 2 + Math.random() * 2;
- entArray.push(ballEnt);
- stage.addChild(ballEnt);
- }
- }
- //Modified from code examples
- function animateMainLoop(){
- // create a bounding box for the little ballEnts
- var ballBoundingBoxPadding = 20;
- var ballBoundingBox = new PIXI.Rectangle(-ballBoundingBoxPadding,-ballBoundingBoxPadding,renderer.width + ballBoundingBoxPadding * 2, renderer.height + ballBoundingBoxPadding * 2);
- for (var i = 0; i < entArray.length; i++)
- {
- var ballEnt = entArray[i];
- ballEnt.position.x += Math.sin(ballEnt.direction) * ballEnt.speed;
- ballEnt.position.y += Math.cos(ballEnt.direction) * ballEnt.speed;
- // wrap the ballEnts by testing their bounds...
- if (ballEnt.position.x < ballBoundingBox.x)
- {
- ballEnt.position.x += ballBoundingBox.width;
- }
- else if (ballEnt.position.x > ballBoundingBox.x + ballBoundingBox.width)
- {
- ballEnt.position.x -= ballBoundingBox.width;
- }
- if (ballEnt.position.y < ballBoundingBox.y)
- {
- ballEnt.position.y += ballBoundingBox.height;
- }
- else if (ballEnt.position.y > ballBoundingBox.y + ballBoundingBox.height)
- {
- ballEnt.position.y -= ballBoundingBox.height;
- }
- }
- }
Add Comment
Please, Sign In to add comment