Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[XP] Pacman Game (event-based with a script)

Hey there, I've been working on mini-games to add into my game, some are stil not ready for "public release"

For this work, you go need 3 variables: Gems, Score, Hi-Score
Gems is only used for detect the end-game
Score is the result score you get when you win a game
Hi-Score is the "record", this one is changed everytime you win the game with a Score higher then the previous Hi-Score

and one Switch: Powerup
Powerup is used for set you "powered up" or however is typed, so is YOU who eat the enemies for 5 seconds, and they run from you blinking :D, and if you ate them you receive extra score and they will spawn on center after X seconds

and one animation: Ghost respawn
is for eye-candy purpose only =)

and for last, a small script, I made myself,
The script is used for display the HUD only on the Pacman map, see the script and configure it yourself (more custumizable then how I made it, might be hard :P)

#===============================================================================
# Pacman HUD
#-------------------------------------------------------------------------------
# By 2R
#_______________________________________________________________________________
module RR
  #hud opacity (currently set as transparent)
  PACMANHUDOPA = 0
  #hud skin (currently using default, write your own betwen " " to change)
  PACMANHUDSKIN = "001-Blue01" 
  #hud X
  PACMANHUDX = 0
  #hud y
  PACMANHUDY = 0
  #icon for the gems
  PACMANGEMSICON = "035-Item04"
  #display gems info true or false
  PACMANGEMSDISPLAY = false
  #variable ID where gems are stored
  PACMANGEMS = 1
  #variable for be used for Score
  PACMANSCORE = 2
  #variable where is stored the high-score
  PACMANHISCORE = 3
  #map ID for display HUD
  PACMANMAP = 1
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window

  def draw_pacmangems(x, y)
    pacmangems = $game_variables[RR::PACMANGEMS].to_s
    bitmap = RPG::Cache.icon(RR::PACMANGEMSICON)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.font.color = normal_color
    self.contents.draw_text(x + 28, y + 24, 212, 32, pacmangems)
  end

  def draw_pacmanscore(x, y)
    pacmanscore = $game_variables[RR::PACMANSCORE].to_s
    self.contents.font.color = normal_color
    self.contents.draw_text(x, y, 212, 32, "Score:")
    self.contents.draw_text(x + 4, y + 24, 212, 32, pacmanscore)
  end
 
  def draw_pacmanhiscore(x, y)
    pacmanhiscore = $game_variables[RR::PACMANHISCORE].to_s
    self.contents.font.color = normal_color
    self.contents.draw_text(x , y, 212, 32, "Hi-Score: ")
    if $game_variables[RR::PACMANHISCORE] >= 10
      self.contents.draw_text(x + 4, y + 24, 212, 32, pacmanhiscore)
    else
      self.contents.draw_text(x + 4, y + 24, 212, 32, "- - - -")
    end
  end
end

#==============================================================================
# ** Window_NameInput
#------------------------------------------------------------------------------
#  This window is used to display the Pacman HUD
#==============================================================================

class Window_PacmanHUD < Window_Base

  def initialize
    super(0, 0, 640, 100)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
 
  def refresh
    self.contents.clear
    draw_pacmanscore(0, 0)
    draw_pacmanhiscore(240, 0)
    if RR::PACMANGEMSDISPLAY == true
      draw_pacmangems(400, 0)
    end
  end

  def update
    super
  end

end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================

class Scene_Map

  alias pacmanHUD_main main
  def main
    @pacmanHUD = Window_PacmanHUD.new
    @pacmanHUD.opacity = RR::PACMANHUDOPA
    @pacmanHUD.x = RR::PACMANHUDX
    @pacmanHUD.y = RR::PACMANHUDY
    if $game_map.map_id == RR::PACMANMAP
        @pacmanHUD.visible = true
    else
        @pacmanHUD.visible = false
    end
    pacmanHUD_main
    @pacmanHUD.dispose
  end

  alias pacmanHUD_update update
  def update
    if $game_map.map_id == RR::PACMANMAP
        @pacmanHUD.visible = true
    else
        @pacmanHUD.visible = false
    end
    if $pacmanScore == true
      @pacmanHUD.refresh
      $pacmanScore = false
    end
    pacmanHUD_update
  end

end

#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
#  This class handles the map. It includes scrolling and passable determining
#  functions. Refer to "$game_map" for the instance of this class.
#==============================================================================

class Game_Map
  attr_accessor :pacmanScore
end

#==============================================================================
# ** Interpreter (part 4)
#------------------------------------------------------------------------------
#  This interpreter runs event commands. This class is used within the
#  Game_System class and the Game_Event class.
#==============================================================================

class Interpreter
 
  alias pacmanScore command_122
  def command_122
    $pacmanScore = true
    pacmanScore
  end

end

The events required for this to work are:

Gems (the jewels you eat for win)
Options: Move Animation, Through
Trigger: Player touch

List of Event
Control Variables: [0001: Pacman Gems] += 1
Control Variables: [0002: Pacman Score] += 10
Play SE: '002-System02', 80, 100
Erase Event

Powerup (the item wich make you powered up, and can eat the enemies)
Options: Move Animation, Through
Trigger: Player touch

List of Event
Control Variables: [0001: Pacman Gems] += 1
Control Variables: [0002: Pacman Score] += 50
Play SE: '002-System04', 80, 100
Move Route: This event
> Graphic (None)
> Switch ON [0001]
> Wait 100 frame(s)
> Switch OFF [0001]
Erase Event

Ghost (the enemies who try kill you)
PAGE 1
Options: Move Animation, Always on Top
Autonomous Movement:
> Type: Custom
>> Move Route: Move toward player, repeat action
> Speed Fast
> Frequency: Highest
Trigger: event touch

List of Event
Text: Booohh!
Play SE: '014-Move02', 80, 100
Transfer Player: [002: RR Game Room], (011, 010) (this where player is transfered when loose)
Control Variables: [0001: Pacman Gems] = 0
Control Variables: [0002: Pacman Score] = 0
Control Switches: [0001: Pacman Powerup] = OFF

--------------------------------------------------------
PAGE 2
Conditions: Switch 0001 Pacman Powerup is ON
Options: Move Animation, Always on Top
Autonomous Movement:
> Type: Custom
>> Move Route: Move away from player, repeat action
> Speed Fast
> Frequency: Highest
Trigger: player touch

List of Event
Control Variables: [0002: Pacman Score] += 400
Play SE: '010-System10', 80, 100
Show Animation: This event [Ghost Respawn]
Set Move Route: This event
> Wait 60 frames
Set event Location: This event [012, 013], Up (this where this ghost go spawn after you "eat" him)
Set Move Route: Wait 60 frames

Startup (the start event, for prepare stuff)
Page1:
Trigger: Autorun

List of Event
Change Menu Access: Disabled
Change Save Access: Disabled
Control Variables [0001: Pacman Gems] = 0
Control Variables [0002: Pacman Score] = 0
Control Switches [0001: Pacman Powerup] = OFF
Text: Menu & Save are disabled on this area
Control Self Switch: A
----------------------------------------
Page 2
Selfswitch A is ON
Trigger: Autorun

List of event:
Erase event

Victory (the victory event, for when you collect all the X gems, you win)
Variable 0001 Pacman Gems is: 246 (the ammount of total gems on map)
Trigger: Autorun

List of event:
Conditional Branch: Variable [0002 Pacman Score] >= Variable [0003 Pacman Hi Score]
> Control Variables [0003 Pacman Hi Score] = Variable [0002 Pacman Score]
Brach end
Text: Yey you won
Text: Next time you play, you will see a hi-score showing up
Text: Returning to Game Room
Transfer Player [0002:RR Game Room], (013,017) (this transfer player to the area you want the player when win go to)
Change Menu Access: Enabled
Change Save Access: Enabled
Control Variables [0001: Pacman Gems] = 0
Control Variables [0002: Pacman Score] = 0
Control Switchs [0001: Pacman Powerup] = OFF
Change items: [trofee] +1 (this is the item, the victory player receives)


screenshot
http://www.the-2r.com/pacman.jpg[/img]


here is the demo link:

www.the-2r.com/Pacman.exe

soon i learn a little bit more about scripting, specificaly about the Comment tricks, I might be able to reduce the over-use of eventing so much for this mini-game, but meanwhile it go continues this way, and it works ;-)

note: you can use this "system", for make diverse kind of mini-games, you can use it's idea to make a kind "Catch the pig" mini-game, a kind of "Pick the 10 gold coins, before thiefs catch you" and so on, or you can try do as I did, make a Pacman mini-game, for be used on a Gaming House, where winner receives a prize, case loose, receives nothing

have fun, and i think is no need to say, if you want use it, give me a tiny credit line, a litttttle one =P

bye

PS: yeha i'm the 2R but if I'd create a 2R Module instead of RR Module, I think would get some incompatible isues, since script might consider 2R as a kind of value
 
This works great, can't believe this hasn't any replies yet. good work buhuhu. Also, i saw there will come more games? Great ;)
 
hehe thanks :), and yeha so far it been working great, if you want make a full copy of Pacman just replace the graphics, since system itself is all there (even the hud with hi-score, etc)

since that only use 3 editable events (ghost, gem, powerup), all you need do is, modify your own and copy/paste it, all the way, as I did, I didn't added new graphics for show people, that system can be done by using just default rpgxp stuff

and yeha I'm currently working on 2 other mini-games, but i'm having some problems, but hopefuly i'll finish them soon ;-)

cuz the best RPGs I've played so far, all had some mini-games inside, so I've been working on create some =)

and I hope I be able to full understand the use of Comments on a script, for reduce the stuff inside a event (so easier modifiable, or however is spelled)

bye :)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top