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

Username:   Password: 
 RegisterRegister   
 need help with pic.rotate
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
CodeMonkey2000




PostPosted: Thu Nov 02, 2006 7:05 pm   Post subject: need help with pic.rotate

im making a game with a spider-bot-tank-thingy, and i need help with rotating the turret. i'm using pic.rotate, but when i rotate it, the whole turret doesnt show up. this isnt the full source, but just the part im having trouble with.

code:

setscreen ("offscreenonly")
var turret1, turret : int

drawfillbox (2, 4, 6, 18, 15)
drawfilloval (4, 4, 4, 4, 15)

turret := Pic.New (0, 0, 8, 18)
Pic.Draw (turret, 96, 95, picCopy)
loop
    for x : 1 .. 360
        turret1 := Pic.Rotate (turret, x, 4, 4)
        cls
        Pic.Draw (turret1, 150, 150, picCopy)
        View.Update
    end for
end loop

Sponsor
Sponsor
Sponsor
sponsor
bruized




PostPosted: Thu Nov 02, 2006 7:20 pm   Post subject: (No subject)

I think that all you need to do is create a large margin on the bottom and left side so that when it does rotate the picture it doesn't cut off your actual turret.
CodeMonkey2000




PostPosted: Thu Nov 02, 2006 7:36 pm   Post subject: (No subject)

how would you do that? Pic.Rotate (picID, angle, x, y : int) : int
x and y are where it should rotate, and angle is well, the angle.
bruized




PostPosted: Thu Nov 02, 2006 7:41 pm   Post subject: (No subject)

Your turret is imported from a picture right? All you have to do is edit the picture in Adobe Photoshop or something and add some space on the bottom and on the left.
CodeMonkey2000




PostPosted: Thu Nov 02, 2006 7:46 pm   Post subject: (No subject)

the picture is not imported, at the begining it is drawn through turing's modules, and then it takes a "screenshot" and uses that as a reference later.
bruized




PostPosted: Thu Nov 02, 2006 7:48 pm   Post subject: (No subject)

Sorry, I'm not thinking clearly and not really paying attention. If I could I'd delete the post before, but i can't. If you were importing the picture then it would work but you're not... Confused how could I be so stupid (*shakes head*)
richcash




PostPosted: Thu Nov 02, 2006 8:15 pm   Post subject: (No subject)

If you're picture is not imported, then why don't you rotate everything you draw in your turret using sine and cosine?
bruized




PostPosted: Thu Nov 02, 2006 8:25 pm   Post subject: (No subject)

Either that, or you could simply draw the picture farther away from the bottom left and when you Pic.New simply leave more space on the bottom left hand corner. That way there is adequate space to allow for the clipping not to be seen (it only clips part of the background of the picture not the actual turret.

Like so...

code:
setscreen ("offscreenonly")
var turret1, turret : int

drawfillbox (38, 40, 42, 54, 15)
drawfilloval (40, 40, 4, 4, 15)

turret := Pic.New (0, 0, 60, 60)
Pic.Draw (turret, 96, 95, picCopy)
loop
    for x : 1 .. 360
        turret1 := Pic.Rotate (turret, x, 40, 40)
        cls
        Pic.Draw (turret1, 150, 150, picCopy)
        View.Update
    end for
end loop


That was done quick so it may not be what you want it, but the main idea is I drew the picture farther away from the bottom left which left more room, yada yada yada. You get the point Wink
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Thu Nov 02, 2006 10:34 pm   Post subject: (No subject)

wow, thnx
Dan




PostPosted: Thu Nov 02, 2006 11:18 pm   Post subject: (No subject)

Ack, each time that loop is run it is making a new pic and never freeing it. Affter some time it will use up all the space turing alows for pics and will crash. You need to add a Pic.Free at the end of the forlop.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
DemonZ




PostPosted: Fri Nov 03, 2006 2:09 am   Post subject: (No subject)

no no thats not it, if u want the pic to not cut off while rotating, the when you do Pic.Rotate (pic, angle, x, y) set the parameters of x and y as -1, this will rotate the picture in the specified margin without cutting it off, and if u want it to rotate according to the center, than just draw ur pic but when u do the x and y subtract the x and y values form the Pic.Height and Pic.Width of ur pic, here is some sample source-pseudo code for u to experiment and understand with:
code:
PSEUDO:
% rotates tank turret
for i: 1 .. 35
Tankturret (i) := Pic.Rotate (P1_Tank (0), i * 10, -1, -1)
end for
% draws tank turret
    Pic.Draw (Tankturret (Tank_angle), round (x) - Pic.Width (Tankturret (Tank_angle)) div 2, round (y) - Pic.Height (Tankturret (Tank_angle)) div 2, picMerge)
% Draws ur tank

This way your x and y are centered in the middle and ur boundaries are set to -1 so that all of the picture is rotated within the margins
If u dont understand what I mean just ask.
bruized




PostPosted: Fri Nov 03, 2006 3:53 pm   Post subject: (No subject)

I definitely don't understand what you mean. I just don't really get it. It doesn't click.

I also don't understand what Hacker Dan said. Was he talking about my code? When you pic.rotate it actually creates a totally new picture? or what...

I'm kinda new and so I don't know a lot about Turing.
CodeMonkey2000




PostPosted: Fri Nov 03, 2006 7:01 pm   Post subject: (No subject)

i get what hackerdan was saying. if you let the privious program run, it will eventually slwo dwon ur comp, then crash.
code:

setscreen ("offscreenonly")
var turret1, turret, angle : int := 1
var rotate : boolean := false

drawfillbox (38, 40, 42, 54, 15)
drawfilloval (40, 40, 4, 4, 15)

turret := Pic.New (0, 0, 60, 60)
Pic.Draw (turret, 96, 95, picCopy)

loop
    angle += 1
    if angle = 360 then
        angle := 1
    end if
    cls
    turret1 := Pic.Rotate (turret, angle, 40, 40)
    Pic.Draw (turret1, 150, 150, picCopy)
    Pic.Free (turret1)
    rotate := false
    locate (1, 1)

    View.Update
end loop


not sure what demonZ mnet....
DemonZ




PostPosted: Sat Nov 04, 2006 2:33 pm   Post subject: (No subject)

ok first lets start with the basics: if u want to have a game where the player is going to rotate then you will need to familiarize yourself with these commands:
COMMANDS
Pic.Rotate
arrays
round
sind
cosd
Pic.Height
Pic.Width
for loops
These are just some of the most important commands youll need to know, first lets start with declaring some variables
code:

var controls : array char of boolean % This is for input.keydown
var x, y, dx, dy : real % These must be real in order for the rotate to fully work
var tankangle : int
var picture : array 0 .. 35 % The picture that you are using to make ur tank rotate must be an array so that it can store all the rotated pictures from 0 to 360 degrees

Now lets assign the values to these variables
code:

x := % put where ever you want ur tank to start out at
y := % put where ever you want ur tank to start out at
dx := 0
dy := 0
picture (0) := Pic.FileNew ("Name of picture") % The subscript beside picture is 0 to let u know that 0 degree is the original degree of the pic

Now we will use a for loop to actually generate the rotated versions of the pic
for i : 1 .. 35
picture (i) := Pic.Rotate (picture (0), i * 10, -1, -1)
end for

Now here are the controls for the tank to rotate
code:

loop
Input.KeyDown (controls)
if controls (KEY_UP_ARROW) then
x := x - dx
y:= y + dy
dx := sind (tankangle * 10) % this will rotate the tank by 1 degree times 10 ex 1 := 10 degrees 24 := 240 degrees
dy := cosd (tankangle * 10) % the same thing here
elsif controls (KEY_DOWN_ARROW) then
x := x + dx
y := y - dy
dx := sind (tankangle * 10)
dy := cosd (tankangle * 10)
elsif controls (KEY_LEFT_ARROW) then
tankangle := (tankangle + 1) mod 35 % This will make sure that when the picture is fully rotated, it will reset back to zero according to the mod
elsif controls (KEY_RIGHT_ARROW) then
tankangle := (tankangle - 1) mod 35
end if
Pic.Draw (picture (tankangle), x + (Pic.Width (picture (tankangle) div 2), y + (Pic.Height (picture (tankangle) div 2), picMerge) % actually draw the pic after the if statement

Now We Will put all of this together and we will get the picture to rotate
DemonZ




PostPosted: Sat Nov 04, 2006 2:47 pm   Post subject: (No subject)

and if u didnt understand that, then here is an example of Pic.Rotate used in action with a box drawn in turing
code:

var controls : array char of boolean
var x, y, dx, dy : real
var picture : array 0 .. 35 of int
var angle : int

drawfillbox (0, 0, 50, 100, blue)
picture (0) := Pic.New (0, 0, 50, 100)
cls

x := 100
y := 100
dx := 0
dy := 0
angle := 0

for i : 1 .. 35
    picture (i) := Pic.Rotate (picture (0), i * 10, -1, -1)
end for

setscreen ("graphics:max,max,offscreenonly")

loop
    Input.KeyDown (controls)
    if controls (KEY_UP_ARROW) then
        x := x - dx
        y := y + dy
        dx := sind (angle * 10)
        dy := cosd (angle * 10)
    elsif controls (KEY_DOWN_ARROW) then
        x := x + dx
        y := y - dy
        dx := sind (angle * 10)
        dy := cosd (angle * 10)
    elsif controls (KEY_LEFT_ARROW) then
        angle := (angle + 1) mod 35
    elsif controls (KEY_RIGHT_ARROW) then
        angle := (angle - 1) mod 35
    end if
    Pic.Draw (picture (angle), round (x) - Pic.Width (picture (angle)) div 2, round (y) - Pic.Height (picture (angle)) div 2, picMerge)
    delay (20)
    View.Update
    cls
end loop

sorry the last post had a couple mistakes in it that i forgot to correct this is how u do it
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 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: