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

Username:   Password: 
 RegisterRegister   
 Control Problems via Input.KeyDown ()
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
Flashkicks




PostPosted: Fri May 13, 2005 12:00 pm   Post subject: Control Problems via Input.KeyDown ()

Hay hay ppl'z! This is Flashkicks here! I am just trying to make simple asteroids game and its been awhile. I was just seeing if anyone can remember or tell me how to have two things going at one withOUT using a process. Example, have my spaceship move, while shooting lasers at the same time. Here's the code.
code:
%%%%%%%%%%%%%%%%
%              %
%%%  JoyPad  %%%
%              %
%%%%%%%%%%%%%%%%
% Billy Boldt  %
%%%% % % % %%%%%


%% Button : ground (y) := orange
setscreen ("graphics:max;max")
View.Set ("offscreenonly")

drawfillbox (0, 0, maxx, maxy, 7)
var shipX, shipY, laserX, laserY : int
shipX := 10
shipY := maxy div 2
laserX := shipX
laserY := shipY
proc eraseShip
    drawfillbox (shipX - 10, shipY, shipX + 50, shipY + 25, 7)
end eraseShip

proc DrawShip
    drawfilloval (shipX + 25, shipY + 15, 25, 10, 28)
    drawfillbox (shipX - 10, shipY, shipX + 25, shipY + 10, 28)
    drawfilloval (shipX + 35, shipY + 20, 7, 3, 1)
    drawfillbox (shipX + 27, shipY + 2, shipX + 50, shipY + 4, 23)
    drawfillbox (shipX + 25, shipY, shipX + 27, shipY + 5, 23)
end DrawShip

proc eraseLaser
    drawfillbox (laserX + 51, laserY + 2, laserX + 75, laserY + 4, 7)
end eraseLaser

proc DrawLaser
    drawfillbox (laserX + 51, laserY + 2, laserX + 75, laserY + 4, 1)
end DrawLaser

proc Controls
    var input : array char of boolean
    var speed : int := 3
    loop
        Input.KeyDown (input)
        if input (KEY_UP_ARROW) then
            eraseShip
            shipY := shipY + speed
            DrawShip
            View.Update
        end if
        if input (KEY_DOWN_ARROW) then
            eraseShip
            shipY := shipY - speed
            DrawShip
            View.Update
        end if
        if input (KEY_LEFT_ARROW) then
            eraseShip
            shipX := shipX - speed
            DrawShip
            View.Update
        end if
        if input (KEY_RIGHT_ARROW) then
            eraseShip
            shipX := shipX + speed
            DrawShip
            View.Update
        end if
        if input (KEY_TAB) then
            laserX := shipX
            laserY := shipY
            loop
                eraseLaser
                laserX := laserX + 10
                DrawLaser
                View.Update
                exit when laserX >= maxx
            end loop
        end if
        if shipX <= 0 then
            shipX := 0
        end if
        if shipX >= maxx - 50 then
            shipX := maxx - 50
        end if
        if shipY <= 0 - 25 then
            shipY := maxy
        end if
        if shipY >= maxy + 25 then
            shipY := 0
        end if
    end loop
end Controls

DrawShip
Controls

So run it and you will see once you shoot- you can not move. And I've made a game like this before so i KNOW its possible. Good Luck-and have fun!
~Flashkicks
Sponsor
Sponsor
Sponsor
sponsor
Dylan-182




PostPosted: Fri May 13, 2005 12:07 pm   Post subject: (No subject)

Surprised i tried it and its coolness i have no idea how 2 help u with it Rolling Eyes but so far its cool Razz i think im guna look at the code n figure out how 2 do this for myself Very Happy then maybe go on 2 make a cool game of my own... Thinking lol ne ways sry i culdnt help but at least i got 2 see that this sorta thing is possible with turing, gives me sumthin 2 aim for Very Happy
Delos




PostPosted: Fri May 13, 2005 12:12 pm   Post subject: (No subject)

My general comment on this (after having looked through your code), is to set up your 'main' loop to be the one that controls all movement/firing etc. Break down these actions into procedures, somewhat like the way you have it.
This way, if one of the arrow keys are pressed, the corresponding movement is called via a procedure/function.
When the key to fire is pressed, the object be be fired is created, and then in subsequent checks by the main loop, its status is checked and changed (i.e., its x-/y- pos'ns are altered, etc etc). Of course, these changes are done in a seperate procedure altogether. Compartmentalization is good! Don't put additional loops within your main loop...
This is the general idea that I used when making ~Star Catcher~ [/shameless plug].
jamonathin




PostPosted: Fri May 13, 2005 12:23 pm   Post subject: (No subject)

Now some of the variables can be changed to boolean, and I heard it a million tiem to do so, but it's my personal preference not to, say what you will, but anyways here's a code for what you need. I didn't edit your program, beacause you'll remember more you edit your program yourself.
Turing:

setscreen ("graphics:400;500,nobuttonbar,position:center;center,offscreenonly,title:SiMaCz Productionz")
colorback (black)
var dif : int := 3 %Difference of movement
var done, laserwait : int := 0 %Tells program when another laser is allowed to fire
var x, y : int := 20 %Player co-ordinates
var laserx, lasery, hold : array 1 .. 10 of int
var key : array char of boolean
drawfillbox (0, 0, 15, 20, 2)
var ship : int := Pic.New (0, 0, 15, 20)
cls
for i : 1 .. upper (hold) %Max amount of lasers
    laserx (i) := 0 %Just defaulting everything to zero
    lasery (i) := 0
    hold (i) := 0
end for

procedure shoot_lasers %Shoots the lasers
    for i : 1 .. upper (hold) %Checking for all lasers
        if hold (i) = 1 then %If the current laser(i) is being shot then . .
            Draw.ThickLine (laserx (i), lasery (i), laserx (i), lasery (i) + 15, 2, 13) %Draw laser
            lasery (i) += dif * 2 %Move laser twice the speed of the player
            if lasery (i) > maxy then %If its greater than the screen then reset it
                hold (i) := 0
            end if
        end if
    end for
end shoot_lasers

procedure draw
    cls
    shoot_lasers %Calling shoot_lasers
    Pic.Draw (ship, x, y, picMerge) %Space ship, just change the variable to an acutal picture
    View.Update
end draw

loop
    Input.KeyDown (key) %Just Checking teh boundries for movement
    if key (KEY_LEFT_ARROW) and x > dif then
        x -= dif
    elsif key (KEY_RIGHT_ARROW) and x + Pic.Width (ship) < maxx - dif then
        x += dif
    end if
    if key (KEY_UP_ARROW) and y + Pic.Height (ship) < maxy - dif then
        y += dif
    elsif key (KEY_DOWN_ARROW) and y > 30 then
        y -= dif
    end if
    if key (' ') and done = 0 then %If we're allowed to shoot another laser
        for i : 1 .. upper (hold)
            if hold (i) = 0 and done = 0 then %If the current laser is free to be shot
                laserx (i) := x + (Pic.Width (ship) div 2) %Centering the laser
                lasery (i) := y + Pic.Height (ship) %Making it drawn at the top of the ship
                hold (i) := 1 %Making it taken
                done := 1 %Telling the program to delay before shooting again
            end if
        end for
    end if
    if done = 1 and laserwait < 20 then %Waiting untill laserwait is 20
        laserwait += 1 %This will make a delay of [20 * (whatever delay is set)] before shooting again
    elsif done = 1 and laserwait >= 20 then %Now its ok to shoot, so reset laserwait
        laserwait := 0
        done := 0
    end if
    draw %Draw everything
    delay (5) %delay, drrrrrr...
end loop


Have fun. Smile

Edit: Once again, I should type faster Razz
Flashkicks




PostPosted: Fri May 13, 2005 12:47 pm   Post subject: (No subject)

Hay- thanks very much for that demo. I will try to incorporate it into mine.. I will let you now how it goes!
~Flashkicks

Hold on- I have ONE question that I have been seeing a lot lately. Well, not the question, but .. yeah.Okay----what is this;

+=

??.. Anyways..

:: EDIT ::

(About 15 minutes later)
Okay, that demo proggy you left me is wonderful, however, I can NOT interpret it into my program :'( .. Im not sure what to do now. I tried the whole upper with hold and everything and it just wont shoot any lasers at all... I dont want to just copy all your code so do you think you can get me started as of what to do next to interpret it into my coding??.. I will keep trying but Im really just getting frustrated. Anyway, thanks, and hopefully you can help me out.. BTY-My teacher liked the sample you left Laughing lol.. Kay, c ya!
~Flashkicks

:: EDIT ::
Okay- I got it to shoot now, but once 10 lasers are shot-its DONE! You cant shoot no more Sad.. achoo Help!!.....
jamonathin




PostPosted: Fri May 13, 2005 1:49 pm   Post subject: (No subject)

Ok, this is what += means.
Turing:

x -= 2
 % Is the same thing as
x := x - 2

% And . .

y += 7
 % Is the same thing as
y := y + 7

% And . .

z *= 5
 % Is the same thing as
z := z * 5

% And . .

a /= 9
 % Is the same thing as
a := a / 9


And for your shooting problem. . . when do you reset the shots? Do you ever make it so when the laser gets past the top of the screen that you reset it, making it available to shoot again?

Take a look at this again
Turing:

procedure shoot_lasers %Shoots the lasers
    for i : 1 .. upper (hold) %Checking for all lasers
        if hold (i) = 1 then %If the current laser(i) is being shot then . .
            Draw.ThickLine (laserx (i), lasery (i), laserx (i), lasery (i) + 15, 2, 13) %Draw laser
            lasery (i) += dif * 2 %Move laser twice the speed of the player
            if lasery (i) > maxy then %If its greater than the screen then reset it
                hold (i) := 0
            end if
        end if
    end for
end shoot_lasers


Once the lasery is > maxy, I reset that laser, making it available to shoot again, and I use a for loop to check through all 10 lasers to save up room.
Flashkicks




PostPosted: Mon May 16, 2005 7:57 am   Post subject: (No subject)

haha-sorry.. I had a silly mistake and everything werks fine.. Embarassed My Baad.. Anyways.. I thank you very much.. Now comes the asteroids Laughing
~Flashkicks

:UPDATE:

OKAY-wtfrick... Evil or Very Mad My asteroids arent werking either.. I feel like I cant do anything.. Anyways.. Heres what I have for it- they draw but they never move..
code:
proc asteroids
    type asteroids :
        record
            x : int
            y : int
            size : int
            spd : int
            dx : int
        end record

    var rock : array 1 .. 100 of asteroids
    % Declare initial values
    for i : 1 .. 10
        rock (i).x := Rand.Int (maxx, maxx + 400)
        rock (i).y := Rand.Int (0, maxy)
        rock (i).size := 30
        % rock (i).spd := -1 - rock (i).size
        % rock (i).dx := Rand.Int (-2 - rock (i).size, 2 + rock (i).size)
    end for
    % Make move
    for i : 1 .. 10
        drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 7)
        rock (i).x -= 5
        drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 43)
        delay (5)
    end for
end asteroids

I call asteroids in my main Controls loop... Maybe I shouldnt be going through this using a record Confused But I thought it would be a good idea cuz then I could eventually keep track of different sizes of asteroids..
jamonathin




PostPosted: Tue May 17, 2005 8:17 am   Post subject: (No subject)

Ok, there's nothing wrong with using a record, it just how you're using it.

Declare everything outside of the procedure. This is what your record should look like:
Turing:

var rock : array 1 .. 100 of
    record
        x, y, size, spd, dx : int
    end record

Now here's why your asteroids wont move. You "Declare initial values", and then you decide to "Make move". The when we run through the procedure again, you declare, then move. We run through the procedure again, you declare, them move. You only need to "declare" them once, not everytime in the procedure, because then they wont go anywhere. So add that to the bottom of your array.
Turing:

var rock : array 1 .. 100 of
    record
        x, y, size, spd, dx : int
    end record
for i : 1 .. upper (rock) %The amount in array (which is 100)
    rock (i).x := Rand.Int (maxx, maxx + 400)
    rock (i).y := Rand.Int (0, maxy)
    rock (i).size := 30
end for


Now, all thats left is to move, and that's what should be in your "asteroids" procedure.
I noticed that you're using the "draw over top of the old ball to get rid of it" technique, don't. There's no need to. Clear the last screen, and then Update.

Now, we need to change our setscreen/View.Set options to offscreenonly to use View.Update. But we only do this once, and not inside any loop or procedure. Just at the top of your program.
Turing:

setscreen ("graphics:640;480, position:center;center, nobuttonbar, offscreenonly, title: SiMaCz Productionz")
colorback(black)
cls


Now your loop and procedure is small, and this is what your entire program should look like.

Turing:

setscreen ("graphics:640;480, position:center;center, nobuttonbar, offscreenonly, title: SiMaCz Productionz")
colorback (black)
cls
var rock : array 1 .. 100 of
    record
        x, y, size, spd, dx : int
    end record
for i : 1 .. upper (rock) %The amount in array (which is 100)
    rock (i).x := Rand.Int (maxx, maxx + 400)
    rock (i).y := Rand.Int (0, maxy)
    rock (i).size := Rand.Int (10, 20)
    rock (i).spd := round (19 - (rock (i).size) / 1.007) %rock(i).spd must be whole/int so we use round()
    if rock (i).spd = 0 then %Checking if the speed is 0
        rock (i).spd := 1
    end if
    %rock (i).dx := not sure what this does
end for
proc asteroids
    % Make move
    for i : 1 .. upper (rock)
        rock (i).x -= rock (i).spd
        drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 43)
        drawoval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 42)%For effect
    end for
end asteroids
loop
    cls
    asteroids
    View.Update
    exit when hasch %Exit when keyboard is touched
    delay (5)
end loop
Sponsor
Sponsor
Sponsor
sponsor
Flashkicks




PostPosted: Tue May 17, 2005 9:26 am   Post subject: (No subject)

Okay.. I tried all your stuff (which by the way was WOW, wut a cool program you made.. I love the "effect Razz ..lol.. Anyway") and it like.. Okay, the program RUNS- but not anything like yours.. First, the asteroids dont move quickly and swiftly. Also, my ship is lagging like a mad mother monkey Confused Im not sure what to do.. I will put my code in here so you can see how I have it ALL set up. If you comment out the "asteroids" in the 'DrawShipAndShoot' procedure, youll notice how nice and smooth it runs.. But oce I throw the 'asteroids' in there, it goes BOOM...lol
code:
%%%%%%%%%%%%%%%%
%              %
%%%  JoyPad  %%%
%              %
%%%%%%%%%%%%%%%%
% Billy Boldt  %
%%%% % % % %%%%%


%% Button : ground (y) := orange
setscreen ("graphics:max;max, offscreenonly")
colorback (7)
cls
%% Variables %%
drawfillbox (0, 0, maxx, maxy, 7)
var key : array char of boolean
var shipX, shipY : int
shipX := 10
shipY := maxy div 2
var laserX, laserY, hold : array 1 .. 10 of int
var done, laserwait : int := 0 % Tells program when another laser is allowed to fire
var dif : int := 3 % Difference of movement
var level : array 1 .. 10 of int

for i : 1 .. upper (hold) % Give the lasers initial values
    laserX (i) := 0     % Just defaulting everything to zero
    laserY (i) := 0
    hold (i) := 0
end for

proc eraseShip
    drawfillbox (shipX - 10, shipY, shipX + 50, shipY + 25, 7)
end eraseShip

proc DrawShip
    drawfilloval (shipX + 25, shipY + 15, 25, 10, 28)
    drawfillbox (shipX - 10, shipY, shipX + 25, shipY + 10, 28)
    drawfilloval (shipX + 35, shipY + 20, 7, 3, 1)
    drawfillbox (shipX + 27, shipY + 2, shipX + 50, shipY + 4, 23)
    drawfillbox (shipX + 25, shipY, shipX + 27, shipY + 5, 23)
end DrawShip

proc Shoot
    for i : 1 .. upper (hold)
        if hold (i) = 1 then
            drawfillbox (laserX (i) + 51, laserY (i) + 2, laserX (i) + 75, laserY (i) + 4, 7)
            laserX (i) += dif * 3
            drawfillbox (laserX (i) + 51, laserY (i) + 2, laserX (i) + 75, laserY (i) + 4, 1)
            if laserX (i) > maxx then   % If its greater than the screen then reset it
                hold (i) := 0
            end if
        end if
    end for
end Shoot

var rock : array 1 .. 100 of
    record
        x, y, size, spd, dx : int
    end record
for i : 1 .. upper (rock) %The amount in array (which is 100)
    rock (i).x := Rand.Int (maxx, maxx + 400)
    rock (i).y := Rand.Int (0, maxy)
    rock (i).size := Rand.Int (10, 20)
end for

proc asteroids
    % Make move
    for i : 1 .. upper (rock)
        drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 7)
        rock (i).x -= 5
        drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 43)
        drawoval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 42) %For effect
        delay (5)
        View.Update
        if rock (i).x <= 0 then
            rock (1).x := Rand.Int (maxx, maxx + 400)
            rock (1).y := Rand.Int (0, maxy)
        end if
    end for
end asteroids

proc DrawShipAndShoot
    Shoot
    DrawShip
    % asteroids
    View.Update
end DrawShipAndShoot

proc shoots
    for i : 1 .. upper (hold)
        if hold (i) = 0 and done = 0 then % If the current laser is free to be shot
            laserX (i) := shipX
            laserY (i) := shipY
            hold (i) := 1 % Making it taken
            done := 1     % Telling the program to delay before shooting again
        end if
    end for
end shoots

loop
    Input.KeyDown (key)
    if key (KEY_LEFT_ARROW) and shipX > dif then
        eraseShip
        shipX -= dif
    elsif key (KEY_RIGHT_ARROW) then
        eraseShip
        shipX += dif
    end if
    if key (KEY_UP_ARROW) then
        eraseShip
        shipY += dif
    elsif key (KEY_DOWN_ARROW) and shipY > 30 then
        eraseShip
        shipY -= dif
    end if
    if key (KEY_TAB) and done = 0 then % If we're allowed to shoot another laser
        shoots
    end if
    if done = 1 and laserwait < 20 then % Waiting untill laserwait is 20
        laserwait += 1 % This will make a delay of [20 * (whatever delay is set)] before shooting again
    elsif done = 1 and laserwait >= 20 then % Now its ok to shoot, so reset laserwait
        laserwait := 0
        done := 0
    end if
    if shipX <= 0 then % Checking for ship bounderies
        shipX := 0
    elsif shipX >= maxx - 40 then
        shipX := maxx - 40
    end if
    if shipY >= maxy - 30 then
        shipY := maxy - 30
    end if
    DrawShipAndShoot     % Draw everything
end loop

I think im missing something major(but is probably very small Mad ) .. If you can catch it than I must say, your Good...lol.. You've helped a lot alreay and Im still sitting here every stinkin day werking on it.. But once again-Im stuck:(..
jamonathin




PostPosted: Tue May 17, 2005 1:04 pm   Post subject: (No subject)

Here's your code, I added a cool background for yas.

The reason it went incredibly slow was because you were delaying(5) and updating the screen (View.Update) 100 times in that for loop. You only need View.Update once, and thats before your delay. I changed things so that only one asteroid comes at a time, and as you shoot more, you can change the new variable i made (rocks) to a higher value, so more asteroids come.

I cleaned up a couple of little things that I forget, but I left the collision for you Wink. If you need help with it just ask, but your programs lookin good so far, keep goin. Smile

Turing:
%%%%%%%%%%%%%%%%
%              %
%%%  JoyPad  %%%
%              %
%%%%%%%%%%%%%%%%
% Billy Boldt  %
%%%% % % % %%%%%


%% Button : ground (y) := orange
setscreen ("graphics:max;max, offscreenonly,nobuttonbar")%nobuttonbar = no button bar :P
colorback (7)
cls

%COol Background
var stars : int := 100
var starx, stary, sdif : array 1 .. 100 of int
for i : 1 .. stars
    starx (i) := Rand.Int (1, maxx) %Making a default for the star somewhere on the screen
    stary (i) := Rand.Int (1, maxy)
    sdif (i) := Rand.Int (2, 7)
end for

proc move_stars
    for i : 1 .. stars %For all of the stars
        starx (i) -= sdif (i) %Move them to their corresponding speed
        drawdot (starx (i), stary (i), white) %Draw them
        if starx (i) < 0 then %If they're off the screen
            starx (i) := maxx %Reset at maxx
            stary (i) := Rand.Int (1, maxy) %Reset for a random y
            sdif (i) := Rand.Int (2, 7) %Reset a random speed
        end if
    end for
end move_stars
%% Variables %%
drawfillbox (0, 0, maxx, maxy, 7)
var key : array char of boolean
var shipX, shipY : int
shipX := 10
shipY := maxy div 2
var laserX, laserY, hold : array 1 .. 10 of int
var done, laserwait : int := 0 % Tells program when another laser is allowed to fire
var dif : int := 3 % Difference of movement
var level : array 1 .. 10 of int
var rocks : int := 2

for i : 1 .. upper (hold) % Give the lasers initial values
    laserX (i) := 0     % Just defaulting everything to zero
    laserY (i) := 0
    hold (i) := 0
end for

proc DrawShip
    drawfilloval (shipX + 25, shipY + 15, 25, 10, 28)
    drawfillbox (shipX - 10, shipY, shipX + 25, shipY + 10, 28)
    drawfilloval (shipX + 35, shipY + 20, 7, 3, 1)
    drawfillbox (shipX + 27, shipY + 2, shipX + 50, shipY + 4, 23)
    drawfillbox (shipX + 25, shipY, shipX + 27, shipY + 5, 23)
end DrawShip

proc Shoot
    for i : 1 .. upper (hold)
        if hold (i) = 1 then
            laserX (i) += dif * 3
            drawfillbox (laserX (i) + 51, laserY (i) + 2, laserX (i) + 75, laserY (i) + 4, 1)
            if laserX (i) > maxx then   % If its greater than the screen then reset it
                hold (i) := 0
            end if
        end if
    end for
end Shoot

var rock : array 1 .. 100 of
    record
        x, y, size, spd, dx : int
    end record
for i : 1 .. upper (rock) %The amount in array (which is 100)
    rock (i).x := Rand.Int (maxx, maxx + 400)
    rock (i).y := Rand.Int (0, maxy)
    rock (i).size := Rand.Int (10, 20)
    rock (i).spd := Rand.Int (1, 3)
end for

proc asteroids
    % Make move
    for i : 1 .. rocks div 2
        rock (i).x -= rock (i).spd
        drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 43)
        drawoval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 42) %For effect
        if rock (i).x <= 0 then
            rock (1).x := Rand.Int (maxx, maxx + 200)
            rock (1).y := Rand.Int (50, maxy - 60)
        end if
    end for
end asteroids

proc DrawShipAndShoot
    cls
    move_stars
    asteroids
    Shoot
    DrawShip
    View.Update
end DrawShipAndShoot

proc shoots
    for i : 1 .. upper (hold)
        if hold (i) = 0 and done = 0 then % If the current laser is free to be shot
            laserX (i) := shipX
            laserY (i) := shipY
            hold (i) := 1 % Making it taken
            done := 1     % Telling the program to delay before shooting again
        end if
    end for
end shoots

loop
    Input.KeyDown (key)
    if key (KEY_LEFT_ARROW) and shipX > dif then
        shipX -= dif
    elsif key (KEY_RIGHT_ARROW) then
        shipX += dif
    end if
    if key (KEY_UP_ARROW) then
        shipY += dif
    elsif key (KEY_DOWN_ARROW) and shipY > 30 then
        shipY -= dif
    end if
    if key (KEY_TAB) and done = 0 then % If we're allowed to shoot another laser
        shoots
    end if
    if done = 1 and laserwait < 20 then % Waiting untill laserwait is 20
        laserwait += 1 % This will make a delay of [20 * (whatever delay is set)] before shooting again
    elsif done = 1 and laserwait >= 20 then % Now its ok to shoot, so reset laserwait
        laserwait := 0
        done := 0
    end if
    if shipX <= 0 then % Checking for ship bounderies
        shipX := 0
    elsif shipX >= maxx - 40 then
        shipX := maxx - 40
    end if
    if shipY >= maxy - 30 then
        shipY := maxy - 30
    end if
    DrawShipAndShoot     % Draw everything
end loop
Flashkicks




PostPosted: Wed May 18, 2005 7:55 am   Post subject: (No subject)

Hay man!!.. I got the whole asteroids thing werking and I guess I shoudla told you that yesterday already bcuz I had it werking near the end of class- not sure if its as efficient as yours though..lol.. but anyways, I really like the background idea so I will throw that in mine.. Im werking on the collision detection right now and its going good, Im just making a life gauge and its giving me hassles..lol.. I'll let you know how it turns out.. TTY soon..
~Flashkicks

:: UPDATE ::
Okay.. The life gauge is all set and its kinda nifty.. It disappears when its not being used..lol.. But anyways.. Okay, not the asteroids. I made a lil procedure to check for collision with a laser and the rock. This is what I've got;
code:
proc RockHit
    for i : 1 .. upper (rock)
        if laserX (i) + 24 >= rock (i).x - 10 and laserY (i) > rock (i).y - 10 and laserY (i) < rock (i).y + 10 then
            drawfilloval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 14) % Eventually it'll explode
            drawfilloval (maxx div 2, maxy div 2, 200, 200, 12) % This is just to check if the rock is hit or not
        end if
    end for
end RockHit


It works maybe 40% of the time.. Any ideas Why it only werks so seldom??..
NOTE: the red oval in the middle is not part of the game, its just my way of checking if a rock is hit.. you know..
jamonathin




PostPosted: Wed May 18, 2005 11:23 am   Post subject: (No subject)

This is the method that I use for collision with lasers.

- I Start off with a for loop running every rock
- Then I run a for loop inside that running for every laser shot
- Then I run a for loop inside That, checking the length of the laser

And what the third for loop does is it checks every pixel on that laser, and as a result, if any point on it touches anything you dont want it to, it'll know.

This method's very efficient. Actually last night I was playing some Intellevision games on my PS2 and I got addicted to Astrosmash! and decided to make it. I dont know when I'll be submitting it, I'm gonnan be busy in the next few weeks, but I'm actually almost done, I only need all of those special features that the actual game has . . .Thinking But I'm trying to make it exactly like the real game.

Anyways, here's your code that you should use.
code:

proc RockHit
    for i : 1 .. upper (rock) %Checking Every Rock
        for x : 1 .. lasers %Checking Every Laser / Not sure which variable you used (max lasers)
            for q : 0 .. 24 %Checking Ever Point In Every Laser
                if laserY (x) >= rock (i).y - 10 and laserY <= rock (i).y + 10 and laserX (x) + q >= rock (i).x - 10 and laserX (x) + q <= rock (i).x + 10 then
                    cls
                    delay (1577) %Just to see if it works. Do whatever.
                end if
            end for
        end for
    end for
end RockHit
Flashkicks




PostPosted: Thu May 19, 2005 7:57 am   Post subject: (No subject)

Hmmm.. The procedure yopu gave is kinda confusing me.. I dont get how the "checking every point in laser" would werk.. Well- I guess I understand but I dont know if I ever woudla thought of that..lol.. Anyways- You said to use my lasers variable for
code:
        for x : 1 .. done %Checking Every Laser / Not sure which variable you used (max lasers)
but I tried all my variables, when I use laserX(i), or laserwait then my "array subscript is out of range". But if I get NO errors then the program runs fine but the lasers never detect once they've hit a rock.. (it doesnt werk) If you scroll up you can see all the variables I used and Im not sure if I have to change something.. Ill keep trying; hope for the best..lol..
~Flashkicks

::UPDATE::
Okay nevermind, .. I got it to werk now..lol.. Its pretty sweet man.. Now I get to design a nifty lil proc for them blowing up Laughing Thats always fun.. KAY- Ill tty soon, and let you know how things are going..
~Flashkicks
jamonathin




PostPosted: Thu May 19, 2005 8:18 am   Post subject: (No subject)

Send your code over, I wanna see how its goin Smile
Flashkicks




PostPosted: Thu May 19, 2005 9:05 am   Post subject: (No subject)

Okay, so I this right here is what i want it to look like.
code:
drawfillbox (0, 0, maxx, maxy, 7) % background
var boomX, boomY : int := 200 % to randomize 10 pixels wide in a square

drawfilloval (200, 200, 20, 20, 62) % draw original asteroid
drawoval (200, 200, 20, 20, 37) % effect
delay (500) % .. Here it comes!!....
for l : 1 .. 10
    randint (boomX, 189, 212)
    randint (boomY, 189, 212)
    for i : 1 .. 12
        drawfilloval (boomX, boomY, i, i, 12)
        delay (5)
    end for
    for i : 1 .. 12
        drawfilloval (boomX, boomY, i, i, 14)
        delay (5)
    end for
    for i : 1 .. 12
        drawfilloval (boomX, boomY, i, i, 7)
        delay (5)
    end for
end for

So run that and you will see what I mean.. Now when I transfered it into my actual program, it lagged like you wouldnt believe, yet didnt even do the explosion(effect).

::UPDATE::
hahahaha.. Okay.. Sorry. This was really dumb of me.. In my actual program that I sent you I forgot to tell the computer WHERE to draw all the explosions.. This is what it SHOULD look like..
code:
var boomX, boomY : int
proc Boom
    for i : 1 .. upper (rock)
        randint (boomX, rock (i).x - 10, rock (i).x + 10)
        randint (boomY, rock (i).y - 10, rock (i).y + 10)
    end for
    for i : 1 .. upper (rock) % <--Maybe thats the problem; should I NOT use that??
        drawfilloval (boomX, boomY, i, i, 12)
        delay (5)
    end for
    for i : 1 .. upper (rock) % <--Maybe thats the problem; should I NOT use that??
        drawfilloval (boomX, boomY, i, i, 14)
        delay (5)
    end for
    for i : 1 .. upper (rock) % <--Maybe thats the problem; should I NOT use that??
        drawfilloval (boomX, boomY, i, i, 7)
        delay (5)
    end for
end Boom

There we go.. But either way, it still lags like a biznitch.. And I dont know how to make it run swiftly and smooth like an Iced Cuppicinno...
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  [ 23 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: