代码之家  ›  专栏  ›  技术社区  ›  OmniOwl

Wren类不实现字段

  •  0
  • OmniOwl  · 技术社区  · 3 年前

    我正在努力学习如何使用 Dome Wren 。为了做到这一点,我已经开始制作一个简单的Flappy Bird克隆。

    我遇到的问题是收到错误消息

    Bird does not implement bird_idle

    然后它指向我的主类中的第63行,如下所示:

    class Main {
      resources=(value){ _resources = value }
      bird=(value){ _bird = value }
      construct new() {
        _resources = Resources.new()
        _bird = Bird.new(_resources.birdIdle, _resources.birdFlap, _resources.obstacleTile.width * 2, _resources.obstacleTile.height * 4, 10, 4)
      }
      init() {}
      update() {}
      draw(alpha) {
        Canvas.cls()
        Canvas.draw(_bird.bird_idle, _bird.center.x, _bird.center.y) <-- this is line 63
      }
    }
    
    var Game = Main.new()
    

    由于我是雷恩的新手,我不太明白这意味着什么,就像你看看下面我的鸟类一样,我应该实现 bird_idle 。那么我做错了什么?

    class Bird {
      bird_idle=(value){ _bird_idle = value } <-- Right?
      bird_flap=(value){ _bird_flap = value }
      center=(value){ _center = value }
      gravity=(value){ _gravity = value }
      force=(value){ _force = value }
      velocity=(value){ _velocity = value }
      velocityLimit=(value){ _velocityLimit = value }
      isGameRunning=(value){ _isGameRunning = value }
    
      construct new(idle, flap, horizontalPosition, verticalPosition, drag, jumpForce) {
        _bird_idle = idle
        _bird_flap = flap
        _center = Vector.new(horizontalPosition + (idle.width * 0.5), verticalPosition + (idle.height*0.5))
        _gravity = drag
        _force = jumpForce
        _velocityLimit = 1000
        _isGameRunning = true
      }
    
      jump() {
        _velocity = -_force
      }
    
      isTouchingCeiling() {
        var birdTop = _center.y - (_bird_idle.height * 0.5)
        if(birdTop < 0) {
          return true
        }
        return false
      }
      
      isTouchingGround() {
        var birdBottom = _center.y + (_bird_idle.height * 0.5)
        if(birdBottom > height) {
          return true
        }
        return false
      }
    }
    
    0 回复  |  直到 3 年前
        1
  •  0
  •   user19242326 user19242326    3 年前

    您忘记添加 getter :

    class Bird {
      
      construct new(idle) {
         _bird_idle = idle
      }
    
      bird_idle=(value){_bird_idle = value }
      bird_idle{_bird_idle} // You need this if you want to access the field _bird_idle.
    }
    
    var my_bird = Bird.new("Idle")
    my_bird.bird_idle = "Not Idle"
    System.print(my_bird.bird_idle) // Output: Not Idle
    
    推荐文章