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

Username:   Password: 
 RegisterRegister   
 (URGENT) Need help closing window and continuing.
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
kartikitrak




PostPosted: Tue Jan 04, 2011 6:31 pm   Post subject: (URGENT) Need help closing window and continuing.

What is it you are trying to achieve?
I want to be able to close the console cheat engine and be able to continue the game with the cheat applied.


What is the problem you are having?
I am currently making a platform based game, but I am unable to continue to game when my console cheat feature closes. I understand that my code is still inefficient, but if you want you can comment on that too. I would upload my source code with all the pictures, however my level map itself is 88.3mb(due to its large size).


Describe what you have tried to solve this problem
I am still a noob(newcomer) to turing, however I still know things. I have tried basic stuff like exit commands, Window methods, and procedures.


Turing:


%Platformer

%Imports Classes
%import TitlePageCl in "titlePage.t", DeadPageCl in "deadpage.t", WinPageCl in "winpage.t"


% Creates a window
var winID : int := Window.Open ("graphics: 595;400, offscreenonly,nobuttonbar, title: Square?")

/*Creates variables for classes
 var TitlePage1 : ^TitlePageCl
 new TitlePage1

 var DeadPage1 : ^DeadPageCl
 new DeadPage1

 var WinPage1 : ^WinPageCl
 new WinPage1*/


% Type used for points and vectors to track
type Vector :
    record
        x : real
        y : real
    end record

% Picture(s) used for background and collision detection
var platform1 : int := Pic.FileNew ("platform1.bmp")
var platform2 : int := Pic.FileNew ("platform2.bmp")

% Holds keyboard data
var chars : array char of boolean
var pressedChars : array char of boolean
Input.KeyDown (chars)
pressedChars := chars

% Position and velocity of the player
var pos : Vector
pos.x := 150;
pos.y := 175
var vel : Vector
vel.x := 0;
vel.y := 0

% Position of the camera
var cam : Vector
cam.x := 0;
cam.y := 0

% Size of the player
var size : Vector
size.x := 15;
size.y := 15

% Collision booleans and directions
var isTouchingGround : boolean := false
var isTouchingWall : boolean := false
var wallDir : int := 0

%Score
var scoreSeconds : int := 0

%Pause Key Variable
var PauseKey : char

%Font Varialbes
var font1 : int := Font.New ("Fixedsys:30")
var font2 : int := Font.New ("Fixedsys:12")

%Variables for level changing
var level1b : boolean := true
var level2b : boolean := false


%Console Window and Settings(code)


var console : int := Pic.FileNew ("console.jpg")
var consoleText : string
var x, y, mouse : int
var consoleTextFont : int := Font.New ("Arial:9")
var realCommand : boolean := false

proc consoleWindow
    var winID2 : int := Window.Open ("graphics: 370;340,nobuttonbar, title: Console")

    loop
        Mouse.Where (x, y, mouse)
        Pic.Draw (console, 0, 0, picCopy)
        locate (20, 4)
        colorback (26)
        get consoleText
        exit
    end loop

    if consoleText = "teleport1" then
        realCommand := true
    end if

    if consoleText = "teleport2" then
        realCommand := true
    end if

    if consoleText = "homepos" then
        realCommand := true
    end if

    if consoleText = "shrink" then
        realCommand := true
    end if

    loop
        if realCommand = true then
            Font.Draw ("Console: User has implemented the following: ", 25, maxy - 55, consoleTextFont, white)
            Font.Draw (consoleText, 25, maxy - 70, consoleTextFont, white)
            delay (2500)
            exit
        else
            Font.Draw ("Invalid Command Line", 25, maxy - 55, consoleTextFont, white)
            delay (2500)
            exit
        end if
    end loop

    loop
        Font.Draw ("You can only apply one command at a time.", 25, maxy - 170, consoleTextFont, white)
        delay (2500)
        Window.Hide (winID2)
        exit
    end loop


end consoleWindow

% Faster to draw alot of fillboxes
proc fillbox (x : real, y : real, x2 : real, y2 : real, c : int)
    Draw.FillBox (round (x + cam.x), round (y + cam.y), round (x2 + cam.x), round (y2 + cam.y), c)
end fillbox

proc deadScreen
    cls
    put "dead"
end deadScreen

proc levelChange
    % Draws background
    if level1b = true then
        Pic.Draw (platform1, round (cam.x), round (cam.y), picCopy)
    elsif level2b = true then
        pos.x := 150;
        pos.y := 175
        cls
        Pic.Draw (platform2, round (cam.x), round (cam.y), picCopy)
    end if
end levelChange

proc level
    loop
        %Updates Score
        scoreSeconds := scoreSeconds + 1

        %Fills non-picture areas with a distracting colour
        drawfill (-100, -100, green, black)

        % Get keyboard state
        Input.KeyDown (chars)

        %Pause button
        if chars (' ') then
            Font.Draw ("Game Paused", maxx div 2, maxy - 50, font1, red)
            Font.Draw ("Press any key to continue", maxx div 2, maxy - 100, font2, 11)
            Draw.FillStar (150, 285, 300, 400, yellow)
            View.Update
            PauseKey := getchar
        end if

        %Cheats button
        if chars ('c') then
            /*cls
             put scoreSeconds
             delay (1000)*/

            consoleWindow
        end if

        %Restart button
        if chars ('r') then
            pos.x := 150;
            pos.y := 275
        end if


        % Move dependent of collision with level and what keys are down
        if (isTouchingGround) then
            if chars ('w') then
                vel.y += 15
            end if

            if chars ('a') then
                vel.x -= 1
            end if
            if chars ('d') then
                vel.x += 1
            end if
        else
            % Wall Jump
            if (isTouchingWall) then
                if chars ('w') then
                    vel.y += 15
                    vel.x += 5 * wallDir
                end if
            end if

            if chars ('a') then
                vel.x -= 0.1
            end if
            if chars ('d') then
                vel.x += 0.1
            end if
        end if

        % isTouchingGround is by default false and also helps with jump
        isTouchingGround := false

        % If moving left
        if (round (vel.x) < 0) then
            if (whatdotcolour (round (pos.x + vel.x - size.x + cam.x), round (pos.y - size.y + cam.y)) = black or whatdotcolour (round (pos.x + vel.x - size.x + cam.x), round (pos.y + size.y +
                    cam.y)) =
                    black) then


                isTouchingWall := true
                wallDir := 1

                vel.x := 0
            else
                pos.x += vel.x
                isTouchingWall := false
            end if

            % If moving right
        elsif (round (vel.x) > 0) then
            % Does the player hit a wall?
            if (whatdotcolour (round (pos.x + vel.x + size.x + cam.x), round (pos.y - size.y + cam.y)) = black or whatdotcolour (round (pos.x + vel.x + size.x + cam.x), round (pos.y + size.y +
                    cam.y)) =
                    black) then
                % Find where the player hit the wall
                isTouchingWall := true
                wallDir := -1

                vel.x := 0
            else
                pos.x += vel.x
                isTouchingWall := false
            end if
        end if

        %If Dead
        if pos.y - size.y < -50 then
            %DeadPage1 -> deadPage
        end if


        % If moving down
        if (vel.y < 0) then
            % Does the player hit a floor?
            if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + vel.y - size.y + cam.y)) = black or whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + vel.y - size.y +
                    cam.y)) =
                    black) then
                % Find where the player hit the floor
                for i : round (vel.y) .. 0
                    if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + i - size.y + cam.y)) ~= black and whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + i -
                            size.y +
                            cam.y))
                            ~= black) then
                        % Move the player there
                        pos.y := round (pos.y) + i;
                    end if
                end for

                isTouchingGround := true

                vel.y := 0
            else
                pos.y += vel.y
            end if
            % If moving up
        elsif (vel.y > 0) then
            % Does the player hit a ceiling?
            if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + vel.y + size.y + cam.y)) = black or whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + vel.y + size.y +
                    cam.y)) =
                    black) then
                % Find where the player hit the ceiling
                for decreasing i : round (vel.y) .. 0
                    if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + i + size.y + cam.y)) ~= black and whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + i +
                            size.y +
                            cam.y))
                            ~= black) then
                        % Move the player there
                        pos.y := round (pos.y) + i;
                    end if
                end for
                vel.y := 0
            else
                pos.y += vel.y
            end if
        end if

        % Move camera to center it on the player
        cam.x -= round ((pos.x + cam.x - maxx / 2) / 10)
        cam.y -= round ((pos.y + cam.y - maxy / 2) / 10)

        % Move downward to simulate gravity, less when against a wall
        if (isTouchingWall and vel.y < 0) then
            vel.y -= 9.8 / 30
        else
            vel.y -= 9.8 / 10
        end if

        % Set a maximum speed, less against a wall
        if (isTouchingWall) and (vel.y < -10) then
            vel.y := -10
        end if

        if (vel.y < -15) then
            vel.y := -15
        elsif (vel.y > 15) then
            vel.y := 15
        end if

        if (vel.x < -15) then
            vel.x := -15
        elsif (vel.x > 15) then
            vel.x := 15
        end if

        % Simulates friction
        if (isTouchingGround) then
            vel.x /= 1.2
        end if

        % Sets previous key states to the current key states
        pressedChars := chars

        % Clears
        cls

        levelChange

        % Draws player
        fillbox (pos.x - size.x, pos.y - size.y, pos.x + size.x, pos.y + size.y, blue)

        % Updates window
        Window.Update (winID)

        % Delays
        delay (7)
    end loop
end level

var backgroundTitle : int := Pic.FileNew ("title.jpg")
var backgroundInstruction : int := Pic.FileNew ("instructions.jpg")
var backgroundPassword : int := Pic.FileNew ("password.jpg")
var password1 : string


proc instruction
    loop
        Input.KeyDown (chars)
        cls
        Pic.Draw (backgroundInstruction, 0, 0, picCopy)
        if chars (KEY_ENTER) then
            cls
            level
        end if
        View.Update
    end loop
end instruction


proc password
    loop
        View.Set ("offscreenonly")
        cls
        Pic.Draw (backgroundPassword, 0, 0, picCopy)
        locate (13, 12)
        View.Update
        get password1
        if password1 = "awesome" then
            cls
            level
        end if
    end loop
end password



proc titlePage

    %Starts Playing Music
    Music.PlayFileLoop ("Music.mp3")


    loop
        View.Set ("offscreenonly")
        Mouse.Where (x, y, mouse)
        Pic.Draw (backgroundTitle, 0, 0, picCopy)
        if x > 100 and x < 250 and y > 200 and y < 230 and mouse = 1 then
            level
        end if

        if x > 100 and x < 550 and y > 140 and y < 180 and mouse = 1 then
            instruction
            View.Update

        end if

        if x > 100 and x < 500 and y > 80 and y < 120 and mouse = 1 then
            password
            View.Update
            exit
        end if
        View.Update
    end loop

end titlePage


titlePage



Please specify what version of Turing you are using
Turing 4.1.1
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: Tue Jan 04, 2011 6:58 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

Deleted your duplicate thread. Please use the edit button when possible.
kartikitrak




PostPosted: Tue Jan 04, 2011 7:05 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

I'm sorry. I just want some help with this.
TokenHerbz




PostPosted: Tue Jan 04, 2011 7:11 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

Try closing the Cheat window instead of hiding it.

Replace "Window.Hide(windowID)" from your cheat proc with "Window.Close(windowID)"
kartikitrak




PostPosted: Tue Jan 04, 2011 7:13 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

Thanks Token for the advice, however I have tried that and it doesn't seem to work. It actually seems worse than the hide because it glitches and still doesn't work.
Tony




PostPosted: Tue Jan 04, 2011 7:16 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

What kind of "unable to continue to game" are you experiencing? It might be that you are not returning the focus to the main window.

Some other notes: you are just hiding console windows, they are still there. And you are creating a new one, every time.

Also, I don't understand why you have a bunch of loops with a tail-end exit -- they never loop; seems unnecessary.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kartikitrak




PostPosted: Tue Jan 04, 2011 7:18 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

thanks tony. However, I am unable to re-write what you said to me just know it code. I understand somewhat, what you are saying.

Also. This is what is happening. I enter console, and then I enter a cheat or just a random text and it should close automatically, however when it closes, you can't resume the actually game play. It just freezes up.
kartikitrak




PostPosted: Tue Jan 04, 2011 7:20 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

When I replace the Window.Hide with Window.Close (winID2), I get an error saying "Close of closed stream number 2" What does this mean?
Sponsor
Sponsor
Sponsor
sponsor
ClayWall




PostPosted: Tue Jan 04, 2011 7:21 pm   Post subject: Re: (URGENT) Need help closing window and continuing.

Take Window.Hide (winID2) out of the loop and put it at the very end of the proc, and if I remember right you will have to use Window.Update on your other window if you are using offscreenonly.

Also, why do you have loops with an exit with no exit clause, this makes those loops useless.
TokenHerbz




PostPosted: Tue Jan 04, 2011 7:22 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

Yes, As tony pointed out, you have alot of un needed code in it.

Anyways, right at the END of that procedure for your cheat, try to Window.SetActive(mainWINDOW) and let me know what happens,

I'll attempt to syphon threw some of this code looking for the error, hope i dont over look it, as its not the easiest to read Razz
kartikitrak




PostPosted: Tue Jan 04, 2011 7:24 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

thanks guy for your constructive criticism.
kartikitrak




PostPosted: Tue Jan 04, 2011 7:26 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

Okay. Token with your tips. Sadly nothing actually changes. I'm sorry if this code is messed up. I'm still a newb at turing.
kartikitrak




PostPosted: Tue Jan 04, 2011 7:28 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

good news guys. I removed the loops and the exits in the console procedures and its resuming. I'm just going to test out if the cheats apply.
Anyway. Now please comment on the GUI. and simplifing the code.
kartikitrak




PostPosted: Tue Jan 04, 2011 7:32 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

OMFG!! YOU GUYS ARE THE BEST PEOPLE EVER! IT WORKS PERFECTLY! THANKS TO TOKENHERBZ ,TONY AND CLAYWALL
Tony




PostPosted: Tue Jan 04, 2011 7:38 pm   Post subject: RE:(URGENT) Need help closing window and continuing.

Runtime error I'm getting is "Keyboard input from invisible window is now allowed"

TokenHerbz @ Tue Jan 04, 2011 7:22 pm wrote:
Anyways, right at the END of that procedure for your cheat, try to Window.SetActive(mainWINDOW) and let me know what happens

I've tried this out, it works.

Turing 4.1 through CrossOver.

----
Edit: I seem to be off my game today. I think it's time for a nap.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: