Announcement
Announcement
| 2nd Quarter Contest Announcement posted! See the Community Announcements section. |
![]() ![]() |
Mar 19 2012, 08:01 PM
Post
#1
|
|
![]() ![]() Type: Designer Alignment: Unaligned |
Hey guys, In the last two weeks i've started to learn Ruby/RGSS2 and I'm in the middle of throwing together my first script. I decided to try building a scrolling shooter type minigame and it's going pretty well so far, I'm learning a lot.
So far I've got a controllable rectangle with a scrolling background and a few windows for information. The code runs and seems to be working but the problem is that after a while, the game crashes and I don't know why, but it happens more frequently after periods of it having no input. And so I am here, asking for help. Would anyone mind looking through my code and help me with this? I apologise for my messy script, I hope you can follow whats happening. I code like I paint, I just throw ideas together and tidy it up later. CODE class Game_Party < Game_Unit attr_accessor :ship_max_hp attr_accessor :ship_max_shld attr_accessor :ship_level attr_accessor :ship_mov_spd_x attr_accessor :ship_mov_spd_y attr_accessor :ship_hp_degen alias init_ship initialize unless $@ def initialize(*args) init_ship(*args) @ship_level = 1 @ship_max_hp = 1000 @ship_max_shld = 0 @ship_mov_spd_x = 2 @ship_mov_spd_y = 2 @ship_hp_degen = 2 end def ship_gain_level(n) p "Ship LEVEL UP!" @ship_level += n end def ship_increase_max_hp(n) @ship_max_hp += n end def ship_increase_mov_spd_x(n) @ship_mov_spd_x += n end def ship_increase_mov_spd_y(n) @ship_mov_spd_y += n end end #class #=============================================================================== class Scene_Ship < Scene_Base attr_reader :planet attr_reader :distance attr_reader :drops def initialize(dest_planet, dest_dist) @planet = dest_planet @distance = dest_dist @max_ship_hp = $game_party.ship_max_hp @cur_ship_hp = @max_ship_hp @max_ship_shld = $game_party.ship_max_shld @cur_ship_shld = @max_ship_shld @movement_speed_x = $game_party.ship_mov_spd_x @movement_speed_y = $game_party.ship_mov_spd_y @ship_hp_degen = $game_party.ship_hp_degen @bg_speed = 4 @drops = ["Item A", "Item B", "Item C"] @reached_dist = false end def start super setup_all end def setup_all play_bgm setup_viewports setup_windows setup_bg setup_ship end def setup_ship @ship_sprite = Sprite.new(@ship_viewport) @ship_sprite.x = 25 @ship_sprite.y = (416/2) - (@ship_sprite.height/2) @ship_sprite.bitmap = Bitmap.new(320, 240) @ship_sprite.bitmap.fill_rect(0, 0, 80, 20, Color.new(200, 60, 60)) end def setup_viewports @bg_viewport = Viewport.new(0, 0, 544, 416) @bg_viewport.z = 10 @ship_viewport = Viewport.new(0, 0, 544, 416) @ship_viewport.z = 11 end def setup_windows @info = Window_Ship_Info.new @complete = Window_Ship_Complete.new(@planet, @drops) @enter_orbit_cmd = Window_Command.new(100, ["Enter Orbit"]) @enter_orbit_cmd.x = (544 / 2) - (@enter_orbit_cmd.width / 2) @enter_orbit_cmd.y = (@complete.y + @complete.height) @enter_orbit_cmd.active = false @enter_orbit_cmd.visible = false @complete.visible = false end def setup_bg @bg_img = Plane.new(@bg_viewport) @bg_img.bitmap = Cache.system("ship_bg") end def update super @info.refresh(@distance, @max_ship_hp, @cur_ship_hp) @ship_sprite.update scroll_bg if @reached_dist == false if @distance > 0 @distance -= 1 if @cur_ship_shld == 0 decrease_ship_hp(@ship_hp_degen) end end if @distance == 0 @reached_dist = true show_end_windows @enter_orbit_cmd.update if Input.trigger?(Input::C) Sound.play_decision process_end end end if @reached_dist == false move_ship_input end end def scroll_bg @bg_viewport.ox += @bg_speed end def decrease_ship_hp(amnt) if @cur_ship_hp > 0 @cur_ship_hp -= amnt end end def move_ship_input if Input.press?(Input::LEFT) && @ship_sprite.x >= 20 @ship_sprite.x -= @movement_speed_x elsif Input.press?(Input::RIGHT) && @ship_sprite.x <= 300 @ship_sprite.x += @movement_speed_x end if Input.press?(Input::DOWN) && @ship_sprite.y <= 416 - 60 - 32 @ship_sprite.y += @movement_speed_y elsif Input.press?(Input::UP) && @ship_sprite.y >= 20 @ship_sprite.y -= @movement_speed_y end return end def show_end_windows @complete.visible = true @enter_orbit_cmd.visible = true @enter_orbit_cmd.active = true end def process_end RPG::BGM.stop @ship_sprite.dispose unless @ship_sprite.disposed? @bg_img.dispose unless @bg_img.disposed? @info.dispose unless @info.disposed? @complete.dispose unless @complete.disposed? @enter_orbit_cmd.dispose unless @enter_orbit_cmd.disposed? $scene = Scene_Map.new end def play_bgm bgm = RPG::BGM.new("Battle9", 80, 140) bgm.play end def get_planet return @planet end end #class #============================================================================== class Window_Ship_Info < Window_Base def initialize super (0, 416-64, 544, 64) #refresh() end def refresh(distance, max_hp, cur_hp) create_contents self.contents.draw_text(0, 0, 170, WLH, "Remaining Distance: #{distance}") hp_item = $data_items[26] draw_icon(hp_item.icon_index, 172, 0) draw_ship_hp_gauge(max_hp, cur_hp, 200, 0) end def draw_ship_hp_gauge(max_hp, cur_hp, x, y, width = 120) gw = width * cur_hp / max_hp gc1 = hp_gauge_color1 gc2 = hp_gauge_color2 current = cur_hp.floor normsize = self.contents.font.size self.contents.font.size = 16 self.contents.font.bold = true self.contents.fill_rect(x + 2, y + 14, width, 10, gauge_back_color) self.contents.gradient_fill_rect(x, y + 12, gw, 10, gc1, gc2) self.contents.draw_text(x, y, width, WLH, "#{current} / #{max_hp}", 2) self.contents.font.size = normsize self.contents.font.bold = false end end #class #=============================================================================== class Window_Ship_Complete < Window_Base def initialize(planet, drops) super(0, 416/3 - 80/2, 544, 200) @destination_planet = planet @drops = drops refresh end def refresh create_contents draw_destination draw_drops end def draw_destination self.contents.draw_text(0, 0, 544, WLH, "You have arrived safetly at: #{@destination_planet}", 1) end def draw_drops drops_pos_strt = (WLH * 2) + 24 normsize = self.contents.font.size self.contents.font.size = 14 self.contents.font.bold = true self.contents.draw_text(0, 0, 544, drops_pos_strt, "You recieved the following items: ") self.contents.font.bold = false for d in 0...@drops.size self.contents.draw_text(32, drops_pos_strt + 20 +(12*d), 544, 20, @drops[d]) end self.contents.font.size = normsize end end #class If I call my Scene_Ship with the destination set at around 10000 I've been getting crashes. Is it because I'm running too much stuff, too quickly? If anyone tries this out for me you'll need the attached pic in Graphics/System folder.
Attached File(s)
|
|
|
|
Mar 27 2012, 12:47 PM
Post
#2
|
|
![]() I am the resource hog . . . ![]() Type: Designer Alignment: Chaotic Neutral |
Im not no pro scripter, but that seems like that could be the case. On the under def.refresh try adding a wait of ( 1 - 3 ) frames and see what happens
but what error do you get when it crashes? -------------------- Support The EasternDragon
![]() Yes, I created a game . . . that somehow never made it to the light ![]() Super Realeases by me ![]() ![]() ![]() www.nv-usg.com Spoiler: |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 18th May 2013 - 09:49 AM |
|
|