game of life

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

game of life

Post by vtl » Mon Dec 29, 2008 2:12 am

в общем вот, решил накодить игру "жизнь".
из вики правила:
Место действия этой игры — «вселенная» — это размеченная на клетки поверхность, безграничная, ограниченная, или замкнутая. В компьютерных реализациях игры чаще всего используют поверхность тора. Каждая клетка на этой поверхности может находиться в двух состояниях: быть живой или быть мёртвой. Клетка имеет восемь соседей. Распределение живых клеток в начале игры называется первым поколением. Каждое следующее поколение рассчитывается на основе предыдущего по таким правилам:
пустая (мёртвая) клетка ровно с тремя живыми клетками-соседями оживает;
если у живой клетки есть две или три живые соседки, то эта клетка продолжает жить; в противном случае (если соседок меньше двух или больше трёх) клетка умирает (от «одиночества» или от «перенаселённости»).
Игрок не принимает прямого участия в игре, а лишь расставляет «живые» клетки, которые взаимодействуют согласно правилам уже без его участия.
Эти простые правила приводят к огромному разнообразию форм, которые могут возникнуть в игре.
прога пока альфа или по крайней мере ver. 0.1, т.к. сделан минимум: мышью или стилусом меняем состояние клеток, любая хард кнопка начинает / отрубает симуляцию. буду доделывать: хочу снизу панельку сделать типа вкл.\выкл., возможно запись в гиф, может еще подгрузка тайлов любых, посмотрим что сделаю...

Code: Select all

//------------------------------------------------------------
// Conway's Game of Life
//------------------------------------------------------------

w = 240
h = 320

init_pics
init_vars
clear(#ffffff)

draw:

  handle_pen_keys(st_down, 0, 0)
  handle_hard_keys(hk_down, 0)
  paint
  
  if (active = 1)
  {
    next_matrix
  }

  frame(100)

goto draw

//------------------------------------------------------------
//запуск / стоп по кнопке
//------------------------------------------------------------

hk_down:

  if (active = 0)
  {
    active = 1
  }
  else
  {
    active = 0
  }

ret

//------------------------------------------------------------
//смена состояния клетки вручную
//------------------------------------------------------------

st_down:

  j = (gpx + w / 2) / step
  i = (gpy + h / 2) / step
  
  if (i >= 0 & i < col_sz & j >= 0 & j < row_sz)
  {
    if (matrix[j + i * row_sz] = 1)
    {
      matrix[j + i * row_sz] = 0
    }
    else
    {
      matrix[j + i * row_sz] = 1
    }
  }

ret

//------------------------------------------------------------
//прорисовка
//------------------------------------------------------------

paint:

  i = 0

  while(i < col_sz)
  {
  j = 0
    while(j < row_sz)
    {
      if (matrix[j + i * row_sz] = 0)
      {
        fpixi(cell, -w / 2 + step / 2 + j * step, -h / 2 + step / 2 + i * step, 1, 0, 0)
      }
      else
      {
        fpixi(cell, -w / 2 + step / 2 + j * step, -h / 2 + step / 2 + i * step, 1, 0, 1)
      }

      j + 1
    }

  i + 1
  }

ret

//------------------------------------------------------------
//основное - получить из текущего поколения следующее
//------------------------------------------------------------

next_matrix:

  i = 0
  while(i < col_sz)
  {
    j = 0
    while(j < row_sz)
    {
      sum = 0

      k = 0
      while(k < 8)
      {
        newj = j + off_matrix[2 * k]
        newi = i + off_matrix[2 * k+1]

        if (newi >=0 & newi < col_sz & newj >= 0 & newj < row_sz)
        {
          sum = sum + matrix[newi * row_sz + newj]
        }
       
        k + 1
      }

      if (sum = 3 | (sum = 2 & matrix[i * row_sz + j] = 1))
      {
        new_matrix[i * row_sz + j] = 1
      }
      else
      {
        new_matrix[i * row_sz + j] = 0
      }

      j + 1
    }

    i + 1
  }

  i = 0
  while(i < col_sz)
  {
    j = 0
    while(j < row_sz)
    {
    matrix[i * row_sz + j] = new_matrix[i * row_sz + j]
    j + 1
    }
  i + 1
  }

ret

//------------------------------------------------------------
//инициализация переменных
//------------------------------------------------------------

init_vars:

  row_sz = w / step
  col_sz = h / step
  matrix = new_array(row_sz * col_sz)
  new_matrix = new_array(row_sz * col_sz)
  off_matrix = new_array(16)

  i = 0
  while(i < row_sz * col_sz)
  {
    matrix[i] = 0
    i + 1
  }

  off_matrix[0] = -1  off_matrix[1] = -1  off_matrix[2] = 0  off_matrix[3] = -1  off_matrix[4] = 1  off_matrix[5] = -1
  off_matrix[6] = -1  off_matrix[7] = 0                                          off_matrix[8] = 1  off_matrix[9] = 0
  off_matrix[10] = -1 off_matrix[11] = 1  off_matrix[12] = 0 off_matrix[13] = 1  off_matrix[14] = 1 off_matrix[15] = 1

  simulate = 0

ret

//------------------------------------------------------------
//инициализация спрайтов
//------------------------------------------------------------
init_pics:

  b = #5050ff
  s = #000000
  d = #4030c0
  l = #50d050

  cell = "
.333333333333333333.
3dddddddddddddddddd3
3dddddddddddddddddd3
3dd0ddd0dddd0ddd0dd3
3ddd0d0dddddd0d0ddd3
3dddd0dddddddd0dddd3
3ddd0d0dddddd0d0ddd3
3dd0ddd0dddd0ddd0dd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddd000000dddddd3
3dddd00dd0b0b00dddd3
3ddd0dddd0b0b0d0ddd3
3dd0ddddd0bbb0dd0dd3
3dd0dddddd000ddd0dd3
3dddddddddddddddddd3
3dddddddddddddddddd3
.333333333333333333.
+
.333333333333333333.
3llllllllllllllllll3
3llllllllllllllllll3
3lll000llllll000lll3
3ll00050llll00050ll3
3ll00000llll00000ll3
3ll00000llll00000ll3
3lll000llllll000lll3
3llllllllllllllllll3
3llllllllllllllllll3
3llllllllllllllllll3
3llllllllllllllllll3
3ll0llllllllllll0ll3
3ll0llllllllllll0ll3
3lll0llllllllll0lll3
3llll00llllll00llll3
3llllll000000llllll3
3llllllllllllllllll3
3llllllllllllllllll3
.333333333333333333.

"
  make_pixi(cell)
  step = get_pixi_xsize(cell)

ret
Attachments
Untitled-2.gif
Untitled-2.gif (9.36 KiB) Viewed 12664 times

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

life 0.2

Post by vtl » Tue Dec 30, 2008 3:43 pm

версия 0.2. добавил интерфейс, сохранение \ загрузку, запись видео, выбор частоты кадров, очистку всего. идеи всё еще имеются, буду работать. скрин в аттаче.

Code: Select all

//------------------------------------------------------------
// Conway's Game of Life
//------------------------------------------------------------

clear(#ffffff)
init_pics
init_vars
draw_interface

draw:

  handle_pen_keys(handle_st_down, handle_st_press, 0)
  handle_hard_keys(handle_playstop, 0)
  paint
  
  if (simulate = 1)
  {
    next_matrix
  }

  frame(sp)

goto draw

//------------------------------------------------------------
//обработка стилуса - нажание
//------------------------------------------------------------

handle_st_press:

  j = (gpx + w / 2) / stepx
  i = (gpy + h / 2) / stepy
  
  if (i >= 0 & i < col_sz & j >= 0 & j < row_sz)
  {
    if (last_i != i | last_j != j)
    {
      if (matrix[j + i * row_sz] = 1)
      {
        matrix[j + i * row_sz] = 0
      }
      else
      {
      matrix[j + i * row_sz] = 1
      }

      last_i = i
      last_j = j
    }
  }

ret

//------------------------------------------------------------
//обработка стилуса - начало нажатия
//------------------------------------------------------------

handle_st_down:

  li = last_i
  lj = last_j
  handle_st_press
  if (last_i != li | last_j != lj)
  {
    ret
  }

  if(gpr(b_s1_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_minus
    ret
  }

  if(gpr(b_s2_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_plus
    ret
  }

  if(gpr(b_p_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_playstop
    ret
  }

  if(gpr(b_e_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    erase_matrix
    ret
  }

  if(gpr(b_r_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_record
    ret
  }

  if(gpr(b_l_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_load
    ret
  }

  if(gpr(b_s_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_save
    ret
  }


ret

//------------------------------------------------------------
//обработка интерфейса -
//------------------------------------------------------------

handle_minus:

  if (sp > minsp)
  {
    sp - stepsp
    pixi(button_speedback, b_sb_x, b_y, 1, 0, 0)
    print("$sp", b_sb_x - b_s / 2, b_y - b_s / 6, 0)
  }

ret

//------------------------------------------------------------
//обработка интерфейса +
//------------------------------------------------------------

handle_plus:

  if (sp < maxsp)
  {
    sp + stepsp
    pixi(button_speedback, b_sb_x, b_y, 1, 0, 0)
    print("$sp", b_sb_x - b_s / 2, b_y - b_s / 6, 0)
  }

ret

//------------------------------------------------------------
//обработка запуска \ стоп
//------------------------------------------------------------

handle_playstop:

  if (simulate = 0)
  {
    simulate = 1
    fpixi(button_play, b_p_x, b_y, 1, 0, 1)
  }
  else
  {
    simulate = 0
    fpixi(button_play, b_p_x, b_y, 1, 0, 0)
  }

ret

//------------------------------------------------------------
//обработка записи видео
//------------------------------------------------------------

handle_record:

  if (record = 0)
  {
    if (file_dialog(str, "Сохранение видео в gif", "gif", "temp.ini") = 1)
      {
        video_export_gif(str, -w / 2, -h / 2, w, h - panel_size)
        record = 1
        fpixi(button_rec, b_r_x, b_y, 1, 0, 1)
      }
  }
  else
  {
    stop_video_export
    record = 0
    fpixi(button_rec, b_r_x, b_y, 1, 0, 0)
  }

ret

//------------------------------------------------------------
//обработка загрузки
//------------------------------------------------------------

handle_load:

  if (file_dialog(str, "Загрузить запись", "dat", "temp.ini") = 1)
  {
    file = fopen(str, "rb")
    
    i = 0
    rl = 0
    orl = -1

read:

    if (rl > row_sz | i / row_sz > col_sz)
    {
      goto readed
    }

    ch = fgetc(file)

    if (ch = '0')
    {
      load_matrix[i] = 0
      rl + 1
      i + 1
      goto read
    }

    if (ch = '1')
    {
      load_matrix[i] = 1
      rl + 1
      i + 1
      goto read
    }

    if (ch = '2')
    {
      if (orl != -1 & rl != orl)
      {
        goto readed
      }

      orl = rl 
      rl = 0
      goto read
    }

    if (ch !='3')
    {
      goto readed
    }

    row_sz = orl
    col_sz = i / row_sz
    matrix = new_array(row_sz * col_sz)
    new_matrix = new_array(row_sz * col_sz)

    j = 0
    while(j < i)
    {
      matrix[j] = load_matrix[j]
      j + 1
    }

readed:
   
    fclose(file)
  }
  

ret

//------------------------------------------------------------
//обработка сохранения
//------------------------------------------------------------

handle_save:

  if (file_dialog(str, "Сохранить запись", "dat", "temp.ini") = 1)
  {
    file = fopen(str, "wb")
    
    i = 0
    while(i < col_sz)
    {
      j = 0

      while(j < row_sz)
      {
        if (matrix[j + i * row_sz] = 0)
        {
          fputc('0', file)
        }
        else
        {
          fputc('1', file)
        }

        j + 1
      }

      fputc('2', file)
      i + 1
    }

    fputc('3', file)
    fclose(file)
  }

ret

//------------------------------------------------------------
//получение следующей матрицы (такт клеточного автомата)
//------------------------------------------------------------

next_matrix:

  i = 0
  while(i < col_sz)
  {
    j = 0
    while(j < row_sz)
    {
      sum = 0

      k = 0
      while(k < 8)
      {
        newj = j + off_matrix[2 * k]
        newi = i + off_matrix[2 * k+1]

        if (newi >=0 & newi < col_sz & newj >= 0 & newj < row_sz)
        {
          sum = sum + matrix[newi * row_sz + newj]
        }
       
        k + 1
      }

      if (sum = 3 | (sum = 2 & matrix[i * row_sz + j] = 1))
      {
        new_matrix[i * row_sz + j] = 1
      }
      else
      {
        new_matrix[i * row_sz + j] = 0
      }

      j + 1
    }

    i + 1
  }

  i = 0
  while(i < col_sz)
  {
    j = 0
    while(j < row_sz)
    {
    matrix[i * row_sz + j] = new_matrix[i * row_sz + j]

    j + 1
    }

  i + 1
  }

ret

//------------------------------------------------------------
//инициализация переменных
//------------------------------------------------------------

init_vars:

  w = 240
  h = 320
  panel_size = 20

  b_y = h / 2 - panel_size + b_s / 2
  b_s1_x = -w / 2 + b_s / 2
  b_sb_x = b_s1_x + b_s * 2
  b_s2_x = b_sb_x + b_s * 2
  b_p_x = b_s2_x + b_s
  b_e_x = b_p_x + b_s
  b_r_x = b_e_x + b_s
  b_l_x = b_r_x + b_s
  b_s_x = b_l_x + b_s

  row_sz = w / stepx
  col_sz = (h - panel_size) / stepy
  last_i = -1
  last_j = -1

  matrix = new_array(row_sz * col_sz)
  erase_matrix
  new_matrix = new_array(row_sz * col_sz)
  off_matrix = new_array(16)
  load_matrix = new_array(w * (h - panel_size))
  str = new_string(512)

  off_matrix[0] = -1  off_matrix[1] = -1  off_matrix[2] = 0  off_matrix[3] = -1  off_matrix[4] = 1  off_matrix[5] = -1
  off_matrix[6] = -1  off_matrix[7] = 0                                          off_matrix[8] = 1  off_matrix[9] = 0
  off_matrix[10] = -1 off_matrix[11] = 1  off_matrix[12] = 0 off_matrix[13] = 1  off_matrix[14] = 1 off_matrix[15] = 1

  video_export_realtime(1)
  video_export_hq(1)

  simulate = 0
  record = 0

  sp = 100
  maxsp = 1000
  minsp = 10
  stepsp = 10

ret

//------------------------------------------------------------
//затереть основную матрицу
//------------------------------------------------------------

erase_matrix:

i = 0
  while(i < row_sz * col_sz)
  {
    matrix[i] = 0
    i + 1
  }

ret

//------------------------------------------------------------
//начальная прорисовка интерфейса
//------------------------------------------------------------

draw_interface:

  i = 0
  while(i < w / b_s)
  {
    pixi(button_null, -w / 2 + b_s / 2 + b_s * i, h / 2 - b_s / 2, 1, 0)
    i + 1
  }

  fpixi(button_speed, b_s1_x, b_y, 1, 0, 0)
  pixi(button_speedback, b_sb_x, b_y, 1, 0, 0)
  print("$sp", b_sb_x - b_s / 2, b_y - b_s / 6, 0)
  fpixi(button_speed, b_s2_x, b_y, 1, 0, 1)
  fpixi(button_play, b_p_x, b_y, 1, 0, 0)
  pixi(button_erase, b_e_x, b_y, 1, 0)
  fpixi(button_rec, b_r_x, b_y, 1, 0, 0)
  fpixi(button_saveload, b_l_x, b_y, 1, 0, 0)
  fpixi(button_saveload, b_s_x, b_y, 1, 0, 1)

ret

//------------------------------------------------------------
//прорисовка матрицы
//------------------------------------------------------------

paint:

  i = 0
  while(i < col_sz)
  {
  j = 0
    while(j < row_sz)
    {
      if (matrix[j + i * row_sz] = 0)
      {
        fpixi(cell, -w / 2 + stepx / 2 + j * stepx, -h / 2 + stepy / 2 + i * stepy, 1, 0, 0)
      }
      else
      {
        fpixi(cell, -w / 2 + stepx / 2 + j * stepx, -h / 2 + stepy / 2 + i * stepy, 1, 0, 1)
      }

      j + 1
    }

  i + 1
  }

ret

//------------------------------------------------------------
//инициализация спрайтов
//------------------------------------------------------------

init_pics:

  d = #4030c0
  l = #50d050

  cell = "
.333333333333333333.
3dddddddddddddddddd3
3dddddddddddddddddd3
3dd0ddd0dddd0ddd0dd3
3ddd0d0dddddd0d0ddd3
3dddd0dddddddd0dddd3
3ddd0d0dddddd0d0ddd3
3dd0ddd0dddd0ddd0dd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddd000000dddddd3
3dddd00dd0d0d00dddd3
3ddd0dddd0d0d0d0ddd3
3dd0ddddd0ddd0dd0dd3
3dd0dddddd000ddd0dd3
3dddddddddddddddddd3
3dddddddddddddddddd3
.333333333333333333.
+
.333333333333333333.
3llllllllllllllllll3
3llllllllllllllllll3
3lll000llllll000lll3
3ll00050llll00050ll3
3ll00000llll00000ll3
3ll00000llll00000ll3
3lll000llllll000lll3
3llllllllllllllllll3
3llllllllllllllllll3
3llllllllllllllllll3
3llllllllllllllllll3
3ll0llllllllllll0ll3
3ll0llllllllllll0ll3
3lll0llllllllll0lll3
3llll00llllll00llll3
3llllll000000llllll3
3llllllllllllllllll3
3llllllllllllllllll3
.333333333333333333.
"
  make_pixi(cell)
  stepx = get_pixi_xsize(cell)
  stepy = get_pixi_ysize(cell)

  f = #000000
  s = #3f3f3f
  g = #00af00
  b = #9f9f9f
  p = #00ff00
  r = #505050

  button_play = "
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbggbbbbbbbbbbbf
fbbbbbgpgbbbbbbbbbbf
fbbbbbgppgbbbbbbbbbf
fbbbbbgpppgbbbbbbbbf
fbbbbbgppppgbbbbbbbf
fbbbbbgpppppgbbbbbbf
fbbbbbgppppppgbbbbbf
fbbbbbgppppppgbbbbbf
fbbbbbgpppppgbbbbbbf
fbbbbbgppppgbbbbbbbf
fbbbbbgpppgbbbbbbbbf
fbbbbbgppgbbbbbbbbbf
fbbbbbgpgbbbbbbbbbbf
fbbbbbggbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
+
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbssbbbbssbbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbbssbbbbssbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
"
  make_pixi(button_play)
  b_s = get_pixi_xsize(button_play)

  e = #ff0000
  a = #a00000

  button_erase = "
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbaaabbbbbbaaabbbf
fbbaeeeabbbbaeeeabbf
fbbaeeeeabbaeeeeabbf
fbbbaeeeeaaeeeeabbbf
fbbbbaeeeeeeeeabbbbf
fbbbbbaeeeeeeabbbbbf
fbbbbbbaeeeeabbbbbbf
fbbbbbbaeeeeabbbbbbf
fbbbbbaeeeeeeabbbbbf
fbbbbaeeeeeeeeabbbbf
fbbbaeeeeaaeeeeabbbf
fbbaeeeeabbaeeeeabbf
fbbaeeeabbbbaeeeabbf
fbbbaaabbbbbbaaabbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
"
  make_pixi(button_erase)

  button_rec = "
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbaaaabbbbbbbf
fbbbbbaaeeeeaabbbbbf
fbbbbaeeeeeeeeabbbbf
fbbbaeeeeeeeeeeabbbf
fbbbaeeeeeeeeeeabbbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbbaeeeeeeeeeeabbbf
fbbbaeeeeeeeeeeabbbf
fbbbbaeeeeeeeeabbbbf
fbbbbbaaeeeeaabbbbbf
fbbbbbbbaaaabbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
+
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbssssssssssbbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbbssssssssssbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
"
  make_pixi(button_rec)

  button_saveload = "
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbpbbpppbpppbppbbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpppbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbppbpppbpbpbppbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
+
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbeeebeeebebebeebbf
fbbebbbebebebebebbbf
fbbebbbebebebebebbbf
fbbebbbebebebebebbbf
fbbeeebeeebebebeebbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebbebbebbbf
fbbbbebebebbebbebbbf
fbbeeebebebbebbeebbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
"
  make_pixi(button_saveload)

  button_speed = "
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbaaaaaaaaaaaabbbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbbaaaaaaaaaaaabbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
+
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbggbbbbbbbbf
fbbbbbbbgbbgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbgggggppgggggbbbf
fbbgppppppppppppgbbf
fbbgppppppppppppgbbf
fbbbgggggppgggggbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbbggbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
"
  make_pixi(button_speed)

  button_speedback = "
.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.
"
  make_pixi(button_speedback)

  button_null = "
.ffffffffffffffffff.
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
.ffffffffffffffffff.
"
  make_pixi(button_null)

ret

Attachments
my2.gif
my2.gif (26.14 KiB) Viewed 12647 times

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: game of life

Post by goglus » Tue Dec 30, 2008 4:33 pm

класс
надо выложить на wiki

User avatar
Al_Rado
Posts: 239
Joined: Tue Dec 04, 2007 2:33 pm
Location: Krasnodar
Contact:

Re: game of life

Post by Al_Rado » Tue Dec 30, 2008 4:44 pm

Работает, прикольно... Только смысл игры не понимаю
ВекторКодПиксельПолигон - ВотЧтоЯЛюблю!

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: game of life

Post by vtl » Tue Dec 30, 2008 5:45 pm

Я ее еще буду доделывать, есть идейки... ну а смысл... Черт его знает, клеточный автомат, упрощенная модель популяции, почитай на вики русской:) можно еще в сети покопать, распространенная вещь, интересная довольно)

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: game of life

Post by vtl » Wed Dec 31, 2008 8:05 pm

версия 0.3. добавил загрузку пользовательской картинки клетки, выбор режима (0, инверсия, 1) и размера (1, 3, 5 клеток) кисти. небольшая косметика в том числе и кода. багов не заметил, но всё же. в аттаче на картинке используется пользовательский тайл.

Code: Select all

//------------------------------------------------------------
// Conway's Game of Life
//------------------------------------------------------------

clear(#ffffff)
init_pics
init_vars
draw_interface

draw:

  handle_pen_keys(handle_st_down, handle_st_press, 0)
  handle_hard_keys(handle_playstop, 0)
  paint
  
  if (simulate = 1)
  {
    if (time > sp / minsp)
    {
      next_matrix
      time = 0
    }
    else
    {
      time + 1
    }
  }

  frame(minsp)

goto draw

//------------------------------------------------------------
//обработка стилуса - нажание
//------------------------------------------------------------

handle_st_press:

  j = (gpx + w / 2) / stepx
  i = (gpy + h / 2) / stepy
  
  if (i >= 0 & i < col_sz & j >= 0 & j < row_sz)
  {
    if (flag_st_down = 1 | last_i != i | last_j != j)
    {
      kmax = brush_s / 2

      k1 = -kmax
      while(k1 <= kmax)
      {
        k2 = -kmax
        while(k2 <= kmax)
        {
          ik = (gpy + h / 2) / stepy + k1
          jk = (gpx + w / 2) / stepx + k2

          if (ik >= 0 & ik < col_sz & jk >= 0 & jk < row_sz)
          {
            if (brush_m = 0)
            {
              matrix[jk + ik * row_sz] = 1
              goto nextk2
            }

            if (brush_m = 1)
            {
              if (matrix[jk + ik * row_sz] = 1)
              {
                matrix[jk + ik * row_sz] = 0
              }
              else
              {
                matrix[jk + ik * row_sz] = 1
              }
              goto nextk2
            }
            
            matrix[jk + ik * row_sz] = 0
          }

nextk2:
          k2 + 1
        }

        k1 + 1
      }

      last_i = i
      last_j = j
    }
  }

ret

//------------------------------------------------------------
//обработка стилуса - начало нажатия
//------------------------------------------------------------

handle_st_down:

  flag_st_down = 1
  handle_st_press
  flag_st_down = 0

  if(gpr(b_s1_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_minus
    ret
  }

  if(gpr(b_s2_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_plus
    ret
  }

  if(gpr(b_p_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_playstop
    ret
  }

  if(gpr(b_e_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    erase_matrix
    ret
  }

  if(gpr(b_r_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_record
    ret
  }

  if(gpr(b_l_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_load
    ret
  }

  if(gpr(b_s_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_save
    ret
  }

  if(gpr(b_bm_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_mode
    ret
  }

  if(gpr(b_bs_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_size
    ret
  }

  if(gpr(b_i_x - b_s /2, b_y - b_s / 2, b_s, b_s) = 1)
  {
    handle_image
    ret
  }

ret

//------------------------------------------------------------
//обработка интерфейса -
//------------------------------------------------------------

handle_minus:

  if (sp > minsp)
  {
    sp - stepsp
    pixi(button_speedback, b_sb_x, b_y, 1, 0, 0)
    print("$sp", b_sb_x - b_s + 4, b_y - b_s / 6, 0)
  }

ret

//------------------------------------------------------------
//обработка интерфейса +
//------------------------------------------------------------

handle_plus:

  if (sp < maxsp)
  {
    sp + stepsp
    pixi(button_speedback, b_sb_x, b_y, 1, 0, 0)
    print("$sp", b_sb_x - b_s + 4, b_y - b_s / 6, 0)
  }

ret

//------------------------------------------------------------
//обработка запуска \ стоп
//------------------------------------------------------------

handle_playstop:

  if (simulate = 0)
  {
    simulate = 1
    fpixi(button_play, b_p_x, b_y, 1, 0, 1)
  }
  else
  {
    simulate = 0
    fpixi(button_play, b_p_x, b_y, 1, 0, 0)
  }

ret

//------------------------------------------------------------
//обработка загрузки
//------------------------------------------------------------

handle_load:

  if (file_dialog(str, "Загрузить запись", "dat", "temp.ini") = 1)
  {
    file = fopen(str, "rb")
    
    i = 0
    rl = 0

read:

    if (rl > row_sz | i / row_sz > col_sz)
    {
      goto readed
    }

    ch = fgetc(file)

    if (ch = '0')
    {
      load_matrix[i] = 0
      rl + 1
      i + 1
      goto read
    }

    if (ch = '1')
    {
      load_matrix[i] = 1
      rl + 1
      i + 1
      goto read
    }

    if (ch = '2')
    {
      if (rl != row_sz)
      {
        goto readed
      }

      orl = rl
      rl = 0
      goto read
    }

    if (ch !='3')
    {
      goto readed
    }

    row_sz = orl
    col_sz = i / row_sz
    matrix = new_array(row_sz * col_sz)
    new_matrix = new_array(row_sz * col_sz)

    j = 0
    while(j < i)
    {
      matrix[j] = load_matrix[j]
      j + 1
    }

readed:
   
    fclose(file)
  }
  

ret

//------------------------------------------------------------
//обработка сохранения
//------------------------------------------------------------

handle_save:

  if (file_dialog(str, "Сохранить запись", "dat", "temp.ini") = 1)
  {
    file = fopen(str, "wb")
    
    i = 0
    while(i < col_sz)
    {
      j = 0

      while(j < row_sz)
      {
        if (matrix[j + i * row_sz] = 0)
        {
          fputc('0', file)
        }
        else
        {
          fputc('1', file)
        }

        j + 1
      }

      fputc('2', file)
      i + 1
    }

    fputc('3', file)
    fclose(file)
  }

ret

//------------------------------------------------------------
//обработка загрузки картинки
//------------------------------------------------------------

handle_image:

  if (file_dialog(str, "Загрузить изображение", "gif", "temp.ini") = 1)
  {
    cell = load_pixi(str)
    init_sizes
  }

ret

//------------------------------------------------------------
//обработка режима кисти
//------------------------------------------------------------

handle_mode:

  if (brush_m < 2)
  {
    brush_m + 1
  }
  else
  {
    brush_m = 0
  }
  fpixi(button_mode, b_bm_x, b_y, 1, 0, brush_m)

ret

//------------------------------------------------------------
//обработка размера кисти
//------------------------------------------------------------

handle_size:

  if (brush_s < 5)
  {
    brush_s + 2
  }
  else
  {
    brush_s = 1
  }
  fpixi(button_size, b_bs_x, b_y, 1, 0, brush_s / 2)

ret

//------------------------------------------------------------
//обработка записи видео
//------------------------------------------------------------

handle_record:

  if (record = 0)
  {
    if (file_dialog(str, "Сохранение видео в gif", "gif", "temp.ini") = 1)
      {
        video_export_gif(str, -w / 2, -h / 2, w, h - panel_size)
        record = 1
        fpixi(button_rec, b_r_x, b_y, 1, 0, 1)
      }
  }
  else
  {
    stop_video_export
    record = 0
    fpixi(button_rec, b_r_x, b_y, 1, 0, 0)
  }

ret

//------------------------------------------------------------
//получение следующей матрицы (такт клеточного автомата)
//------------------------------------------------------------

next_matrix:

  i = 0
  while(i < col_sz)
  {
    j = 0
    while(j < row_sz)
    {
      sum = 0

      k = 0
      while(k < 8)
      {
        newj = j + off_matrix[2 * k]
        newi = i + off_matrix[2 * k+1]

        if (newi >=0 & newi < col_sz & newj >= 0 & newj < row_sz)
        {
          sum = sum + matrix[newi * row_sz + newj]
        }
       
        k + 1
      }

      if (sum = 3 | (sum = 2 & matrix[i * row_sz + j] = 1))
      {
        new_matrix[i * row_sz + j] = 1
      }
      else
      {
        new_matrix[i * row_sz + j] = 0
      }

      j + 1
    }

    i + 1
  }

  i = 0
  while(i < col_sz)
  {
    j = 0
    while(j < row_sz)
    {
    matrix[i * row_sz + j] = new_matrix[i * row_sz + j]

    j + 1
    }

  i + 1
  }

ret

//------------------------------------------------------------
//инициализация переменных
//------------------------------------------------------------

init_vars:

  w = 240
  h = 320
  panel_size = 20

  b_y = h / 2 - panel_size + b_s / 2
  b_s1_x = -w / 2 + b_s / 2
  b_sb_x = b_s1_x + b_s * 3 / 2
  b_s2_x = b_sb_x + b_s * 3 / 2
  b_p_x = b_s2_x + b_s
  b_e_x = b_p_x + b_s
  b_l_x = b_e_x + b_s
  b_s_x = b_l_x + b_s
  b_i_x = b_s_x + b_s
  b_bm_x = b_i_x + b_s
  b_bs_x = b_bm_x + b_s
  b_r_x = b_bs_x + b_s

  init_sizes

  off_matrix = new_array(16)
  load_matrix = new_array(w * (h - panel_size))
  str = new_string(512)

  off_matrix[0] = -1  off_matrix[1] = -1  off_matrix[2] = 0  off_matrix[3] = -1  off_matrix[4] = 1  off_matrix[5] = -1
  off_matrix[6] = -1  off_matrix[7] = 0                                          off_matrix[8] = 1  off_matrix[9] = 0
  off_matrix[10] = -1 off_matrix[11] = 1  off_matrix[12] = 0 off_matrix[13] = 1  off_matrix[14] = 1 off_matrix[15] = 1

  video_export_realtime(1)
  video_export_hq(1)

  simulate = 0
  record = 0
  brush_s = 1
  brush_m = 0

  sp = 100
  maxsp = 1000
  minsp = 10
  stepsp = 10
  time = 0

  flag_st_down = 0

ret

//------------------------------------------------------------
//инициализация переменных зависящих от изображения
//------------------------------------------------------------

init_sizes:

    stepx = get_pixi_xsize(cell)
    stepy = get_pixi_ysize(cell)
    
    row_sz = w / stepx
    col_sz = (h - panel_size) / stepy
    last_i = -1
    last_j = -1

    matrix = new_array(row_sz * col_sz)
    erase_matrix
    new_matrix = new_array(row_sz * col_sz)
ret

//------------------------------------------------------------
//затереть основную матрицу
//------------------------------------------------------------

erase_matrix:

i = 0
  while(i < row_sz * col_sz)
  {
    matrix[i] = 0
    i + 1
  }

ret

//------------------------------------------------------------
//начальная прорисовка интерфейса
//------------------------------------------------------------

draw_interface:

  i = 0
  while(i < w / b_s)
  {
    pixi(button_null, -w / 2 + b_s / 2 + b_s * i, h / 2 - b_s / 2, 1, 0)
    i + 1
  }

  fpixi(button_speed, b_s1_x, b_y, 1, 0, 0)
  pixi(button_speedback, b_sb_x, b_y, 1, 0, 0)
  print("$sp", b_sb_x - b_s + 4, b_y - b_s / 6, 0)
  fpixi(button_speed, b_s2_x, b_y, 1, 0, 1)
  fpixi(button_play, b_p_x, b_y, 1, 0, 0)
  pixi(button_erase, b_e_x, b_y, 1, 0)
  fpixi(button_saveload, b_l_x, b_y, 1, 0, 0)
  fpixi(button_saveload, b_s_x, b_y, 1, 0, 1)
  pixi(button_image, b_i_x, b_y, 1, 0)
  fpixi(button_mode, b_bm_x, b_y, 1, 0, 0)
  fpixi(button_size, b_bs_x, b_y, 1, 0, 0)
  fpixi(button_rec, b_r_x, b_y, 1, 0, 0)

ret

//------------------------------------------------------------
//прорисовка матрицы
//------------------------------------------------------------

paint:

  i = 0
  while(i < col_sz)
  {
  j = 0
    while(j < row_sz)
    {
      if (matrix[j + i * row_sz] = 0)
      {
        fpixi(cell, -w / 2 + stepx / 2 + j * stepx, -h / 2 + stepy / 2 + i * stepy, 1, 0, 0)
      }
      else
      {
        fpixi(cell, -w / 2 + stepx / 2 + j * stepx, -h / 2 + stepy / 2 + i * stepy, 1, 0, 1)
      }

      j + 1
    }

  i + 1
  }

ret

//------------------------------------------------------------
//инициализация спрайтов
//------------------------------------------------------------

init_pics:

  d = #4030c0
  l = #50d050

  cell = "
33333333333333333333
3dddddddddddddddddd3
3dddddddddddddddddd3
3dd0ddd0dddd0ddd0dd3
3ddd0d0dddddd0d0ddd3
3dddd0dddddddd0dddd3
3ddd0d0dddddd0d0ddd3
3dd0ddd0dddd0ddd0dd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddddddddddddddd3
3dddddd000000dddddd3
3dddd00dd0d0d00dddd3
3ddd0dddd0d0d0d0ddd3
3dd0ddddd0ddd0dd0dd3
3dd0dddddd000ddd0dd3
3dddddddddddddddddd3
3dddddddddddddddddd3
33333333333333333333
+
33333333333333333333
3llllllllllllllllll3
3llllllllllllllllll3
3lll000llllll000lll3
3ll00050llll00050ll3
3ll00000llll00000ll3
3ll00000llll00000ll3
3lll000llllll000lll3
3llllllllllllllllll3
3llllllllllllllllll3
3llllllllllllllllll3
3llllllllllllllllll3
3ll0llllllllllll0ll3
3ll0llllllllllll0ll3
3lll0llllllllll0lll3
3llll00llllll00llll3
3llllll000000llllll3
3llllllllllllllllll3
3llllllllllllllllll3
33333333333333333333
"
  make_pixi(cell)

  f = #000000
  s = #3f3f3f
  g = #009f00
  b = #9f9f9f
  p = #00df00
  r = #505050

  button_play = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbggbbbbbbbbbbbf
fbbbbbgpgbbbbbbbbbbf
fbbbbbgppgbbbbbbbbbf
fbbbbbgpppgbbbbbbbbf
fbbbbbgppppgbbbbbbbf
fbbbbbgpppppgbbbbbbf
fbbbbbgppppppgbbbbbf
fbbbbbgppppppgbbbbbf
fbbbbbgpppppgbbbbbbf
fbbbbbgppppgbbbbbbbf
fbbbbbgpppgbbbbbbbbf
fbbbbbgppgbbbbbbbbbf
fbbbbbgpgbbbbbbbbbbf
fbbbbbggbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbssbbbbssbbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbsrrsbbsrrsbbbbf
fbbbbbssbbbbssbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_play)
  b_s = get_pixi_xsize(button_play)

  e = #ff0000
  a = #a00000

  button_erase = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbaaabbbbbbaaabbbf
fbbaeeeabbbbaeeeabbf
fbbaeeeeabbaeeeeabbf
fbbbaeeeeaaeeeeabbbf
fbbbbaeeeeeeeeabbbbf
fbbbbbaeeeeeeabbbbbf
fbbbbbbaeeeeabbbbbbf
fbbbbbbaeeeeabbbbbbf
fbbbbbaeeeeeeabbbbbf
fbbbbaeeeeeeeeabbbbf
fbbbaeeeeaaeeeeabbbf
fbbaeeeeabbaeeeeabbf
fbbaeeeabbbbaeeeabbf
fbbbaaabbbbbbaaabbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_erase)

  button_rec = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbaaaabbbbbbbf
fbbbbbaaeeeeaabbbbbf
fbbbbaeeeeeeeeabbbbf
fbbbaeeeeeeeeeeabbbf
fbbbaeeeeeeeeeeabbbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbbaeeeeeeeeeeabbbf
fbbbaeeeeeeeeeeabbbf
fbbbbaeeeeeeeeabbbbf
fbbbbbaaeeeeaabbbbbf
fbbbbbbbaaaabbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbssssssssssbbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbsrrrrrrrrrrsbbbf
fbbbbssssssssssbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_rec)

  button_saveload = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbpbbpppbpppbppbbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpppbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbpbbpbpbpbpbpbpbbf
fbbppbpppbpbpbppbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbeeebeeebebebeebbf
fbbebbbebebebebebbbf
fbbebbbebebebebebbbf
fbbebbbebebebebebbbf
fbbeeebeeebebebeebbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebebebebbbf
fbbbbebebebbebbebbbf
fbbbbebebebbebbebbbf
fbbeeebebebbebbeebbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_saveload)

  button_speed = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbaaaaaaaaaaaabbbf
fbbaeeeeeeeeeeeeabbf
fbbaeeeeeeeeeeeeabbf
fbbbaaaaaaaaaaaabbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbggbbbbbbbbf
fbbbbbbbgbbgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbgggggppgggggbbbf
fbbgppppppppppppgbbf
fbbgppppppppppppgbbf
fbbbgggggppgggggbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbgppgbbbbbbbf
fbbbbbbbbggbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_speed)

  button_speedback = "
ffffffffffffffffffffffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffffffffffffffffffffffff
"
  make_pixi(button_speedback)

  button_image = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbb33333333333333bbf
fbb3lllllldddddd3bbf
fbb3l0ll0ld0dd0d3bbf
fbb3lllllldddddd3bbf
fbb3l0ll0ldd00dd3bbf
fbb3ll00lld0dd0d3bbf
fbb3lllllldddddd3bbf
fbb33333333333333bbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbsbbsssbbsbbssbbbf
fbbsbbsbsbsbsbsbsbbf
fbbsbbsbsbsssbsbsbbf
fbbssbsssbsbsbssbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_image)

  button_mode = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbb333333333333bbbf
fbb3llllllllllll3bbf
fbb3lll0llll0lll3bbf
fbb3ll000ll000ll3bbf
fbb3lll0llll0lll3bbf
fbb3llllllllllll3bbf
fbb3llllllllllll3bbf
fbb3llllllllllll3bbf
fbb3l0llllllll0l3bbf
fbb3l0llllllll0l3bbf
fbb3ll0llllll0ll3bbf
fbb3lll000000lll3bbf
fbb3llllllllllll3bbf
fbbb333333333333bbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbb333333333333bbbf
fbb3lllllldddddd3bbf
fbb3lll0lld0d0dd3bbf
fbb3ll000ldd0ddd3bbf
fbb3lll0lld0d0dd3bbf
fbb3lllllldddddd3bbf
fbb3lllllldddddd3bbf
fbb3lllllldddddd3bbf
fbb3l0llll000ddd3bbf
fbb3l0llllddd0dd3bbf
fbb3ll0llldddd0d3bbf
fbb3lll000dddd0d3bbf
fbb3lllllldddddd3bbf
fbbb333333333333bbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbb333333333333bbbf
fbb3dddddddddddd3bbf
fbb3dd0d0dd0d0dd3bbf
fbb3ddd0dddd0ddd3bbf
fbb3dd0d0dd0d0dd3bbf
fbb3dddddddddddd3bbf
fbb3dddddddddddd3bbf
fbb3dddddddddddd3bbf
fbb3ddd000000ddd3bbf
fbb3dd0dddddd0dd3bbf
fbb3d0dddddddd0d3bbf
fbb3d0dddddddd0d3bbf
fbb3dddddddddddd3bbf
fbbb333333333333bbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_mode)

  button_size = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbssssbbbbbbbbf
fbbbbbbssssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbbbssbbbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbssbbbbbbssbbbbf
fbbbbssbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbsssbbbbbbf
fbbbbbbbbbsssbbbbbbf
fbbbbbbsssbbbbbbbbbf
fbbbbbbsssbbbbbbbbbf
fbbbbssssssssssbbbbf
fbbbbssssssssssbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
+
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbssbbbbbbssbbbbf
fbbbbssbbbbbbssbbbbf
fbbbbbbbbbbssbbbbbbf
fbbbbbbbbbbssbbbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbbbbbbbbbssbbbbf
fbbbbssbbbbbbssbbbbf
fbbbbssbbbbbbssbbbbf
fbbbbbbssssssbbbbbbf
fbbbbbbssssssbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_size)

  button_null = "
ffffffffffffffffffff
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
fbbbbbbbbbbbbbbbbbbf
ffffffffffffffffffff
"
  make_pixi(button_null)

ret
Attachments
screen.gif
screen.gif (5.86 KiB) Viewed 12613 times

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: game of life

Post by goglus » Wed Dec 31, 2008 10:04 pm

звгрузка сильная вес4ь
Attachments
222.png
222.png (3.06 KiB) Viewed 12611 times

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: game of life

Post by vtl » Wed Dec 31, 2008 10:43 pm

))) подкидывайте еще идеи что приделать, по возможности добавлю. надо еще наглядность довести как-то, балунтипы что ли к кнопкам да и кнопки доделать по мелочи...
в общем вот пояснение по кнопкам, чтоб людей не пугать:
минус, число, плюс - задаем скорость обновления кадра в мс
play\pause - запустить\тормознуть симуляцию
крест - очистить экран
load\save - загрузка\сохранение расстановок клеток
load и две клетки - загрузка изображения клетки из файл. файл гиф с двумя кадрами.
изображение клетки - задание режима кисти. только рисовать живые; инвертировать; только мертвые
1 2 3 - задание размера кисти
record - запись в файл гиф

по ходу думаю следующие мелочи:
1. сделать циклическое наращивание скорости без тыканья
2. систематизировать и доделать иконки
3. подсказки?
4. исходник на два файла разбить и еще переглядеть код
5. выложить все архивом, небольшой комплект тайлов и сохранений

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: game of life

Post by goglus » Fri Jan 02, 2009 3:16 pm

http://wiki.pixi.su/game:life
вывесил на wiki

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: game of life

Post by vtl » Fri Jan 02, 2009 3:27 pm

goglus wrote:http://wiki.pixi.su/game:life
вывесил на wiki
рано навесил, я уже 0.4 почти сделал, если с косяком разберусь что в отдельную тему вывел... вообще хз почему он происходит...

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: game of life

Post by goglus » Fri Jan 02, 2009 4:12 pm

так правь прямо на вики
там без регистрации

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

0.4 is out

Post by vtl » Fri Jan 02, 2009 9:35 pm

версия 0.4.

добавил:
-тул след кадр;
-тул инверсия;
-тул скриншот;
-тул тайл по-умолчанию;
-примеры тайлов;
-примеры сейвов;

исправил:
-перерисовал всю панель, терь с мелкими подписями (убил кучу времени с пиксельной графикой);
-помудрил с маштабируемостью (вроде под любой экран и тайл, полоска снизу панели - излишки заданной высоты при данном тайле);
-тайл по-умолчанию другой;
-кое-что в алгоритмах;
-вытащил ascii графику в гифы, а их в тар;

кстати, как в вики удалять файлы? а то загрузить можно, а ошибочное не удалишь...
Attachments
screen.gif
скриншот
screen.gif (12.68 KiB) Viewed 12560 times
life.zip
соурс
(13.49 KiB) Downloaded 676 times

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: game of life

Post by goglus » Fri Jan 02, 2009 11:30 pm

да забить просто
классно получилось

User avatar
vtl
Posts: 31
Joined: Sun Dec 28, 2008 6:41 pm
Location: Saint Petersburg, Russia
Contact:

Re: game of life

Post by vtl » Sat Jan 03, 2009 12:30 am

0.41. косметический фикс после загрузки тайла \ сейва.
Attachments
life.zip
(13.54 KiB) Downloaded 665 times

User avatar
goglus
Posts: 122
Joined: Tue Dec 04, 2007 4:19 pm
Contact:

Re: game of life

Post by goglus » Sat Jan 03, 2009 10:39 pm

монструозный получился проект

Post Reply