Jump to content

K31V

Members
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

0 Neutral

About K31V

  • Rank
    Newbie
  • Birthday 03/30/1991

Profile Information

  • Location
    Minnesota
  • Interests
    CSCI
  1. What suppose to happen is: When "thunder" collides with "pokeball," "pokeball suppose to be remove from the canvas The sprites "thunder" and "pokeball" are not colliding. if (this.intersect(pokeball)) { pokeball.image = game.assets['explosion.png']; game.currentScene.removeChild(this); There's no error on the console between the 2 sprites.
  2. It's a long shot but I'm giving this a shot. I'm dealing with enchant.js and I get the grasp of it but not entirely. My biggest problem is having my function shootingPokeball and function makePokeball in SCENE 2 to collide with one anothe I'm programming through a website: 9leap.net // --- Guide --- // Stage 1: // Avoid the POKEBALLS to remain alive for 15 seconds. Grab as many RARE CANDY for points (20). // Stage 2: // Shoot down as many POKEBALLS to collect points (10 each). window.onload = myGame; enchant(); // GAME function myGame() { var game = new Core(600, 600); game.fps = 24; // PRELOADS game.preload('pokeball.png', 'shock.png', 'rarecandy.png', 'explosion.png', 'magneton.png', 'space.png', 'space2.png'); game.preload ('warsong.mp3', 'capturedEnd.mp3', 'ff4.mp3', 'quick.mp3', 'punch.mp3'); game.score = 0; game.onload = function () { game.deck = new Sprite(49, 48); game.deck.image = game.assets['magneton.png']; game.deck.x = (game.width - game.deck.width) / 2; game.deck.y = (game.height - game.deck.height) / 2; game.rootScene.addChild(game.deck); game.bgm = game.assets['quick.mp3']; // Intro sound game.bgm.play(); game.screenMsg = new Label("Dodge the incoming dangers <br>until Stage 2. <br>When Stage 2 begins, <br>shoot down as many dangers as you can."); game.screenMsg.color = 'gold'; game.rootScene.addChild(game.screenMsg); game.deck.addEventListener(Event.TOUCH_END, function (event) { game.pushScene(stage1()); }); }; game.start(); //-------------- //-----SCENE 2-- //-------------- function stage2() { var scene = new Scene(); var pokeballArray [qw, ]; // BG FOR STAGE 2 var bg = new Sprite(game.width, game.height); bg.image = game.assets['space2.png']; scene.addChild(bg); scene.timerDown = { frameCount: 10 * game.fps, tick: function () { if (game.isStarted) { this.frameCount -= 1; } } }; // TIME var timeLabel = new Label(""); scene.addChild(timeLabel); timeLabel.color = 'gold'; // MAIN HERO var char = heroChar(scene); scene.addChild(char); // Rebind input.a key to spacebar game.keybind(32, 'a'); // 32 is the ASCII code for a space. // Add an event listener for each frame. game.addEventListener(Event.ENTER_FRAME, function () { // fire a shock blast in the spacebar is down, but only // every 3rd frame if (game.input.a && game.frame % 3 === 0) { shootingPokeball(char); } }); scene.addEventListener(Event.ENTER_FRAME, function () { if (scene.timerDown.frameCount > 0) { if (game.frame % 24 === 0) { makePokeball(char, scene, pokeballArray); } scene.timerDown.tick(); timeLabel.text = 'Time: ' + Math.ceil(scene.timerDown.frameCount / game.fps); } else if (scene.timerDown.frameCount !== -1) { scene.timerDown.frameCount = -1; game.screenMsg.text = 'Congratualations!<br>Score: ' + game.score; game.popScene(); game.bgm.stop(); game.bgm = game.assets['ff4.mp3']; game.bgm.play(); game.end(); } }); return scene; } // VILLIAN FOR STAGE 2 function makePokeball(char, evil) { var pokeball = new Sprite(48, 48); pokeball.image = game.assets['pokeball.png']; var magneton = heroChar(); // pokeball SPEED FROM TOP STAGE 2 pokeball.gravity = 10; // RANDOM pokeball SPAWNING POINT pokeball.x = randomInt(0, game.width - pokeball.width); pokeball.y = randomInt(-1 * game.height, -1 * pokeball.height); evil.addChild(pokeball); // EVENT LISTENERS pokeball.addEventListener(Event.ENTER_FRAME, function () { game.isStarted = true; if (pokeball.y > game.height) { evil.removeChild(pokeball); } else { pokeball.y += pokeball.gravity; } // COLLISONS FOR STAGE 2 if (pokeball.intersect(char)) { evil.removeChild(pokeball); shootingPokeball(); scoringScene(villain, true); } }); pokeball.addEventListener(Event.ENTER_FRAME, function (event) { if (pokeball.scaleX > 1.0) { pokeball.isGrowing = false; } else if (pokeball.scaleX < 0.8) { pokeball.isGrowing = true; } if (pokeball.isGrowing) { pokeball.scaleX += 0.5; } else { pokeball.scaleX -= 0.035; } pokeball.scaleY = pokeball.scaleX; }); game.punchSound = game.assets['punch.mp3']; return pokeball; } // SHOOTING FOR STAGE 2 function shootingPokeball(char, pokeball, pokeballArray) { var thunder = new Sprite(15, 18); thunder.image = game.assets['shock.png']; // Add a speed property to the thunder. thunder.speed = 10; // How fast will thunder move? // Position the thunder blast over char's eyes thunder.x = char.x + 35; thunder.y = char.y + -25; // Add thunder to scene. game.currentScene.addChild(thunder); // Event listeners thunder.addEventListener(Event.ENTER_FRAME, function () { // MOVE UP TOWARD CANVAS this.y -= this.speed; // EXPLOSION if (this.intersect(pokeball)) { pokeball.image = game.assets['explosion.png']; game.currentScene.removeChild(this); } // Delete if off screen. if (this.y < 0 - this.height) { game.rootScene.removeChild(this); // this = null; } }); return thunder; } // HERO FOR STAGE 2 function heroChar() { var magneton = new Sprite(49, 48); magneton.image = game.assets['magneton.png']; // Add a speed property to the magneton. magneton.speed = 10; // How fast will magneton move? magneton.x = (game.width + magneton.width) / 2; magneton.y = game.height - magneton.height; // Add magneton to scene. game.rootScene.addChild(magneton); // Event listeners for magneton. magneton.addEventListener(Event.ENTER_FRAME, function () { // Move. if (game.input.right && !game.input.left) { magneton.x += magneton.speed; } else if (game.input.left && !game.input.right) { magneton.x -= magneton.speed; } // Check limits. if (magneton.x > game.width - magneton.width) { magneton.x = game.width - magneton.width; } else if (magneton.x < 0) { magneton.x = 0; } }); return magneton; } //------------- //---SCENE 1--- //------------- function stage1() { var scene = new Scene(); // BG FOR STAGE 1 var bg = new Sprite(game.width, game.height); bg.image = game.assets['space.png']; scene.addChild(bg); // Sounds game.bgm = game.assets['warsong.mp3']; // background music game.bgm.play(); scene.timerUp = { frameCount: 0, tick: function () { if (game.isStarted) { this.frameCount += 1; // COUNTDOWN } } }; var timeLabel = new Label(""); scene.addChild(timeLabel); timeLabel.color = 'red'; var char = safeChar(scene); var candy = collectRareCandy(scene); // Event Listener scene.addEventListener(Event.ENTER_FRAME, function () { if (game.frame % 12 === 0) { dodgePokeball(char, scene); } scene.timerUp.tick(); timeLabel.text = 'Time: ' + Math.floor(scene.timerUp.frameCount / game.fps); if (scene.timerUp.frameCount >= 5 * game.fps) { scoringScene(scene, false); } }); return scene; } // VILLAIN FOR STAGE 1 function dodgePokeball(char, villain) { var pokeball = new Sprite(48, 48); pokeball.image = game.assets['pokeball.png']; // pokeball SPEED. pokeball.gravity = 15; // Position pokeball in random x and random y above screen. pokeball.x = randomInt(0, game.width - pokeball.width); pokeball.y = randomInt(-1 * game.height, -1 * pokeball.height); villain.addChild(pokeball); // Add an event listener to the pokeball Sprite to move it. pokeball.addEventListener(Event.ENTER_FRAME, function () { // Game starts when first drop starts falling. game.isStarted = true; // Move. if (pokeball.y > game.height) { // if below canvas, remove. villain.removeChild(pokeball); } else { // else move down as usual. pokeball.y += pokeball.gravity; } // COLLISIONS if (pokeball.intersect(char)) { villain.removeChild(pokeball); scoringScene(villain, true); } game.punchSound = game.assets['punch.mp3']; }); return pokeball; } // COLLECT FOR STAGE 1 function collectRareCandy(rare, char, hp) { var candy = new Sprite(50, 49); candy.image = game.assets['rarecandy.png']; // candy SPEED. candy.gravity = 8; // Position candy in random x and random y above screen. candy.x = randomInt(0, game.width - candy.width); candy.y = randomInt(-1 * game.height, -1 * candy.height); rare.addChild(candy); // Add an event listener to the candy Sprite to move it. candy.addEventListener(Event.ENTER_FRAME, function () { game.isStarted = true; // Move. if (candy.y > game.height) { // if below canvas, remove. } else { // else move down as usual. candy.y += candy.gravity; } // COLLISIONS if (candy.intersect(char)) { hp.removeChild(candy); game.currentScene(hp, true); } }); // CANDY SCALING candy.addEventListener(Event.ENTER_FRAME, function (event) { if (candy.scaleX > 1.0) { candy.isGrowing = false; } else if (candy.scaleX < 0.8) { candy.isGrowing = true; } if (candy.isGrowing) { candy.scaleX += 0.035; } else { candy.scaleX -= 0.035; } candy.scaleY = candy.scaleX; }); return candy; } // HERO FOR STAGE 1 function safeChar(main) { var char = new Sprite(49, 48); char.image = game.assets['magneton.png']; // SPEED IN STAGE 1 char.speed = 13; char.x = (game.width + char.width) / 2; char.y = game.height - char.height; main.addChild(char); var candy = new Sprite(32, 23); candy.image = game.assets['rarecandy.png']; // EVENT LISTENERS char.addEventListener(Event.ENTER_FRAME, function () { if (game.input.right && !game.input.left) { char.x += char.speed; } else if (game.input.left && !game.input.right) { char.x -= char.speed; } if (char.x > game.width - char.width) { char.x = game.width - char.width; } else if (char.x < 0) { char.x = 0; } }); return char; } // SCORE SCENE function scoringScene(scoring, gameOver) { game.score += Math.floor(scoring.timerUp.frameCount / game.fps); if (!gameOver) { game.score += 200; game.replaceScene(stage2()); } else { // ENDING MESSAGE game.screenMsg.text = 'Hope you had fun! Better luck next time.<br>Score: ' + game.score; game.popScene(); game.bgm.stop(); game.bgm = game.assets['capturedEnd.mp3']; game.bgm.play(); game.punchSound.play(); game.end(); } }
  3. K31V

    Help a newbie out

    The program is a 50/50 chance game of winning or losing. The player must reach 100 HP in the 50/50 game in order to win. If the player reaches 100 HP, I want add a message saying ("Congratulations, you have won!") and the game finishes. I already got down the code where if you lose it'll say ("you have fought your last battle and you've lost.."). The other thing is where do I input a message saying ("You must win the next battle if you want to survive.") when the player's HP is equal or less than 10 HP before hitting 0 HP within the code.
  4. K31V

    Help a newbie out

    Hopefully this will help clarify things up: <!DOCTYPE> <html> <head> <title>Requisite Warrior </title> </head> <body> <h1>Requisite Warrior </h1> <script> // Define entities. /* requisiteWarrior starts out with a health of 20. * When she does battle, there is a 50/50 chance that she will emerge * victorious. Victory ramps up her health by 8, defeat down by 10. * The requisiteWarrior dies when her health drops below 0. */ var requisiteWarrior = { health: 20, /* doBattle makes requisiteWarrior do battle. If she wins, her health * is increased; if she looses it is reduced. * Returns whether the battle resulted in victory or not. */ doBattle: function () { var isVictorious = Math.random() > 0.5; if (isVictorious) { this.health += 8; // 'this' is very important! } else { this.health -= 10; // 'this' is very important! } return isVictorious; } isAlive: function () { if (this.health >= 0) { return true; } else { return false; } } }; var isWon = null, // stores result of last battle. msg = ''; // a temporary variable for composing messages. // Begin game. (Game ends when requisiteWarrior is no longer alive.) window.alert('Do battle!'); while (requisiteWarrior.isAlive()) { isWon = requisiteWarrior.doBattle(); // battle! if (isWon) { msg = 'Victory! Health is up to ' + requisiteWarrior.health + '.\nClick OK to do battle again.'; } else if (requisiteWarrior.isAlive()) { msg = 'Defeat. Health is down to ' + requisiteWarrior.health + '.\nClick OK to do battle again.'; } else { msg = 'Alas, you have fought your last battle. :-('; } window.alert(msg); } // Ending message window.alert('You provided great service and were valued for you bravery.'); </script> </body> </html>
  5. K31V

    Help a newbie out

    It's a 50/50 game. You start with 20 HP and you lose 10 HP when you lose and gain 8 HP when you win. I want the window.alert(); to show up to warn the player when the character's HP is equal or less than 10 HP, and that's where I'm stuck at.
  6. K31V

    Help a newbie out

    So how do I make it so almostDead can run with the window.alert(); if the player's health is less than 10? And where should I put it to make it functional? almostDead: function () { if (this.health >= 10) { window.alert(Your health is low!);}
  7. How do I add a window.alert popup where if the warrior’s health drops dangerously low, the user is told she must win the next battle to stay alive. I tried inputting function and window.alert(); every where but the program doesn't work. What must I do to make it work? If you can, can you give me some tips how to improve my skills. I would greatly appreciate it. Thanks! --------------------------------------------------------------------------------------------- <!DOCTYPE> <html> <head> <title>Requisite Warrior</title> </head> <body> <h1>Requisite Warrior</h1> <script> var requisiteWarrior = { health: 20, doBattle: function () { var isVictorious = Math.random() > 0.5; if (isVictorious) { this.health += 8; // 'this' is very important! } else { this.health -= 10; // 'this' is very important! } return isVictorious; }, almostDead: function () { if (this.health >= 10) { window.alert(Your health is low!);} } isAlive: function () { if (this.health >= 0) { return true; } else { return false; } } }; var isWon = null, msg = ''; // Begin game. window.alert('Do battle!'); while (requisiteWarrior.isAlive()) { isWon = requisiteWarrior.doBattle(); if (isWon) { msg = 'Victory! Health is up to ' + requisiteWarrior.health + '.\nClick OK to do battle again.'; } else if (requisiteWarrior.isAlive()) { msg = 'Defeat. Health is down to ' + requisiteWarrior.health + '.\nClick OK to do battle again.'; } else { msg = 'Alas, you have fought your last battle. :-('; } window.alert(msg); } // Ending message window.alert('You provided great service and were valued for you bravery.'); </script> </body> </html>
×
×
  • Create New...