| 1 | module main |
| 2 | |
| 3 | @[heap] |
| 4 | interface IGameObject { |
| 5 | mut: |
| 6 | name string |
| 7 | speed f32 |
| 8 | owner ?&IGameObject |
| 9 | collision(mut o IGameObject) |
| 10 | } |
| 11 | |
| 12 | @[heap] |
| 13 | struct GameObject implements IGameObject { |
| 14 | mut: |
| 15 | name string |
| 16 | speed f32 |
| 17 | owner ?&IGameObject |
| 18 | } |
| 19 | |
| 20 | fn (mut gameobject GameObject) collision(mut o IGameObject) { |
| 21 | _ = o |
| 22 | if gameobject != gameobject.owner { |
| 23 | eprintln('Collision') |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | fn main() { |
| 28 | mut ship := &GameObject{ |
| 29 | name: 'ship' |
| 30 | } |
| 31 | mut rocket := &GameObject{ |
| 32 | name: 'rocket' |
| 33 | owner: ship |
| 34 | } |
| 35 | rocket.collision(mut ship) |
| 36 | } |
| 37 | |