The Forum Site - Join the conversation
Forums: Technology & Internet:
Programming

Can anyone help me create a NetLogo game?

Reply to Topic
AuthorMessage
CompSciStu On May 31, 2009




New York, New York
#1New Post! May 31, 2009 @ 23:25:16
I decided to make Brick Breaker for a school project and so far I have what I estimate to be about half of what I need.

breed [ paddles paddle ]
breed [balls ball]
breed [blocks block ]
globals [ score lives ]

to setup
ca
create-balls 1
ask balls [ ball-setup ]
draw-paddle
create-level
set lives 5
set score 0
end

to draw-paddle
ask patches with [ pxcor = -2 or pxcor = -1 or pxcor = 0 or pxcor = 1 or pxcor = 2 and pycor = min-pycor ] [ sprout-paddles 1]
ask paddles [ setup-paddles ]
end

to setup-paddles
set color white
set heading 0
set shape "paddle"

end

to ball-setup
set heading 45
set shape "circle"
set color red
setxy 0 (min-pycor + 1)
end

to setup-blocks
set color blue
set shape "square"
end

to create-level
ask patches with [ abs pycor < 2 and abs pxcor < 14 ] [ sprout-blocks 1]
ask blocks [setup-blocks]
end

to begin-bouncing
fd 1
if any? paddles-on patch-ahead 1 and [who] of paddles = 3 or [who] of paddles = 4
[ set heading (- heading)
fd 0.01]
if any? paddles-on patch-ahead 1 and [who] of paddles = 2 or [who] of paddles = 1
[ set heading -60
fd 0.01]
if any? paddles-on patch-ahead 1 and [who] of paddles = 5
[ set heading -90
fd 0.01]
if any? blocks-here
[ set heading (180 - heading)
ask blocks-here [die]
set score score + 10]
if abs [pxcor] of patch-ahead 1 = max-pxcor
[ set heading (- heading)
]
if abs [pycor] of patch-ahead 1 = max-pycor
[ set heading (180 - heading)
]

wait 0.1
end

to move-paddle-left
if [pxcor] of one-of paddles != min-pxcor
[ask paddles [ setxy (pxcor - 1) ycor ] ]
end

to move-paddles-right
if [ pxcor] of one-of paddles != max-pxcor
[ask paddles [setxy (pxcor + 1) ycor ]]
end

to go
ask balls [ begin-bouncing ]
end


The buttons are setup,go,left and right and the monitors are score and lives. I need it to reset and subtract a life when the ball doesn't fall the on paddle, I need it to bounce a little more realistically and I need it to add a row when an entire board is clear until there are ten rows (when this happens it should say "WINNER" or something along those lines). Also a huge problem is that when the paddle goes too far left or right the whole thing stops and has an error.
nigg3rbr0 On January 08, 2013




New York, New York
#2New Post! Jan 06, 2013 @ 19:04:09
@CompSciStu Said

I decided to make Brick Breaker for a school project and so far I have what I estimate to be about half of what I need.

breed [ paddles paddle ]
breed [balls ball]
breed [blocks block ]
globals [ score lives ]

to setup
ca
create-balls 1
ask balls [ ball-setup ]
draw-paddle
create-level
set lives 5
set score 0
end

to draw-paddle
ask patches with [ pxcor = -2 or pxcor = -1 or pxcor = 0 or pxcor = 1 or pxcor = 2 and pycor = min-pycor ] [ sprout-paddles 1]
ask paddles [ setup-paddles ]
end

to setup-paddles
set color white
set heading 0
set shape "paddle"

end

to ball-setup
set heading 45
set shape "circle"
set color red
setxy 0 (min-pycor + 1)
end

to setup-blocks
set color blue
set shape "square"
end

to create-level
ask patches with [ abs pycor < 2 and abs pxcor < 14 ] [ sprout-blocks 1]
ask blocks [setup-blocks]
end

to begin-bouncing
fd 1
if any? paddles-on patch-ahead 1 and [who] of paddles = 3 or [who] of paddles = 4
[ set heading (- heading)
fd 0.01]
if any? paddles-on patch-ahead 1 and [who] of paddles = 2 or [who] of paddles = 1
[ set heading -60
fd 0.01]
if any? paddles-on patch-ahead 1 and [who] of paddles = 5
[ set heading -90
fd 0.01]
if any? blocks-here
[ set heading (180 - heading)
ask blocks-here [die]
set score score + 10]
if abs [pxcor] of patch-ahead 1 = max-pxcor
[ set heading (- heading)
]
if abs [pycor] of patch-ahead 1 = max-pycor
[ set heading (180 - heading)
]

wait 0.1
end

to move-paddle-left
if [pxcor] of one-of paddles != min-pxcor
[ask paddles [ setxy (pxcor - 1) ycor ] ]
end

to move-paddles-right
if [ pxcor] of one-of paddles != max-pxcor
[ask paddles [setxy (pxcor + 1) ycor ]]
end

to go
ask balls [ begin-bouncing ]
end


The buttons are setup,go,left and right and the monitors are score and lives. I need it to reset and subtract a life when the ball doesn't fall the on paddle, I need it to bounce a little more realistically and I need it to add a row when an entire board is clear until there are ten rows (when this happens it should say "WINNER" or something along those lines). Also a huge problem is that when the paddle goes too far left or right the whole thing stops and has an error.


how did you fix the problems?
Reply to Topic<< Previous Topic | Next Topic >>

1 browsing (0 members - 1 guest)

Quick Reply
Be Respectful of Others

      
Subscribe to topic prefs

Similar Topics
    Forum Topic Last Post Replies Views
New posts   Statistics
Mon Oct 31, 2011 @ 04:43
1 1568
New posts   Philosophy
Thu Sep 03, 2009 @ 06:19
49 7870
New posts   Jokes & Humor
Tue Jun 23, 2009 @ 15:44
0 447
New posts   Local
Sun Oct 19, 2008 @ 03:51
5 1408
New posts   Random
Thu Nov 15, 2007 @ 17:03
6 506