Computer Science Canada

array fun

Author:  upthescale [ Sat May 06, 2006 11:35 am ]
Post subject:  array fun

ok,i learned arrays and whatdotc olor, so here is an odd program....left click to get points on the, and riht click to randomzize colors...now this mgiht seem weird but im just learnign so i was expermienting...god arrays are soo cool


code:

setscreen ("offscreenonly;graphics:1200;800;position:center;center;nobuttonbar;nocursor")
var x, y, b : int
var score : int := 0
type people :
    record
        x : int
        y : int
        col : int
    end record
var bodies : array 1 .. 60 of people
for i : 1 .. 60
    randint (bodies (i).x, 1, 900)
    randint (bodies (i).y, 400, 800)
    randint (bodies (i).col, 1, 99)
end for
loop
    mousewhere (x, y, b)
    colorback (100)
    cls
    for i : 1 .. 60
        drawfillarc (bodies (i).x, bodies (i).y, 30, 30, 34, 7, bodies (i).col)
        bodies (i).y -= 1
        if bodies (i).y < 78 then
            bodies (i).y += 3
            bodies (i).x += 3
        end if
        if bodies (i).x > 900 then
            bodies (i).y -= 3
        end if
        if bodies (i).y < -10 then
            randint (bodies (i).x, 1, 900)
            randint (bodies (i).y, 400, 800)
        end if
        if whatdotcolor (x, y) = bodies (i).col and b = 1 then
            randint (bodies (i).x, 1, 1200)
            randint (bodies (i).y, 400, 800)
            score += 1
        end if
        buttonchoose ("multibutton")
        var x2, y2, button, left, middle, right : int
        mousewhere (x2, y2, button)
        left := button mod 10
        middle := (button - left) mod 100
        right := button - middle - left
        if right = 100 then
            randint (bodies (i).col, 1, 255)
        end if
    end for
    locate (1, 1)
    put "Score ", score ..
    drawfillbox (0, 0, 900, 50, blue)
    drawline (1200, -50, 900, 50, 7)
    View.Update
end loop

Author:  Clayton [ Sat May 06, 2006 6:45 pm ]
Post subject: 

k, a couple of things:
1) you can just hold down any button to get the (pac-men?), try and find a way to fix that

2)try and get into the habit of using commands such as Mouse.Where, or View.Set instead of mousewhere, or setscreen as it can help you get into OOP when you get there

Author:  upthescale [ Sat May 06, 2006 7:56 pm ]
Post subject: 

wuts oop? like i no wut it stands for but what can u do with ity and why wud it matter? the styscreen i used to go Mouse.Where but i got lazy of the capitals and the period lol

Author:  Cervantes [ Sat May 06, 2006 9:00 pm ]
Post subject: 

OOP is Object Oriented Programming. It's a programming paradigm, and a very powerful one, at that.

I agree that "Mouse.Where" should be used over "mousewhere", but the reason is closer to Modularity than OOP. With "Mouse.Where", you've got the "Where" method for the "Mouse" module. With mousewhere, you've got the "mousewhere", you've got this "mousewhere" method lumped somewhere nonsensicle, mixed into a huge pile of other functions that are totally unrelated.


: