Re: Untitled

From Soft Mousedeer, 2 Years ago, written in Plain Text, viewed 2 times. This paste will perish in 1 Second. This paste is a reply to Untitled from Gentle Cheetah - go back
URL https://paste.paivola.fi/view/dc04bf42/diff Embed
Viewing differences between Untitled and Re: Untitled
object FlappyBugApp extends App {

  val sky        = rectangle(ViewWidth, ViewHeight,  LightBlue)
  val ground     = rectangle(ViewWidth, GroundDepth, SandyBrown)
  val trunk      = rectangle(30, 250, SaddleBrown)
  val foliage    = circle(200, ForestGreen)
  val tree       = trunk.onto(foliage, TopCenter, Center)
  val rootedTree = tree.onto(ground, BottomCenter, new Pos(ViewWidth / 2, 30))
  val scenery    = sky.place(rootedTree, BottomLeft, BottomLeft)


  val bugPic = Pic("ladybug.png")


Pic("ladybug.png")


  def rockPic(obstacle: Obstacle) = circle(obstacle.radius * 2, Black)


  val game = new Game()
  
  val gui = new View(game, "FlappyBug"){
"FlappyBug"){
    var background = scenery
    def makePic = {
      for (obs <- &lt;- game.obstacles){
        this.background = this.background.place(rockPic(obs), obs.pos)
      }
      this.background.place(bugPic, game.bug.pos)     
      
    }
    override def onKeyDown(painettu: Key)={
      if (painettu == Key.Space) game.activateBug() 
    }
    override def onTick() ={
      game.timePasses()
      print("time")
print(&quot;time&quot;)
      this.background = this.background.shiftLeft(backgroundSpeed)
    }
    override def isDone() =  game.isLost
  }
  
  gui.start()

}

---------------------
class Obstacle(val radius: Int) {
  var currentPos = randomLaunchPosition()

  def pos = this.currentPos
  
  def approach() = {
    if (this.isActive())
      this.currentPos = this.currentPos.addX(-ObstacleSpeed)
    else 
      this.currentPos = randomLaunchPosition()
  }

  override def toString = "center &quot;center at &quot; + this.pos + ", &quot;, radius &quot; + this.radius

  def touches(bug: Bug)={
    this.pos.distance(bug.pos) &lt; this.radius + bug.radius
  }
  def isActive() = {
    this.currentPos.x >= &gt;= (-1.0*this.radius) 
  }
  private def randomLaunchPosition() ={
    val launchX = 1000 + this.radius + Random.nextInt(499)
    val launchY = Random.nextInt(400)
    new Pos(launchX, launchY)
  }
}
----------------------
//Palaute
The farthest obstacle by its X-coordinate seems to be at (1392.0,75.0)
Thus approaching the obstacles 41.0 times should have them all on screen. Farthest:(982.0,75.0).
The obstacle that was created at the farthest location is now at: (902.0,75.0).
And the pixel at the previous location of that obstacle (982.0,75.0) should be showing the background, not the obstacle.
Reason for failure:
Color(0, 0, 0) was not equal to Color(255, 202, 24), but Color(0, 0, 0) was equal to Black.
Black.

-----------------------
class Game {
  val bug = new Bug(new Pos(100.0,40.0))
  val obstacles = Vector(new Obstacle(70), new Obstacle(30), new Obstacle(20))
  
  def activateBug(){
    bug.flap(15)
  }
  
  def timePasses(){
    bug.fall()
    for (obs <- this.obstacles){
      obs.approach()
    }    
  }

  def isLost = {
    var obsTouchBug = false
    for (obs <- obstacles){
      if (obs.touches(this.bug)){
        obsTouchBug = true
        
      }
    }    
     obsTouchBug==true || !this.bug.isInBounds
  }

}

Replies to Re: Untitled rss

Title Name Language When
Re: Re: Untitled Voluminous Marmoset text 2 Years ago.

Reply to "Re: Untitled"

Here you can reply to the paste above