Advertisement
Guest User

Untitled

a guest
Oct 24th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.47 KB | None | 0 0
  1. #------------------------------------------------------------------------------#
  2. # Galv's Invader Mini Game
  3. #------------------------------------------------------------------------------#
  4. # For: RPGMAKER VX ACE
  5. # Version 1.2
  6. # Thanks Ocedic for add-on ideas
  7. #------------------------------------------------------------------------------#
  8. # 2013-03-20 - Version 1.2 - added options for reset ratio and max gun powerup
  9. # 2013-03-20 - Version 1.1 - added enemy types, new gun type, new powerup
  10. # 2013-03-18 - Version 1.0 - release
  11. #------------------------------------------------------------------------------#
  12. # A simple shooter mini game that can be played within Ace with a script call.
  13. #
  14. # The game is designed to be simple. Enemies are random, they shoot random
  15. # lazors at you. Powerups are random. Slowly during the course of the game
  16. # the enemies spawn faster and faster until eventually the player will be
  17. # overrun completely and die. A set time through the game, a reset powerup will
  18. # spawn. If the player manages to get it, they get another chance at more
  19. # points as it sets the spawn speed back to the start.
  20. # Variables are used for current score and high score which you can use in
  21. # your game to give your player bonuses for doing well or not.
  22. #
  23. # You'll need the demo for all the graphics (but feel free to create your own)
  24. #
  25. # NOTE: This is intended to be simple for now. Please don't ask for add-ons
  26. # or improvements. I might improve it later but for now, it is what it is.
  27. #------------------------------------------------------------------------------#
  28.  
  29. #------------------------------------------------------------------------------#
  30. # CONTROLS
  31. #------------------------------------------------------------------------------#
  32. # Left and Right - moves left and right
  33. # Space/Z/Enter - fire your lazor
  34. # ESC/X - Leave the mini game
  35. # A - Use held item (currently only nuke)
  36. #------------------------------------------------------------------------------#
  37. # POWERUPS
  38. #------------------------------------------------------------------------------#
  39. # Heath - restores shields completely. If shields full, adds to an bonus bar
  40. # Zzzz - resets enemy spawn rate to beginning (spawned only at a set time)
  41. # Nuke - Can only hold one nuke at a time. Press A to destroy all enemies.
  42. #
  43. # Lazors - Get lazors or increases number of lazors fired
  44. # Lazorball - Get lazorballs or increases number of lazorballs fired
  45. #
  46. # NOTE: Obtaining weapons equips them or improves them if already equipped
  47. # NOTE2: Yes, I do know it's not spelled "lazor"
  48. #------------------------------------------------------------------------------#
  49.  
  50. #------------------------------------------------------------------------------#
  51. # SCRIPT CALL:
  52. #------------------------------------------------------------------------------#
  53. # SceneManager.call(Scene_Invaders) # Starts the minigame.
  54. #------------------------------------------------------------------------------#
  55.  
  56. ($imported ||= {})["Galv_Invaders"] = true
  57. module Galv_SI
  58.  
  59. #------------------------------------------------------------------------------#
  60. # SCRIPT SETTINGS
  61. #------------------------------------------------------------------------------#
  62.  
  63. #----------------#
  64. # PLAYER OPTIONS #
  65. #----------------#
  66.  
  67. PLAYER_SHIELDS = 1 # Hits player can take before game over
  68.  
  69. MAX_SHOTS = 10 # Maxium number of shots player can have on screen at a time
  70. Max_Gun_Level = 1 # Max gun powerup level (5 is the highest)
  71.  
  72. SE = ["Attack2",50,150] # "SE_Name",volume,pitch - SE for player laser
  73. SE1 = ["Heal5",50,160] # "SE_Name",volume,pitch - SE for player lazorball
  74. NSE = ["Explosion3",50,100] # "SE_Name",volume,pitch - SE for nuke
  75.  
  76. PSE = ["Damage5",50,150] # "SE_Name",volume,pitch - SE when player damaged
  77. KSE = ["GabeN",80,100] # "SE_Name",volume,pitch - SE when destroyed
  78.  
  79. BSE = ["Down4",50,150] # "SE_Name",volume,pitch - SE when bonus shield gain
  80. PUSE = ["Item1",50,150] # "SE_Name",volume,pitch - SE when get powerup
  81.  
  82. SHIP_SPEED = 5 # Speed at which player can move ship left and right
  83. LAZOR_SPEED = 5 # Speed the lazor fires
  84.  
  85.  
  86. #---------------#
  87. # ENEMY OPTIONS #
  88. #---------------#
  89.  
  90. SPAWN_SPEED = 100 # Lower means faster spawn. Higher is slower spawn.
  91.  
  92. LEVEL2 = 10 # Seconds until level 2 ships can start spawning
  93. LEVEL3 = 100000
  94. LEVEL1_HP = 1 # Level 1 enemies have this much hp
  95. LEVEL2_HP = 3 # Level 2 enemies have this much hp
  96. LEVEL3_HP = 3 # Level 3 enemies have this much hp
  97.  
  98. ELAZOR_SPEED = 5 # Enemy lazor speed
  99.  
  100. ASE = ["Attack2",50,110] # "SE_Name",volume,pitch - SE for enemy shooting
  101. DSE = ["fallbig",70,100] # "SE_Name",volume,pitch - SE for enemy dying
  102.  
  103.  
  104. #---------------#
  105. # OTHER OPTIONS #
  106. #---------------#
  107.  
  108. SCORE_VAR = 70 # Variable id to keep track of score
  109. HIGH_SCORE_VAR = 71 # Variable id to keep track of highest score
  110.  
  111. RESET_PUP = 99999 # Seconds between reset powerup spawns. If the
  112. # player manages to get this, the enemy spawn rate is
  113. # reset and has a chance to earn more points!
  114. RESET_AMOUNT = 0.5 # Ratio of difficulty when reset powerup is obtained
  115.  
  116. SOUND_TIMER = 5 # Prevent enemy lazor sound spam by increasing this
  117.  
  118. DESTROY_PUPS = false # Can destroy powerups true or false
  119.  
  120. LAZOR_DAMAGE = 1 # Damage done when lazors hit
  121. COLLIDE_DAMAGE = 4 # Damage done when collide with enemy
  122.  
  123. BGM_LIST = [ # don't touch
  124. # List of BGM's to random. ["BGM_Name",volume,pitch]
  125.  
  126. ["GabeN",100,100],
  127.  
  128. # ["Battle5",100,110], # Add more as required
  129. # ["Battle5",100,110], # Add more as required
  130. # ["Battle5",100,110], # Add more as required
  131.  
  132. ] # don't touch
  133.  
  134.  
  135. #------------------------------------------------------------------------------#
  136. # END OF SCRIPT SETTINGS
  137. #------------------------------------------------------------------------------#
  138. end
  139.  
  140.  
  141. #-------------------------------------------------------------------------------
  142. # CACHE
  143. #-------------------------------------------------------------------------------
  144.  
  145. module Cache
  146. def self.space(filename)
  147. load_bitmap("Graphics/Invaders/", filename)
  148. end
  149. end # module Cache
  150.  
  151. #-------------------------------------------------------------------------------
  152. # SCENE
  153. #-------------------------------------------------------------------------------
  154.  
  155. class Scene_Invaders < Scene_Base
  156. def start
  157. $game_system.save_bgm
  158. super
  159. SceneManager.clear
  160. Graphics.freeze
  161. initialize_game
  162. end
  163.  
  164. def initialize_game
  165. play_bgm
  166. init_variables
  167. create_backdrop
  168. create_sprites
  169. create_stats
  170. end
  171.  
  172. def play_bgm
  173. m = Galv_SI::BGM_LIST[rand(Galv_SI::BGM_LIST.count)]
  174. RPG::BGM.new(m[0],m[1],m[2]).play
  175. end
  176.  
  177. def init_variables
  178. @nukeall = false
  179. @sound_timer = Galv_SI::SOUND_TIMER
  180. @enemy_wave = 1
  181. @guns = 1
  182. @gun_type = 0
  183. @bonus_shields = 0
  184. @reset_pup = Galv_SI::RESET_PUP * 60
  185. @player_shields = Galv_SI::PLAYER_SHIELDS
  186. $game_variables[Galv_SI::SCORE_VAR] = 0
  187. @plazors = []
  188. @elazors = []
  189. @enemies = []
  190. @explodes = []
  191. @pups = []
  192. @spawn_timer = rand(Galv_SI::SPAWN_SPEED)
  193. @ticker = 100
  194. @game_time = 0
  195. @alien_count = 0
  196. @pups_count = 0
  197. @difficulty = 0.to_f
  198. @dead = false
  199. end
  200.  
  201. def create_backdrop
  202. @backdrop = Plane.new
  203. @backdrop.bitmap = Cache.space("backdrop")
  204. @backdrop.z = -1
  205. @flash = Sprite.new
  206. @flash.bitmap = Bitmap.new(Graphics.width,Graphics.height)
  207. @flash.bitmap.fill_rect(@flash.bitmap.rect,Color.new(255,255,255))
  208. @flash.z = 2000
  209. @flash.opacity = 0
  210. end
  211.  
  212. def create_sprites
  213. @player = Sprite_Player.new(@viewport1)
  214. @item_held = Sprite.new
  215. @item_held.x = Graphics.width / 4 + 40
  216. @item_held.y = 15
  217. @item_held.z = 100
  218. end
  219.  
  220. def draw_item_held
  221. @item_held.bitmap.dispose if @item_held.bitmap
  222. @item_held.opacity = 255
  223. return @item_held.opacity = 0 if @item.nil?
  224. @item_held.bitmap = Cache.space("item_" + @item.to_s)
  225. end
  226.  
  227. def create_stats
  228. @score_window = Window_InvaderScore.new
  229. @score_window
  230. end
  231.  
  232. def play_time
  233. @game_time / 60
  234. end
  235.  
  236. def update
  237. update_flash
  238. @game_time += 1
  239. @reset_pup -= 1
  240. super
  241. update_backdrop
  242. update_player
  243. update_splosions
  244. update_plazors
  245. update_elazors
  246. update_enemies
  247. # update_pups
  248. if !@dead
  249. update_spawn
  250. else
  251. update_game_over
  252. end
  253. end
  254.  
  255. def update_flash
  256. @flash.opacity -= 3 if @flash.opacity > 0
  257. end
  258.  
  259. def update_backdrop
  260. @backdrop.oy -= 1
  261. end
  262.  
  263. def update_spawn
  264. if @spawn_timer <= 0
  265. t = alien_type
  266. if rand(alien_type).to_i == alien_type
  267. @enemies << Sprite_Alien.new(@viewport1,@alien_count,t)
  268. @alien_count += 1
  269. else
  270. @enemies << Sprite_Alien.new(@viewport1,@alien_count,0)
  271. @alien_count += 1
  272. end
  273. @spawn_timer = 50 + rand(Galv_SI::SPAWN_SPEED) / 2 - @difficulty
  274. end
  275. @ticker -= 1
  276. if @ticker <= 0
  277. @difficulty += 1
  278. @ticker = 100
  279. end
  280. @spawn_timer -= 1
  281. end
  282.  
  283. def alien_type
  284. r = rand(play_time)
  285. if r < Galv_SI::LEVEL2
  286. return 0
  287. elsif r < Galv_SI::LEVEL3
  288. return 1
  289. else
  290. return 2
  291. end
  292. end
  293.  
  294. def update_player
  295. @player.update
  296. update_player_actions
  297. end
  298.  
  299. def init_game_over
  300. RPG::BGM.fade(10)
  301. @game_over = Sprite.new
  302. @game_over.bitmap = Cache.space("game-over")
  303. @game_over.opacity = 0
  304. @game_over.z = 500
  305. end
  306.  
  307. def update_game_over
  308. @game_over.opacity += 3
  309. if @game_over.opacity >= 255 && Input.trigger?(:C)
  310. dispose_graphics
  311. initialize_game
  312. end
  313. end
  314.  
  315. def update_player_actions
  316. if Input.trigger?(:C) && !@dead
  317. return if Galv_SI::MAX_SHOTS * @guns <= @plazors.count
  318. player_shoot
  319. end
  320. if Input.trigger?(:B)
  321. SceneManager.goto(Scene_Map)
  322. end
  323. if Input.trigger?(:X) && @item && !@dead
  324. @nukeall = true
  325. RPG::SE.new(Galv_SI::NSE[0],Galv_SI::NSE[1],Galv_SI::NSE[2]).play
  326. @difficulty *= 0.75
  327. @flash.opacity = 225
  328. @item = nil
  329. draw_item_held
  330. end
  331. end
  332.  
  333. def player_shoot
  334. case @gun_type
  335. when 0 # Normal Lazers
  336. RPG::SE.new(Galv_SI::SE[0],Galv_SI::SE[1],Galv_SI::SE[2]).play
  337. case @guns
  338. when 1
  339. @plazors << Sprite_Lazor.new(@viewport1,@player.x,@player.y)
  340. when 2
  341. 2.times { |i|
  342. @plazors << Sprite_Lazor.new(@viewport1,@player.x - 20 + i * 40,@player.y)
  343. }
  344. when 3
  345. 3.times { |i|
  346. @plazors << Sprite_Lazor.new(@viewport1,@player.x - 20 + i * 20,@player.y)
  347. }
  348. when 4
  349. 4.times { |i|
  350. @plazors << Sprite_Lazor.new(@viewport1,@player.x - 30 + i * 20,@player.y)
  351. }
  352. when 5
  353. 5.times { |i|
  354. @plazors << Sprite_Lazor.new(@viewport1,@player.x - 30 + i * 15,@player.y)
  355. }
  356. end
  357. end
  358. end
  359.  
  360.  
  361. def update_plazors
  362. @plazors.each_with_index { |lazor,i|
  363. lazor.update
  364. if lazor.y < -10
  365. lazor.dispose
  366. @plazors.delete_at(i)
  367. end
  368. }
  369. end
  370.  
  371. def update_elazors
  372. @elazors.each_with_index { |lazor,i|
  373. next if !lazor
  374. lazor.update
  375. if lazor.y > Graphics.height
  376. lazor.dispose
  377. @elazors[i] = false
  378. elsif lazor.y > (Graphics.height - @player.height) && player_hit?(lazor.x,lazor.y)
  379. damage_player(Galv_SI::LAZOR_DAMAGE)
  380. lazor.dispose
  381. @elazors[i] = false
  382. end
  383. }
  384. end
  385.  
  386. def update_enemies
  387. @sound_timer += 1
  388. @enemies.each_with_index { |enemy,i|
  389. next if enemy.nil?
  390. enemy.update
  391. if enemy_hit?(enemy) || @nukeall
  392. enemy.hp -= @nukeall ? enemy.mhp : 1
  393. if enemy.hp <= 0
  394. destroy_enemy(enemy.mhp)
  395. @explodes << Sprite_Splosion.new(@viewport1,enemy.x,enemy.y)
  396. enemy.dispose
  397. @enemies[i] = nil
  398. else
  399. RPG::SE.new(Galv_SI::PSE[0],Galv_SI::PSE[1],Galv_SI::PSE[2]).play
  400. enemy.flash(Color.new(255,155,155),20)
  401. end
  402. elsif enemy.y > (Graphics.height - @player.height) && player_hit?(enemy.x,enemy.y)
  403. destroy_enemy(enemy.mhp)
  404. @explodes << Sprite_Splosion.new(@viewport1,enemy.x,enemy.y)
  405. enemy.dispose
  406. @enemies[i] = nil
  407. damage_player(Galv_SI::COLLIDE_DAMAGE)
  408. elsif rand(1000) > (995 - @difficulty)
  409. if @elazors[i].nil?
  410. if @sound_timer >= Galv_SI::SOUND_TIMER
  411. RPG::SE.new(Galv_SI::ASE[0],Galv_SI::ASE[1],Galv_SI::ASE[2]).play
  412. @sound_timer = 0
  413. end
  414. @elazors[i] = Sprite_ELazor.new(@viewport1,enemy.x,enemy.y)
  415. end
  416. end
  417. }
  418. @nukeall = false
  419. end
  420.  
  421. # def update_pups
  422. # if @reset_pup <= 0
  423. # @pups << Sprite_Powerup.new(@viewport1,@pups_count,999)
  424. # @reset_pup = (Galv_SI::RESET_PUP + @enemy_wave) * 60
  425. # end
  426. # if rand(1000) > (998) && !@dead
  427. # @pups << Sprite_Powerup.new(@viewport1,@pups_count,rand(4))
  428. # @pups_count += 1
  429. # end
  430. # @pups.each_with_index { |pup,i|
  431. # next if pup.nil?
  432. # pup.update
  433. # if enemy_hit?(pup,false) && Galv_SI::DESTROY_PUPS
  434. # RPG::SE.new(Galv_SI::DSE[0],Galv_SI::DSE[1],Galv_SI::DSE[2]).play
  435. # @explodes << Sprite_Splosion.new(@viewport1,pup.x,pup.y)
  436. # pup.dispose
  437. # @pups[i] = nil
  438. # elsif pup.y > (Graphics.height - @player.height) && player_hit?(pup.x,pup.y)
  439. # do_powerup(pup.type)
  440. # pup.dispose
  441. # @pups[i] = nil
  442. # end
  443. # }
  444. # end
  445.  
  446. def damage_player(amount)
  447. RPG::SE.new(Galv_SI::PSE[0],Galv_SI::PSE[1],Galv_SI::PSE[2]).play
  448. @player.flash(Color.new(255,155,155),20)
  449. if @bonus_shields > 0
  450. @bonus_shields = [@bonus_shields - amount,0].max
  451. else
  452. @player_shields -= amount
  453. end
  454. @score_window.refresh(@player_shields.to_f,@bonus_shields)
  455. destroy_player if @player_shields <= 0
  456. end
  457.  
  458. def destroy_enemy(score)
  459. RPG::SE.new(Galv_SI::DSE[0],Galv_SI::DSE[1],Galv_SI::DSE[2]).play
  460. $game_variables[Galv_SI::SCORE_VAR] += score
  461. if $game_variables[Galv_SI::SCORE_VAR] > $game_variables[Galv_SI::HIGH_SCORE_VAR]
  462. $game_variables[Galv_SI::HIGH_SCORE_VAR] += score
  463. end
  464. @score_window.refresh(@player_shields.to_f,@bonus_shields)
  465. end
  466.  
  467. def destroy_player
  468. @player_shields = 0
  469. @explodes << Sprite_Splosion.new(@viewport1,@player.x,@player.y,2)
  470. @player.opacity = 0
  471. @player.x = -100
  472. RPG::SE.new(Galv_SI::KSE[0],Galv_SI::KSE[1],Galv_SI::KSE[2]).play
  473. @score_window.refresh(@player_shields.to_f,@bonus_shields)
  474. init_game_over
  475. @dead = true
  476. end
  477.  
  478. def update_splosions
  479. @explodes.each_with_index { |ex,i|
  480. ex.update
  481. if ex.finished?
  482. ex.dispose
  483. @explodes.delete_at(i)
  484. end
  485. }
  486. end
  487.  
  488. def player_hit?(x,y)
  489. if x.between?(@player.x - player_width / 6, @player.x + player_width / 6) &&
  490. y.between?(@player.y - player_height, @player.y)
  491. return true
  492. end
  493. return false
  494. end
  495.  
  496. def enemy_hit?(enemy, kill = true)
  497. @plazors.each_with_index { |lazor,i|
  498. if lazor.x.between?(enemy.x - enemy.width / 2, enemy.x + enemy.width / 2) &&
  499. lazor.y.between?(enemy.y - enemy.height / 2, enemy.y + enemy.height / 2)
  500. if kill
  501. lazor.dispose
  502. @plazors.delete_at(i)
  503. end
  504. return true
  505. end
  506. }
  507. false
  508. end
  509.  
  510. def player_width
  511. @player.bitmap.width
  512. end
  513. def player_height
  514. @player.bitmap.height
  515. end
  516.  
  517. def terminate
  518. super
  519. SceneManager.snapshot_for_background
  520. dispose_graphics
  521. $game_system.replay_bgm
  522. end
  523.  
  524. def dispose_graphics
  525. @item_held.bitmap.dispose if @item_held.bitmap
  526. @plazors.each { |object| object.dispose if object }
  527. @elazors.each { |object| object.dispose if object }
  528. @enemies.each { |object| object.dispose if object }
  529. @explodes.each { |object| object.dispose if object }
  530. @pups.each { |object| object.dispose if object }
  531. @backdrop.bitmap.dispose
  532. @backdrop.dispose
  533. @player.bitmap.dispose
  534. @player.dispose
  535. if @game_over
  536. @game_over.bitmap.dispose
  537. @game_over.dispose
  538. end
  539. @score_window.dispose
  540. end
  541. end # Scene_Invaders < Scene_Base
  542.  
  543. #-------------------------------------------------------------------------------
  544. # PLAYER SPRITE
  545. #-------------------------------------------------------------------------------
  546.  
  547. class Sprite_Player < Sprite
  548. def initialize(viewport)
  549. super(viewport)
  550. init_position
  551. end
  552.  
  553. def init_position
  554. setup_player_image
  555. end
  556.  
  557. def dispose
  558. super
  559. end
  560.  
  561. def update
  562. super
  563. update_src_rect
  564. update_position
  565. end
  566.  
  567. def setup_player_image
  568. @cell = 1
  569. self.bitmap = Cache.space("player")
  570. @cw = bitmap.width / 3
  571. self.src_rect.set(@cell * @cw, 0, @cw, height)
  572. self.ox = @cw / 2
  573. self.oy = height
  574. self.x = Graphics.width / 2
  575. self.y = Graphics.height - height / 4
  576. end
  577.  
  578. def width
  579. self.bitmap.width / 3
  580. end
  581. def height
  582. self.bitmap.height
  583. end
  584.  
  585. def update_src_rect
  586. @cell = 1 if @cell > 3
  587. sx = @cell * @cw
  588. self.src_rect.set(sx, 0, @cw, height)
  589. end
  590.  
  591. def update_position
  592. if Input.press?(:LEFT) && !Input.press?(:RIGHT)
  593. @cell = 0
  594. self.x -= Galv_SI::SHIP_SPEED if self.x > width / 2
  595. elsif Input.press?(:RIGHT) && !Input.press?(:LEFT)
  596. @cell = 2
  597. self.x += Galv_SI::SHIP_SPEED if self.x < Graphics.width - width / 2
  598. else
  599. @cell = 1
  600. end
  601. end
  602. end # Sprite_Player < Sprite
  603.  
  604.  
  605. #-------------------------------------------------------------------------------
  606. # LAZOR SPRITES
  607. #-------------------------------------------------------------------------------
  608.  
  609. class Sprite_Lazor < Sprite
  610. def initialize(viewport,x,y,type = 0,dir = 0)
  611. super(viewport)
  612. self.x = x
  613. self.y = y - 20
  614. @type = type
  615. @dir = dir
  616. setup_lazor_image
  617. end
  618.  
  619. def dispose
  620. super
  621. end
  622.  
  623. def update
  624. super
  625. update_position
  626. end
  627.  
  628. def setup_lazor_image
  629. case @type
  630. when 0
  631. self.bitmap = Cache.space("lazor")
  632. when 1
  633. self.bitmap = Cache.space("lazor_ball")
  634. end
  635. self.ox = bitmap.width / 2
  636. self.oy = bitmap.height / 2
  637. end
  638.  
  639. def update_position
  640. self.y -= Galv_SI::LAZOR_SPEED
  641. case @dir
  642. when 1
  643. self.x -= Galv_SI::LAZOR_SPEED.to_f / 4
  644. when 2
  645. self.x += Galv_SI::LAZOR_SPEED.to_f / 4 + 1
  646. when 3
  647. self.x -= Galv_SI::LAZOR_SPEED
  648. when 4
  649. self.x += Galv_SI::LAZOR_SPEED
  650. end
  651. end
  652. end # Sprite_Lazor < Sprite
  653.  
  654.  
  655. class Sprite_ELazor < Sprite
  656. def initialize(viewport,x,y)
  657. super(viewport)
  658. self.x = x
  659. self.y = y - 20
  660. setup_lazor_image
  661. end
  662.  
  663. def dispose
  664. super
  665. end
  666.  
  667. def update
  668. super
  669. update_position
  670. end
  671.  
  672. def setup_lazor_image
  673. self.bitmap = Cache.space("elazor")
  674. self.ox = bitmap.width / 2
  675. self.oy = bitmap.height / 2
  676. end
  677.  
  678. def update_position
  679. self.y += Galv_SI::ELAZOR_SPEED
  680. end
  681. end # Sprite_ELazor < Sprite
  682.  
  683. #-------------------------------------------------------------------------------
  684. # ALIEN SPRITES
  685. #-------------------------------------------------------------------------------
  686.  
  687. class Sprite_Alien < Sprite
  688. attr_accessor :hp
  689. attr_reader :mhp
  690.  
  691. def initialize(viewport,id,type = 0)
  692. super(viewport)
  693. @type = type
  694. @id = id
  695. @move = true # true is right, false is left
  696. @speed = rand(2) + 1
  697. @ticker = 0
  698. setup_enemy
  699. init_position
  700. end
  701.  
  702. def init_position
  703. self.x = rand(Graphics.width)
  704. self.y = -10
  705. end
  706.  
  707. def dispose
  708. super
  709. end
  710.  
  711. def update
  712. super
  713. update_move
  714. end
  715.  
  716. def update_move
  717. case @move
  718. when true # Right
  719. self.x += 1 * (@ticker * 0.06) if self.x <= Graphics.width
  720. when false # Left
  721. self.x -= 1 * (@ticker * 0.06) if self.x > 0
  722. end
  723. @ticker -= 1
  724. self.y += @speed
  725. if @ticker <= 0
  726. @move = self.x < Graphics.width / 2 ? true : false
  727. @ticker = rand(90)
  728. end
  729. end
  730.  
  731. def setup_enemy
  732. self.bitmap = Cache.space("alien" + @type.to_s)
  733. self.ox = bitmap.width / 2
  734. self.oy = bitmap.height / 2
  735.  
  736. case @type
  737. when 0
  738. @hp = Galv_SI::LEVEL1_HP
  739. when 1
  740. @hp = Galv_SI::LEVEL2_HP
  741. when 2
  742. @hp = Galv_SI::LEVEL3_HP
  743. @speed = 1
  744. end
  745. @mhp = @hp
  746. end
  747.  
  748. def width
  749. self.bitmap.width
  750. end
  751. def height
  752. self.bitmap.height
  753. end
  754. end # Sprite_Alien < Sprite
  755.  
  756. #-------------------------------------------------------------------------------
  757. # EXPLOSION SPRITES
  758. #-------------------------------------------------------------------------------
  759.  
  760. class Sprite_Splosion < Sprite
  761. def initialize(viewport,x,y,zoom = 1)
  762. super(viewport)
  763. self.x = x
  764. self.y = y
  765. @timer = 10
  766. setup_explosion_image(zoom)
  767. end
  768.  
  769. def dispose
  770. super
  771. end
  772.  
  773. def update
  774. super
  775. wait_for_timer
  776. end
  777.  
  778. def setup_explosion_image(zoom)
  779. self.bitmap = Cache.space("explode")
  780. self.ox = bitmap.width / 2
  781. self.oy = bitmap.height / 2
  782. self.zoom_x = zoom
  783. self.zoom_y = zoom
  784. end
  785.  
  786. def wait_for_timer
  787. @finished = true if @timer <= 0
  788. @timer -= 1
  789. end
  790.  
  791. def finished?
  792. @finished
  793. end
  794. end # Sprite_Splosion < Sprite
  795.  
  796.  
  797. #-------------------------------------------------------------------------------
  798. # POWERUP SPRITES
  799. #-------------------------------------------------------------------------------
  800.  
  801. class Sprite_Powerup < Sprite
  802.  
  803. end # Sprite_Powerup < Sprite
  804.  
  805. #-------------------------------------------------------------------------------
  806. # SCORE WINDOW
  807. #-------------------------------------------------------------------------------
  808.  
  809. class Window_InvaderScore < Window_Base
  810. def initialize
  811. super(0, 0, Graphics.width, Graphics.height)
  812. self.opacity = 0
  813. refresh
  814. end
  815.  
  816. def refresh(shields = Galv_SI::PLAYER_SHIELDS.to_f,bonus_shields = 0)
  817. contents.clear
  818. draw_score("Sale: ", score, 4, 0, contents.width - 8, 2)
  819. draw_score("Best Sale: ", high_score, -(Graphics.width / 2) + 70, 0, contents.width - 8, 2)
  820. draw_shields(shields, 4, 0)
  821. draw_bonus_shields(bonus_shields)
  822. end
  823.  
  824. def draw_shields(shields, x, y, width = Graphics.width / 4)
  825. draw_gauge(x, y, width, shields / Galv_SI::PLAYER_SHIELDS.to_f, text_color(1),
  826. text_color(4))
  827. end
  828.  
  829. def draw_bonus_shields(x,width = Graphics.width / 4)
  830. w = width * x / Galv_SI::PLAYER_SHIELDS.to_f
  831. rect = Rect.new(4, 0, w, 12)
  832. contents.fill_rect(rect, text_color(1))
  833. end
  834.  
  835. def score
  836. $game_variables[Galv_SI::SCORE_VAR]
  837. end
  838. def high_score
  839. $game_variables[Galv_SI::HIGH_SCORE_VAR]
  840. end
  841.  
  842. def draw_score(value, unit, x, y, width, align)
  843. cx = text_size(unit).width
  844. draw_text(x, y, width - cx - 2, line_height, value, align)
  845. draw_text(x, y, width, line_height, unit, align)
  846. end
  847.  
  848. def open
  849. refresh
  850. super
  851. end
  852. end # Window_InvaderScore < Window_Base
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement