What Went Wrong?
Author |
Message |
TheLastFall
|
Posted: Tue Oct 09, 2007 11:02 am Post subject: What Went Wrong? |
|
|
Okay, I made this really horrible shooting process. For some reason the bullets don't go one by one but all at the same time, causing it to look messed up. I just want it to shoot one bullet at a time. But something went horribly wrong. Is there any possible way to fix it? I also just started Process and fork so don't knock me on how horrible they are.
Here is the code.
code: |
setscreen ("graphics: max,max;")
var chars : array char of boolean
var rad, xpo, ypo, xbu, ybu, r, bulclr, bulnum : int
rad := 5
xpo := maxx div 2
ypo := maxy div 2
bulnum := 0
r := 1
const DLY : int := 5
process Move
if chars ('w') then
ypo := ypo + 1
r := 1
elsif chars ('s') then
ypo := ypo - 1
r := 2
elsif chars ('a') then
xpo := xpo - 1
r := 3
elsif chars ('d') then
xpo := xpo + 1
r := 4
end if
end Move
process Bullets
if chars (' ') then
bulnum -= 1
end if
end Bullets
process Reload
if chars (KEY_SHIFT) then
bulnum := 5
end if
end Reload
process Shoot
xbu := xpo
ybu := ypo
if bulnum < 0 then
if chars (' ') and r = 1 then
for bulsho : 1 .. maxy
delay (DLY)
ybu += 1
drawfilloval (xbu, ybu, 1, 1, bulclr)
end for
end if
if chars (' ') and r = 2 then
for bulsho : 1 .. maxy
delay (DLY)
ybu -= 1
drawfilloval (xbu, ybu, 1, 1, bulclr)
end for
end if
if chars (' ') and r = 3 then
for bulsho : 1 .. maxx
delay (DLY)
xbu -= 1
drawfilloval (xbu, ybu, 1, 1, bulclr)
end for
end if
if chars (' ') and r = 4 then
for bulsho : 1 .. maxx
delay (DLY)
xbu += 1
drawfilloval (xbu, ybu, 1, 1, bulclr)
end for
end if
end if
end Shoot
loop
Input.KeyDown (chars)
setscreen ("offscreenonly")
View.Update
delay (DLY)
cls
drawfilloval (xpo, ypo, rad, rad, black)
bulclr := Rand.Int (99, 103)
fork Bullets
forkReload
fork Shoot
fork Move
end loop
|
Edited by Clayton: Try [code] tags next time, not italics tags.
Where did I go wrong? Is it even possible to fix this code?
Sorry code, you will be missed. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Euphoracle
|
Posted: Tue Oct 09, 2007 2:27 pm Post subject: RE:What Went Wrong? |
|
|
You really shouldn't be using processes like that. You can accomplish all that correctly in just a loop. Processes in this situation like to cause instability and weird results if they conflict/are poorly coded. |
|
|
|
|
|
TheLastFall
|
Posted: Thu Oct 11, 2007 10:05 am Post subject: Re: What Went Wrong? |
|
|
Well I simplifyied my code... to some extent. Now I still have the same problem but with a little more added to it. After you view the code you'll understand what I mean.
code: |
setscreen ("graphics:max,max;")
var chars : array char of boolean
var rad, xpo, ypo, xbu, ybu, r, bulclr, bulnum : int
rad := 5
xpo := maxx div 2
ypo := maxy div 2
bulnum := 0
r := 1
const DLY : int := 5
procedure Move
if chars ('w') then
ypo := ypo + 1
r := 1
xbu := xpo
ybu := ypo + 10
elsif chars ('s') then
ypo := ypo - 1
r := 2
xbu := xpo
ybu := ypo - 10
elsif chars ('a') then
xpo := xpo - 1
r := 3
xbu := xpo - 10
ybu := ypo
elsif chars ('d') then
xpo := xpo + 1
r := 4
xbu := xpo
ybu := ypo + 10
end if
end Move
process Shoot
if bulnum < 5 then
if chars (' ') and r = 1 then
for bulsho : 1 .. maxy
delay (DLY)
ybu += 1
drawline (xbu, ybu, xbu, ybu + 5, bulclr)
if xbu = maxx or xbu = 0 or ybu = maxy or ybu = 0 then
xbu := xpo
ybu := ypo
end if
end for
end if
if chars (' ') and r = 2 then
for bulsho : 1 .. maxy
delay (DLY)
ybu -= 1
drawline (xbu, ybu, xbu, ybu - 5, bulclr)
if xbu = maxx or xbu = 0 or ybu = maxy or ybu = 0 then
xbu := xpo
ybu := ypo
end if
end for
end if
if chars (' ') and r = 3 then
for bulsho : 1 .. maxx
delay (DLY)
xbu -= 1
drawline (xbu, ybu, xbu - 5, ybu, bulclr)
if xbu = maxx or xbu = 0 or ybu = maxy or ybu = 0 then
xbu := xpo
ybu := ypo
end if
end for
end if
if chars (' ') and r = 4 then
for bulsho : 1 .. maxx
delay (DLY)
xbu += 1
drawline (xbu, ybu, xbu + 5, ybu, bulclr)
if xbu = maxx or xbu = 0 or ybu = maxy or ybu = 0 then
xbu := xpo
ybu := ypo
end if
end for
end if
end if
end Shoot
procedure Gun
if r = 1 then
drawline (xpo, ypo, xpo, ypo + 10, black)
end if
if r = 2 then
drawline (xpo, ypo, xpo, ypo - 10, black)
end if
if r = 3 then
drawline (xpo, ypo, xpo - 10, ypo, black)
end if
if r = 4 then
drawline (xpo, ypo, xpo + 10, ypo, black)
end if
end Gun
loop
Input.KeyDown (chars)
setscreen ("offscreenonly")
View.Update
delay (DLY)
cls
drawfilloval (xpo, ypo, rad, rad, black)
bulclr := Rand.Int (255, 255)
Move
fork Shoot
Gun
if chars (' ') then
bulnum += 1
end if
if chars (KEY_SHIFT) then
bulnum := 0
end if
end loop
|
Simple controls; WASD to move, space to shoot, and shift to reload although I haven't gotten to that yet.
I'm confused to where the error is, but it's suppose to me just one little circle when space is pressed.
Possibly any way to just cause one bullet to come out when space is pressed. At least slow down the shots.
I just had to change a bit of the code. But I still have a problem with where the bullets appear and the shooting. |
|
|
|
|
|
|
|