Unsure how to make sprites appear in a random location, and then have them fall to the ground. I'm pretty lost.
Author |
Message |
NextGhosst
|
Posted: Mon Nov 17, 2008 10:22 am Post subject: Unsure how to make sprites appear in a random location, and then have them fall to the ground. I'm pretty lost. |
|
|
Hey, I'm doing one of those catch the fruit type games, but I'm not really sure how to get the sprites to fall from "The tree", I realize I have to specify the maximum and minimum x/y values for which the objects can fall, but I really don't know HOW to do it. I've looked in the compiled turing help guide, but found nothing.
Here is a copy of my code right now...
My attempt at the random positioning is at the bottom of the code, and I changed the colour in the area I'm currenting working on, but totally lost at. There is a second window, but none of the information is relevant.
Turing: |
%***********************************
%EPIC! The Game. *
%Date: Tuesday, November 4th, 2008.*
%Controls: Guess. *
%Purpose: None. *
%***********************************
%Declares wicker basket as a sprite.
var pic1 : int := Pic.FileNew ("wicker basket.gif")
var sprite1 : int := Sprite.New (pic1 )
%Declares background, and specifies the image.
var bg : int := Pic.FileNew ("background.bmp")
%Variables for all of the falling objects.
var fallingapple : int := Pic.FileNew ("apple.gif")
var fallingsprite1 : int := Sprite.New (fallingapple )
var fallingbomb : int := Pic.FileNew ("bomb.gif")
var fallingsprite2 : int := Sprite.New (fallingbomb )
var fallinggrapes : int := Pic.FileNew ("grapes.gif")
var fallingsprite3 : int := Sprite.New (fallinggrapes )
var fallingorange : int := Pic.FileNew ("orange.gif")
var fallingsprite4 : int := Sprite.New (fallingorange )
var fallingpoisonbottle : int := Pic.FileNew ("poison bottle.gif")
var fallingsprite5 : int := Sprite.New (fallingpoisonbottle )
%Position of wicker basket sprite.
var x : int := 230
var y : int := 0
%Initial Position of falling apple sprite
var x1 : int := 186
var y1 : int := 57
%Initial Position of falling bomb sprite
var x2 : int := 273
var y2 : int := 76
%Initial Position of falling grapes sprite
var x3 : int := 422
var y3 : int := 123
%Initial position of falling orange sprite
var x4 : int := 535
var y4 : int := 96
%Initial Position of falling poison bottle sprite
var x5 : int := 296
var y5 : int := 126
var centered : boolean := false
var centeredsprite : boolean := true
%Do I need the lines below, if I want to make the objects fall independently??
var chars, charsfallingapple, charsfallingbomb, charsfallinggrapes, charsfallingpoisonbottle : array char of boolean
setscreen ("graphics:720;417") %Sets screen aspect ratio to 720x417px
View.Set ("offscreenonly")
View.Set ("nocursor")
%MUSIC!!! =D
fork BackgroundMusic
for a : 1 .. maxx by 5
drawline (a, 0, a, maxy, black)
end for
Sprite.SetHeight (sprite1, 6)
loop
Pic.Draw (bg, 0, 0, picCopy)
Input.KeyDown (chars )
if chars (KEY_LEFT_ARROW) then
x - = 3
end if
if chars (KEY_RIGHT_ARROW) then
x + = 3
end if
if x < 0 then
x := 0
end if
if x > 600 then
x := 600
end if
Sprite.SetPosition (sprite1, x, y, centered )
Sprite.Show (sprite1 )
View.Update
end loop
[color=darkorchid ]%Random number generator to determine which object will fall.
var randomizer, randomizer2 : int
loop
randomizer2 := Rand.Int (1, 5)
delay (1590)
if randomizer2 = 1 then
delay (550)
Sprite.SetPosition (fallingsprite1, x1, y1, centeredsprite )
Sprite.SetHeight (fallingsprite1, 1)
Sprite.Show (fallingsprite1 )
elsif randomizer2 = 2 then
delay (1500)
Sprite.SetPosition (fallingsprite2, x2, y2, centeredsprite )
Sprite.SetHeight (fallingsprite2, 2)
Sprite.Show(fallingsprite2 )
elsif randomizer2 = 3 then
delay (980)
Sprite.SetPosition (fallingsprite3, x3, y3, centeredsprite )
Sprite.SetHeight (fallingsprite3, 3)
Sprite.Show(fallingsprite3 )
elsif randomizer2 = 4 then
delay (320)
Sprite.SetPosition (fallingsprite4, x4, y4, centeredsprite )
Sprite.SetHeight (fallingsprite4, 4)
Sprite.Show(fallingsprite4 )
elsif randomizer2 = 5 then
delay (1000)
Sprite.SetPosition (fallingsprite5, x5, y5, centeredsprite )
Sprite.SetHeight (fallingsprite5, 5)
Sprite.Show(fallingsprite5 )
end if
end loop[/ color]
|
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
S_Grimm
![](http://compsci.ca/v3/uploads/user_avatars/18926424384e6d86e5cf4d6.jpg)
|
Posted: Mon Nov 17, 2008 11:22 am Post subject: RE:Unsure how to make sprites appear in a random location, and then have them fall to the ground. I\'m pretty lost. |
|
|
you need to have the Y location variables change (ie ypos := ypos -1) to make them fall. |
|
|
|
|
![](images/spacer.gif) |
NextGhosst
|
Posted: Mon Nov 17, 2008 5:36 pm Post subject: RE:Unsure how to make sprites appear in a random location, and then have them fall to the ground. I\'m pretty lost. |
|
|
Thanks, do you know if I'd have to put that..INSIDE the loop at the bottom, below where I labeled random number generator? I mean for each individual sprite would I have to say that [ypos := ypos -1] or whatever I want to say.
I don't get WHY the sprites don't appear though...I have sprite show and I set the coordinates for the sprite to appear at I think... |
|
|
|
|
![](images/spacer.gif) |
|
|