Untitled

From Gentle Cheetah, 2 Years ago, written in Plain Text, viewed 2 times. This paste will shuffle off the mortal coil in 1 Second.
URL https://paste.paivola.fi/view/cc24e52c Embed
Download Paste or View Raw
  1. object FlappyBugApp extends App {
  2.  
  3.   val sky        = rectangle(ViewWidth, ViewHeight,  LightBlue)
  4.   val ground     = rectangle(ViewWidth, GroundDepth, SandyBrown)
  5.   val trunk      = rectangle(30, 250, SaddleBrown)
  6.   val foliage    = circle(200, ForestGreen)
  7.   val tree       = trunk.onto(foliage, TopCenter, Center)
  8.   val rootedTree = tree.onto(ground, BottomCenter, new Pos(ViewWidth / 2, 30))
  9.   val scenery    = sky.place(rootedTree, BottomLeft, BottomLeft)
  10.  
  11.  
  12.   val bugPic = Pic("ladybug.png")
  13.  
  14.  
  15.   def rockPic(obstacle: Obstacle) = circle(obstacle.radius * 2, Black)
  16.  
  17.  
  18.   val game = new Game()
  19.  
  20.   val gui = new View(game, "FlappyBug"){
  21.     var background = scenery
  22.     def makePic = {
  23.       for (obs <- game.obstacles){
  24.         this.background = this.background.place(rockPic(obs), obs.pos)
  25.       }
  26.       this.background.place(bugPic, game.bug.pos)    
  27.      
  28.     }
  29.     override def onKeyDown(painettu: Key)={
  30.       if (painettu == Key.Space) game.activateBug()
  31.     }
  32.     override def onTick() ={
  33.       game.timePasses()
  34.       print("time")
  35.       this.background = this.background.shiftLeft(backgroundSpeed)
  36.     }
  37.     override def isDone() =  game.isLost
  38.   }
  39.  
  40.   gui.start()
  41.  
  42. }
  43.  
  44. ---------------------
  45. class Obstacle(val radius: Int) {
  46.   var currentPos = randomLaunchPosition()
  47.  
  48.   def pos = this.currentPos
  49.  
  50.   def approach() = {
  51.     if (this.isActive())
  52.       this.currentPos = this.currentPos.addX(-ObstacleSpeed)
  53.     else
  54.       this.currentPos = randomLaunchPosition()
  55.   }
  56.  
  57.   override def toString = "center at " + this.pos + ", radius " + this.radius
  58.  
  59.   def touches(bug: Bug)={
  60.     this.pos.distance(bug.pos) < this.radius + bug.radius
  61.   }
  62.   def isActive() = {
  63.     this.currentPos.x >= (-1.0*this.radius)
  64.   }
  65.   private def randomLaunchPosition() ={
  66.     val launchX = 1000 + this.radius + Random.nextInt(499)
  67.     val launchY = Random.nextInt(400)
  68.     new Pos(launchX, launchY)
  69.   }
  70. }
  71. ----------------------
  72. //Palaute
  73. The farthest obstacle by its X-coordinate seems to be at (1392.0,75.0)
  74. Thus approaching the obstacles 41.0 times should have them all on screen. Farthest:(982.0,75.0).
  75. The obstacle that was created at the farthest location is now at: (902.0,75.0).
  76. And the pixel at the previous location of that obstacle (982.0,75.0) should be showing the background, not the obstacle.
  77. Reason for failure:
  78. Color(0, 0, 0) was not equal to Color(255, 202, 24), but Color(0, 0, 0) was equal to Black.
  79.  

Replies to Untitled rss

Title Name Language When
Re: Untitled Soft Mousedeer text 2 Years ago.

Reply to "Untitled"

Here you can reply to the paste above