美文网首页
Treasure Hunter(寻宝者游戏)KTBYTE(试讲2

Treasure Hunter(寻宝者游戏)KTBYTE(试讲2

作者: 数据分析jacky | 来源:发表于2022-08-25 14:51 被阅读0次
    image.png
    image.png
    /** POSITION: -1732;-1373 */
    // global variables
    PImage bg = loadImage("https://static.ktbyte.com/images/Fun2a/ocean.jpg"); // create variable bg of type PImage, set to: loadImage("https://static.ktbyte.com/images/Fun2a/ocean.jpg")
    Sprite ship = new Sprite("https://static.ktbyte.com/images/Fun2a/ship.png", 320, 240, 80, 80); // create variable ship of type Sprite, set to: new Sprite("https://static.ktbyte.com/images/Fun2a/ship.png", 320, 240, 80, 80)
    Sprite treasure = new Sprite("https://static.ktbyte.com/images/Fun2a/treasure.png", 320, 240, 50, 50); // create variable treasure of type Sprite, set to: new Sprite("https://static.ktbyte.com/images/Fun2a/treasure.png", 320, 240, 50, 50)
    Sprite button = new Sprite(320, 50, 100, 50); // create variable button of type Sprite, set to: new Sprite(320, 50, 100, 50)
    Integer startTime = 15; // create variable startTime of type Integer, set to: 15
    Integer timer = 0; // create variable timer of type Integer, set to: 0
    Integer score = 0; // create variable score of type Integer, set to: 0
    Boolean start = false; // create variable start of type Boolean, set to: false
    Integer speed = 5; // create variable speed of type Integer, set to: 5
    
    
    /** POSITION: -664;-1302 */
    // draw function
    // runs 60 times per second
    void draw() {
      image(bg, 320, 240, width, height); // draw image bg at: (320, 240) with width: width, height: height
      ship.display(); //draw ship on screen
      treasure.display(); //draw treasure on screen
      button.display(); //draw button on screen
      text("开始", 320, 50); // display "开始" at (320, 50)
      text("得分:" + score, 80, 50); // display "得分:" + score at (80, 50)
      text("时间:" + (startTime - timer/60), 550, 50); // display "时间:" + (startTime - timer/60) at (550, 50)
      if (start == true) {
        moveShip(); // run function moveShip with inputs: null
        if (startTime - timer/60 <= 0) {
          start = false; // set start to: false
        }
        timer = timer + 1; // set timer to: timer + 1
      }
      if (ship.touchingSprite(treasure)) {
        score = score + 1; // set score to: score + 1
        treasure.moveToPoint(random(0, width), random(0, height));
        if (timer > startTime * 60) {
          start = false; // set start to: false
        }
      }
    }
    
    /** POSITION: -1093;-1026 */
    void moveShip() {
      if (pressed("LEFT")) {
        ship.moveX(-speed);
      }
      if (pressed("RIGHT")) {
        ship.moveX(speed);
      }
      if (pressed("UP")) {
        ship.moveY(-speed);
      }
      if (pressed("DOWN")) {
        ship.moveY(speed);
      }
    }
    
    /** POSITION: -1708;-853 */
    // mousePressed function
    // runs when mouse clicked on canvas
    void mousePressed() {
      if (button.touchingPoint(mouseX, mouseY)) {
        start = true; // set start to: true
        score = 0; // set score to: 0
        timer = 0; // set timer to: 0
      }
    }
    
    /** POSITION: -1707;-552 */
    // setup function
    // runs at the beginning
    void setup() {
      treasure.moveToPoint(random(0, width), random(0, height));
      button.setColor(0, 255, 0);
      fill(0, 0, 0); // set shapes to color: 0, 0, 0
    }
    
    
    

    相关文章

      网友评论

          本文标题:Treasure Hunter(寻宝者游戏)KTBYTE(试讲2

          本文链接:https://www.haomeiwen.com/subject/svitnrtx.html