Posted: Sun May 16, 2010 9:43 am Post subject: Shooting Help
What is it you are trying to achieve?
I am trying to get my character to shoot things from its mouth or hands either or.
What is the problem you are having?
no clue where to start
Describe what you have tried to solve this problem
everything i can think of
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
none atm
Turing:
<Add your code here>
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
Monduman11
Posted: Sun May 16, 2010 9:44 am Post subject: Re: Shooting Help
i know it has something to do with the x and y positions of the character and that i have to use an animation but other than that im stuck.
this is what i have so far
loop
Input.KeyDown (chars)
if chars ('s')then
drawfillbox(posx,posy,60,500,9)
end if
View.Update
end loop
BigBear
Posted: Sun May 16, 2010 10:00 am Post subject: RE:Shooting Help
to make an object such as a bullet move you have to draw it with variables for the x and y positions.
Then you need to change the variables in the way you want the bullet to move.
Monduman11
Posted: Sun May 16, 2010 10:01 am Post subject: Re: Shooting Help
ive tried that and i must be doing it wrong because all it does is make the box bigger or smaller.
do i have to use an animation though? or can you just do it from the actual script?
BigBear
Posted: Sun May 16, 2010 10:16 am Post subject: RE:Shooting Help
Post your code make sure your parameters for your drawfillbox call are correct
drawfillbox (xStart, yStart, xEnd, yEnd, black)
otherwise if you have xEnd at the same spot it will draw back to that spot and make your box grow
Monduman11
Posted: Sun May 16, 2010 10:56 am Post subject: Re: Shooting Help
so this is what i was trying to do
Input.KeyDown (chars)
if chars ('s')then
drawfilloval(posx+ 30,posy+ 30, 7, 7 ,9)
end if
View.Update
delay(20)
but all it does it draw it in the same spot
andrew.
Posted: Sun May 16, 2010 11:05 am Post subject: RE:Shooting Help
That's because you never change the value of posx and posy. When you check for the input, modify the varibles, then draw the box again.
Monduman11
Posted: Sun May 16, 2010 11:10 am Post subject: Re: Shooting Help
so u mean like this? but how do i get it to move constantly? cause it only moves when i keep the "s" pressed
Sponsor Sponsor
BigBear
Posted: Sun May 16, 2010 11:10 am Post subject: RE:Shooting Help
It draws it at whatever posx is +30 so if xpos is 50 it draws it at 80
you need to change the value of posx in a loop to make it move
Turing:
var xPos :int:=20 var yPos :int:=20 loop
xPos +=5 drawfilloval(xPos, yPos, 7, 7, 9) delay(100) cls endloop
Monduman11
Posted: Sun May 16, 2010 11:25 am Post subject: Re: RE:Shooting Help
BigBear @ Sun May 16, 2010 11:10 am wrote:
It draws it at whatever posx is +30 so if xpos is 50 it draws it at 80
you need to change the value of posx in a loop to make it move
Turing:
var xPos :int:=20 var yPos :int:=20 loop
xPos +=5 drawfilloval(xPos, yPos, 7, 7, 9) delay(100) cls endloop
i tried implementing ur code but all it does it freeze my game. i know the code is correct but it doesnt seem to want to run in my game.
This is what im trying to put in
Turing:
var chars :arraycharofboolean Input.KeyDown(chars) var xPos :int:=20 var yPos :int:=20
Posted: Sun May 16, 2010 12:46 pm Post subject: Re: Shooting Help
The problem with that, is it hits the if statement before you can press enter, and then hits the end of the program. When you check for input, it should be inside the loop so that the user can press enter any time they feel like and fire the bullet. But we only want the bullet to START when we press enter, and after that continue going. We can do this by using a boolean variable (true or false). Create a boolean variable up top with your other variables, and set it to false by default. When we press enter set it to true and set its location to the same (or offset by some amount) position as the player. Add an if statement so when it is true the bullet moves (the xPos += 5 part).
BigBear
Posted: Sun May 16, 2010 12:53 pm Post subject: RE:Shooting Help
You have to press Enter in order to enter the loop that moves the bullet.
try putting another loop around the whole thing
and putting Input.KeyDown (chars) inside of that loop.
Course you will not exit that inside loop
and then even if you do your xPos will not restart back at 20
TerranceN
Posted: Sun May 16, 2010 2:30 pm Post subject: Re: RE:Shooting Help
BigBear @ Sun May 16, 2010 12:53 pm wrote:
try putting another loop around the whole thing
and putting Input.KeyDown (chars) inside of that loop.
Besides the reasons you mentioned, this solution is not very scalable. Consider that you may also want to be able to move the player whether the bullet has been fired or not. You would have to put player movement code both in the if statement and outside so it would work at both times. Now imagine all the other things you would be doing in a typical game. This would quickly turn into confusing code with multiple instances of most of the code, making it much harder to modify anything. Functions could help with the multiple instances of code, but it can still be confusing to work with.
I'm not trying to shoot down your idea, but I have seen people attempt coding like this before, and it gets pretty messy.
Monduman11
Posted: Sun May 16, 2010 3:46 pm Post subject: Re: Shooting Help
so like this?
Turing:
var ball :boolean
ball :=false var chars :arraycharofboolean