Posted: Wed Feb 25, 2009 9:03 pm Post subject: Shooting bullets
Im having a terrible problem with getting my shooting to work. So far there is a little box that shoots at me using a rand.int.
When the attack procedure is activatated the bullet is supposed to come out. The bullet moves with coding bullet_x-=25 which does move the bullet but not at a continuos speed. It moves but only in increments when the rand.int statement is true.
Anybody have any ideas on this. i will post code if anyone wants to see it...
Sponsor Sponsor
saltpro15
Posted: Wed Feb 25, 2009 9:06 pm Post subject: RE:Shooting bullets
why use rand.int anyway? and posting the code would be helpful
platky
Posted: Thu Feb 26, 2009 8:30 am Post subject: Re: Shooting bullets
Posted: Thu Feb 26, 2009 12:12 pm Post subject: RE:Shooting bullets
1) Post the source code and the [colour="red"]PICTURES[/colour] in a .zip file and post them as an attachment. I can't compile without them.
2)
code:
random:= Rand.Int(1,5000)
if random <=100 then
enemy_attack
else
enemy_miss
end if
Should be in it's own procedure. call it something like IsAttacking.
3)
code:
random:= Rand.Int(1,5000)
if random <=100 then
enemy_attack
else
enemy_miss
end if
View.Update
delay(18)
cls
The cls Deletes the Bullet from the screen. Use an array to track if bullets are on the screen and a procedure to move them
ie
code:
var bulletList : array 1..10 of boolean
var bulletX : array 1..10 of int
var bulletU : array 1..10 of int
var numBullet : int
procedure enemy_attack
for (int i = numBullet + 1; i <= numBullet + 1; i ++)
bulletX (i) := enemy_x
bulletY (i) := whatever your y position for bullets is
bulletList (i) := true
numBullet += 1
end for
end enemy_attack
procedure moveBullet
for (int i := 1; i <= numBullet; i++)
Draw Bullet (bulletX (i), bulletY (i))
bulletX += velocity of Bullets
end for
end moveBullet
platky
Posted: Thu Feb 26, 2009 2:19 pm Post subject: RE:Shooting bullets
im getting a few errors:
Turing:
for(int i = numBullet + 1; i <= numBullet + 1; i ++)
says there is an expected ":" on int
this happens in both cases where it is written
Posted: Thu Feb 26, 2009 7:04 pm Post subject: RE:Shooting bullets
That's because
code:
for (int i = 1; i <= numBullet + 1; i ++)
is C, C++, Java or one of a bunch of related languages. The turing equivalent is:
code:
for i : 1 .. numBullet + 1
The other one is probably a type mismatch between integer (int) and floating-point (real). You can use the methods round, floor or ceil to convert from a real number to an integer, depending on what you want.
@AJ: Apparently the board only likes the US spelling - "color". Kinda stupid, but then it's probably more effort to change than its worth.
S_Grimm
Posted: Fri Feb 27, 2009 6:48 am Post subject: RE:Shooting bullets
oops my bad. I've been programming in Java for a long time now. Regardless, DemonWasp summed up to solution properly.
@DemonWasp: Its AV not AJ. Thanks tho. I wrote the code in the quick reply box, so i dind bother trying to fix it. my bad.
platky
Posted: Fri Feb 27, 2009 10:03 am Post subject: Re: Shooting bullets
Thanks for the help the previous stuff is fixed but i now get a new error...
The error is with the Draw.FIllOval for the bullet. IT says the variable has no value. I have no idea what variable?
Sponsor Sponsor
S_Grimm
Posted: Fri Feb 27, 2009 11:53 am Post subject: RE:Shooting bullets
Ok, i tried to write code myself, based on how i would write it in Java. So, what you have to do is modify it to Turing.
The error is either the bulletX(i) or bulletY (i)
Edit: Use flexible arrays to keep track of the bullets. then you can use "upper" for the bullets. Once i can use my personal computer, ill post a modified copy of your code using flexible arrays to initalize the bulletList.
platky
Posted: Sat Feb 28, 2009 1:54 pm Post subject: RE:Shooting bullets
i still cant seem to fix this problem. Every time i change sumthing a new problem arises...
I also cant figure out how to get my guy to change the direction he is facing according to what button is pressed
S_Grimm
Posted: Sun Mar 01, 2009 9:02 pm Post subject: RE:Shooting bullets
To change his direction, just flip the image in paint or photoshop and then import it as a second sprite. Then, have a boolean state so when left arrow is pressed it draws left (ie facingLeft = true) or vise versa
platky
Posted: Tue Mar 03, 2009 10:44 am Post subject: Re: Shooting bullets
Instead of making my enemy shoot i decided to work on making my character shoot. The problem is that when i use cls and view.update the screen gets messed up. When i dont the bullet is a continuos beam... any ideas?
Also Take the View.Update and cls out of the for loop
code:
procedure movebullet
if bullet_fired then
drawfilloval (move_x + 25, bullet_y, 10, 10, 41)
bullet_y += 3 %bullet speed
if bullet_y > maxy then
bullet_fired := false
end if
end moveBullet
...........
loop
for
blah blah blah
moveBullet
end for
View.Update
cls
end loop
platky
Posted: Wed Mar 04, 2009 1:37 pm Post subject: Re: Shooting bullets
I just noticed i made a huge mistake and copied someone elses code into it that i was looking at. Here is my actually code:
Turing:
View.Set("graphics:700;350,position:center;center,nobuttonbar,nocursor,title:Tank Man") var x,y :int var rotate:int var velocity:int var gravity:int:=1 var random:int var time1:real
var dude :int var dude_left:int var arm :int var arm2:array0..35ofint var arm_left:int var arm_left2:array0..35ofint var arm_leftsolid:int var tankman_right:boolean:=true
var wep:int:=3
var title:int var level1:int var font1:int
var enter:string(1)
var health:int var enemy_damage:int var damage:int
var bulletList:array1..10ofboolean var bulletX:int var bulletY:int var bulletVeloc:int:=10 var numBullet:int:=1
health:=100
velocity:=0
x:=100
rotate:=0
y:=0
font1:=Font.New("arial black:12") var keys :arraycharofboolean
var enemy_x:int:=maxx-25 var enemy_y:int:=22 %Sprite Testing---- var numframes:int:=Pic.Frames("zerosheet.gif") var pics:array1..numframes ofint var delaytime:int Pic.FileNewFrames("zerosheet.gif",pics,delaytime) var sprite:int
sprite:=Sprite.New(pics(1)) Sprite.SetPosition(sprite,200,10,false)
for rep:0..35
arm2 (rep):=Pic.Rotate(arm,rep*10,Pic.Width(arm)div2 -6,Pic.Height(arm)div2+4) endfor var temparm:= arm2 (0) for rep:0..35
arm_left2 (rep):=Pic.Rotate(arm_left,rep*10,Pic.Width(arm_left)div2+6,Pic.Height(arm_left)div2+4) endfor var temparm_left:=arm_left2(0)
%Enemy Stuff -------------------------------- %-------------------------------------------- proc enemy
Draw.FillBox(maxx-30,30,maxx-5,15,purple) end enemy
proc moveBullet
for i:1..numBullet+1 Draw.FillOval(bulletX, bulletY,3,3,white)
bulletX-= bulletVeloc
endfor end moveBullet
proc enemy_attack
for i:1..numBullet+1
bulletX :=enemy_x
bulletY:= enemy_y
bulletList (i):=true
numBullet +=1
moveBullet
endfor end enemy_attack
proc isattacking
random:=Rand.Int(1,5000) if random <=0then
enemy_attack
endif end isattacking
%------------------------------- %-------------------------------