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

Username:   Password: 
 RegisterRegister   
 My Space Game
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
upthescale




PostPosted: Fri May 05, 2006 2:28 pm   Post subject: My Space Game

I know a lot of my games are the same, but i would like to make a shooting game. Also, in the code below, I LEAREND ARRAYS!...PROCESSES! AND WHATDOTCOLOR! now whatdotcolor isn't in their yet becasue this is the reason why i posted the code..Does any one no what i shud continue to do? shoot aliens? catch stuff? I would like you to reply and tell me an idea thanks!


code:

/*A space program rather...You control the ship with your mouse, and there are limits so you cannot go off of
 the screen. Till' further notice, this program stays the way it is*/
setscreen ("offscreenonly;graphics:1000;800;position:center;center;nobuttonbar;nocursor;title:Space Game 1.1")
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Variables
var shipx, shipy, b : int
var x, y, button, left, middle, right : int
var bulletx, bullety : int
%Variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Background
type stars :
    record
        starx : int
        stary : int
        color1 : int
        sizex : int
        sizey : int
    end record
var star : array 1 .. 200 of stars
for i : 1 .. 200
    randint (star (i).starx, 1, 1000)
    randint (star (i).stary, 1, 1000)
    randint (star (i).sizex, 1, 2)
    randint (star (i).sizey, 1, 2)
    randint (star (i).color1, 1, 255)
end for
%Background
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Background
proc background
    colorback (7)
    cls
    for i : 1 .. 200
        drawfilloval (star (i).starx, star (i).stary, star (i).sizex, star (i).sizey, 0)
        star (i).stary -= 3
        if star (i).stary < 0 then
            randint (star (i).starx, 1, 1000)
            randint (star (i).stary, 1, 1000)
        end if
    end for
end background
%Background
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Ship
proc ship
    mousewhere (shipx, shipy, b)
    drawfillbox (shipx, 0, shipx + 30, 90, yellow)
    drawfillbox (shipx + 100, 0, shipx + 68, 90, yellow)
    drawfillbox (shipx + 70, 140, shipx + 30, 40, yellow)
    drawfillbox (shipx + 60, 120, shipx + 40, 60, 7)
    %Boundries
    if shipx < 0 then
        cls
        background
        drawfillbox (30, 0, 0, 90, yellow)
        drawfillbox (100, 0, 68, 90, yellow)
        drawfillbox (70, 140, 30, 40, yellow)
        drawfillbox (60, 120, 40, 60, 7)
    end if
    if shipx > 900 then
        cls
        background
        drawfillbox (970, 0, 1000, 90, yellow)
        drawfillbox (900, 0, 930, 90, yellow)
        drawfillbox (930, 140, 970, 40, yellow)
        drawfillbox (940, 120, 960, 60, 7)
    end if
    %Boundries
end ship
%Ship
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Shoot
proc shoot1
    bullety := 140
    bulletx := shipx
    loop
        bullety += 8
        drawfillbox (shipx, bullety, shipx + 35, bullety + 35, 0)
        View.Update
        background
        ship
        if bullety > 800 then
            if b = 1 then
                bullety := 140
            end if
        end if
    end loop
end shoot1
%Shoot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Mouse Shoot
proc mouse_shoot
    mousewhere (x, y, b)
    color (0)
    buttonchoose ("multibutton")
    mousewhere (x, y, button)
    left := button mod 10
    middle := (button - left) mod 100
    right := button - middle - left
    if left = 1 then
        shoot1
        if bullety > 800 then
            bullety := 140
        end if
    end if
    if right = 100 then
    end if
end mouse_shoot
%Mouse Shoot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
    background
    ship
    mouse_shoot
    delay (5)
    View.Update
end loop





ok that was updaated.... i just addted sapce ship limits so u can'ty go off screen, and u can shoot....now ive nevwer been able to shoot b4 so i jsut learned, and u will find a problem,,,,when u shoot and u move the ship afterwards, the bullet will follow...any one no y?
Sponsor
Sponsor
Sponsor
sponsor
HellblazerX




PostPosted: Fri May 05, 2006 4:24 pm   Post subject: (No subject)

In the code, where you draw the bullet:

code:
drawfillbox (shipx, bullety, shipx + 35, bullety + 35, 0)


you draw the bullet using the the x-coordinate of the ship, not the bullet itself, so you need to change that to this:

code:
drawfillbox (bulletx, bullety, bulletx + 35, bullety + 35, 0)


However, if you do this, you'll notice that you bullet will only shoot in one place. Why? Because of your procedure shoot1:

code:
proc shoot1
    bullety := 140
    bulletx := shipx
    loop
        bullety += 8
        drawfillbox (bulletx, bullety, bulletx + 35, bullety + 35, 0)
        View.Update
        background
        ship
        if bullety > 800 then
            if b = 1 then
                bullety := 140
            end if
        end if
    end loop
end shoot1


When the user first shoots, from the main loop that is, the bulletx becomes the value of shipx. However, by calling that procedure, you've gotten yourself into an infinite loop, and you can never reach the line where bulletx becomes the new value of shipx. What I suggest you do is to have just one loop, instead of having that infinite nest loop inside your procedure.
upthescale




PostPosted: Fri May 05, 2006 8:23 pm   Post subject: (No subject)

um so what do i do?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: