Need to fix a position of the ball
Author |
Message |
V1RU5
|
Posted: Tue Jun 15, 2010 7:54 pm Post subject: Need to fix a position of the ball |
|
|
What is it you are trying to achieve?
I need to make the ball to a set position at the beginning of my game so basically I have two teams, the ball should be in the hands of one of the teams, but I am not able to do this.
What is the problem you are having?
I am not able to set the position of the ball at the beginning of the game.
Describe what you have tried to solve this problem
I set the x, y of the ball to a certain position, but it always moves when I press run. Add me on msn or post here if you can help: hasankanjee@gmail.com. BTW, this is due tomorrow so it would be great if someone could help me right now.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
import GUI
RGB.SetColor (255, 136 / 255, 197 / 255, 64 / 255)
View.Set ("graphics:1010;615, nocursor, offscreenonly, nobuttonbar")
var counter : int := 0
var timeWhenButtonPressed : int := 0
var timeNow : int := 0
var enemyHealth : int := 100
var yourHealth : int := 100
var xPos : int
var yPos : int
var button : int
var x : int := 400
var y : int := 500
var gravity : int
var xColr, yColr, buttonColr : int
var colr : int
var horizSpeed : int := 2
var vertSpeed : int := 2
const CIRCLE_RADIUS : int := 20
const TITLE_FONT := Font.New ("Harrington:45")
const HEALTH_FONT := Font.New ("Courier New:25")
var introScreen := Pic.FileNew ("Title.bmp")
var background := Pic.FileNew ("level1.bmp")
var teammate1 := Pic.FileNew ("teammate1.bmp")
var teammate2 := Pic.FileNew ("teammate2.bmp")
var teammate3 := Pic.FileNew ("teammate3.bmp")
var enemy2 := Pic.FileNew ("enemy2.bmp")
var enemy3 := Pic.FileNew ("enemy3.bmp")
var tennisBall := Pic.FileNew ("tennis ball.bmp")
var fall : array 0 .. 5 of int
fall (0) := Pic.FileNew ("enemy1.bmp")
fall (1) := Pic.FileNew ("fall.bmp")
fall (2) := Pic.FileNew ("fall2.bmp")
fall (3) := Pic.FileNew ("fall3.bmp")
fall (4) := Pic.FileNew ("fall4.bmp")
fall (5) := Pic.FileNew ("fall5.bmp")
proc StartGame
loop
var sprite : int := Sprite.New (fall (0))
Sprite.SetPosition (sprite, 800, 280, false)
Sprite.Show (sprite )
delay (15)
Pic.Draw (background, 0, 0, picCopy)
Pic.Draw (teammate1, 50, 280, picMerge)
Pic.Draw (teammate2, 100, 285, picMerge)
Pic.Draw (teammate3, 75, 280, picMerge)
Pic.Draw (enemy2, 850, 270, picMerge)
Pic.Draw (enemy3, 825, 300, picMerge)
% update ball position here
Mouse.Where (xPos, yPos, button )
if button = 1 and xPos > 0 and xPos < maxx and yPos > 0 and yPos < maxy then
horizSpeed := ((xPos - x ) div 18)
vertSpeed := ((yPos - y ) div 11)
timeWhenButtonPressed := Time.Elapsed
end if
%If the ball bounces off of the screen, push it back to the edge
if x < CIRCLE_RADIUS and sign (horizSpeed ) = - 1 then
x := CIRCLE_RADIUS
horizSpeed := 0
elsif x > maxx - CIRCLE_RADIUS and sign (horizSpeed ) = 1 then
x := maxx - CIRCLE_RADIUS - 5
horizSpeed := 0
elsif y < CIRCLE_RADIUS and sign (vertSpeed ) = - 1 then
y := CIRCLE_RADIUS
vertSpeed := 0
elsif y > maxy - CIRCLE_RADIUS and sign (vertSpeed ) = 1 then
y := maxy - CIRCLE_RADIUS
vertSpeed := 0
end if
if whatdotcolour (x + horizSpeed, y + vertSpeed ) = 255 then
vertSpeed := -vertSpeed
end if
if whatdotcolour (x, y ) = 64 or whatdotcolour (x, y ) = 63 then
for i : 0 .. 5
Sprite.ChangePic (sprite, fall (i ))
View.Update
delay (80)
end for
end if
timeNow := Time.Elapsed
timeNow - = timeWhenButtonPressed
put timeNow
if timeNow > 15000 then
x := 10000
end if
Draw.Text ("Health: " + intstr (enemyHealth ) + "", 25, 25, HEALTH_FONT, green)
%Decreases the vertical speed (gravity)
if whatdotcolour (x, y ) not= 255 then
vertSpeed := vertSpeed - 3
end if
if whatdotcolour (x, y ) = 39 or whatdotcolour (x, y ) = 63 or whatdotcolour (x, y ) = 64 then
enemyHealth - = 10
horizSpeed := -horizSpeed
vertSpeed := -vertSpeed
elsif whatdotcolour (x, y ) = 14 or whatdotcolour (x, y ) = 27 or whatdotcolour (x, y ) = 128 then
yourHealth - = 10
horizSpeed := -horizSpeed
vertSpeed := -vertSpeed
end if
%If the ball is on the ground, then stop it from moving horizontally
if y = CIRCLE_RADIUS then
horizSpeed := 0
end if
%If the ball has not hit a left or right wall,
%it will continue moving in the horizontal direction
%it was moving before
x := x + horizSpeed
y := y + vertSpeed
% draw ball here
Pic.Draw (tennisBall, x, y, picMerge)
var xColour, yColour, button4 : int
var colr_ : int
%Show the dot colour of the current mouse position
% loop
% Mouse.Where (xColour, yColour, button4)
% colr_ := whatdotcolour (xColour, yColour)
% var info : string := "(" + intstr(xColour)+ "," + intstr(yColour)+ ") Dot Colour: " + intstr (colr_)
% Draw.FillBox (0, maxy - 20, 200, maxy, gray)
% Draw.Text (info, 0, maxy - 15, defFontID, blue)
% delay(10)
% View.Update ()
% end loop
%End of Program
% update screen, then clear it for the next frame
View.Update ()
Draw.Cls ()
Sprite.Hide (sprite )
end loop
end StartGame
proc Credits
cls
Draw.Text ("By: Hasan Kanjee", maxx div 2 - 200, maxy div 2, TITLE_FONT, blue)
View.Update
Draw.Text ("By: Adnan Rashid", maxx div 2 - 200, maxy div 2 - 100, TITLE_FONT, blue)
View.Update
end Credits
var button3 : int := GUI.CreateButton (450, maxy div 2 + 100, 0, "Credits", Credits )
View.Update
var button2 : int := GUI.CreateButton (450, maxy div 2, 0, "Start Game", StartGame )
View.Update
Pic.ScreenLoad ("Title.bmp", 0, 0, picUnderMerge)
View.Update
loop
exit when GUI.ProcessEvent
end loop
% End of Program
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
V1RU5
|
Posted: Tue Jun 15, 2010 9:57 pm Post subject: RE:Need to fix a position of the ball |
|
|
OMGGG plzz someone help I need to hand this is tomorrow I will pay who ever helps me $10!! PLZZ I NEED HELP!! |
|
|
|
|
|
Cezna
|
Posted: Wed Jun 16, 2010 2:23 pm Post subject: RE:Need to fix a position of the ball |
|
|
And how exactly do you propose you would transfer the $10?
No one here is going to do your work for you, nor should they. |
|
|
|
|
|
TheGuardian001
|
Posted: Wed Jun 16, 2010 2:49 pm Post subject: Re: Need to fix a position of the ball |
|
|
On top of which, we can't actually run your code to see what's wrong without the images you used. |
|
|
|
|
|
V1RU5
|
Posted: Wed Jun 16, 2010 2:50 pm Post subject: RE:Need to fix a position of the ball |
|
|
Ok nvm, Im done! |
|
|
|
|
|
|
|