Sujet n°10621
Posté par chinleroi le 11 Nov - 14:37 (2011)
Titre : Pitié
Bonjour a tous.
J'ai un énorme souci j'utilise psp ds v 0.4 et j'ai effacé le script ds résolution sans l'enregistrer quelque part Résignation man
Svp si quelqu'un pourrait copier coller ce script pour moi sa serait sympa ^^.
Merci de votre compréhension.

Posté par Ashikata le 11 Nov - 15:24 (2011)
Non, pas de pitié...
Bon ok le voici mais je mérite un cadeau.
Spoiler
Code:
#===========================================#
#¤Class Tilemap | Scripté Par Youri
#===========================================#
#Crédits Strictements obligatoirs
#===========================================#
class Tilemap
  attr_accessor :viewport
  attr_accessor :ox
  attr_accessor :oy
  attr_accessor :tileset #bitmap du tileset
  attr_accessor :autotiles #tableau contenant les bitmaps des autotiles
  attr_accessor :update_count # mise a jours toute les x fps
  attr_accessor :map_data
  attr_accessor :priorities
  attr_accessor :visible
  attr_reader :min_bmp
  Autotiles = [
    [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
      [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],
    [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
      [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],
    [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
      [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
    [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
      [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],
    [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
      [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
    [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
      [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ] ]
  def initialize(viewport=false, update_count=10, tile_size_x=16, tile_size_y=16, visible=true, tileset=false, autotiles=false, map_data=Table.new(1,1,3), priorities=Table.new(1))
    viewport.class.to_s != "Viewport" ? @viewport=Viewport.new(0,0,640,480) : @viewport=viewport
    tileset.class.to_s != "Bitmap" ? @tileset=Bitmap.new(1,1) : @tileset=tileset
    autotiles.class.to_s != "Array" ? @autotiles=Array.new(6) : @autotiles=autotiles
    @ox=ox
    @oy=oy   
    @map_data=map_data
    @priorities=priorities
    @visible=visible
    @tiled=false #si la ma est faite
    @dispose=false #detection de l'effacement
    @update_count=update_count.to_i
    @tiles_size=[tile_size_x.to_i ,tile_size_y.to_i ]
    @tiles={}
    @atiles={}
    @bitmap_tiles={}
    @autotile_update_ids=[] # tableau des id tiles(autotiles) a mettre a jour
    @autotile_max_count=[] # tableau contenant le nombre de frammes par autotiles
    @autotile_count=[] #tableau contenant l'avancement du compteur de frammes des autotiles
    @rect=Rect.new(0, 0, 32, 32)
    @dest_rect = Rect.new(0, 0, @tiles_size[0], @tiles_size[1])
  end
  def update(forced=false)
    @ox /= 32/@tiles_size[0]
    @oy /= 32/@tiles_size[1]
    if not @tiled
      @tiled=true
      create_map
    end
    update_autotiles if forced or (Graphics.frame_count % @update_count == 0)
    update_pos
  end
  def create_map
    for i in 0..6
      @autotile_max_count[i] = @autotiles[i].width / 96
      @autotile_count[i] = 1
    end   
    @min_bmp=true
    for z in 0... @map_data.zsize
      for x in 0... @map_data.xsize
        for y in 0...@map_data.ysize
          id = @map_data[x, y, z]
          next if id == 0
          c = @priorities[id]
          if @min_bmp
            id < 384 ? sprite_at(x, y, c, z, id) : sprite_t2(x, y, c, z, id)
          else
            id < 384 ? sprite_at(x, y, c, z, id) : sprite_t(x, y, c, z, id)
          end
        end
      end
    end
  end
  def sprite_t(x,y,z,c,id)
    name="#{x};#{y};#{z};#{id}"
    if @bitmap_tiles[id]
      if @tiles[name]
        @tiles[name].bitmap=@bitmap_tiles[id]
      else
        @tiles[name] = Sprite.new(@viewport)
        @tiles[name].x = x*@tiles_size[0]
        @tiles[name].y = y*@tiles_size[1]
        @tiles[name].ox=@ox
        @tiles[name].oy=@oy
        @tiles[name].z = z*150 + c
        @tiles[name].bitmap=@bitmap_tiles[id]
        @tiles[name].visible=@visible
      end
    else
      rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
      x *= @tiles_size[0]
      y *= @tiles_size[1]
      dest_rect = Rect.new(0, 0, @tiles_size[0], @tiles_size[1])
      @bitmap_tiles[id]=Bitmap.new(@tiles_size[0], @tiles_size[1])
      @bitmap_tiles[id].stretch_blt(dest_rect, @tileset, rect)
      @tiles[name] = Sprite.new(@viewport)
      @tiles[name].x = x
      @tiles[name].y = y
      @tiles[name].z= z*150 + c
      @tiles[name].ox=@ox
      @tiles[name].oy=@oy
      @tiles[name].bitmap=@bitmap_tiles[id]
      @tiles[name].visible=@visible
    end
  end
  def sprite_t2(x,y,z,c,id)
    name="px033;#{z};#{c};"
    if @bitmap_tiles[id]
      if @tiles[name]
        @tiles[name].bitmap.blt(x*@tiles_size[0],y*@tiles_size[1],@bitmap_tiles[id],Rect.new(0,0,@tiles_size[0],@tiles_size[1]))
      else
        @tiles[name] = Sprite.new(@viewport)
        @tiles[name].ox=@ox
        @tiles[name].oy=@oy
        @tiles[name].z = z*150 + c
        @tiles[name].bitmap=Bitmap.new(@map_data.xsize*@tiles_size[0],@map_data.ysize*@tiles_size[1])
        @tiles[name].bitmap.blt(x*@tiles_size[0],y*@tiles_size[1],@bitmap_tiles[id],Rect.new(0,0,@tiles_size[0],@tiles_size[1]))
        @tiles[name].visible=@visible
      end
    else
      rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
      x *= @tiles_size[0]
      y *= @tiles_size[1]
      dest_rect = Rect.new(0, 0, @tiles_size[0], @tiles_size[1])
      @bitmap_tiles[id]=Bitmap.new(@tiles_size[0], @tiles_size[1])
      @bitmap_tiles[id].stretch_blt(dest_rect, @tileset, rect)
      if @tiles[name]
        @tiles[name].bitmap.blt(x,y,@bitmap_tiles[id],Rect.new(0,0,@tiles_size[0],@tiles_size[1]))
      else
        @tiles[name] = Sprite.new(@viewport)
        @tiles[name].ox=@ox
        @tiles[name].oy=@oy
        @tiles[name].z = z*150 + c
        @tiles[name].bitmap=Bitmap.new(@map_data.xsize*@tiles_size[0],@map_data.ysize*@tiles_size[1])
        @tiles[name].bitmap.blt(x,y,@bitmap_tiles[id],Rect.new(0,0,@tiles_size[0],@tiles_size[1]))
        @tiles[name].visible=@visible
      end
    end
  end
  def sprite_at(x,y,z,c,id)
    name="#{x};#{y};#{z};#{id}"
    @atiles[name]=id
    if @bitmap_tiles[id]
      if @tiles[name]
        @tiles[name].bitmap=@bitmap_tiles[id]
      else
        @tiles[name] = Sprite.new(@viewport)
        @tiles[name].x = x*@tiles_size[0]
        @tiles[name].y = y*@tiles_size[1]
        @tiles[name].ox=@ox
        @tiles[name].oy=@oy
        @tiles[name].z = z*150 + c
        @tiles[name].bitmap=@bitmap_tiles[id]
        @tiles[name].visible=@visible
      end
    else
      bitmap=get_autotile_bmp(id)
      x *= @tiles_size[0]
      y *= @tiles_size[1]
      @bitmap_tiles[id]=Bitmap.new(@tiles_size[0], @tiles_size[1])
      @bitmap_tiles[id].stretch_blt(@dest_rect, bitmap, @rect)
      @tiles[name] = Sprite.new(@viewport)
      @tiles[name].x = x
      @tiles[name].y = y
      @tiles[name].z= z*150 + c
      @tiles[name].ox=@ox
      @tiles[name].oy=@oy
      @tiles[name].bitmap=@bitmap_tiles[id]
      @tiles[name].visible=@visible
      if not @autotile_update_ids.include?(id)
        @autotile_update_ids.push(id) if @autotile_max_count[id / 48 - 1] > 1
      end
    end
  end
  def get_autotile_bmp(id)
    autotile = @autotiles[id / 48 - 1]
    frammes = @autotile_max_count[id / 48 - 1]
    id %= 48
    bitmap=Bitmap.new(32,32)
    tiles = Autotiles[id / 8][id % 8]
    frames = autotile.width / 96
    anim = (Graphics.frame_count / @update_count) % frames * 96
    for i in 0...4
      tile_position = tiles[i] - 1
      src_rect = Rect.new(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)
      bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
    end
    return bitmap
  end
  def update_autotiles
    for i in 0...@autotile_update_ids.length
      id=@autotile_update_ids[i]
      bitmap=get_autotile_bmp(id)
      @bitmap_tiles[id]=Bitmap.new(@tiles_size[0], @tiles_size[1])
      @bitmap_tiles[id].stretch_blt(@dest_rect, bitmap, @rect)
    end
  end
  def update_pos
    for i in @tiles
      i[1].ox=@ox
      i[1].oy=@oy
      i[1].visible=@visible
      if @atiles[i[0]]
        i[1].bitmap=@bitmap_tiles[@atiles[i[0]]]
      end
    end
  end
  def dispose
    for i in @tiles
      i[1].bitmap.clear
      i[1].bitmap=nil
      i[1].dispose
      @tiles.delete(i[0])
    end
    for i in @bitmap_tiles
      i[1].clear
      @bitmap_tiles.delete(i[0])
    end
    @dispose=true
  end
  def disposed?
    return @dispose
  end
  def change_tile(x,y,z,id)
    return false if z > 2
    old_id=@map_data[x,y,z]
    if @min_bmp
      if old_id
        if old_id > 0
          c=@priorities[old_id]
          name="px033;#{c};"
          @tiles[name].bitmap.fill_rect(x*@tiles_size[0], y*@tiles_size[1], @tiles_size[0], @tiles_size[1], Color.new(0,0,0,0))
        end
      end
    else
      if old_id
        if old_id > 0
          c=@priorities[old_id]
          name="#{x};#{y};#{c};#{old_id}"
          #@tiles[name].bitmap.clear
          @tiles[name].bitmap=nil
          @tiles[name].dispose
          @tiles.delete(name)
          p 0
        end
      end
    end
    @map_data[x,y,z]=id
    if @min_bmp
      id1=@map_data[x,y,0]
      if id1 > 0
        id1 < 384 ? sprite_at(x, y, @priorities[id1], id1) : sprite_t2(x, y, @priorities[id1], id1)
      end
      id1=@map_data[x,y,1]
      if id1 > 0
        id1 < 384 ? sprite_at(x, y, @priorities[id1], id1) : sprite_t2(x, y, @priorities[id1], id1)
      end
      id1=@map_data[x,y,2]
      if id1 > 0
        id1 < 384 ? sprite_at(x, y, @priorities[id1], id1) : sprite_t2(x, y, @priorities[id1], id1)
      end
    else
      id < 384 ? sprite_at(x, y, c, id) : sprite_t(x, y, c, id)
    end
    return true
  end
  def resize_tiles(x=16,y=16)
    dispose
    @tiles_size=[x,y]
    @dest_rect = Rect.new(0, 0, @tiles_size[0], @tiles_size[1])
    create_map
    @dispose=false
  end
end

class Spriteset_Map
  attr_accessor :tilemap
end

Posté par chinleroi le 11 Nov - 17:45 (2011)
Sa ne marche pas ils me disent qu'il y a e erreur 70 --"

Posté par Ashikata le 11 Nov - 20:41 (2011)
Il me semble l'avoir bien copié pourtant. =/
Tu utilises quel navigateur ? Car pour moi je sais que je ne peux pas copier de code depuis Chrome parce que ça me fait des erreurs...
Si le problème vient de là, essaye Firefox, ou IE (je sais plus lequel je prend pour ça).

Posté par Sphinx le 11 Nov - 22:47 (2011)
Le plus simple : tu reDL DS0.4 (c'est pas très long) et tu reprends le script manquant Clin d'œil foireux

=> La balise code a quelques soucis (elle ajoute dans les lignes qui contiennent des . et un @ - le début des boucles for principalement - des balises mailto, d'où les erreurs)