Advertisement
Guest User

Invader customization #1 - max score

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