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

Username:   Password: 
 RegisterRegister   
 Need help with my space shooter for my turing class
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MoTi0n




PostPosted: Tue Oct 16, 2007 9:44 am   Post subject: Need help with my space shooter for my turing class

Hey I'm trying to make a space shooter for my turing class but my Teacher doesent know how to get the shooting to work properly lol, when he shows me how to get it to shoot everything stops the projectile starts going and then everything starts moving again. I need to get it to work like that space ace program http://compsci.ca/v3/viewtopic.php?t=14764&highlight=space+invaders, where you shoot and u can continue to strafe while the projectile is flying across the screen, anny suggestions?


Heres what i have so far:



code:
%Variables Dictionary
%declare variable by name and type
var picID : int %.......................................sets aside memory and names it for gamepiece
var picIDback : int %...................................sets aside memory and names it for background
var chars : array char of boolean %.....................sets up keystroke decisions true or false
var key : string (1)
var y : int := 0
var x : int := 0
%*********************************
%
%
%*********************************
%Procedures/Subprograms/Subroutines
%do each seperatly in a block
%><><><><><><><><><><><><><><><><>ORBITAL CANNON GAMEPIECE MADE WITHM OSTLY DRAWFILL BOX'S AND LINES
proc gamepiece (x : int, y : int)
    drawfillbox (82, 60, 120, 100, grey) %...........main box
    drawbox (82, 60, 120, 100, black)
    drawfillbox (98, 100, 104, 133, yellow) %........yellow cannon shaft
    drawbox (98, 100, 104, 133, black)
    drawline (96, 102, 106, 102, red)
    drawline (96, 102 + 2, 106, 102 + 2, red)
    drawline (96, 102 + 4, 106, 102 + 4, red)
    drawline (96, 102 + 6, 106, 102 + 6, red)
    drawline (96, 102 + 8, 106, 102 + 8, red)
    drawline (96, 102 + 10, 106, 102 + 10, red) %....red conductors on cannon shaft
    drawline (96, 102 + 12, 106, 102 + 12, red)
    drawline (96, 102 + 14, 106, 102 + 14, red)
    drawline (96, 102 + 16, 106, 102 + 16, red)
    drawline (96, 102 + 18, 106, 102 + 18, red)
    drawline (96, 102 + 20, 106, 102 + 20, red)
    drawline (96, 102 + 22, 106, 102 + 22, red)
    drawline (96, 102 + 24, 106, 102 + 24, red)
    drawline (96, 102 + 26, 106, 102 + 26, red)
    drawline (96, 102 + 28, 106, 102 + 28, red)
    drawline (95, 133, 107, 133, black) %...........tip of laser
    drawline (95, 133, 99, 143, black)
    drawline (107, 133, 103, 143, black)
    drawline (99, 143, 103, 143, black)
    drawoval (101, 80, 5, 5, black) %...............mainbody detail
    drawoval (101, 80, 8, 12, black)
    drawfilloval (101, 80, 2, 2, red)
    drawline (85, 63, 85, 97, red)
    drawline (117, 63, 117, 97, red)
    drawline (88, 66, 88, 94, red)
    drawline (114, 66, 114, 94, red)
    drawline (82, 78, 74, 76, black) %..............left thruster
    drawline (74, 76, 74, 86, black)
    drawline (74, 86, 82, 84, black)
    drawline (120, 78, 128, 76, black) %............right thruster
    drawline (128, 76, 128, 86, black)
    drawline (128, 86, 120, 84, black)

    drawfill (124, 80, grey, black) %...............Fills right thruster with colour
    drawfill (77, 80, grey, black) %................Fills left thruster with colour
    drawfill (101, 138, grey, black) %..............Fills left thruster with colour
    drawfillbox (92, 55, 110, 60, grey) %...........Lil box on the bottom of body
    drawbox (91, 55, 110, 60, black)

end gamepiece

%<><><><><><><><><><><><><><><><><><><><><><><><><><>STARS
proc dots
    drawfilloval (150, 50, 1, 1, 92)
end dots
%><><><><><><><><><><><><><><><><><><><><><><><><><><SPACE BACKROUND
proc background
    drawfillbox (0, 0, 639, 479, 17)
    %dots
end background
%><><><><><><><><><><><><><><><><><><><><><><><><><><INTRODUCTION
proc instructions
    for c : 1 .. 20 by 5
        drawbox (0 + c, 0 + c, 639 - c, 479 - c, c)
    end for
    locate (8, 22)
    put "Revenge of the Kuley Clones!" ..
    locate (9, 31)
    put "INSTRUCTIONS" ..
    locate (11, 12)
    put "Destroy as many Kuley clones as possible to Increase your score" ..
    locate (13, 28)
    put "RIGHT ARROW - MOVE RIGHT" ..
    locate (15, 28)
    put "LEFT ARROW - MOVE LEFT" ..
    locate (16, 28)
    put "SPACE - SHOOT" ..
    locate (25, 25)
    put "touch anykey to continue" ..
    View.Update
    getch (key)
end instructions

%*********************************
%
%
%*********************************
%Mainline
%step by step enter the program
instructions
gamepiece (0, 0)
drawbox (68, 48, 135, 145, black)
picID := Pic.New (48, 48, 152, 152) %..............Screencapture for gamepiece
Pic.Draw (picID, 100, 100, picMerge)
background
picIDback := Pic.New (0, 0, 639, 479) %............Screencapture for background
Pic.Draw (picIDback, 0, 0, picCopy)
View.Update

put picID
put picIDback

setscreen ("offscreenonly")
loop %.............................................Repeats for keystroke action
    Input.KeyDown (chars)
    locate (1, 1)

    if chars (KEY_RIGHT_ARROW) then %..............checks for right arrow key
        x := x + 5
    end if

    if chars (KEY_LEFT_ARROW) then %.................checks for left arrow key
        x := x - 5
    end if

    if chars (' ') then%..........................................where i will insert shooting action
    end if

    %..............................................prevents gamepiece from going left offscreen
    if x < 0 then
        x := x + 5
    end if

    %..............................................prevents gamepiece from going right offscreen
    if x > 540 then
        x := x - 5
    end if

    locate (20, 20) %...............................location of coords below
    put x : 5 .. %..................................shows coords

    Pic.Draw (picID, x, y, picMerge)
    View.Update
    Pic.Draw (picIDback, x, y, picCopy)
end loop

%*********************************
[/code]
Sponsor
Sponsor
Sponsor
sponsor
Bored




PostPosted: Tue Oct 16, 2007 8:56 pm   Post subject: Re: Need help with my space shooter for my turing class

All you really need to do is use a variable to keep track of the shots position like you have for the laser you've made there. Then when you shoot it simply checks to see if the shot is already moving, if not it simply moves it to the appropriate x and y position. Each time if the shot is still on the screen you move it up so many pixels.

Some psuedo code:
code:
if key pressed and can shoot (shot offscreen) then
    move shot to start position
end if

if shot is moving (on screen) then
    move shot
end if
MoTi0n




PostPosted: Tue Oct 16, 2007 11:31 pm   Post subject: Re: Need help with my space shooter for my turing class

thanks, I'll try to work it out tommorow at school :p
MoTi0n




PostPosted: Wed Oct 17, 2007 12:52 pm   Post subject: Re: Need help with my space shooter for my turing class

Yeah this is all me and my teacher can come up with so far lol...and it has to be done by friday Sad

code:
if chars (' ') then
        for c : 1 .. 350
            drawfilloval (x + 54, y + 100 + c, 3, 3, red)
            View.Update
            drawfilloval (x + 54, y + 100 + c, 3, 3, black)
        end for
[/code]

I may just ditch the proper projectile because my teacher thinks its too complex and a waste of time
Carey




PostPosted: Fri Oct 19, 2007 12:06 pm   Post subject: RE:Need help with my space shooter for my turing class

try having a main loop with the essentials in it and the shot moving proc

code:
loop
     if one of the arrow keys pressed then
        movePlane
     end if

     if shoot key pressed and canShoot then
          shoot
     end if

     moveShot
     checkShot
     draw
     View.Update
     cls
end loop


where movePlane moves the plane @ the bottom of the screen, shoot makes the bullet coords equal to the plane coords, canShoot is a fcn that returns if you can shoot or not, moveShot adds some amount to the bullet y coord, checkShot checks to see if the bullet has hit something, and draw draws all the enemies, plane, bullet(s), etc. on to the screen.

hopefully that helps.

even if the deadline for your project was today Smile
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  [ 5 Posts ]
Jump to:   


Style:  
Search: