Jump to content


Check out our Community Blogs

psycho

Member Since 11 Oct 2009
Offline Last Active Aug 01 2010 03:45 PM
-----

Posts I've Made

In Topic: Return largest integer in an array using recursive function

01 August 2010 - 03:45 PM

Great!!
Thanks for the info, I got it working now.
I just had to change the while for an if.

In Topic: Reading longest word within a string.

11 April 2010 - 11:07 PM

Hey WingedPanther,
Thanks for helping me out. I've updated the code to this, inside the procedure:
 Begin 
                        counter := counter_temp;
                        counter_max := counter;
                        counter_temp := 0;
End;
But it still won't work! Is my algorithm totally invalid?
Thanks again!

In Topic: Help Space Invaders

26 October 2009 - 08:16 PM

Never mind mates, I got it going :thumbup1:
I just embedded the if statement that checks for the spacebar in the ship's movement procedure.
Now to finish off the martians...

In Topic: Help Space Invaders

26 October 2009 - 05:34 PM

Yes, I've used the debugger function to see what's up, but I can't find the logical error behind all this.
Maybe I need to insert the readkey function within a loop?
If I call the bullet procedure from the keypressed statement in the main program (like the ship's movement for instance), the bullet will only move when you press a key, but the ship will move without a problem...
Anyway, I'm out of ideas :closedeyes:
Thanks again wingedpanther

In Topic: Help Space Invaders

25 October 2009 - 07:28 PM

Guess who's back!
I'm almost done with the game, I still have to finish the movement for the enemies, their shooting and as always, fix the freaking bugs! I managed to get around the shooting function for the spaceship, and I am pleased to announce that I did not have to use an array or a record for such action. All I did was declare two separate variables containing the x,y coordinates of the ship and then applying them to the 2D array.
Now here's the problem: I can't make the ship shoot and move at the same time, meaning that until you press the space bar, the ship won't move unless the bullet is drawn on the screen... Could it be because I am calling the readkey and keypressed functions from two different procedures? (One to move the ship and the other to shoot).
Here's some of the code, mainly the shooting procedure and the moving one:
procedure crear_bala(variable_dario_x,variable_dario_y:byte;var bala_x,bala_y:byte;var puntaje : integer; var Poder_Disparar : boolean; var matriz : tm_matriz; var punta_a:byte);
Begin

if keypressed then
 begin
 if (not Poder_Disparar) and (readkey = spacebar) then
    
	  	 begin
          Poder_Disparar := true;
          bala_x:=punta_a;
          bala_y:=37; {variable que tomo del proc de dario}
	    end;
    end;

  IF (Poder_Disparar) and (bala_y>1) THEN
    begin
      dec(bala_y);
      if ((matriz[bala_x,bala_y]<>'M') and (matriz[bala_x,bala_y]<>'R')
            and (matriz[bala_x,bala_y]<>'^')) then
        begin
          matriz[bala_x,bala_y] := 'I';
          gotoxy(bala_x,bala_y);
          write(matriz[bala_x,bala_y]);
          if matriz[bala_x,bala_y+1]='I' then
            begin
              matriz[bala_x,bala_y+1]:=' ';
              gotoxy (bala_x,bala_y+1);
              write (matriz[bala_x,bala_y+1]);
            end;
        end;
BTW that's for the bullet, it's in spanish i know... crear_bala = bullet creation poder_disparar = canshoot
And for the movemente:
procedure Mover_Nave(var matriz: tm_matriz; var punta_d, punta_i, punta_a: byte; var tecla:char);
var
        fil, col, i: byte;
begin
        i:=0;
        if (tecla='d') then
                begin
                col:=punta_d;
                for fil:=38 downto 36 do
                        begin
                        while (matriz[col,fil]='^') do
                                begin
                                int(matriz[col,fil],matriz[col+1,fil]);
                                gotoxy(col+1,fil);
                                write(matriz[col+1,fil]);
                                gotoxy (col,fil);
                                write (matriz[col,fil]);
                                dec(col);
                                end;
                        inc(i);
                        col:=punta_d-i;
                        end;
                inc(punta_d);
                inc(punta_i);
                inc(punta_a);
                end;
        i:=0;
        if (tecla='a') then
                begin
                col:=punta_i;
                for fil:=38 downto 36 do
                        begin
                        while (matriz[col,fil]='^') do
                                begin
                                int(matriz[col,fil],matriz[col-1,fil]);
                                gotoxy(col-1,fil);
                                write(matriz[col-1,fil]);
                                gotoxy (col,fil);
                                write (matriz[col,fil]);
                                inc(col);
                                end;
                        inc(i);
                        col:=punta_i+i;
                        end;
                dec(punta_d);
                dec(punta_i);
                dec(punta_a);
                end;
end;
MAIN LOOP this is where I need help also...
begin
  dis_mars_fil:=6;
  dis_mars_col:=6;
  clrscr;
  perdiste:=false;
  colicion:=false;
  hay_tiro:=false;
  cant_vidas:=3;
  cargar(m_matriz,punta_marcianos_x,punta_marcianos_y);
  mostrar(m_matriz);
  cargar_nave(m_matriz,pd,pi,pa);
  vida (m_matriz);
  gotoxy (1,2);
  write('012345678901234567892123456789312345678941234567895123456789612345678971234567');

  while not perdiste do
    begin
      delay(50);
      resta_vida (colicion,cant_vidas,perdiste,m_matriz);
      p_disparo_marciano (m_matriz,hay_tiro,colicion,punta_marcianos_x,filnav,punta_marcianos_y,colnav,x_bala,y_bala);
		crear_bala(variable_dario_x,variable_dario_y,bala_x,bala_y,puntaje,Poder_Disparar,m_matriz,pa);
      if keypressed then
                        begin
                        teclapresionada:=readkey;
								mover_nave(m_matriz, pd, pi, pa, teclapresionada);
                        end;


    end;
end.

All variables are declared correctly, I just need help with the keypressed and readkey functions. I only posted the code I need help with cause the rest is too long, I uploaded it as an attacthment if you guys wanna take a glander at the whole thing...
Please help me! I need to finish this by Thursday or im screwed! THANK YOU ALL

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download