
-----------------------------------
Shinkei
Wed Apr 27, 2011 1:08 am

Help with Avalanche Game
-----------------------------------
What is it you are trying to achieve?



What is the problem you are having?
I want to make an avalanche game where objects fall down(preferably triangles) and hit the player(in this case it is a cube).
I need help on collision detection as well as objects falling randomly.


Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)








Please specify what version of Turing you are using
4.11

-----------------------------------
Raknarg
Wed Apr 27, 2011 7:38 am

RE:Help with Avalanche Game
-----------------------------------
Well, then you'll need two things:
1. Arrays
2. Input.KeyDown
Ever used either of those?

-----------------------------------
Shinkei
Wed Apr 27, 2011 7:42 am

RE:Help with Avalanche Game
-----------------------------------
I have Input.KeyDown for the character
But I have no clue about the falling objects.

-----------------------------------
Raknarg
Wed Apr 27, 2011 9:01 am

Re: Help with Avalanche Game
-----------------------------------
Well, I'll try to give you a brief overview of them, but I would suggest looking up the Turing Tutorial in the Tutorial section.
So arrays are essentially single variables that can hold more than one piece of information. Imagine it like a box with a bunch of different compartments inside. You call it like this:

var thingy : array 1 .. 5 of int

Those numbers can be set to anything, as well as the identifier. You could have an array of chars, strings, reals, nats, or even procedures if you wanted.
Falling objects are rather simple. I'll give you a code snippet:

setscreen ("offscreenonly")
var objectx, objecty : array 1 .. 5 of int

for i : 1 .. 5 
    objectx (i) := Rand.Int (0, maxx)
    objecty (i) := Rand.Int (0, maxy)
end for

loop
    for i : 1 .. 5
        objecty (i) := objecty (i) - 1
        if objecty (i) < 0 then
            objecty (i) := maxy
            objectx (i) := Rand.Int (0, maxx)
        end if
        Draw.FillOval (objectx (i), objecty (i), 5, 5, 7)
    end for
    View.Update
    delay (5)
    cls
end loop

All you would have to to is have the objects constantly falling, and reset their x and y positions when they hit the ground.
FYI in case you didn't know, to access a certain element within an array, you call the variable name and a number.
ex:

var foo : array 1 .. 3 of int
foo (1) := 3
put foo (1)

So that way you can set variables inside the array. However, you can do this simply using a for loop, too!

var foo : array 1 .. 5 of int
for i : 1 .. 5
     foo (i) := i * i
end for
for j : 1 .. 5
     put foo (i) 
end for

This code would have an output of:
1
4
9
16
25
Anyways, hope that helps.
Again, check the actual tutorial for more info.

-----------------------------------
apython1992
Wed Apr 27, 2011 1:37 pm

RE:Help with Avalanche Game
-----------------------------------
If you understand how to get certain properties about an object (position, length, width, etc), then collision detection will be a piece of cake.

-----------------------------------
Raknarg
Wed Apr 27, 2011 3:36 pm

RE:Help with Avalanche Game
-----------------------------------
He could just use Math.Distance instead. Wish I knew about that earlier. 
Of course, thats only good for certain kinds of collision...

-----------------------------------
apython1992
Wed Apr 27, 2011 3:38 pm

RE:Help with Avalanche Game
-----------------------------------
Ahh. I don't know Turing, but yes, that would be helpful.

-----------------------------------
Raknarg
Wed Apr 27, 2011 3:56 pm

RE:Help with Avalanche Game
-----------------------------------
All I know is turing. C++ is too much work ;P

-----------------------------------
Insectoid
Wed Apr 27, 2011 3:59 pm

RE:Help with Avalanche Game
-----------------------------------
Slightly off-topic, but Raknarg, why not learn C? You need to (read: should) learn it before C++ anyway, and it's fairly similar to Turing mechanics-wise. Not a hard language at all to learn.

-----------------------------------
apython1992
Wed Apr 27, 2011 4:00 pm

RE:Help with Avalanche Game
-----------------------------------
I don't really enjoy C++ a whole lot. I use it only when I need fast code.  And sometimes when I need fast code I still don't use it :P

-----------------------------------
Raknarg
Wed Apr 27, 2011 4:04 pm

Re: Help with Avalanche Game
-----------------------------------
Thats what Turing is for :D


#include 
int.main;
{
     cout 