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

Username:   Password: 
 RegisterRegister   
 Maze Game: Collision and Levels.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
lasttimelord12




PostPosted: Sat Apr 25, 2015 12:31 pm   Post subject: Maze Game: Collision and Levels.

What is it you are trying to achieve?
I'm trying to make the walls collide with my character (a very detailed blue dot Confused), and I am also trying to achieve creating levels in processes.


What is the problem you are having?
My level process doesn't work unless I put the code in the movement loop. The collisions do not work either.

Describe what you have tried to solve this problem
I've tried using whatdotcolour, but I cannot figure out how to tell whatdotcolour what the wall colour is.


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

Turing:


<% Date Started : April 10th 2015
% Purpose : A game where you must control the object through a maze.
setscreen ("graphics")

%Declaring title fonts
var titlefont : int
var authorfont, startfont : int
var startgame : string (1)
var finished : boolean := false
var trans : boolean := false

%Variables for the graphics.

%Declaring variables for movement
var x := 10
var y := 10
var r := 10
var r2 := 10
var chars : array char of boolean
var c:=black

%Declaring the fonts
titlefont := Font.New ("Chiller:36:bold")
authorfont := Font.New ("Chiller:14:bold")
startfont := Font.New ("Chiller:12:italic")
%Create a process to play the music throughout the program
process menumusic
    loop
        exit when finished
        Music.PlayFile ("Black Vortex cut.mp3") %Play Music in main menu
    end loop
end menumusic
%Opening Sequence

procedure opening
var r:int:=100
var name:string
    put "Enter your name.."..
    get name
    put "Thanks ", name
    cls

for b:1..50
        delay (100)
    drawfilloval (300,240,420,410,black)
    drawfilloval (300,200,r,r,white)
        r:=r+2
    end for
    cls
   
drawfilloval (300,240,420,410,black)

locate (5,25)
    put "Person 1: Is he awake?"
        delay (1000)
    locate (10,40)
    put "Person 2: I'm not sure"
        delay (1000) 
     locate (5,15)
     put "Person 1:If he is awake, there's trouble for us"
     locate (10,50)
    delay (1000)
end opening

procedure level1
drawline (0,0,0,800,black)
drawline (0,0,700,0,black)
drawline (639,0,639,400,black)
drawline (0,350,700,350,black)
end level1
   

%Main Menu%
fork menumusic      % Begin playing the music
delay (1000)
%Add in the background image


Font.Draw ("ESCAPE", 250, 350, titlefont, blue)  %Game Title
delay (1000)
Font.Draw ("By Josh", 250, 50, authorfont, blue)  %Developer Name
delay (1000)
Font.Draw ("Press Any Button to Begin!", 250, 200, startfont, blue) % Startgame propt
 getch (startgame)
delay (100)
cls

%INTRODUCTION TO GAME
delay (100)
locate (12, 25)
put "Welcome to ESCAPE"
delay (2000)
cls
locate (12, 25)
put "You have been captured"
delay (2000)
cls
locate (12, 25)
put "As you awake in your chamber, two people are watching you"
delay (2000)
cls
locate (12, 25)
put "You need to get out"
delay (2000)
cls
locate (12, 25)
put "Use the left/right arrow keys to move left/right"
delay (2000)
put "And the up and down arrows to move down"
cls
locate (12, 25)
put "Good Luck!"
delay (100)
cls
delay (100)
% opening


loop
drawline (0,0,0,800,black)
drawline (0,0,700,0,black)
drawline (639,0,639,400,black)
drawline (0,350,700,350,black)
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW)  and View.WhatDotColour(y+1,x) not= c then
        y := y + 5

    end if

    if chars (KEY_RIGHT_ARROW) then
        x := x + 5
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 5
    end if
    if chars (KEY_DOWN_ARROW) then
        y := y - 5
    end if
    delay (10)
    cls
    drawfilloval (x, y, r, r2, blue)
end loop

>



Please specify what version of Turing you are using
4.1.1



Turing Part 2.zip
 Description:
This is the file with the Turing file AND resourced needed the fully experience the program

Download
 Filename:  Turing Part 2.zip
 Filesize:  14.46 MB
 Downloaded:  166 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Sat Apr 25, 2015 12:53 pm   Post subject: Re: Maze Game: Collision and Levels.

lasttimelord12 wrote:

My level process doesn't work unless I put the code in the movement loop.

I don't recommend using processes for anything other than playing audio files in the background unless you really know what you are doing.

lasttimelord12 wrote:

I've tried using whatdotcolour, but I cannot figure out how to tell whatdotcolour what the wall colour is.

Actually that isn't really the problem here. Notice that you move your "character" 5 pixels per iteration of your loop so its coordinates will always be multiples of 5. Also, your upper boundary is drawn at the 350 pixel mark. Now suppose you are about the collide with the wall, what are your current coordinates? Does checking 1 pixel about your current position tell you if the wall is there?
lasttimelord12




PostPosted: Sat Apr 25, 2015 12:58 pm   Post subject: Re: Maze Game: Collision and Levels.

Dreadnought @ April 25th, 12:53 pm wrote:
lasttimelord12 wrote:

My level process doesn't work unless I put the code in the movement loop.

I don't recommend using processes for anything other than playing audio files in the background unless you really know what you are doing.

lasttimelord12 wrote:

I've tried using whatdotcolour, but I cannot figure out how to tell whatdotcolour what the wall colour is.

Actually that isn't really the problem here. Notice that you move your "character" 5 pixels per iteration of your loop so its coordinates will always be multiples of 5. Also, your upper boundary is drawn at the 350 pixel mark. Now suppose you are about the collide with the wall, what are your current coordinates? Does checking 1 pixel about your current position tell you if the wall is there?


Aahh...
You would think for somebody like me, who learnt basic game programming over the span of a year would notice these things...

Also, I meant procedures...I type process. I'll fix that
lasttimelord12




PostPosted: Sat Apr 25, 2015 2:52 pm   Post subject: Re: Maze Game: Collision and Levels.

Dreadnought @ April 25th, 12:53 pm wrote:
lasttimelord12 wrote:

My level process doesn't work unless I put the code in the movement loop.

I don't recommend using processes for anything other than playing audio files in the background unless you really know what you are doing.

lasttimelord12 wrote:

I've tried using whatdotcolour, but I cannot figure out how to tell whatdotcolour what the wall colour is.

Actually that isn't really the problem here. Notice that you move your "character" 5 pixels per iteration of your loop so its coordinates will always be multiples of 5. Also, your upper boundary is drawn at the 350 pixel mark. Now suppose you are about the collide with the wall, what are your current coordinates? Does checking 1 pixel about your current position tell you if the wall is there?


I changed the values, and all sides work except to the right. When moving right the dot still goes through the lines. Why is this?
Here is the code

Input.KeyDown (chars)

if chars (KEY_UP_ARROW) and View.WhatDotColour(x,y+5) not= c then
y := y + 5

end if

if chars (KEY_RIGHT_ARROW)and View.WhatDotColour(x+5,y) not= c then
x := x + 5
end if
if chars (KEY_LEFT_ARROW) and View.WhatDotColour(x-5,y) not= c then
x := x - 5
end if
if chars (KEY_DOWN_ARROW) and View.WhatDotColour(x,y-5) not= c then
y := y - 5
end if
delay (10)
cls
drawfilloval (x, y, r, r2, blue)
end loop
Insectoid




PostPosted: Sat Apr 25, 2015 3:08 pm   Post subject: RE:Maze Game: Collision and Levels.

Your ball only moves by multiples of 5 and you only 5 pixels ahead, which means every time your ball moves there are 4 pixels that go unchecked. Where is your right wall?
lasttimelord12




PostPosted: Sat Apr 25, 2015 4:04 pm   Post subject: Re: RE:Maze Game: Collision and Levels.

Insectoid @ April 25th, 3:08 pm wrote:
Your ball only moves by multiples of 5 and you only 5 pixels ahead, which means every time your ball moves there are 4 pixels that go unchecked. Where is your right wall?


My right wall is at

drawline (639,0,639,400,black)

starting at 639 x and 0y, ending at 639 x and 400y
Insectoid




PostPosted: Sat Apr 25, 2015 4:30 pm   Post subject: RE:Maze Game: Collision and Levels.

Will 639 ever be checked by your collision detection algorithm?
lasttimelord12




PostPosted: Sat Apr 25, 2015 4:39 pm   Post subject: Re: RE:Maze Game: Collision and Levels.

Insectoid @ April 25th, 4:30 pm wrote:
Will 639 ever be checked by your collision detection algorithm?


Oh, no it wouldn't because 639 isn't a multiple of 5..
Thanks!

EDIT: Now the issue is that the ball gets stuck in between the walls.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Sat Apr 25, 2015 4:52 pm   Post subject: RE:Maze Game: Collision and Levels.

There's a number of reasons that could happen. Try walking through your code starting when your ball is 1 frame away from hitting the wall. Go through the code yourself, writing down the value of each variable on paper every time it changes and evaluating all of the if/then statements yourself, without a computer. You will probably only have to do a couple of frames before you figure out what's going wrong.

Remember, learning to debug properly is as important as learning to program at all.
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 1  [ 9 Posts ]
Jump to:   


Style:  
Search: