Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Descending Objects Using Arrays
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Warsick




PostPosted: Thu Feb 11, 2010 11:45 am   Post subject: Descending Objects Using Arrays

What is it you are trying to achieve?
I'm attempting to use arrays to draw a moving background.
I'm attempting to have stars fly by in the background simulating as if an object that is remaining still is moving, I've had it before but it was quite sometime ago.

Having a circle in the middle of the screen while small circles at the top of the output window slowly descend at different rates in the background. When the small circles reach the bottom of the output window the reset and start at the very top (which I'm positive I could pull off). I just need a refresh on the idea.

What is the problem you are having?
I don't entirely remember how arrays function. I know if I can see just how to implement just one array I should be able to remember how I've done it previously.


Describe what you have tried to solve this problem
I've tried to piece together the bits of coding I remember but after looking at Python and Java it gets a little messed up.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I know this is probably 90% wrong.

Turing:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%% Stars %%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var starX, starY, starVX, starVY, starR : int


var stars : array 1 .. 4 of int

procedure drawScenery
    for i : 1 .. 4
        stars(i) := (drawfilloval (starX, starY, starR, starR, 0))
        starX := maxx div 2
        starY := starY - 1
     end for
end drawScenery
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%% End Stars %%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Please specify what version of Turing you are using
Currently using 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Turing_Gamer




PostPosted: Thu Feb 11, 2010 12:43 pm   Post subject: Re: Descending Objects Using Arrays

1) for every star there has to be their own separte coords, so array everything.
2) adjust all the stars like this: star_move(i) += 1
3) ...your code just confused me now...
USEC_OFFICER




PostPosted: Thu Feb 11, 2010 12:57 pm   Post subject: RE:Descending Objects Using Arrays

Wrong wrong wrong. (not to turing_gamer) You'll need starX, starY etc. in arrays for each star. Also StarX should be declared before the game starts or else it'll jump around the screen. Unless the radius of the stars are changing, you'll won't need a star radius.
Insectoid




PostPosted: Thu Feb 11, 2010 1:50 pm   Post subject: RE:Descending Objects Using Arrays

What you need is an array of X values and an array of Y values. Then, with a for loop you call the procedure Draw.Star() and pass it the x and y's. ie Draw.Star(starX(i), starY(i), height, width, color) or whatever the parameters are.
Warsick




PostPosted: Mon Mar 08, 2010 2:05 pm   Post subject: Re: Descending Objects Using Arrays

Okay I have successfully have made the array, now I'm having problems implying it so the objects declared descend separately.

I've been able to have my code descend but they descend in a bulk and I'd like to have a timed based interval between when each object.

code:

    for s : 0 .. 25
        starY(s) -= 1
        drawfilloval (starX(s), starY(s), starR, starR, starC)
    end for


I know what I'm trying to achieve is solely based on this statement I'm just having a hard time implementing the right code in the right location.

Edit: To any of those who seen my previous post, I was able to troubleshoot that specific problem myself and solved it. Sorry for any inconvenience.
USEC_OFFICER




PostPosted: Mon Mar 08, 2010 4:43 pm   Post subject: RE:Descending Objects Using Arrays

So you want them to decend one at a time? You can't use a for statement for that. (Unless you use delay and View.Update in the for loop, which only works if you don't want anything else to happen.)
Warsick




PostPosted: Tue Mar 09, 2010 9:48 am   Post subject: Re: Descending Objects Using Arrays

I was thinking of having an if statement involved. I've done this exact same thing three years ago but I've lost the file.

Kind of the jist of what I'm trying to accomplish, it makes perfect sense in my head but Turing and I are at a disagreement.
Most likely most of you guys are too.

code:

var setObjectValue : array 0 .. 25 of boolean
var x : array 0 .. 25 of int
var y : array 0 .. 25 of int
var num, num2 : int

num := 0
num2 := 0
r := 2
c := 31

for i : 0 .. 25
     x(i) := Rand.Int (0, maxx)
     y(i) := maxy + r
end for

procedure drawObject
for i : 0 .. 25
     y(i) -= 1
     num += 1

% The Main Problem
     if num > num2 then
         setObjectValue(i) := true
         delay (10)
         num2 += 50
     end if
     if setObjectValue(i) = true then
         drawfilloval (x, y, r, r, c)
     end if

% Causing the Object to start at the top again in a random position.
     if y(i) < 0 then
        y(i) := maxy + r
        x(i) := Rand.Int (r, maxx - r)
     end if
end for
end drawObject

loop
   drawObject
end loop


I'm hoping it could be something that simple but I'm at a stand still with this code.
Turing_Gamer




PostPosted: Tue Mar 09, 2010 12:37 pm   Post subject: RE:Descending Objects Using Arrays

That is basically it in a nutshell. One thing though: You don't have a piece of code saying if num <= num2 then setObjectValue(i) := false

Hmmm... I might have a program which is similar to this...
Sponsor
Sponsor
Sponsor
sponsor
USEC_OFFICER




PostPosted: Tue Mar 09, 2010 12:48 pm   Post subject: RE:Descending Objects Using Arrays

I assume you mean your snow-falling program.
Turing_Gamer




PostPosted: Tue Mar 09, 2010 12:51 pm   Post subject: RE:Descending Objects Using Arrays

It is not mine. But here is something from my space shooter...
Turing:
var meteorx, meteory, radius : array 1 .. 25 of int
var meteor_speed := 5

for i : 1 .. 25
    radius (i) := Rand.Int (10, 20)
    meteorx (i) := Rand.Int (0 + radius, maxx - radius)
    meteory (i) := Rand.Int (maxy + 100, maxy + 300)
end for
loop
    for i : 1 .. 25
        meteory (i) := meteory (i) - meteor_speed
        if meteory (i) <= -10 - radius then
            radius (i) := Rand.Int (10, 20)
            meteorx (i) := Rand.Int (0 + radius, maxx - radius)
            meteory (i) := Rand.Int (maxy + 100, maxy + 300)
        end if
        Draw.FillOval (meteorx (i), meteory (i), radius, radius, brown)
    end for
end loop
Warsick




PostPosted: Wed Mar 10, 2010 9:16 am   Post subject: Re: Descending Objects Using Arrays

Thanks for the help guys.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: