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 Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
jamonathin




PostPosted: Sun May 22, 2005 10:04 am   Post subject: (No subject)

Flashkicks wrote:
Hay- in the new stuff you added, is there anywhere I can add something so that the laser will be depleted imiediately after it hits an asteroid?.. You know, so it doesnt keep shooting through killing all the asteroids behind it?.. I tried throwing some code in a few procedures and its just.. Okay, if it hits a rock, then another laser will immediatly shoot out even if Im NoT pressing/holding "Tab" .. Any ideas why that might be happeneding?? Ill keep playing around with it........
~Flashkicks


Yup, really simple. Look at his proc: proc shoots, and this line:
proc shoots wrote:
if hold (i) = 0 and done = 0 then

Now for a recap, 'hold (i)' tells the program that the current laser is free and can be reshot, and 'done' is just the delay inbetween the two lasers.

Now take a look at proc Shoot, and these lines:
proc Shoot wrote:

if hold (i) = 1 then
laserX (i) += dif * 3

The X-Value on the laser only moves when 'hold (i) = 1'. So if we look back at the other procedure (which is acutally after this procedure in the coding) It will reset any laser whos 'hold (i)' is equal to one.

Now, I'm not at home or school so I done have your current code, but where ever you check collision with the lasers, just make the 'hold (i)' equal to 0, and the program will/should take care of the rest.

Try it out and tell me how it goes.
Sponsor
Sponsor
Sponsor
sponsor
Flashkicks




PostPosted: Fri May 27, 2005 7:56 am   Post subject: (No subject)

Okay, in mycollision procedure where it checks if a rock has been hit, I added the one simple line of

hold (i) := 0

And as soon as the first asteroid is shot it gives the error

"Array subscript outta range"

.. And so I've tried SO many things and can not figure out what Im missing.. I've tried seperate for statements and changing hold(i) to different variables.. And still, nothing happens.. Any ideas??..
~Flashkicks
jamonathin




PostPosted: Fri May 27, 2005 8:12 am   Post subject: (No subject)

Here's what you have to look at (since i dont know where your updated code is): what the array number on hold (var hold : array 1 .. ? of ***), then you need to check your for loop. Does the max number exceed the '?' in your hold variable? Does the for loop start at 0? Check those things out first, because that's the only reason you're getting that message.
Flashkicks




PostPosted: Mon May 30, 2005 7:42 am   Post subject: (No subject)

woops, sorry-Here, Ill add the code in. Just comment out the lil intro part that requires the pic Wink..
code:
%%%%%%%%%%%%%%%%
%              %
%%%  JoyPad  %%%
%              %
%%%%%%%%%%%%%%%%
% Billy Boldt  %
%%%% % % % %%%%%


%% Button : ground (y) := orange
setscreen ("graphics:max;max, offscreenonly,nobuttonbar")
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
var barX, barY, meterX, meterY : int
var track : int := 0
var track2 : int := 5
barX := 10
barY := maxy - 10
meterX := 10
meterY := maxy - 10
var stars : int := 100
var starx, stary, sdif : array 1 .. 100 of int
var death : boolean := false
var fig : int := Font.New ("Chiller:72")
var fig2 : int := Font.New ("Wide Latin:38")

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

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 moveStars
    for i : 1 .. stars
        starx (i) -= sdif (i) % Move them to their corresponding speed
        drawdot (starx (i), stary (i), white)
        if starx (i) < 0 then
            starx (i) := maxx
            stary (i) := Rand.Int (1, maxy)
            sdif (i) := Rand.Int (2, 7)
        end if
    end for
end moveStars

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
            laserX (i) += dif * 3
            drawfillbox (laserX (i) + 51, laserY (i) + 2, laserX (i) + 75, laserY (i) + 4, 9)
            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 .. 30 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 (50, maxy - 50)
    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
end for

var grow, gx, gy, gend : array 1 .. upper (rock) of int %grow: size, gx: x-coord, gy: y-coord, gend: finishes explosion
for i : 1 .. upper (grow) %Making defaults for variables
    grow (i) := 0
    gend (i) := 0
end for

proc newRock (thing : int) %Created a new asteroid, same material from above
    rock (thing).x := Rand.Int (maxx, maxx + 400)
    rock (thing).y := Rand.Int (0, maxy)
    rock (thing).size := Rand.Int (10, 20)
    rock (thing).spd := round (19 - (rock (thing).size) / 1.007) %rock(i).spd must be whole/int so we use round()
    if rock (thing).spd = 0 then     %Checking if the speed is 0
        rock (thing).spd := 1
    end if
end newRock

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, 62) % 43 orange
        drawoval (rock (i).x, rock (i).y, rock (i).size, rock (i).size, 37) % 42 For effect
        if rock (i).x <= 0 - 25 then % Resets asteroids back when gone off screen
            newRock (i)
        end if
    end for
end asteroids

proc Lose % Game Over
    cls
    color (12)
    locatexy (10, maxy - 10)
    Font.Draw ("YOU DIED", maxx div 2 - 170, maxy div 2, fig, 12)
    death := true
end Lose

proc LifeMeter
    drawbox (barX, barY, barX + 200, barY + 10, 12)
    drawfillbox (meterX + 1, meterY + 1, meterX + track2, meterY + 9, 43)
    if meterX + track2 > 200 then
        Lose
    end if
    View.Update
    track2 += 5
end LifeMeter

proc CrashCheck
    for i : 1 .. upper (rock)
        if rock (i).x < shipX + 60 and rock (i).x > shipX - 20 and rock (i).y > shipY and rock (i).y < shipY + 25 then
            LifeMeter
        end if
    end for
end CrashCheck

proc Boom (boomx, boomy, current, thing : int)
    if thing <= rock (current).size and gend (current) not= -7 then %Red Circle
        drawfilloval (boomx, boomy, thing, thing, 12)
        if thing <= rock (current).size then
            gend (current) := -7 %Just a number, moving onto the yellow/orange
        end if
    elsif gend (current) = -7 then
        drawfilloval (boomx, boomy, rock (current).size, rock (current).size, 12) %red
        drawfilloval (boomx, boomy, (thing - rock (current).size) * 2, (thing - rock (current).size) * 2, 43) %orange
        drawfilloval (boomx, boomy, thing - rock (current).size, thing - rock (current).size, 14) %yellow
        if thing - rock (current).size >= round (rock (current).size / 2) then %Once its too big, its done.
            gend (current) := 0
        end if
    end if
end Boom
var count : int := 0
proc RockHit
    for i : 1 .. upper (rock)     % Checking Every Rock
        for x : 1 .. upper (hold)     % Checking Every Laser
            for q : 0 .. 24     % Checking Ever Point In Every Laser
                if laserY (x) >= rock (i).y - 15 and laserY (x) <= rock (i).y + 15 and laserX (x) + q >= rock (i).x - 10 and laserX (x) + q <= rock (i).x + 10 then
                    grow (i) := 1                     %Starting the growth of the explosion
                    gx (i) := rock (i).x %Making the x-coord equal to gx (so it can hold onto it)
                    gy (i) := rock (i).y %Making the y-coord equal to gx (so it can hold onto it)
                    newRock (i) %Creating a new rock, using 'i' which is the current one shot down
                    count := count + 1
                end if
            end for
        end for
    end for
end RockHit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc ReAssignValues
    for j : 1 .. upper (rock)
        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 (50, maxy - 50)
            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
            grow (i) := 0
            gend (i) := 0
        end for
    end for
end ReAssignValues
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc DrawShipAndShoot
    cls
    moveStars
    Shoot
    DrawShip
    asteroids
    CrashCheck
    RockHit
    for i : 1 .. upper (grow)     %Checking if any asteroids have exploded
        if grow (i) > 0 then     %Start exploding if they are
            grow (i) += 1     %Changing the radius of the explosion
            Boom (gx (i), gy (i), i, grow (i))     %Boom (x-coord, y-coord, which asteroid, radius of a'roid)
            if gend (i) = 1 then     %In the proc 'Boom' we make gend 1 when its finished
                grow (i) := 0     %Now we can reset that asteroids explosion for future use
            end if
        end if
    end for
    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
var Asteroids : int := Pic.FileNew ("Asteroids.bmp")

loop
    Pic.Draw (Asteroids, 0, 0, picMerge)
    % Font.Draw ("ASTEROIDS", 40, 400, fig2, 28)
    for decreasing i : 28 .. 21
        Font.Draw ("ASTEROIDS", 40, 400, fig2, i)
        delay (50)
        View.Update
    end for
    for i : 21 .. 28
        Font.Draw ("ASTEROIDS", 40, 400, fig2, i)
        delay (50)
        View.Update
    end for
    exit when hasch
end loop
Pic.Free (Asteroids)
delay (1000)
proc NextLevel
    cls
    drawfillbox (0, 0, maxx, maxy, 7)
    Font.Draw ("Next Level", 40, 400, fig, 28)
    delay (2000)
    count := 0
    View.Update
end NextLevel
loop
    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
        if death = true then % Once you die, the game is over.
            exit
        end if
        if count = 10 then
            ReAssignValues
            % delay (1000)
            NextLevel
            exit
        end if
    end loop
end loop


Also, you will notice my "Levels" isnt very good either.. It only shows on screen for like a split second. Sad I cant get that to werk nicely either.. Anyways.. Im sure you know where to look and you understand what does what.. Im gonna keep trying to get my levels to look a lil better here Rolling Eyes lol... TTYL
~Flashkicks
jamonathin




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

Your View.Update was in the wrong spot. View.Update must go before an delay.
code:

proc NextLevel
    cls
    drawfillbox (0, 0, maxx, maxy, 7)
    Font.Draw ("Next Level", 40, 400, fig, 28)
    View.Update
    delay (2000)
    count := 0
end NextLevel


Also, use >= rather than =, it's more accurate, because you could be on 9 and hit 2 at the same time (juss happened to me)
code:

if count >= 10 then
            ReAssignValues
            % delay (1000)
            NextLevel
            exit
        end if


Other than that I dont see any other errors, just make your levels better, and reset the asteroids to maxx. There should be more asteroids per level. All you ahve to do is add 1 to a variable every time you use the nextlevel proc. Then change how many asteroids move accordingly. You sould also have to shoot down more than 10 asteroids.
Flashkicks




PostPosted: Mon May 30, 2005 8:55 am   Post subject: (No subject)

Haha... Silly little errors.. I hate those.. Maybe Im too unfocused and Im not conentrating enough.. Im trying to make my final project at the same time and not just that- but the 'boss' for my Asteroids game as well..lol.. *phew*.. But thanks for that.. But now Im still stuck on the stupid non-depleting missiles...lol... *gRRRRrrr*
~Flashkicks
jamonathin




PostPosted: Mon May 30, 2005 1:40 pm   Post subject: (No subject)

Your "hold" variable tells the program if that laser can be shot, so just add a "hold (x) := 0" into your proc, like this:

Turing:

roc RockHit
    for i : 1 .. upper (rock)     % Checking Every Rock
        for x : 1 .. upper (hold)     % Checking Every Laser
            for q : 0 .. 24     % Checking Ever Point In Every Laser
                if laserY (x) >= rock (i).y - 15 and laserY (x) <= rock (i).y + 15 and laserX (x) + q >= rock (i).x - 10 and laserX (x) + q <= rock (i).x + 10  then
                    grow (i) := 1                     %Starting the growth of the explosion
                    gx (i) := rock (i).x %Making the x-coord equal to gx (so it can hold onto it)
                    gy (i) := rock (i).y %Making the y-coord equal to gx (so it can hold onto it)
                    hold (x) := 0 %Laser no longer alive
                    newRock (i) %Creating a new rock, using 'i' which is the current one shot down
                    count := count + 1
                end if
            end for
        end for
    end for
end RockHit
Flashkicks




PostPosted: Tue May 31, 2005 9:46 am   Post subject: (No subject)

Why is it that you make things seem so simple??..lol.. It werks great.. I think its bcuz I kept trying to change that variable in a different procedure.. Unless I tried it but used the wrong array Rolling Eyes Either way- the game is 99.9% DONE!! I made this really cool 'boss' thingy and it werks already. But the Asteroids game is supposed to be run with a joystick (which I got werking already as well Laughing ) But incorporating the joystick into my 'boss' program is giving me huge difficulties. I KNOW its possible but its just a matter of figuring out how it will werk... Ill figure it out.. Anyways-enuff rambling.. Thanks a bunch. Ill give you my whole proggy in a PM once I am COMPLETELY 100% done with it. (dont werry, you will be able to use the keyboard and not the joystick...)
~Flashkicks
Sponsor
Sponsor
Sponsor
sponsor
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 2 of 2  [ 23 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: