Computer Science Canada

Need help with "shooting a projectile" and a "password menu"

Author:  Alex C. [ Tue Jan 10, 2012 9:13 pm ]
Post subject:  Need help with "shooting a projectile" and a "password menu"

What is it you are trying to achieve?

1) Have a image fire a projectile vertically
2) Create a password entry area (for cheats and such unlockables =D)


What is the problem you are having?

I have no knowledge on either of those topics... =(


Describe what you have tried to solve this problem

BooHoo

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

Turing:


View.Set ("nobuttonbar,offscreenonly")
var x, y : int
x := 100
y := 100
var chars : array char of boolean
loop
    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 (/*SHOOTING KEY*/) then
       %SHOOTING CODE
    end if
    drawfilloval (x, y, 40, 40, 56)
    delay (10)
    put "Use the arrow keys to move the ball, and press ESC to exit"
    View.Update
    cls
end loop



for a password screen... yeah no clue Sad

Please specify what version of Turing you are using

um... it's 4.1.1

Author:  chipanpriest [ Tue Jan 10, 2012 9:32 pm ]
Post subject:  Re: Need help with "shooting a projectile" and a "password menu"

You seem to already know how to shoot a projectile given your code. For the password thing, you can do a simple get code. Do something like:

Turing:
var answer : string
get answer : *
if answer = whateverthepasswordis then
cheat := true
end if

Author:  Alex C. [ Tue Jan 10, 2012 9:39 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

alright, but when I try to shoot the projectile & move, the shot follows the character... Sad

Author:  Tony [ Tue Jan 10, 2012 9:48 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

things like
code:

var x, y : int

are ambiguous. Use descriptive names, such as
code:

var character_x, character_y : int

If you find yourself drawing projectiles using the values of character_x, then that is a problem.

Author:  Alex C. [ Tue Jan 10, 2012 10:27 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

thanks! Very Happy

Author:  Velocity [ Wed Jan 11, 2012 12:18 am ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

instead of y := y + 5

Write y += 5 its the same thing, its more advanced, saves you .5 milliseconds and it looks pro. You can do it for any operator. For the password... Seems like you have knowlendge of arrays so make an array say a max 3 range, and call each variable from the array and declare that variable with a password. Any text that u decide
And then make a put and get statement and write if password say (1) of your array = true then .... Whatever the password does. Oh and do you still need help with shooting projectiles?.

Author:  Tony [ Wed Jan 11, 2012 1:09 am ]
Post subject:  Re: RE:Need help with "shooting a projectile" and a "password menu"

Velocity @ Wed Jan 11, 2012 12:18 am wrote:
instead of y := y + 5

Write y += 5 its the same thing

It's almost the same thing. Fun exercise -- find a case where the difference matters. (For most practical purposes, this difference doesn't matter).

Author:  chipanpriest [ Wed Jan 11, 2012 7:05 am ]
Post subject:  Re: Need help with "shooting a projectile" and a "password menu"

Your shot probably follows your player because you are using the same variables for the coordinates of your player and the coordinates of the shot. In order to make the shot not follow your player, you would need separate variables for the player and the shot; for example,

Turing:

    if chars (/*SHOOTING KEY*/) then
       %This would need a separate x and y variable than the ones you are using such as bulletx and bullety
    end if

Author:  Velocity [ Wed Jan 11, 2012 8:40 am ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

tony, in which case would you use one over the other ? Ima look around

Author:  tg851 [ Wed Jan 11, 2012 11:09 am ]
Post subject:  Re: Need help with "shooting a projectile" and a "password menu"

chipanpriest @ Tue Jan 10, 2012 9:32 pm wrote:
You seem to already know how to shoot a projectile given your code. For the password thing, you can do a simple get code. Do something like:

Turing:
var answer : string
get answer : *
if answer = whateverthepasswordis then
cheat := true
end if


its actually
Turing:
var answer : string
get answer : *
if answer = "whateverthepasswordis" then
cheat := true
end if

otherwise it will look for a nonexistent variable, instead of checking the string
also
Tony @ Wed Jan 11, 2012 1:09 am wrote:
Velocity @ Wed Jan 11, 2012 12:18 am wrote:
instead of y := y + 5

Write y += 5 its the same thing

It's almost the same thing. Fun exercise -- find a case where the difference matters. (For most practical purposes, this difference doesn't matter).

x= instead of x:= makes the argument flimsy if x go a change from floor or another command that changes it to something other that int(like from int to true)the error module will throw a fit(I think)

Author:  Tony [ Wed Jan 11, 2012 12:27 pm ]
Post subject:  Re: RE:Need help with "shooting a projectile" and a "password menu"

Velocity @ Wed Jan 11, 2012 8:40 am wrote:
tony, in which case would you use one over the other ? Ima look around

When the following behaviour difference matters
code:

#include <iostream>

int foo = 0;

int& var() {
        std::cout << "eval var" << std::endl;
        return foo;
}

int main() {
        std::cout << "TEST +" << std::endl;
        foo = 1;
        var() = var() + 5;
        std::cout << "result: " << foo << std::endl;

        std::cout << std::endl << "TEST +=" << std::endl;
        foo = 1;
        var() += 5;
        std::cout << "result: " << foo << std::endl;
       
        return 0;
}

Author:  DemonWasp [ Wed Jan 11, 2012 2:41 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

Given that the context is a Turing Help thread, this may be a more pertinent example:

Turing:

fcn modify ( var v : int ) : int
    v := v + 1
    result v
end modify

var a : int := 1

% Depending on which line you uncomment, the result changes.
%a := a + modify(a)     % puts 3
%a += modify(a)         % puts 3
%a := modify(a) + a     % puts 4

put a

Author:  Tony [ Wed Jan 11, 2012 3:44 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

@DemonWasp this looks like an order-of-operation difference, rather than assignment operators. The modify() function is equivalent to ++v.

The important difference with += is that the evaluation takes place only once. This shouldn't even matter for simple variables, as I'd expect a good compiler to rewrite that in whichever version is faster (I'm expecting speed difference to be on the order of ++a vs. a++). This difference could matter if the variable comes from an expression. Here's a Turing example:

code:

var list : array 1 .. 10 of int := init(1,2,3,4,5,6,7,8,9,10)

list[Rand.Int(1,10)] := list[Rand.Int(1,10)] + 1
% vs
list[Rand.Int(1,10)] += 1

Author:  DemonWasp [ Wed Jan 11, 2012 5:16 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

Apparently I'd forgotten just how C-like Turing really can be. Here's your example, translated:

Turing:

% I couldn't find any syntax to allow me to get a pointer to an existing int
% var in 5 minutes, so I gave up. This works alright, even if it gets messy.
var foo : ^ int
new foo

% varr because "var" is a reserved keyword
fcn varr() : ^int
    put "eval varr"
   
    result foo
end varr

% main...

^foo := 1
^(varr()) := ^(varr()) + 5;
put "result: ", ^foo

^foo := 1
^(varr()) += 5
put "result: ", ^foo


In any case, both of these are relatively benign: you have to explicitly say that you wanted something done twice. They only become evil if you start defining macros so that they look like plain variables:
code:

#define RANDOM_ENTRY list[randint(LIST_SIZE)]

// Yes:
RANDOM_ENTRY += 5;

// Whoops:
RANDOM_ENTRY = RANDOM_ENTRY + 5;

Author:  Velocity [ Thu Jan 12, 2012 6:01 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

oooh, okay but tony, i was just talking about how the y+=5 would be better than y := y + 5 in this case

Author:  Raknarg [ Thu Jan 12, 2012 8:54 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

That wasnt the point. The point was that you're missing the subtlety of programming, where small differences, although they appear to be similar, are't exactly the same.

Can be confused with trolling.

Author:  Aange10 [ Thu Jan 12, 2012 9:35 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

Turing:

var list : array 1 .. 10 of int := init(1,2,3,4,5,6,7,8,9,10)

list(Rand.Int(1,10)) := list(Rand.Int(1,10)) + 1
% vs
list(Rand.Int(1,10)) += 1


Is very interesting, but is that really a subtly in the increment operand, or common sense?

+= would definitely be superior in this situation, in my opinion. But as writing code myself, if I saw this problem, I would simply store (Rand.Int (1,10)) into a temp variable.

Author:  Raknarg [ Thu Jan 12, 2012 9:53 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

In a lot of cases it wont make a difference, anyways.

Author:  evildaddy911 [ Fri Jan 13, 2012 4:36 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

its simply quicker to type

Author:  mirhagk [ Fri Jan 13, 2012 6:03 pm ]
Post subject:  RE:Need help with "shooting a projectile" and a "password menu"

and as Tony pointed out, technically could be slightly faster (although probably not if there is a good compiler *cough* not turing *cough*)


: