Guest User

PVGames Character Generator

a guest
Feb 20th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.99 KB | None | 0 0
  1. # Simple, not-so-user friendly Random Character Generator for PVGames graphics
  2. # Made by Piotr "Ekhart" Blaut, for 'Blood Desire' game.
  3. # Date: 19-20/02/2017
  4.  
  5. require 'mini_magick'
  6.  
  7.  
  8. # All layers, in order they are drawn
  9. listOfLayers = {
  10.     "male" => ["shadow", "base", "pants", "feet", "top", "hair", "scars", "facialHair", "head", "accessory"],
  11.     "female" => ["shadow", "base", "pants", "feet", "top", "gloves", "hair", "scars", "head", "accessory"]
  12. }
  13.  
  14. listOfPoses = ["collapse", "collapse_diag", "dead", "dead_diag", "idle1", "idle1_diag", "kneel", "kneel_diag", "running", "running_diag", "sitting1", "sitting1_diag", "sleeping", "sleeping_diag", "walking", "walking_diag"]
  15.  
  16. # Chances of selected layers appearing, in % value
  17. compositionChance = {
  18.     "male" => [100, 100, 100, 100, 100, 90, 20, 50, 10, 10],
  19.     "female" => [100, 100, 100, 100, 100, 35, 100, 3, 10, 10]
  20. }
  21.  
  22. listOfMaleElements = {
  23.     "shadow" => 1,
  24.     "base" => 10,
  25.     "pants" => 16,
  26.     "feet" => 10,
  27.     "top" => 37,
  28.     "hair" => 55,
  29.     "scars" => 5,
  30.     "facialHair" => 20,
  31.     "head" => 20,
  32.     "accessory" => 22
  33. }
  34.  
  35. listOfFemaleElements = {
  36.     "shadow" => 1,
  37.     "base" => 10,
  38.     "pants" => 11,
  39.     "feet" => 7,
  40.     "top" => 41,
  41.     "gloves" => 1,
  42.     "hair" => 65,
  43.     "scars" => 5,
  44.     "head" => 18,
  45.     "accessory" => 27
  46. }
  47.  
  48. # Pick random elements
  49. graphicsComp = []
  50.  
  51. puts "Choose gender: M or F"
  52. gender = gets.strip
  53. gender = "male" if gender == "m" || gender == "M"
  54. gender = "female" if gender == "f" || gender == "F"
  55. for i in 0...listOfLayers[gender].size
  56.     ch = rand(100)
  57.     # Random chance of piece appearing
  58.     if compositionChance[gender][i] >= ch then
  59.         #this element is added
  60.         if gender=="male" then
  61.             graphicsComp << (rand(listOfMaleElements[listOfLayers[gender][i]]) + 1).to_s
  62.         elsif gender=="female" then
  63.             graphicsComp << (rand(listOfFemaleElements[listOfLayers[gender][i]]) + 1).to_s
  64.         end
  65.     else
  66.         # if piece wasn't added, put "nil" in array
  67.         graphicsComp << "none"
  68.     end
  69. end
  70. for position in 0...listOfPoses.size
  71.     # Create a list of filenames
  72.     usedFiles = []
  73.     # For test - only use Idle graphic
  74.     for ex in 0...listOfLayers[gender].size
  75.         #directory = gender + %q{\\} + listOfLayers[gender][ex] + %q{\\} + graphicsComp[ex]
  76.         directory = "#{gender}/#{listOfLayers[gender][ex]}/#{graphicsComp[ex]}"
  77.         if graphicsComp[ex] != "none" then
  78.             Dir.entries(directory).each do |f|
  79.                 usedFiles << directory + "/" + f if f.include?(listOfPoses[position] + ".png")
  80.             end
  81.         end
  82.     end
  83.  
  84.     # Go through all files
  85.     image = MiniMagick::Image.new(usedFiles[0])
  86.     for n in 1...usedFiles.size
  87.         topLayer = MiniMagick::Image.new(usedFiles[n])
  88.         result = image.composite(topLayer) do |c|
  89.             c.compose "Over"
  90.         end
  91.         image = result
  92.     end
  93.     image.write "output_#{listOfPoses[position]}.png"
  94.  
  95.     puts "Generated and saved: #{listOfPoses[position]}"
  96. end
  97. # Generate text file with layers compositionChance
  98. File.open('layers.txt', 'w+') do |file|
  99.     file.puts(usedFiles)
  100. end
  101. puts "Saved used layers to text file"
  102.  
  103. puts "\n \n Press enter button to exit"
  104. dump = gets
Advertisement
Add Comment
Please, Sign In to add comment