Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

> 


———
Before you ask! Read! ;)

You must have 30+ Posts to create a topic here!

Thanks for reading!
———

 
Reply to this topicStart new topic
> Placing battlers on the screen - algorithm?
Tsukihime
post Apr 24 2012, 11:09 PM
Post #1


Level 25
Group Icon

Group: Revolutionary
Posts: 560
Type: None
RM Skill: Undisclosed
Rev Points: 25




So I started implementing the encounter system I wanted described here and ran into a couple issues.

The first most apparent issue is battler placement.
I can't come up with an algorithm that will allow me to "spread" the monsters out in an orderly fashion.

Attached is a visual example of what I mean.

It is an extreme example (I generated 16 enemies to appear on the map), but it illustrates the problem.

What kind of algorithms can I use to try to position the battlers in "good" spots? Realistically there will be at most say 5 or 6 enemies on the screen at the same time, although they can be large.

Here is the script I am using. Instructions are same as described in the other thread: just write numbers into the map's note box to determine which enemies should be in the draw pool. The note I wrote is

enemies

CODE
1 30
2 50
3 20
4 10
5 10
6 10
7 10
8 10
9 5
10 17



Script

CODE
class Game_Map
  
  def note
    @map.note
  end
end

class Game_Player < Game_Character
  
  def make_enemy_count
    #return [1, rand(8)].max
    return 16
  end
  
  def make_enemy_list(numEnemies)
    weight_sum = 0
    enc_list = []
    enc_weight = []
    list = []
    
    $game_map.note.split(/[\r\n]+/).each { |line|
      line = line.split(/\s/)
      enc_list.push(line[0].to_i)
      enc_weight.push(line[1].to_i)
      weight_sum += line[1].to_i
    }
    
    for x in 0 .. numEnemies
      value = rand(weight_sum)
      enc_list.each_with_index do |enemyIdx, i|
        value -= enc_weight[i]
        if value < 0
          list.push(enc_list[i])
          break
        end
      end
    end
    return list
  end
  
  def create_troop(enemy_list)
    new_troop = RPG::Troop.new()
    new_troop.id = $data_troops.length
    new_troop.name = "random_battle"
    enemy_list.each_with_index { |index, i|
      troop_member = RPG::Troop::Member.new
      troop_member.enemy_id = index
      troop_member.x = 100 + (i % 3)*160
      troop_member.y = 120 + ((i / 3)*60)
      
      new_troop.members << troop_member
    }
    $data_troops << new_troop
  end
  
  def make_encounter_troop_id
    numEnemies = make_enemy_count
    enemy_list = make_enemy_list(numEnemies)
    create_troop(enemy_list)
    return -1
  end
end



This post has been edited by Tsukihime: Apr 24 2012, 11:29 PM
Attached File(s)
Attached File  re001.jpg ( 56.22K ) Number of downloads: 8
 


__________________________
My Scripts
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 22nd May 2013 - 03:15 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker