| Start/ | End/ | |||
| True | False | - | Line | Source |
| 1 | /* | |||
| 2 | * [[ Frozen-Bubble ]] | |||
| 3 | * | |||
| 4 | * Copyright (c) 2000-2003 Guillaume Cottenceau. | |||
| 5 | * Java sourcecode - Copyright (c) 2003 Glenn Sanson. | |||
| 6 | * | |||
| 7 | * This code is distributed under the GNU General Public License | |||
| 8 | * | |||
| 9 | * This program is free software; you can redistribute it and/or | |||
| 10 | * modify it under the terms of the GNU General Public License | |||
| 11 | * version 2, as published by the Free Software Foundation. | |||
| 12 | * | |||
| 13 | * This program is distributed in the hope that it will be useful, but | |||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 16 | * General Public License for more details. | |||
| 17 | * | |||
| 18 | * You should have received a copy of the GNU General Public License along | |||
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., | |||
| 20 | * 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| 21 | * | |||
| 22 | * | |||
| 23 | * Artwork: | |||
| 24 | * Alexis Younes <73lab at free.fr> | |||
| 25 | * (everything but the bubbles) | |||
| 26 | * Amaury Amblard-Ladurantie <amaury at linuxfr.org> | |||
| 27 | * (the bubbles) | |||
| 28 | * | |||
| 29 | * Soundtrack: | |||
| 30 | * Matthias Le Bidan <matthias.le_bidan at caramail.com> | |||
| 31 | * (the three musics and all the sound effects) | |||
| 32 | * | |||
| 33 | * Design & Programming: | |||
| 34 | * Guillaume Cottenceau <guillaume.cottenceau at free.fr> | |||
| 35 | * (design and manage the project, whole Perl sourcecode) | |||
| 36 | * | |||
| 37 | * Java version: | |||
| 38 | * Glenn Sanson <glenn.sanson at free.fr> | |||
| 39 | * (whole Java sourcecode, including JIGA classes | |||
| 40 | * http://glenn.sanson.free.fr/jiga/) | |||
| 41 | * | |||
| 42 | * [[ http://glenn.sanson.free.fr/fb/ ]] | |||
| 43 | * [[ http://www.frozen-bubble.org/ ]] | |||
| 44 | */ | |||
| 45 | ||||
| 46 | import net.library.jiga.*; | |||
| 47 | ||||
| 48 | import java.awt.*; | |||
| 49 | ||||
| 50 | public class LaunchBubbleSprite extends Sprite { | |||
| 51 | ||||
| 52 | public final static String LAUNCHER_BACK_CONTEXT_KEY = "back_launcher"; | |||
| 53 | public final static String LAUNCHER_BUBBLES_CONTEXT_KEY = "sprites_launcher"; | |||
| 54 | public final static String LAUNCHER_BUBBLES_BLIND_CONTEXT_KEY = "sprites_blind_launcher"; | |||
| 55 | ||||
| 56 | public final static String LAUNCHER_IMG = "launcher.gif"; | |||
| 57 | public final static String LAUNCHER_ALPHA_IMG = "launcher_alpha.gif"; | |||
| 58 | ||||
| 59 | private int currentColor; | |||
| 60 | private int currentDirection; | |||
| 61 | ||||
| 62 | ||||
| 63 | private Image backgroundImage; | |||
| 64 | private Image spritesImage; | |||
| 65 | private Image spritesBlindImage; | |||
| 66 | ||||
| 464 | 0 | 67 | public LaunchBubbleSprite(GameApplet applet, int initialColor, int initialDirection) { | |
| 68 | ||||
| 69 | super(new Rectangle(276, 362, 86, 76)); | |||
| 70 | ||||
| 71 | currentColor = initialColor; | |||
| 72 | currentDirection = initialDirection; | |||
| 73 | ||||
| 74 | GameContext context = applet.getGameContext(); | |||
| 75 | ||||
| 76 | backgroundImage = (Image)context.getObject(LAUNCHER_BACK_CONTEXT_KEY); | |||
| 77 | spritesImage = (Image)context.getObject(LAUNCHER_BUBBLES_CONTEXT_KEY); | |||
| 78 | spritesBlindImage = (Image)context.getObject(LAUNCHER_BUBBLES_BLIND_CONTEXT_KEY); | |||
| 79 | ||||
| 80 | // Create image | |||
| 95 | 369 | 81 | if (backgroundImage == null || spritesImage == null) { | |
| 95 | 81 | T || _ | ||
| 0 | - | 81 | F || T | |
| 369 | 81 | F || F | ||
| 82 | backgroundImage = applet.createImage(86, 3116); | |||
| 83 | spritesImage = applet.createImage(256, 1312); | |||
| 84 | spritesBlindImage = applet.createImage(256, 1312); | |||
| 85 | ||||
| 86 | createLauncherImages(applet); | |||
| 87 | ||||
| 88 | context.addObject(LAUNCHER_BACK_CONTEXT_KEY, backgroundImage); | |||
| 89 | context.addObject(LAUNCHER_BUBBLES_CONTEXT_KEY, spritesImage); | |||
| 90 | context.addObject(LAUNCHER_BUBBLES_BLIND_CONTEXT_KEY, spritesBlindImage); | |||
| 91 | } | |||
| 92 | } | |||
| 93 | ||||
| 95 | 0 | 94 | private void createLauncherImages(GameApplet applet) { | |
| 95 | ||||
| 96 | Graphics gb = backgroundImage.getGraphics(); | |||
| 97 | Graphics gs = spritesImage.getGraphics(); | |||
| 98 | Graphics gsb = spritesBlindImage.getGraphics(); | |||
| 99 | ||||
| 100 | GameMedia media = applet.getGameMedia(); | |||
| 101 | ||||
| 102 | // Gets game empty background | |||
| 103 | Image imgGame = media.loadImage("background.jpg"); | |||
| 104 | ||||
| 105 | // prepare background | |||
| 3895 | 95 | 106 | for (int i=0 ; i<41 ; i++) { | |
| 107 | gb.setClip(0, i*76, 86, 76); | |||
| 108 | gb.drawImage(imgGame, -276, i*76-362, applet); | |||
| 109 | } | |||
| 110 | ||||
| 111 | // prepare sprites | |||
| 112 | ||||
| 113 | // Retrieve bubbles | |||
| 114 | Image[] bubbles = new Image[8]; | |||
| 760 | 95 | 115 | for (int i=0 ; i<8 ; i++) { | |
| 116 | bubbles[i] = media.loadImage("bubble-"+Integer.toString(i+1)+".gif"); | |||
| 117 | } | |||
| 118 | ||||
| 119 | // Retrieve -colorblind- bubbles | |||
| 120 | Image[] colorblindBubbles = new Image[8]; | |||
| 760 | 95 | 121 | for (int i=0 ; i<8 ; i++) { | |
| 122 | colorblindBubbles[i] = media.loadImage("bubble-colourblind-"+Integer.toString(i+1)+".gif"); | |||
| 123 | } | |||
| 124 | ||||
| 3895 | 95 | 125 | for (int j=0 ; j<41 ; j++) { | |
| 31160 | 3895 | 126 | for (int i=0 ; i<8 ; i++) { | |
| 127 | // Clip area | |||
| 128 | gs.setClip(i*32, j*32, 32, 32); | |||
| 129 | gsb.setClip(i*32, j*32, 32, 32); | |||
| 130 | // Draw background | |||
| 131 | gs.drawImage(imgGame, i*32-302, j*32-390, applet); | |||
| 132 | gsb.drawImage(imgGame, i*32-302, j*32-390, applet); | |||
| 133 | // Draw bubbles | |||
| 134 | gs.drawImage(bubbles[i], i*32, j*32, applet); | |||
| 135 | gsb.drawImage(colorblindBubbles[i], i*32, j*32, applet); | |||
| 136 | } | |||
| 137 | } | |||
| 138 | ||||
| 139 | // Gets launcher image | |||
| 140 | EffectImage launcher = new EffectImage(applet, LAUNCHER_IMG, LAUNCHER_ALPHA_IMG); | |||
| 141 | ||||
| 142 | double rotateAngle = 0.025 * Math.PI; | |||
| 143 | ||||
| 144 | Image result = null; | |||
| 3895 | 95 | 145 | for (int i=0 ; i<41 ; i++) { | |
| 146 | result = launcher.getRotate(rotateAngle*(i-20), 50, 50); | |||
| 147 | ||||
| 148 | // background | |||
| 149 | gb.setClip(0, i*76, 86, 76); | |||
| 150 | gb.drawImage(result, -8, i*76-6, applet); | |||
| 151 | ||||
| 31160 | 3895 | 152 | for (int j=0 ; j<8 ; j++) { | |
| 153 | // Clip area | |||
| 154 | gs.setClip(j*32, i*32, 32, 32); | |||
| 155 | gsb.setClip(j*32, i*32, 32, 32); | |||
| 156 | // draw launcher | |||
| 157 | gs.drawImage(result, j*32-34, i*32-34, applet); | |||
| 158 | gsb.drawImage(result, j*32-34, i*32-34, applet); | |||
| 159 | } | |||
| 160 | } | |||
| 161 | } | |||
| 162 | ||||
| 9696 | 0 | 163 | public void changeColor(int newColor) { | |
| 164 | currentColor = newColor; | |||
| 165 | } | |||
| 166 | ||||
| 121373 | 0 | 167 | public void changeDirection(int newDirection) { | |
| 168 | currentDirection = newDirection; | |||
| 169 | } | |||
| 170 | ||||
| 834589 | 0 | 171 | public void paint(Graphics g, GameApplet applet) { | |
| 172 | Rectangle r = this.getSpriteArea(); | |||
| 173 | ||||
| 174 | g.setClip(r); | |||
| 175 | g.drawImage(backgroundImage, 276, 362-currentDirection*76, applet); | |||
| 176 | g.setClip(302, 390, 32, 32); | |||
| 830914 | 3675 | 177 | if (FrozenBubble.getMode() == FrozenBubble.GAME_NORMAL) { | |
| 178 | g.drawImage(spritesImage, 302-currentColor*32, 390-currentDirection*32, applet); | |||
| 179 | } | |||
| 180 | else { | |||
| 181 | g.drawImage(spritesBlindImage, 302-currentColor*32, 390-currentDirection*32, applet); | |||
| 182 | } | |||
| 183 | } | |||
| 184 | } | |||
| ***TER 96% (25/26) of SOURCE FILE LaunchBubbleSprite.java | ||||