Inscrit le: 28 Aoû 2011, 02:51 Messages: 15 Sexe: Masculin Points d'aide: 0/60
Créations :
Voir ses créations
|
Toujours pas de moi, mais du même auteur que le Galaga, à savoir kellessdee. Un petit script sympathique qui fonctionne bien. Tout d'abord la démo pour vous faire une idée : http://www.mediafire.com/?srrx21rxbw0bc8n maintenant le script : - Code: Tout sélectionner
=begin * DRIVING MINI-GAME * by kellessdee ------------------------------------------------------------------------------ * This is a simple driving mini-game, you create a "Driving" map in the map * editor, and when the player is teleported to said map, the game begins. ------------------------------------------------------------------------------ * To signify a driving mini-game, just change the name of the map * to include %d at the beginning. ------------------------------------------------------------------------------ * There are 2 kinds of events that are used at this time in the game, * Obstacles and Health recovery. To create these in the game, just add events * to the map and include &o (for obstacle) or &h (for health) in the event * name. ------------------------------------------------------------------------------ * If you have any questions or need clarification on this script you can * contact me: * @ http://www.rmxpunlimited.net/forums/ * or by e-mail: kellessdee@gmail.com * You will probably have better luck getting in contact with me @rmxpunlimited, * plus they are a very friendly and helpful rmxp community, so if you want * join up! ------------------------------------------------------------------------------ * You are free to do whatever you wish with this script as long as you give * credit where due! * Thanks to LNER_fan for the car image! ------------------------------------------------------------------------------ * The following module are the configuration settings for the mini-game, * each one is explained within the module. ------------------------------------------------------------------------------ =end module Driving # Speed of the vehicle, how many pixels are travelled when moving SPEED = 5 # How fast the screen scrolls per frame SCROLL_SPEED = 32 # Name of the file in character sets for vehicle GRAPHIC_NAME = 'shmuptestchar' # Color adjustment of aformentioned file GRAPHIC_HUE = 0 # How much damage is inflicted by the obstacles OBSTACLE_DAMAGE = 10 # How much health is recovered by health items HEALTH_BOOST = 25 # The ID of the variable that contains the map ID to go to after game is # finished MAP_VAR_ID = 1 # ID of the variable for X coordinate to transfer player to on said map ID X_VAR_ID = 2 # ID of the variable for X coordinate to transfer player to on said map ID Y_VAR_ID = 3 # ID of the switch that holds whether the player won or lost the match VICTORY_SWITCH_ID = 1 # File name of sound during countdown. If set to nil, there will be no sound COUNTDOWN_SE = 'Audio/SE/002-System02' # File name of sound played when GO! is displayed START_SE = 'Audio/SE/014-Move02' # File name of ME when you win game VICTORY_ME = 'Audio/ME/004-Victory04' # File name of ME when you lose game LOSE_ME = 'Audio/ME/005-Defeat01' # File name of sound when you collide with obstacle OBSTACLE_SE = 'Audio/SE/104-Attack16' # File name of sound when you pick up health boost HEALTH_SE = 'Audio/SE/146-Support04' end
#============================================================================ # ** Game_Vehicle #---------------------------------------------------------------------------- # Handles the vehicle in driving mini-game #============================================================================ class Game_Vehicle < RPG::Sprite #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :damage # Remaining damage left on vehicle #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(viewport) super(viewport) self.bitmap = RPG::Cache.character(Driving::GRAPHIC_NAME, Driving::GRAPHIC_HUE) @h = self.bitmap.height / 4 @w = self.bitmap.width / 4 # Initialize graphic to facing UP self.src_rect = Rect.new(0, @h * 3, @w, @h) # Set up hit box self.ox = @w / 2 self.oy = @h / 2 # Set up Screen location self.x = 320 self.y = 480 - @h # Initialize Animation frames @anim = 0 @crashing = false @damage = 100 @timer = 0 end #-------------------------------------------------------------------------- # * Update Frame #-------------------------------------------------------------------------- def update super if @timer > 0 @timer -= 1 self.whiten end if @timer == 0 && @crashing @crashing = false end # Increase animation frame @anim += 1 if @anim == 16 @anim = 0 end # if # Check if user is moving vehicle case Input.dir8 when 1 # Down Left move_left move_down when 2 # Down move_down when 3 # Down Right move_right move_down when 4 # Left move_left when 6 # Right move_right when 7 # Up Left move_left move_up when 8 # Up move_up when 9 # Up Right move_right move_up end # case # Update Animation frame update_animation # Check for obstacles/pick-ups check_location end # update #-------------------------------------------------------------------------- # * Update Animation Frame Graphic #-------------------------------------------------------------------------- def update_animation # Check which Animation frame self.src_rect = Rect.new((@anim / 4) * @w, @h * 3, @w, @h) end #-------------------------------------------------------------------------- # * Check Vehicle Location #-------------------------------------------------------------------------- def check_location # Check driving map's event at vehicle location x, y = get_map_x, get_map_y event = $game_map.get_event_name(x, y - 1) # if Obstacle if event.include?('&o') && !@crashing Audio.se_play(Driving::OBSTACLE_SE) unless Driving::OBSTACLE_SE == nil # damage vehicle @damage -= Driving::OBSTACLE_DAMAGE @crashing = true @timer = 10 return # if Health Boost elsif event.include?('&h') Audio.se_play(Driving::HEALTH_SE) unless Driving::HEALTH_SE == nil # heal vehicle @damage += Driving::HEALTH_BOOST if @damage > 100 @damage = 100 end # if $game_map.erase_event(x, y - 1) return end # if event = $game_map.get_event_name(x, y + 1) # if Obstacle if event.include?('&o') && !@crashing Audio.se_play(Driving::OBSTACLE_SE) unless Driving::OBSTACLE_SE == nil # damage vehicle @damage -= Driving::OBSTACLE_DAMAGE @crashing = true @timer = 10 return # if Health Boost elsif event.include?('&h') Audio.se_play(Driving::HEALTH_SE) unless Driving::HEALTH_SE == nil # heal vehicle @damage += Driving::HEALTH_BOOST if @damage > 100 @damage = 100 end # if $game_map.erase_event(x, y + 1) return end # if event = $game_map.get_event_name(x - 1, y) # if Obstacle if event.include?('&o') && !@crashing Audio.se_play(Driving::OBSTACLE_SE) unless Driving::OBSTACLE_SE == nil # damage vehicle @damage -= Driving::OBSTACLE_DAMAGE @crashing = true @timer = 10 return # if Health Boost elsif event.include?('&h') Audio.se_play(Driving::HEALTH_SE) unless Driving::HEALTH_SE == nil # heal vehicle @damage += Driving::HEALTH_BOOST if @damage > 100 @damage = 100 end # if $game_map.erase_event(x - 1, y) return end # if event = $game_map.get_event_name(x + 1, y) # if Obstacle if event.include?('&o') && !@crashing Audio.se_play(Driving::OBSTACLE_SE) unless Driving::OBSTACLE_SE == nil # damage vehicle @damage -= Driving::OBSTACLE_DAMAGE @crashing = true @timer = 10 return # if Health Boost elsif event.include?('&h') Audio.se_play(Driving::HEALTH_SE) unless Driving::HEALTH_SE == nil # heal vehicle @damage += Driving::HEALTH_BOOST if @damage > 100 @damage = 100 end # if $game_map.erase_event(x + 1, y) return end # if end # check_location #-------------------------------------------------------------------------- # * Move Vehicle Up #-------------------------------------------------------------------------- def move_up # If graphic is below very top of the screen if self.y - Driving::SPEED >= 0 self.y -= Driving::SPEED end end #-------------------------------------------------------------------------- # * Move Vehicle Down #-------------------------------------------------------------------------- def move_down # If graphic is above bottom of the screen if self.y + Driving::SPEED <= 480 self.y += Driving::SPEED end end # move_down #-------------------------------------------------------------------------- # * Move Vehicle Left #-------------------------------------------------------------------------- def move_left # If graphic is right of left of the screen if self.x - Driving::SPEED >= 0 self.x -= Driving::SPEED end end # move_left #-------------------------------------------------------------------------- # * Move Vehicle Right #-------------------------------------------------------------------------- def move_right # If graphic is left of right of screen if self.x + Driving::SPEED <= 640 self.x += Driving::SPEED end end # move_right #-------------------------------------------------------------------------- # * Get Map X #-------------------------------------------------------------------------- def get_map_x # Convert Screen X into Map X return (self.x + ($game_map.display_x / 4)) / 32 end # get_map_x #-------------------------------------------------------------------------- # * Get Map Y #-------------------------------------------------------------------------- def get_map_y # Convert Screen Y into Map Y return (self.y + ($game_map.display_y / 4)) / 32 end # get_map_y end # Game_Vehicle #============================================================================= # ** Scene_Driving #----------------------------------------------------------------------------- # This scene handles the driving mini-game #============================================================================= class Scene_Driving #--------------------------------------------------------------------------- # * Object Initialization #--------------------------------------------------------------------------- def initialize @victory = false @gameover = false @PREV_MAP_ID = $game_variables[Driving::MAP_VAR_ID] @PREV_MAP_X = $game_variables[Driving::X_VAR_ID] @PREV_MAP_Y = $game_variables[Driving::Y_VAR_ID] end # initialize #--------------------------------------------------------------------------- # * Main Processsing #--------------------------------------------------------------------------- def main # Draw Driving Course @course = Spriteset_Map.new # Create vehicle @vehicle = Game_Vehicle.new(@course.viewport1) # Create Screen display @fg = Sprite.new @fg.bitmap = Bitmap.new(640, 480) @fg.bitmap.font.size = 72 @fg.bitmap.font.bold = true @fg.bitmap.font.italic = true # Create Driving Timer @timer = 160 # Execute Transition Graphics.transition # Starting loop loop do # Update Graphics Graphics.update # Update frame update_start # if timer is finished, start Driving if @timer == 0 break end # if end # loop @fg.bitmap.font.size = 18 @fg.bitmap.font.color = Color.new(255, 255, 255, 255) # Setup Health Bar / Progress Bar update_health_display(100) # Main loop loop do # Update Graphics Graphics.update # Update Input Input.update # Update frame update_drive # If game is over, finish drive if @gameover break end # if end # loop @fg.bitmap.font.size = 72 # Set timer @timer = 160 # Finishing loop loop do # Update Graphics Graphics.update # Update finish if @victory update_finish else update_lose end # timer is finished leave scene if @timer == 0 break end end # Adjust WIN/LOSE switches $game_switches[Driving::VICTORY_SWITCH_ID] = @victory # Prepare transition Graphics.freeze # Change Map $game_map.setup(@PREV_MAP_ID) $game_player.moveto(@PREV_MAP_X, @PREV_MAP_Y) $scene = Scene_Map.new $game_player.set_opacity(255) # Dispose graphics @course.dispose @fg.dispose @vehicle.dispose end # main #--------------------------------------------------------------------------- # * Update drive #--------------------------------------------------------------------------- def update_drive # Temporarily store vehicle hp hp = @vehicle.damage # Scroll Screen $game_map.scroll_up(Driving::SCROLL_SPEED) # Update Map $game_map.update @course.update # Update Vehicle @vehicle.update # Check if hp has changed if hp != @vehicle.damage update_health_display(@vehicle.damage) end if $game_map.display_y == 0 @gameover = true @victory = true end # if end # update_drive #--------------------------------------------------------------------------- # * Update Start #--------------------------------------------------------------------------- def update_start # Update Timer @timer -= 1 case @timer when 159 draw_info('3') when 120..158 @fg.opacity += 20 unless Driving::COUNTDOWN_SE == nil Audio.se_play(Driving::COUNTDOWN_SE) if @timer == 155 end when 119 draw_info('2') when 80..118 @fg.opacity += 20 unless Driving::COUNTDOWN_SE == nil Audio.se_play(Driving::COUNTDOWN_SE) if @timer == 115 end when 79 draw_info('1') when 40..78 @fg.opacity += 20 unless Driving::COUNTDOWN_SE == nil Audio.se_play(Driving::COUNTDOWN_SE) if @timer == 75 end when 39 draw_info('GO!') when 0..38 @fg.opacity += 20 unless Driving::START_SE == nil Audio.se_play(Driving::START_SE) if @timer == 5 end end # case end # update_start #--------------------------------------------------------------------------- # * Update Finish #--------------------------------------------------------------------------- def update_finish # Update Timer @timer -= 1 case @timer when 158..159 Audio.me_play(Driving::VICTORY_ME) unless Driving::VICTORY_ME == nil draw_info('WIN!') when 0..157 @fg.opacity += 10 end # case end # update_finish #--------------------------------------------------------------------------- # * Update Lose #--------------------------------------------------------------------------- def update_lose # Update Timer @timer -= 1 case @timer when 158..159 Audio.me_play(Driving::LOSE_ME) unless Driving::LOSE_ME == nil draw_info('LOSE...') when 0..157 @fg.opacity += 5 end # case end #--------------------------------------------------------------------------- # * Draw Info #--------------------------------------------------------------------------- def draw_info(text) # Clear Bitmap @fg.bitmap.clear # Make transparent @fg.opacity = 0 # Get Center Screen location w = @fg.bitmap.text_size(text).width h = @fg.bitmap.text_size(text).height x = 320 - w / 2 y = 240 - h / 2 # Draw Black Outline @fg.bitmap.font.color = Color.new(0, 0, 0, 255) @fg.bitmap.draw_text(x - 3, y - 3, w, h, text, 1) @fg.bitmap.draw_text(x + 3, y - 3, w, h, text, 1) @fg.bitmap.draw_text(x - 3, y + 3, w, h, text, 1) @fg.bitmap.draw_text(x + 3, y + 3, w, h, text, 1) # Draw White inner Outline @fg.bitmap.font.color = Color.new(255, 255, 255, 255) @fg.bitmap.draw_text(x - 2, y - 2, w, h, text, 1) @fg.bitmap.draw_text(x + 2, y - 2, w, h, text, 1) @fg.bitmap.draw_text(x - 2, y + 2, w, h, text, 1) @fg.bitmap.draw_text(x + 2, y + 2, w, h, text, 1) # Draw Orange Center @fg.bitmap.font.color = Color.new(255, 100, 0, 255) @fg.bitmap.draw_text(x, y, w, h, text, 1) end # draw_info #--------------------------------------------------------------------------- # * Update Health Display #--------------------------------------------------------------------------- def update_health_display(health) @fg.bitmap.clear # Draw bar @fg.bitmap.draw_gradient_bar(16, 16, 304, 12, health, 100, Color.new(255, 0, 0, 255), Color.new(255, 75, 75, 255)) # Draw Label @fg.bitmap.font.color = Color.new(0, 0, 0, 255) @fg.bitmap.draw_text(19, 1, 300, 16, 'Health') @fg.bitmap.draw_text(21, 1, 300, 16, 'Health') @fg.bitmap.draw_text(19, -1, 300, 16, 'Health') @fg.bitmap.draw_text(21, -1, 300, 16, 'Health') @fg.bitmap.font.color = Color.new(255, 255, 255, 255) @fg.bitmap.draw_text(20, 0, 300, 16, 'Health') # Check if health is 0 if health <= 0 @gameover = true end end # update_health_display end # Scene_Driving
#============================================================================= #============================================================================= #============================================================================= # ** MODIFIED CLASSES ******************************************************** #============================================================================= #============================================================================= #=============================================================================
#============================================================================ # ** Spriteset_Map #============================================================================ class Spriteset_Map #-------------------------------------------------------------------------- # * Public Instance Variable #-------------------------------------------------------------------------- attr_reader :viewport1 end # Spriteset_Map #============================================================================ # ** Game_Event #============================================================================ class Game_Event < Game_Character #-------------------------------------------------------------------------- # * New Public Instance Variable #-------------------------------------------------------------------------- attr_reader :event attr_reader :erased end # Game_Event #============================================================================# # ** Scene_Map aliased to check if player is in driving mini-game map # #============================================================================# class Scene_Map #-------------------------------------------------------------------------- # * Alias Update #-------------------------------------------------------------------------- alias driving_update update def update driving_update # If player is in a driving map, start driving if $game_map.is_driving? $scene = Scene_Driving.new end # if end # update end # Scene_Map #============================================================================# # ** Game_Map additional methods # #============================================================================# class Game_Map @@map_info = load_data('Data/MapInfos.rxdata') #--------------------------------------------------------------------------- # * Check if current map has '%d' characters in name, which notates a # * driving map. #--------------------------------------------------------------------------- def is_driving?(id=@map_id) name = @@map_info[id].name return name.include?('%d') end # is_driving? #-------------------------------------------------------------------------- # * Get Event Name #-------------------------------------------------------------------------- def get_event_name(x, y) for event in $game_map.events.values if event.x == x and event.y == y unless event.erased return event.event.name end end end end # get_event_name #-------------------------------------------------------------------------- # * Erase Event #-------------------------------------------------------------------------- def erase_event(x, y) for event in $game_map.events.values if event.x == x and event.y == y event.erase end end end end # Game_Map #============================================================================# # ** Game_Player additional method # #============================================================================# class Game_Player #--------------------------------------------------------------------------- # * Set Opacity #--------------------------------------------------------------------------- def set_opacity(opacity) @opacity = opacity end end # Game_Player #============================================================================ # * Bitmap class, added gradient bars #============================================================================ class Bitmap #-------------------------------------------------------------------------- # * Draw Gradient Bar #-------------------------------------------------------------------------- def draw_gradient_bar(x, y, width, height, min, max, start_color, end_color) # Colors black = Color.new(0, 0, 0, 255) # Draw Bar back self.fill_rect(x, y, width, height, black) self.fill_rect(x - 1, y + 1, 1, height - 2, black) self.fill_rect(x + width, y + 1, 1, height - 2, black) # Get fill amount x += 3 y += 3 height -= 6 width -= 6 fill = (min.to_f / max) * width width = (width.to_f / fill) * 100 dr = (end_color.red - start_color.red) / width.to_f dg = (end_color.green - start_color.green) / width.to_f db = (end_color.blue - start_color.blue) / width.to_f da = (end_color.alpha - start_color.alpha) / width.to_f (0...fill).each {|i| start_color.red += dr unless start_color.red + dr < 0 start_color.green += dg unless start_color.green + dg < 0 start_color.blue += db unless start_color.blue + db < 0 start_color.alpha += da unless start_color.alpha + da < 0 self.fill_rect(x + i, y, 1, height, start_color) } end end
Pour le faire fonctionner sur une map, le nom de la map doit commencer par %d Le nom des obstacles (qui font perdre de la vie) en event doit être &o Et le nom des events qui redonnent de la vie doit être &h La voiture se trouve dans le dossier characters et doit s'appeler shmuptestchar.png ou alors vous la renommez dans le script à la ligne 38. tout les sons sont paramétables entre les lignes 55 et 65, la vitesse de la voiture ligne 34 et la vitesse de défilement de la carte ligne 36. N'hésitez pas à faire des cartes très hautes et à augmenter la vitesse de scrolling, moi j'ai mis 100 et ça speed à mort !!!
|
|