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

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




PostPosted: Sun Sep 04, 2005 8:48 pm   Post subject: Arrays

im trying to make something where if one ball gets to the other side of the map, then another one is made...

There a probelem GROWING my array...
heres the code so far...

code:

%%UFO GAME%%
setscreen("Graphics:300;150")

%%Variables
var counter: int:= 1
var game: boolean := false
var x, y: int                               %Ball
var speed: int := 0                         %Ball other speed
var vx, vy: int                             %ball direction
var sp,sz: int                              %ball speed/size
var num: int := 1                           %number of obsticles
var x1, y1: array 1 .. 20 of int           %obsticle
var vx1, vy1: array 1 .. 20 of int         %obsticle direction
var sp1,sz1: array 1 .. 20 of int          %obsticle speed/size
var level: int         
var ship: array char of boolean

%%Declare
%ball
x := 20
randint(y,20,80)
sp := 1
sz := 5
vx := sp
vy := sp
%obsicle
for i: 1 .. num
    x1(i) := 280
    randint(y1(i),11,139)
    sp1(i) := 1
    sz1(i) := 10
    vx1(i) := sp1(i)
    vy1(i) := sp1(i)
end for

%%Intro
put "Hi, wecome to a UFO game"
put "Just avoid the obsticles"
put "Good luck"
put "More to come later"
Input.Pause
cls

%%Game%%
loop
    %move ship
    Input.KeyDown(ship)
   
    if ship (KEY_UP_ARROW) then
        y := y + vy
    end if
    if ship (KEY_DOWN_ARROW) then
        y := y - vy
    end if
    if ship (KEY_RIGHT_ARROW) then
        x := x + vx
    end if
    if ship (KEY_LEFT_ARROW) then
        x := x - (vx + 1)
    end if
   
    %boundry
    if x <= 0 then
        x *= -1
    end if
    if x >= 300 then
        x *= -1
    end if
    if y <= 0 then
        y *= -1
    end if
    if y >= 150 then
        y *= -1
    end if
   
    for i: 1 .. num
        x1(i) := x1(i) - vx1(i) - speed

        %%Colistion
        if x+sz >= x1(i)-sz1(i) and x-sz <= x1(i)+sz1(i) and y+sz <= y1(i)+sz1(i) and y+sz >= y1(i)-sz1(i) and y-sz >= y1(i)-sz1(i) and y-sz <= y1(i)+sz1(i) then
            game := true
            exit
        end if
        if x1(i) + sz1(i) <= 0 then
            for ii: 1 .. num
                x1(ii) := 280
                randint(y1(ii),11,139)
                sp1(ii) := 1
                sz1(ii) := 10
                vx1(ii) := sp1(ii)
                vy1(ii) := sp1(ii)
                num += 1
            end for
        end if
        drawfilloval(x1(i),y1(i),sz1(i),sz1(i),red)
 
    end for
   
    if game = true then
        exit
    end if
   
    %draw the items
    drawfilloval(x,y,sz,sz,black)
    delay(5)
    cls
end loop
cls
put "Game over"


I dont know how do modify the spots of the array, moving stuff, etc..

I keep geting errors, Help me please

Thanks
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sun Sep 04, 2005 10:40 pm   Post subject: (No subject)

Try learning Flexible Arrays. They allow you to modify the dimensions of your array.
Delos




PostPosted: Mon Sep 05, 2005 10:59 am   Post subject: (No subject)

Additionally, this tut on Records will help you to expedite your code.
MysticVegeta




PostPosted: Tue Sep 06, 2005 1:31 pm   Post subject: (No subject)

[Gandalf] wrote:
Try learning Flexible Arrays. They allow you to modify the dimensions of your array.


modify the number of elements of the array.
Delos




PostPosted: Tue Sep 06, 2005 9:23 pm   Post subject: (No subject)

MysticVegeta wrote:
[Gandalf] wrote:
Try learning Flexible Arrays. They allow you to modify the dimensions of your array.


modify the number of elements of the array.


I think Gandalf's also correct on this one. Using 'new' you can alter the dimensions of arrays. Sure when you get up to 2-dim+ arrays, you get screwed up a little in that the 2nd dim cannot be different for each level of the first...
I'm not sure I see your argument, unless you specifically mean you cannot change the lower and upper bounds of the array. In that case...bah, technicallity!
Flikerator




PostPosted: Fri Sep 09, 2005 10:40 am   Post subject: (No subject)

I thought you could only change the elements in an array;

var numbers : flexible array 1 .. 50 of int

or is that what you meant? Because I dont remember anything about adding a second dimension;

var D1 : array 1 .. 5 of int
var D2 : array 1 .. 5, 1 .. 3 of int
Delos




PostPosted: Fri Sep 09, 2005 9:01 pm   Post subject: (No subject)

Ah, that 'dimension'. My use of the word here was synonymous to the usage of 'elements' also used.
Confusion gone.
[Gandalf]




PostPosted: Sat Sep 10, 2005 9:32 am   Post subject: (No subject)

Exactly why I stayed out of this conversation - it's all technicality.

He wanted to "grow" his array, flexible arrays do that for you, problem solved.
Sponsor
Sponsor
Sponsor
sponsor
Mr. T




PostPosted: Sun Sep 25, 2005 5:00 pm   Post subject: Alex's Opinion

For ball on ball collision, you're gonna need work with the radii of the balls.
code:

if Math.Distance (  x (j), y (j), x (k), y (k)  ) < radius (j) + radius (k) then
    %Handle Collision
end if

If the distance between the centre's of two balls is less than the sum of their radii, a collision occurs.

(courtesy of Cervantes)
codemage




PostPosted: Mon Sep 26, 2005 11:39 am   Post subject: (No subject)

Look up flexible arrays, as said.
In Turing, you can change the size of the array as you go.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: