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

Username:   Password: 
 RegisterRegister   
 bullet shooting
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sammi




PostPosted: Sat Nov 05, 2011 11:17 am   Post subject: bullet shooting

What is it you are trying to achieve?
when i press the spacebar i want the bullets to shoot


What is the problem you are having?
<they wont shoot>


Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


var keys : array char of boolean

% Number of bullets currently on the screen
var numBullets : int := 0

% used so holding space only
% fires once
var firing : boolean
firing := false

% x-location of bullets on screen
var bulletX : array 1 .. 10 of int

%player location
var playerX : int := 100
var playerY : int := 200

loop
    Input.KeyDown (keys) % update keyboard info

    %%%%%%% MOVING %%%%%%%%%%%%
    for i : 1 .. numBullets
        bulletX (i) := bulletX (i) + 2
    end for
    % Move Bullets
    % 2) PUT CODE HERE TO MOVE BULLETS TO THE RIGHT
    for i : 1 .. numBullets
        if keys (' ') = true and firing = false then
        if numBullets < 10 then
            numBullets := numBullets + 2
            firing  = true
        end if
      end if 
    end for
    %%%%%%% FIRE CHECK  %%%%%%%%%%

    % Fire Pressed?

    if keys (' ') = true and firing = true then
        numBullets := numBullets + 1
        bulletX (numBullets) := 100
    end if

    if keys (' ') = false then
        firing := false
    end if




    %%%%%%% REMOVE CHECK  %%%%%%%%

    % this check is only if the furthest bullet
    % has reached the wall, will modify later

    if numBullets > 0 then
        if bulletX (1) > maxx then
            % 3) PUT CODE HERE TO REMOVE BULLET IN SLOT 1

        end if
    end if




    %%%%%%%% DRAWING  %%%%%%%%%%
    cls ()         % clear screen

    % Draw Character
    Draw.FillOval (playerX, playerY, 10, 10, 7)

    % Draw Bullets
    for i : 1 .. numBullets
        Draw.FillOval (bulletX (i), 200, 4, 4, 7)
    end for

    delay (25)

end loop




Please specify what version of Turing you are using
<Answer Here>
Sponsor
Sponsor
Sponsor
sponsor
evildaddy911




PostPosted: Sat Nov 05, 2011 4:10 pm   Post subject: Re: bullet shooting

the reason that the space isnt working is because you need to put

Turing:
if keys (char(ORD_SPACE)) and firing = false then


you dont put " " or key()= true
sammi




PostPosted: Sat Nov 05, 2011 7:10 pm   Post subject: RE:bullet shooting

its still not not working so im going to get rid of all the fancy stuff and try to make a ball appear on the screen by pressing space.
sammi




PostPosted: Sat Nov 05, 2011 9:30 pm   Post subject: RE:bullet shooting

alright so i got right back down to the basics and made my code so that when press spacebar a green bullet appears on the screen but it doesnt go anywhere. I'm familiar with making objects move around the screen if they have an integer value but not when they are arrays. (in this case a round of bullets) I need the black circle to shoot out a bullet when i press spacebar.

Turing:


var keys : array char of boolean

% Number of bullets currently on the screen
var numBullets : int := 0

% used so holding space only
% fires once
var firing : boolean
firing := false

% x-location of bullets on screen
var bulletX : array 1 .. 10 of int

%player location
var playerX : int := 100
var playerY : int := 200

loop
    Input.KeyDown (keys) % update keyboard info

    %%%%%%% MOVING %%%%%%%%%%%%

    % Move Bullets
    % 2) PUT CODE HERE TO MOVE BULLETS TO THE RIGHT

 


    %%%%%%% FIRE CHECK  %%%%%%%%%%

    % Fire Pressed?

    if keys (' ') = true and firing = false then
        numBullets := numBullets + 1
        bulletX (numBullets) := 100
    end if


    %%%%%%% REMOVE CHECK  %%%%%%%%

    % this check is only if the furthest bullet
    % has reached the wall, will modify later
    if numBullets > 0 then
        if bulletX (1) > maxx then
            % 3) PUT CODE HERE TO REMOVE BULLET IN SLOT 1

        end if
    end if

    %%%%%%%% DRAWING  %%%%%%%%%%
    cls ()         % clear screen

    % Draw Character
    Draw.FillOval (playerX, playerY, 10, 10, 7)

    % Draw Bullets
    for i : 1 .. numBullets
        Draw.FillOval (bulletX (i), 200, 4, 4, 10)
    end for

    delay (25)

end loop
Tony




PostPosted: Sat Nov 05, 2011 9:59 pm   Post subject: Re: RE:bullet shooting

sammi @ Sat Nov 05, 2011 9:30 pm wrote:
I'm familiar with making objects move around the screen if they have an integer value but not when they are arrays.

But it's an array of integer values! So when you do my_array(index), you have an integer -- something that you already know how to move.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Sun Nov 06, 2011 4:13 pm   Post subject: RE:bullet shooting

Just a note:
Turing:

if keys (' ') = true and firing = false then
        numBullets := numBullets + 1
        bulletX (numBullets) := 100
    end if

Your program will crash after 11 loops i believe.

Also, you're going to want to work with an array of booleans fro each bullet so you can see whether or not they are dead without having to check them each individually.
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 1  [ 6 Posts ]
Jump to:   


Style:  
Search: