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

Username:   Password: 
 RegisterRegister   
 help with game?
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
programmer1337




PostPosted: Fri Dec 02, 2011 7:39 pm   Post subject: help with game?

What is it you are trying to achieve?
I want to make a fully functional shooting game with humans that pop up on the screen and you shoot them and the game calculates how many times you succesfully shoot them, what i really want out of this is how to get it so that when you have the circle on the human and press the spacebar it calculates one more point, this is the only thing i am having trouble with at the moment.




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

Turing:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Daniel ...
% Date: November 29, 2011
% Filename: TuringGraphics.t
% Description: graphics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View.Set ("graphics:1200;800,offscreenonly")

x := 400
y := 400
var chars : array char of boolean
loop
    cls ()
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        y := y + 3
    end if
    if chars (KEY_RIGHT_ARROW) then
        x := x + 3
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 3
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 3
    end if
    if chars (chr (ORD_SPACE)) then
 
    end if
    Draw.FillBox (0, 450, 1200, 800, 79) %keeps updating the sky, and drawing sky
    Draw.FillBox (0, 0, 1200, 450, green) %keeps updating the grass, and drawing grass
    Draw.FillOval (x, y, 10, 10, red) %Draws oval
    View.Update
end loop

Sponsor
Sponsor
Sponsor
sponsor
RandomLetters




PostPosted: Fri Dec 02, 2011 9:36 pm   Post subject: RE:help with game?

What do you mean by "calculates one more point". What is the "point"? Where the bullet hits? The other corner of the crosshair?
programmer1337




PostPosted: Sat Dec 03, 2011 11:59 am   Post subject: Re: help with game?

well what i mean is that with each hit on the human or whatever it will add one point to your total score, i would know how to calculate the score, but i need to know how to hit the humans so that when you press the spacebar and the dot is on them at the same time, it interprets it as a hit
RandomLetters




PostPosted: Sat Dec 03, 2011 3:20 pm   Post subject: Re: help with game?

one way is to use whatdotcolor, which works if your targets are all the same color, and unique from the background. Before you draw the cursor, check the color of the new coordinate, and if it is the correct color, then you know it hit.
code:

    var targetcolor : int
    targetcolor := 1
    Draw.FillBox (200, 100, 250, 150, targetcolor) %a target
    if whatdotcolor(x, y) = targetcolor then
         %Add score
    end if
    Draw.FillOval (x, y, 10, 10, red) %Draws oval


Alternatively, you can represent targets using shapes or hitboxes, such as a rectangle, and use math to check if the coordinates of the cursor is within a hitbox. http://compsci.ca/v3/viewtopic.php?t=75&highlight=collision
[/code]
programmer1337




PostPosted: Sat Dec 03, 2011 3:36 pm   Post subject: Re: help with game?

this is my current code for mous control, it keeps lagging, can you guys help me?
code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Daniel ...
% Date: November 29, 2011
% Filename: TuringGraphics.t
% Description: graphics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View.Set ("graphics:1200;800,offscreenonly")

var count, count2, count1, x, y, rndInt, rndInt1, rndInt3 : int
var mx, my, mb : int %vars for the mouse where code

x := 400
y := 400

var chars : array char of boolean
loop

    cls ()

    Input.KeyDown (chars)

    mousewhere (mx, my, mb)

    if my > 790 then
        my := 790
    elsif my < 10 then
        my := 10
    end if
    if mx > 1175 then
        mx := 1175
    elsif mx < 10 then
        mx := 10
    end if

    Draw.FillBox (0, 450, 1200, 800, 79) %keeps updating the sky, and drawing sky
    Draw.FillBox (0, 0, 1200, 450, green) %keeps updating the grass, and drawing grass
    Draw.FillOval (mx, my, 5, 5, black) %Draws oval

    rndInt3 := Rand.Int (10, 100)
    rndInt := Rand.Int (10, 1150)
    rndInt1 := Rand.Int (10, 550)
    delay (rndInt3)
    Draw.FillOval (rndInt, rndInt1, 40, 40, brightred)
    Draw.FillOval (rndInt, rndInt1, 30, 30, white)
    Draw.FillOval (rndInt, rndInt1, 10, 10, brightred)


    delay (500)
    View.Update

end loop
DemonWasp




PostPosted: Sat Dec 03, 2011 3:44 pm   Post subject: Re: help with game?

programmer1337 @ Sat Dec 03, 2011 3:36 pm wrote:
code:

    rndInt3 := Rand.Int (10, 100)
    %...
    delay (rndInt3)

    % ...
    delay (500)


Just a guess, but delaying for 1/2 second after a random delay of 1/100th to 1/10th of a second is probably going to cause some "lag".
programmer1337




PostPosted: Sat Dec 03, 2011 3:49 pm   Post subject: Re: help with game?

ok all i want to do is randomly make the ovals pop up and then with the mouse i click on them before they disappear, and that adds a point, so what should i do?
RandomLetters




PostPosted: Sat Dec 03, 2011 3:55 pm   Post subject: RE:help with game?

You should have only one delay in your loop. This delay should be the one which sets the (max) length per frame.

To have targets pop out randomly, instead of another delay, use a counter to count the number of frames that have passed.
Sponsor
Sponsor
Sponsor
sponsor
programmer1337




PostPosted: Sat Dec 03, 2011 3:57 pm   Post subject: Re: help with game?

can you please just start me off, with the counter?
RandomLetters




PostPosted: Sat Dec 03, 2011 7:48 pm   Post subject: RE:help with game?

code:
var c : int
var duration: int
var frame: int
frame := 17 %60 fps

loop
     c += 1            %counts the # of frames

     if c * frame > duration then     %multiplying the # of frames by the time per frame and check if that time is greater
          duration := randomnumber(); %you can change the duration each time
          c := 0
     end if

     delay(frame)
end loop


to make sure the duration doesnt change for slow computers, you can (in fact should) also use things like time.elapsed and time.delaysincelast instead of a counter and delay. However, the concept is still the same.

Maybe I'm editing too much
programmer1337




PostPosted: Sat Dec 03, 2011 9:30 pm   Post subject: Re: help with game?

this is my current code and it isnt working what should i do?
code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Daniel ..
% Date: November 29, 2011
% Filename: TuringGraphics.t
% Description: graphics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View.Set ("graphics:1200;800,offscreenonly")

var count, count2, count1, x, y, rndInt, rndInt1, rndInt3 : int
var mx, my, mb : int %vars for the mouse where code

x := 400
y := 400
var c : int
var duration: int
var frame: int
frame := 17 %60 fps
rndInt := Rand.Int(100, 1000)

var chars : array char of boolean
loop

    cls ()

    Input.KeyDown (chars)

    mousewhere (mx, my, mb)

    if my > 790 then
        my := 790
    elsif my < 10 then
        my := 10
    end if
    if mx > 1175 then
        mx := 1175
    elsif mx < 10 then
        mx := 10
    end if

    Draw.FillBox (0, 450, 1200, 800, 79) %keeps updating the sky, and drawing sky
    Draw.FillBox (0, 0, 1200, 450, green) %keeps updating the grass, and drawing grass
    Draw.FillOval (mx, my, 5, 5, black) %Draws oval

    rndInt3 := Rand.Int (100, 1000)
    rndInt := Rand.Int (10, 1150)
    rndInt1 := Rand.Int (10, 550)
   

loop
     c := c + 1            %counts the # of frames

     if c * frame > duration then     %multiplying the # of frames by the time per frame and check if that time is greater
          duration := rndInt3 %you can change the duration each time
          c := 0
     end if
Draw.FillOval (rndInt, rndInt1, 40, 40, brightred)
    Draw.FillOval (rndInt, rndInt1, 30, 30, white)
    Draw.FillOval (rndInt, rndInt1, 10, 10, brightred)
     delay(frame)
end loop
    View.Update

end loop

Aange10




PostPosted: Sat Dec 03, 2011 9:52 pm   Post subject: RE:help with game?

Problem #1 : Don't copy an paste somebody's code into your own. Why don't you try seeing what your telling the program to do, and see where you messed up?


EDIT: You need to remove
Turing:

Author: Daniel ..


Because you didn't write all of that code. Citations are necessary, or credit should be void. You can't just copy and paste something and call it yours.
programmer1337




PostPosted: Sat Dec 03, 2011 9:58 pm   Post subject: Re: help with game?

dude i wouldnt copy it >.>, and maybe i forgot to take it out sorrryyyy, all i want is help not criticism
ProgrammingFun




PostPosted: Sat Dec 03, 2011 10:01 pm   Post subject: Re: help with game?

programmer1337 @ Sat Dec 03, 2011 9:58 pm wrote:
dude i wouldnt copy it >.>, and maybe i forgot to take it out sorrryyyy, all i want is help not criticism

Copying won't help you...and helping you learn that is the best help you can ever get.
Understanding of coding does not come from copying (nor does anything else), it comes from understanding the code then implementing your own.

And what you have done by claiming authorship is commonly known as plagiarism and this is not a good thing in any industry, or life in general.
(and what do you mean by "i wouldnt copy it"? did someone forcefully make you do it?)
programmer1337




PostPosted: Sat Dec 03, 2011 10:06 pm   Post subject: Re: help with game?

this is what i wanted, i copied his code into my own, then i wanted to make it so it worked, then when it works, i would tweak it and personalize it, then i would know how it works, because now it doesnt work, and im trying to understand it lol
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 2  [ 29 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: