View
Theme
Font Style
7pt
8pt
9pt
10pt
11pt
Line Style
100%
110%
120%
130%
140%
Bold Keyword
Default
Inspector
Kkaefer
Eclipse
SQ Light
Lesser
Dark
Cobalt
Monokai
Rubyblue
Night
SQ Dark
Ambiance
Blackboard
Line Num.
Wrap Lines
Preview
Redraw
JS Tab
HTML Tab
CSS Tab
Live Tab
Prev. Tab
Next Tab
Browser
History…
Help
Edit
Settings
Auto Complete
Match Brackets
Match Highlight
Strip Whitespace
Auto Close Brackets
Auto Close Quotes
Show Print Margin
Undo
Redo
Delete
Select Line
Select All
Find & Replace
Find
Find in Repo.
Find Next
Find Previous
Replace Single
Replace All
Wrap Search
Revert
As Template
Diff Revision
Format
Compress
Text
Zen Coding
Indent
Tab Width
1
2
3
4
5
6
7
8
Indent Unit
1
2
3
4
5
6
7
8
Smart Indent
Use Tabs
Visible Tabs
Shift Left
Shift Right
Put Indent
Number
Increment by 1
Decrement by 1
Increment by 0.1
Decrement by 0.1
Increment by 10
Decrement by 10
Simple Math
Comment
Line
Move Up
Move Down
Copy Up
Copy Down
Go to Line…
Remove Line
Next Point
Prev. Point
Help
Share
Login
You can jump to the latest bin by adding
/latest
to your URL
×
z
Find
→
←
⟲
Replace
⊗
All
Replace
// Mario Demo // (c) 1985 Nintendo // // globals var game_def = null; var tile_plane = null; var sprite_plane = null; var mario = null; var hud_plane = null; var level = {}; var port = null; Effect.Game.setHandler('onInit', 'mario_init'); function mario_init() { Effect.ImageLoader.setMaxLoadsPerFrame(8); // sprite plane sprite_plane = new SpritePlane('sprites'); sprite_plane.setZIndex(4); Effect.Port.attach(sprite_plane); // hud sprite plane hud_plane = new SpritePlane('hud_sprites'); hud_plane.setZIndex(6); hud_plane.setScrollSpeed(0); // fixed, do not scroll hud_plane.setLogic(false); // no logic needed Effect.Port.attach(hud_plane); // set handlers Effect.Game.setHandler('onLogic', 'game_logic_loop'); Effect.Game.setHandler('onDeath', 'game_death'); Effect.Game.setHandler('onLevelComplete', 'game_level_complete'); Effect.Game.setHandler('onWorldComplete', 'game_world_complete'); Effect.Game.setHandler('onPipe', 'game_level_pipe'); Effect.Game.setHandler('onPause', 'game_pause'); Effect.Game.setHandler('onResume', 'game_resume'); Effect.Game.setHandler('onLoadGame', 'game_core_loaded'); Effect.Game.setHandler('onEnableMusic', 'game_resume'); Effect.Game.setHandler('onKeyDown', 'game_key_down'); Effect.Game.setStateHandler('run', 'game_state_run'); Effect.Game.setStateHandler('title', 'game_state_title'); Effect.Game.setStateHandler('level_complete_a', 'game_state_level_complete_a'); Effect.Game.setStateHandler('level_complete_b', 'game_state_level_complete_b'); Effect.Game.setStateHandler('level_complete_c', 'game_state_level_complete_c'); Effect.Game.setStateHandler('world_complete_a', 'game_state_world_complete_a'); Effect.Game.setStateHandler('world_complete_b', 'game_state_world_complete_b'); Effect.Game.setStateHandler('world_complete_c', 'game_state_world_complete_c'); Effect.Game.setKeyHandler('button_4', { onKeyDown: function() { switch (Effect.Game.getState()) { case 'title': game_start_new_game(); break; case 'run': Effect.Game.pause(); break; } // switch state } }); Effect.Game.setResumeKey('button_4'); Effect.Port.setHandler('onMouseDown', function() { if (Effect.Game.getState() == 'title') game_start_new_game(); return false; }); } function game_core_loaded() { // now load level // HUD plane port = Effect.Port; var hud = null; if (!hud_plane.lookupSprite('hud')) { hud = new TextSprite(); hud.id = 'hud'; hud.zIndex = 6; hud.setTableSize(26, 1); hud.setPosition(24, 24); // hud.setFont( 'nes_classic' ); hud.setCustomFont('/fonts/nes_classic.gif', 8, 8); hud_plane.attach(hud); } else { hud = hud_plane.lookupSprite('hud'); } hud.setPadInt(0, 0, mario ? mario.score: 0, 6); // score hud.setPadInt(10, 0, mario ? mario.coins: 0, 2); // coins hud.setString(16, 0, "1-1"); hud.setPadInt(23, 0, 0, 3); // time hud_plane.createSprite(StaticImageSprite, { url: 'hud.gif', x: 24, y: 16 }); hud_plane.createSprite(StaticImageSprite, { url: 'small_coin.gif', x: 24 + (8 * 8), y: 16 + (1 * 8) }); hud_plane.createSprite(StaticImageSprite, { url: 'x.gif', x: 24 + (9 * 8), y: 16 + (1 * 8) }); game_def = Effect.Game.getXML('game.xml'); Effect.Game.loadLevel('world-1-1', 'game_main_title', true); } function game_main_title() { // setup planes with new level data level = Effect.Game.getLevelProps(); tile_plane = Effect.Port.getPlane('tiles'); // connect planes together (for collisions, etc.) sprite_plane.linkTilePlane(tile_plane); tile_plane.linkSpritePlane(sprite_plane); hud_plane.deleteSprites('temp_hud', 'temp_mario', 'temp_x'); // show main title sprite_plane.createSprite('MainTitle', { x: 40, y: 56 }); // show mario level.character_start.match(/^(\d+)\D+(\d+)$/); mario = sprite_plane.createSprite('Character', { x: parseInt(RegExp.$1, 10), y: parseInt(RegExp.$2, 10), state: 'none' }); // scroll to where character will start var destScrollX = parseInt((mario.x + (mario.width / 2)) - (port.portWidth / 2), 10); var destScrollY = parseInt((mario.y + (mario.height / 2)) - (port.portHeight / 2), 10); port.setScroll(destScrollX, destScrollY); tile_plane.show(); sprite_plane.show(); port.draw(true); Effect.Game.logicClock = 0; game_def.konamiIdx = 0; // set game state for 'start' key action control Effect.Game.setState('title'); } function game_reset() { // reset game after end sprite_plane.reset(); sprite_plane.init(); tile_plane.reset(); tile_plane.init(); hud_plane.reset(); hud_plane.deleteSprite('thank_you'); hud_plane.init(); Effect.Game.setKeysActive(true); game_core_loaded(); } function game_start_new_game() { // start brand new game sprite_plane.deleteAll(); mario = sprite_plane.createSprite('Character', { x: 0, y: 0, visible: false }); mario.lives = 3; var level_name = (game_def.konamiIdx == game_def.KonamiCode.Key.length) ? 'test': 'world-1-1'; Effect.Game.loadLevel(level_name, 'game_level_setup', true); } function is_pipe(tx, ty) { // checks if tile at tx, ty is a pipe var tile = tile_plane.lookupTile(tx, ty, 'objectData'); return (tile && (tile.type == 'Pipe')); } function game_level_setup() { // get level props level = Effect.Game.getLevelProps(); level.scroll_x_max = parseInt(level.scroll_x_max, 10); level.time_remain = parseInt(level.time_remain, 10); if (level.game_state == 'standard') level.game_state = 'run'; // kill all sprites and temporary tiles for (var key in sprite_plane.sprites) { var sprite = sprite_plane.sprites[key]; if (sprite.type != 'Character') sprite.destroy(); } tile_plane.reset(); tile_plane.init(); mario.state = 'falling'; if (level.character_start.match(/^(\d+)\D+(\d+)$/)) { mario.x = parseInt(RegExp.$1, 10); mario.y = parseInt(RegExp.$2, 10); } else { mario.x = 0; mario.y = 0; } if (mario.size) mario.y -= 16; mario.star = 0; mario.category = 'character'; mario.flash = 0; mario.facing = 0; // 0=right, 14=left if (mario.flower) mario.setImage(mario.brother + '_flower_power.gif'); else mario.setImage(mario.brother + '_' + (mario.size ? 'large': 'small') + '.gif'); mario.setFrame(0, 0); mario.invincible = false; mario.xd = 0; mario.yd = 0; mario.requestJump = false; mario.requsetFireball = false; mario.zIndex = sprite_plane.zIndex; mario.hide(); if (mario.pipe) { // exiting thru pipe, determine pipe type and position var destPipeType = ''; if (mario.pipe.destTileX && mario.pipe.destTileY) { var tx = mario.pipe.destTileX; var ty = mario.pipe.destTileY; if (is_pipe(tx, ty) && (is_pipe(tx + 1, ty) || is_pipe(tx - 1, ty))) { destPipeType = 'vert'; if (!tile_plane.lookupTile(tx, ty - 1, 'objectData')) { mario.yd = -2; mario.y = ty * tile_plane.tileSizeY; } else { mario.yd = 2; mario.y = ((ty + 1) * tile_plane.tileSizeY) - mario.height; } if (is_pipe(tx + 1, ty)) mario.x = (tx * tile_plane.tileSizeX) + (tile_plane.tileSizeX / 2); else mario.x = (tx * tile_plane.tileSizeX) - (tile_plane.tileSizeX / 2); } else if (is_pipe(tx, ty) && (is_pipe(tx, ty + 1) || is_pipe(tx, ty - 1))) { destPipeType = 'horiz'; mario.x = (tx * tile_plane.tileSizeX); if (!tile_plane.lookupTile(tx - 1, ty, 'objectData')) { mario.xd = -2; mario.facing = 14; } else { mario.xd = 2; mario.facing = 0; } if (is_pipe(tx, ty + 1)) mario.y = ty * tile_plane.tileSizeY; else mario.y = (ty - 1) * tile_plane.tileSizeY; if (!mario.size) mario.y += mario.height; } } if (destPipeType) { mario.state = 'pipe_exit'; mario.zIndex = tile_plane.zIndex - 1; // under tiles } } // from pipe mario.setZIndex(mario.zIndex); sprite_plane.clearSoloSprite(); var destScrollX = parseInt((mario.x + (mario.width / 2)) - (port.portWidth / 2), 10); var destScrollY = parseInt((mario.y + (mario.height / 2)) - (port.portHeight / 2), 10); port.setScroll(destScrollX, destScrollY); if (mario.pipe) game_level_play(); else game_level_intro(); } function game_level_intro() { // show level intro Effect.Game.setState('intro'); // port.setBackground({ color: 'black' }); port.setBackgroundColor('black'); tile_plane.hide(); sprite_plane.hide(); var hud = hud_plane.lookupSprite('hud'); // update world N-N in upper hud hud.setString(16, 0, level.world_num); // create temp hud for "WORLD N-N" in center of screen var temp_hud = new TextSprite(); temp_hud.id = 'temp_hud'; temp_hud.zIndex = 6; temp_hud.setTableSize(9, 5); temp_hud.setPosition(86, 80); // temp_hud.setFont( 'nes_classic' ); temp_hud.setCustomFont('/fonts/nes_classic.gif', 8, 8); hud_plane.attach(temp_hud); temp_hud.setString(0, 0, "WORLD " + level.world_num); temp_hud.setString(7, 4, mario.lives); // temp_hud.port = port; // temp_hud.init(); hud_plane.createSprite(StaticImageSprite, { id: 'temp_x', url: 'x.gif', x: 86 + (4 * 8), y: 80 + (4 * 8) }); // show little mario as well hud_plane.createSprite('Character', { id: 'temp_mario', state: 'none', // prevent falling x: 94, y: 106 }); sprite_plane.setLogic(false); // setTimeout( 'game_level_play()', 4000 ); Effect.Game.scheduleEvent(120, game_level_play); } function game_level_play() { // play level immediately sprite_plane.setLogic(true); hud_plane.deleteSprites('temp_hud', 'temp_mario', 'temp_x'); if (!mario.pipe) mario.levelStartTime = Effect.Game.logicClock; // start timer port.setBackground(); tile_plane.show(); tile_plane.activateScreenObjects(); sprite_plane.show(); mario.show(); port.draw(true); mario.pipe = null; if (level.game_state) { // special game state (world-1-2-intro, etc.) switch (level.game_state) { case 'walk_pipe': Effect.Game.setKeysActive(false); Effect.Game.resetKeys(); Effect.Game.keys.move_right.down = true; break; case 'run': Effect.Game.resetKeys(); Effect.Game.setKeysActive(true); break; } } else { // standard level Effect.Game.resetKeys(); Effect.Game.setKeysActive(true); } var music = Effect.Audio.getTrack(level.background_music); if (!music) alert("Could not locate level music: " + level.background_music); music.rewind(); music.play(); if (mario.state == 'pipe_exit') Effect.Audio.playSound('down_pipe'); // Effect.Game.run(); Effect.Game.setState(level.game_state ? level.game_state: 'run'); } function game_death() { Effect.Game.setState('died'); // kill all sprites except character, and temp tiles for (var key in sprite_plane.sprites) { var sprite = sprite_plane.sprites[key]; if (sprite.type != 'Character') sprite.destroy(); } tile_plane.reset(); tile_plane.init(); // take a life away mario.lives--; if (!mario.lives) return game_over(); Effect.Game.restoreLevelState(); mario.state = 'falling'; if (level.character_start.match(/^(\d+)\D+(\d+)$/)) { mario.x = parseInt(RegExp.$1, 10); mario.y = parseInt(RegExp.$2, 10); } else { mario.x = 0; mario.y = 0; } mario.height = 16; mario.setFrame(0, 0); mario.setImage(mario.brother + '_small.gif'); mario.size = 0; mario.flower = 0; mario.star = 0; mario.category = 'character'; mario.flash = 0; mario.facing = 0; // 0=right, 14=left mario.invincible = false; mario.xd = 0; mario.yd = 0; mario.requestJump = false; mario.requsetFireball = false; mario.show(); var destScrollX = parseInt((mario.x + (mario.width / 2)) - (port.portWidth / 2), 10); var destScrollY = parseInt((mario.y + (mario.height / 2)) - (port.portHeight / 2), 10); port.setScroll(destScrollX, destScrollY); // port.draw(true); sprite_plane.clearSoloSprite(); game_level_intro(); } function game_over() { // no more lives port.setBackgroundColor('black'); tile_plane.hide(); sprite_plane.hide(); // create temp hud for "GAME OVER" in center of screen var game_over = new TextSprite(); game_over.id = 'temp_hud'; game_over.zIndex = 6; game_over.setTableSize(9, 1); game_over.setPosition(86, 106); // game_over.setFont( 'nes_classic' ); game_over.setCustomFont('/fonts/nes_classic.gif', 8, 8); game_over.setString(0, 0, "GAME OVER"); hud_plane.attach(game_over); Effect.Audio.playSound('music_game_over'); Effect.Game.scheduleEvent(30 * 7, game_core_loaded); } function game_level_complete() { // mario has reached castle door, so hide him // and begin bonus stuff Effect.Game.setState('level_complete_b'); mario.state = 'none'; mario.hide(); // mario gets fireworks? depends on timer digit... mario.numFireworks = 0; switch (mario.secRemain % 10) { case 1: case 3: case 6: mario.numFireworks = mario.secRemain % 10; break; } Effect.Audio.playSound('music_bonus'); } function game_next_level() { // load next level Effect.Game.loadLevel(level.next_level, 'game_level_setup', true); } function game_level_pipe() { // travel through pipe Effect.Game.loadLevel(mario.pipe.destLevel, 'game_level_setup', true); } function game_world_complete() { // completed world, walk to princess Effect.Game.setState('world_complete_c'); // set mario to falling mario.state = 'falling'; mario.yd = 0; mario.jumpTimer = 0; // kill keyboard control, set move_right to down Effect.Game.setKeysActive(false); Effect.Game.resetKeys(); Effect.Game.keys.move_right.down = true; // unlock scroll_x_max level.scroll_x_max = 0; // switch music to world_complete Effect.Audio.quiet(); Effect.Audio.getTrack('music_world_complete').play(); // disable soloSprite sprite_plane.clearSoloSprite(); // set time for final state mario.endFinalWalk = Effect.Game.logicClock + 46; } function game_pause() { // called when game is paused if (Effect.Game.getState() != 'title') { Effect.Audio.quiet(); Effect.Audio.playSound('pause'); } } function game_resume() { // called when game is resumed switch (Effect.Game.getState()) { case 'run': if (mario.star) Effect.Audio.playSound('music_starpower'); else Effect.Audio.getTrack(level.background_music).play(); break; } if (Effect.Game.getState() != 'title') { Effect.Audio.playSound('pause'); } } function game_key_down(name, code) { // handle key down, only needed for title if (Effect.Game.getState() == 'title') { if (name == game_def.KonamiCode.Key[game_def.konamiIdx]) { game_def.konamiIdx++; if (game_def.konamiIdx == game_def.KonamiCode.Key.length) { Effect.Audio.playSound('firework'); } } } } function game_logic_loop() { // in game logic loop if (!mario) return; if ((mario.state != 'death') && (Effect.Game.getState() != 'title')) { var destScrollX = parseInt((mario.x + (mario.width / 2)) - (port.portWidth / 2), 10); var destScrollY = parseInt((mario.y + (mario.height / 2)) - (port.portHeight / 2), 10); if (level.scroll_x_min && (destScrollX < level.scroll_x_min)) destScrollX = level.scroll_x_min; else if (level.scroll_x_max && (destScrollX > level.scroll_x_max)) destScrollX = level.scroll_x_max; if (level.scroll_y_min && (destScrollY < level.scroll_y_min)) destScrollY = level.scroll_y_min; else if (level.scroll_y_max && (destScrollY > level.scroll_y_max)) destScrollY = level.scroll_y_max; port.setScroll(parseInt(port.scrollX + ((destScrollX - port.scrollX) / 4), 10), parseInt(port.scrollY + ((destScrollY - port.scrollY) / 4), 10)); } if (mario.dirtyDisplay) { // update HUD var hud = hud_plane.lookupSprite('hud'); hud.setPadInt(0, 0, mario.score, 6); hud.setPadInt(10, 0, mario.coins, 2); mario.dirtyDisplay = false; } if (Effect.Game.getState() != 'title') { var hud = hud_plane.lookupSprite('hud'); hud.setPadInt(23, 0, mario.secRemain, 3); } /* if (Effect.Game.logicClock % 8 == 0) { var html = ''; // var total_sprites = num_keys(sprite_plane.sprites) + num_keys(particle_plane.sprites); // html += 'num_sprites: ' + total_sprites + ', '; html += 'fps: ' + Effect.Game.getCurrentFPS(); // html += ', scroll: ' + port.scrollX + ' x ' + port.scrollY; el('d_info').innerHTML = html; } */ } function game_state_run() { // standard run mode -- decrease timer if (!mario) return; mario.secRemain = level.time_remain - parseInt((Effect.Game.logicClock - mario.levelStartTime) / (30 / 2), 10); if (mario.secRemain <= 0) { mario.secRemain = 0; var hud = hud_plane.lookupSprite('hud'); hud.setPadInt(23, 0, mario.secRemain, 3); if (mario.state != 'death') { // ran out of time, die now mario.die(); } } } function game_state_title() { // title logic if (ua.iphone) Effect.Port.setScroll(Effect.Game.logicClock, 0); } function game_state_level_complete_a() { // level complete part one -- sliding down flagpole // handled elsewhere with sprites } function game_state_level_complete_b() { // level complete part two -- timer bonus mario.secRemain -= 2; mario.addScore(50 * 2); if (mario.secRemain <= 0) { mario.secRemain = 0; var hud = hud_plane.lookupSprite('hud'); hud.setPadInt(23, 0, mario.secRemain, 3); Effect.Game.setState('level_complete_c'); Effect.Audio.getTrack('music_bonus').stop(); mario.nextFirework = Effect.Game.logicClock + 30; sprite_plane.createSprite('CastleFlag', { x: mario.x, y: mario.y }); } } function game_state_level_complete_c() { // level complete part three -- fireworks if (Effect.Game.logicClock >= mario.nextFirework) { if (mario.numFireworks > 0) { sprite_plane.createSprite('Explosion', { frameDelta: 0.3, x: parseInt(port.scrollX + 32 + (Math.random() * (port.portWidth - 64)), 10), y: parseInt(port.scrollY + 32 + (Math.random() * (port.portHeight - 64)), 10) }); Effect.Audio.playSound('firework'); mario.numFireworks--; mario.nextFirework = Effect.Game.logicClock + 15; } else { Effect.Game.setState('level_complete_d'); Effect.Game.scheduleEvent(90, game_next_level); } } } function game_state_world_complete_a() { // destroy bridge if (Effect.Game.logicClock % 2 == 0) { tile_plane.setTile(mario.bridge_tx, mario.bridge_ty, 0, 'data'); tile_plane.setTile(mario.bridge_tx, mario.bridge_ty - 1, 0, 'data'); // for chain mario.bridge_tx--; var tile_idx = tile_plane.lookupTile(mario.bridge_tx, mario.bridge_ty, 'data'); if (tile_idx != '7.gif') { // 7.gif is bridge tile // bridge all gone, send bowser to hell Effect.Game.setState('world_complete_b'); var bowser = sprite_plane.findSprite({ type: 'Bowser' }); if (bowser) { bowser.state = 'death'; bowser.collisions = false; bowser.yd = 4; sprite_plane.setSoloSprite(bowser); level.bowser_killed = true; // to prevent respawn } Effect.Game.scheduleEvent(40, 'onWorldComplete'); } // bridge all gone } // every other frame } function game_state_world_complete_b() { // waiting for bowser to fall, will go to _c via scheduled event } function game_state_world_complete_c() { // mario walking to princess if (Effect.Game.logicClock == mario.endFinalWalk) { Effect.Game.keys.move_right.down = false; var thank_you = new TextSprite(); thank_you.id = 'thank_you'; thank_you.setTableSize(22, 7); thank_you.setPosition(40, 80); // thank_you.setFont( 'nes_classic' ); thank_you.setCustomFont('/fonts/nes_classic.gif', 8, 8); thank_you.setString(3, 0, "THANK YOU MARIO!"); hud_plane.attach(thank_you); } if (Effect.Game.logicClock == mario.endFinalWalk + 90) { var thank_you = hud_plane.lookupSprite('thank_you'); thank_you.setString(0, 4, "BUT OUR PRINCESS IS IN"); thank_you.setString(0, 6, "ANOTHER CASTLE!"); // end of demo, back to main title Effect.Game.scheduleEvent(7 * 30, game_reset); } }
Mario Demo 1.0b | EffectGames.com
/* Basic Framework */ html, body, div, p, form { margin: 0; padding: 0; border: 0; } .container { margin: 0 auto; width: 85%; min-width: 800px; max-width: 2048px; } body { font-family: "Lucida Grande", Helvetica, Arial, sans-serif; font-size: 12px; } .body { font-size: 12px; } a:link { text-decoration:none; color:#4437BB; } a:visited { text-decoration:none; color:#4437BB; } a:active { text-decoration:none; color:#4437BB; } a:hover { text-decoration:underline; cursor:pointer; } a:focus { outline: none; } a { text-decoration:none; cursor:pointer; color:#4437BB; } .clear { clear: both; } .caption { font-family:arial,sans-serif; font-size:11px; cursor:default; color:#aaa; }
Pop out
Help
About
×
×