Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 35 | chris | 1 | unit app_entity_powerup; |
| 2 | |||
| 3 | interface |
||
| 4 | |||
| 5 | uses sux_constant, sux_object, app_constant, app_entity_main, |
||
| 6 | app_game_player, resource_texture; |
||
| 7 | |||
| 8 | type |
||
| 9 | TPowerUp=record |
||
| 10 | typus: SXState; |
||
| 11 | end; |
||
| 12 | SAEPowerUp=class(SAEntity) |
||
| 13 | powerup: TPowerUp; |
||
| 14 | |||
| 15 | procedure onRender; override; |
||
| 16 | |||
| 17 | function getCrystalCount: SXInt; |
||
| 18 | function getBombCount: SXInt; |
||
| 19 | |||
| 20 | procedure appears; |
||
| 21 | procedure setPowerUp(const powerup: SXState); |
||
| 22 | procedure destroyAllCrystals; |
||
| 23 | procedure collect; |
||
| 24 | |||
| 25 | procedure onTimer; override; |
||
| 26 | |||
| 27 | procedure initialize; override; |
||
| 28 | constructor Create(parent:TObject); |
||
| 29 | destructor Destroy; override; |
||
| 30 | end; |
||
| 31 | |||
| 32 | implementation |
||
| 33 | |||
| 34 | uses main, app_entity_crystal, gl_main, OpenGL, app_particle_powerupappears; |
||
| 35 | |||
| 36 | |||
| 37 | // --- SAEPowerUp |
||
| 38 | |||
| 39 | |||
| 40 | procedure SAEPowerUp.onRender; |
||
| 41 | var size: SXFloat; |
||
| 42 | begin |
||
| 43 | inherited; |
||
| 44 | |||
| 45 | size := sx.math._sin(app.game.getGameTimer * 400) * 0.05; |
||
| 46 | |||
| 47 | glPushMatrix; |
||
| 48 | glTranslatef(settings.pos.x, settings.pos.y, 0); |
||
| 49 | glScalef(1 + size, (1 - size), 1); |
||
| 50 | |||
| 51 | gl.gl2D.renderPatternQuad(app.scene.board.settings.icon, SX_GL_BLEND_AVERAGE, |
||
| 52 | sx.convert.ColorRGBOf(1,1,1), 0.5, 0, 0, 1, 1, 0, 0, 23); |
||
| 53 | |||
| 54 | glPopMatrix; |
||
| 55 | end; |
||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | |||
| 60 | function SAEPowerUp.getCrystalCount: SXInt; |
||
| 61 | var e, count: SXInt; |
||
| 62 | begin |
||
| 63 | count := 0; |
||
| 64 | for e := 0 to app.game.entities.getMax do |
||
| 65 | if (app.game.getEntity(e).settings.typus = SX_ENTITY_CRYSTAL) then inc(count); |
||
| 66 | result := count; |
||
| 67 | end; |
||
| 68 | |||
| 69 | |||
| 70 | function SAEPowerUp.getBombCount: SXInt; |
||
| 71 | var e, count: SXInt; |
||
| 72 | begin |
||
| 73 | count := 0; |
||
| 74 | for e := 0 to app.game.entities.getMax do |
||
| 75 | if (app.game.getEntity(e).settings.typus = SX_ENTITY_POWERUP) then |
||
| 76 | begin |
||
| 77 | if (SAEPowerUp(app.game.getEntity(e)).powerup.typus = SX_EPOWERUP_TYPUS_BOMB) then inc(count); |
||
| 78 | end; |
||
| 79 | |||
| 80 | result := count; |
||
| 81 | end; |
||
| 82 | |||
| 83 | |||
| 84 | |||
| 85 | |||
| 86 | procedure SAEPowerUp.appears; |
||
| 87 | var appear: SAPPowerUpAppears; |
||
| 88 | begin |
||
| 89 | appear := SAPPowerUpAppears(app.game.createParticleSystem(SX_PARTICLESYSTEM_POWERUPAPPEARS)); |
||
| 90 | appear.createBubbles(getPos); |
||
| 91 | end; |
||
| 92 | |||
| 93 | |||
| 94 | procedure SAEPowerUp.setPowerUp(const powerup: SXState); |
||
| 95 | begin |
||
| 96 | self.powerup.typus := powerup; |
||
| 97 | case powerup of |
||
| 98 | SX_EPOWERUP_TYPUS_PIXEL : settings.texture := app.scene.board.settings.icon_pixel; |
||
| 99 | SX_EPOWERUP_TYPUS_FLOWERS : settings.texture := app.scene.board.settings.icon_flowers; |
||
| 100 | SX_EPOWERUP_TYPUS_SLOWMOTION : settings.texture := app.scene.board.settings.icon_slowmotion; |
||
| 101 | SX_EPOWERUP_TYPUS_CREATECRYSTALS : settings.texture := app.scene.board.settings.icon_createcrystals; |
||
| 102 | SX_EPOWERUP_TYPUS_CONCAVE : settings.texture := app.scene.board.settings.icon_concave; |
||
| 103 | SX_EPOWERUP_TYPUS_BOMB : settings.texture := app.scene.board.settings.icon_bomb; |
||
| 104 | end; |
||
| 105 | end; |
||
| 106 | |||
| 107 | |||
| 108 | procedure SAEPowerUp.destroyAllCrystals; |
||
| 109 | var e: SXInt; |
||
| 110 | entity: SAEntity; |
||
| 111 | begin |
||
| 112 | for e := app.game.entities.getMax downto 0 do |
||
| 113 | if (e <= app.game.entities.getMax) then |
||
| 114 | begin |
||
| 115 | entity := SAEntity(app.game.entities.getObject(e)); |
||
| 116 | if (entity is SAECrystal) then |
||
| 117 | begin |
||
| 118 | SAECrystal(entity).generateShards; |
||
| 119 | app.game.deleteEntity(entity); |
||
| 120 | end; |
||
| 121 | end; |
||
| 122 | end; |
||
| 123 | |||
| 124 | |||
| 125 | procedure SAEPowerUp.collect; |
||
| 126 | begin |
||
| 127 | case powerup.typus of |
||
| 128 | SX_EPOWERUP_TYPUS_PIXEL : app.game.settings.effects.pixel := 5; |
||
| 129 | SX_EPOWERUP_TYPUS_FLOWERS : app.game.settings.effects.flowers := 7; |
||
| 130 | SX_EPOWERUP_TYPUS_SLOWMOTION : app.game.settings.effects.slowmotion := 4; |
||
| 131 | SX_EPOWERUP_TYPUS_CREATECRYSTALS : app.game.settings.effects.createcrystals := 1; |
||
| 132 | SX_EPOWERUP_TYPUS_CONCAVE : app.game.settings.effects.concave := 10; |
||
| 133 | SX_EPOWERUP_TYPUS_BOMB : destroyAllCrystals; |
||
| 134 | end; |
||
| 135 | app.sound.playSample2D('sounds\pickup'); |
||
| 136 | end; |
||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | procedure SAEPowerUp.onTimer; |
||
| 142 | begin |
||
| 143 | end; |
||
| 144 | |||
| 145 | |||
| 146 | |||
| 147 | |||
| 148 | procedure SAEPowerUp.initialize; |
||
| 149 | begin |
||
| 150 | end; |
||
| 151 | |||
| 152 | |||
| 153 | constructor SAEPowerUp.Create(parent:TObject); |
||
| 154 | var randomvalue: SXInt; |
||
| 155 | totalrandom: SXInt; |
||
| 156 | powerup: SXState; |
||
| 157 | begin |
||
| 158 | inherited Create(parent); |
||
| 159 | |||
| 160 | setupAppearance(nil, 20); |
||
| 161 | setBlending(SX_GL_BLEND_ADDITIVE, 1.0); |
||
| 162 | |||
| 163 | with app.ini.settings.gameplay do |
||
| 164 | begin |
||
| 165 | totalrandom := poweruprandomcrystal + poweruprandomconcave + poweruprandompixel |
||
| 166 | + poweruprandomflowers + poweruprandomslowmotion + poweruprandombomb; |
||
| 167 | randomvalue := sx.math.random.getRandomInt(1, totalrandom); |
||
| 168 | |||
| 169 | // Select powerup by given chances. |
||
| 170 | powerup := SX_NONE; |
||
| 171 | if (randomvalue <= poweruprandomcrystal) then powerup := SX_EPOWERUP_TYPUS_CREATECRYSTALS |
||
| 172 | else if (randomvalue <= poweruprandomcrystal + poweruprandomconcave) then powerup := SX_EPOWERUP_TYPUS_CONCAVE |
||
| 173 | else if (randomvalue <= poweruprandomcrystal + poweruprandomconcave + poweruprandompixel) then powerup := SX_EPOWERUP_TYPUS_PIXEL |
||
| 174 | else if (randomvalue <= poweruprandomcrystal + poweruprandomconcave + poweruprandompixel + poweruprandomflowers) then powerup := SX_EPOWERUP_TYPUS_FLOWERS |
||
| 175 | else if (randomvalue <= poweruprandomcrystal + poweruprandomconcave + poweruprandompixel + poweruprandomflowers + poweruprandomslowmotion) then powerup := SX_EPOWERUP_TYPUS_SLOWMOTION |
||
| 176 | else powerup := SX_EPOWERUP_TYPUS_BOMB; |
||
| 177 | |||
| 178 | // Select bomb if enough crystals are present. |
||
| 179 | if (getCrystalCount >= app.ini.settings.gameplay.spawnpowerupbomboncrystals) then |
||
| 180 | if (getBombCount = 0) then powerup := SX_EPOWERUP_TYPUS_BOMB; |
||
| 181 | |||
| 182 | if (powerup = SX_NONE) then powerup := SX_EPOWERUP_TYPUS_CREATECRYSTALS; |
||
| 183 | setPowerUp(powerup); |
||
| 184 | end; |
||
| 185 | |||
| 186 | app.sound.playSample2D('sounds\powerup_appears'); |
||
| 187 | setFlipVertical(true); |
||
| 188 | |||
| 189 | settings.pos.x := sx.math.random.getRandomFloat(-100, 100); |
||
| 190 | settings.pos.y := sx.math.random.getRandomFloat(-100, 100); |
||
| 191 | appears; |
||
| 192 | end; |
||
| 193 | |||
| 194 | |||
| 195 | destructor SAEPowerUp.Destroy; |
||
| 196 | begin |
||
| 197 | inherited; |
||
| 198 | end; |
||
| 199 | |||
| 200 | |||
| 201 | end. |