-3

Edit: Codes: http://pastebin.com/cGAxmNVC

If you look at the Pipe Part, "if pxcor = 14 [set num num + 1]" this is the scoring. However, it is flawed. As the pipes move toward the bird, the patch num property is set to 0. Because the pxcor is no longer 14. But this means the score will always be 0. So I need help on the scoring. Look at "Pipe".

I'm thinking of finding the max num (num is the patch property), and adding 1. How can I find the max num?

TanMath
  • 598
  • 1
  • 9
  • 27
bttcd5
  • 21
  • 2

1 Answers1

1

Given the strict deadline, I am guessing this is homework for something so I have done some basic help to get you going. I have combined the two pieces of code into one file. I made one syntax correction so that the code will compile (adding `ask turtles' to go).

I didn't make any attempts to fix your logic. You need to think about what happens before the game starts (eg drawing the field of play) and have that in (or called by) the setup procedure. You also need to think about what happens during each tick (probably move the bird, update the score etc) and have that in (or called by) the go procedure, together with the `tick' command.

globals [jump? score]

patches-own [num oldcolor]

to setup
  clear-all
  create-ordered-turtles 1 ; not sure why ordered since only 1 of them
  ask turtles [            ; don't need separate ask, create runs anything in [ ]
    setxy -10 0
    set size 5
    set shape "bird-norm"
  ]
  ask patches [
    set num 0
    if pycor = -16 [set pcolor green]
  ]
end

to go                     ; this should have the tick or it will only run once
  ask turtles [
    set shape "bird-fall"
    set heading 180
    fd 1
    wait 0.1
    if mouse-down? and not jump? [flap]
    set jump? mouse-down?
    if (pycor = -14) or (pcolor = white) [
      ask patch 0 0 [
        set plabel "Game Over"
      ]
      stop
    ]
  ]
end

to move                      ; this has the tick command
  reset-ticks
  wait 0.1
  ask patches [
    set oldcolor pcolor
  ]
  ask patches with [pxcor < max-pxcor] [
    set pcolor [oldcolor] of patch (pxcor + 1) pycor
  ]
  tick
end

to line
    reset-ticks
    let x (random 20 - 6)
    ask patches [
    if ((pxcor > 10) and (pxcor < 15)) and ((pycor > -16) and ((pycor < x) and (pycor > (x - 5)))) [
      set pcolor white
    ]
    if pxcor = 14 [
      set num num + 1
    ]
  ]
end

to pipe
  repeat 10 [move]
  line
end

to flap
  set heading 0
  set shape "bird-norm"
  repeat 5 [
    fd 1
    wait 0.01]
end
JenB
  • 17,620
  • 2
  • 17
  • 45
  • Thank you. I ran the code, and create a button that had "go" and "pipe". However, the pipes work fine. The bird isnt moving at its correct speed. I've decided to change the Flappy Bird game - The white squares are what the bird is supposed to run through, so this solves the pipe problem. About your second paragraph, does this mean I setup creating one white square, and then call the pipe procedure? * Yes this is a major homework. I thought I got everything down, but when I started coding, it was a lot harder than I thought. – bttcd5 Jan 11 '15 at 15:36
  • My second para was about thinking through your design. NetLogo runs a procedure when you hit a button that calls that procedure (or type its name in the command centre). That procedure runs once unless you use a button and tick the forever checkbox and have the tick command in the procedure. You need to work out what procedures you need and whether they are buttons or called by other procedures and whether they are once-off or running and organise your buttons and ticks accordingly. Generally, you need to ask specific questions to get specific answers. – JenB Jan 11 '15 at 18:17