class Object()
#states: [position, health, direction...]
#methods: [move, serializer]
class Player(Object)
#player_methods: [attack...]
class Boss(Object)
#boss_methods: [...]
p1, p2 = new Player(), new Player()
boss = new Boss()
p1.move(..)
p2.move(..)
boss.attack(..)
Renderer.render(p1, p2, boss)
学了几天 elixir 后发现函数式也挺顺手,但是不知道有没有实际用函数式开发游戏的。
global_state[I] {
player1_pos: ..
player1_health: ..
player2_pos: ..
player2_health: ..
boss_pos: ..
boss_health: ..
...
}
fn move: state -> new_state
fn move_player: () -> state -> new_state
fn move_player_by_num: num -> () -> state -> new_state
fn move_boss: state -> new_state
fn boss_attack: state -> new_state
global_state
|> move_player_by_num(1)
|> move_player_by_num(2)
|> move_boss
|> bos_attack
|> render
感觉除了内存占用大一些没其他坏处,有有经验的分享下么?