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 "shooting a projectile" and a "password menu"
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
Alex C.




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
chipanpriest




PostPosted: 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
Alex C.




PostPosted: 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
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Alex C.




PostPosted: Tue Jan 10, 2012 10:27 pm   Post subject: RE:Need help with "shooting a projectile" and a "password menu"

thanks! Very Happy
Velocity




PostPosted: 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?.
Tony




PostPosted: 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).
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
chipanpriest




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: 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
tg851




PostPosted: 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)
Tony




PostPosted: 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;
}
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: 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
Tony




PostPosted: 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
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: 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;
Velocity




PostPosted: 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
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  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: