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

Username:   Password: 
 RegisterRegister   
 Random Pill drawer and eating pacman
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
vertdragon23




PostPosted: Thu Oct 24, 2013 10:10 am   Post subject: Random Pill drawer and eating pacman

What is it you are trying to achieve?
<Trying to draw.fill oval a random pill on right side which pacman can eat, then left side then right etc.

What is the problem you are having?



Describe what you have tried to solve this problem
<Asking a load of people.>


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

Turing:

%slightly glitchy background
colourback (black)
cls
process
        playmusic
    Music.PlayFile ("intro.mp3")
end playmusic
fork playmusic
var font : int
        font := Font.New ("serif:25")
var font2 : int
        font2 := Font.New ("serif:13")
Draw.Text ("Welcome To Pacman", 180, 250, font, red)
Draw.Text ("To win the game, collect 10 pills without dying of boredom", 130, 200, font2, red)

delay (1000)
cls

/*
locate (1,1)
   var timeRunning : int
        timeRunning := Time.Elapsed
        put "This program has run ", timeRunning, " milliseconds" */

% y of Pacman's centre
var y : int := 200
% x of Pacman's centre
var x : int :=200
% direction Pacman moves
var dx, dy : int :=0
 % size of mouth
var mouth : int := 0

var dir : int := 0
var a,b,c,d : boolean :=false
var chars : array char of boolean
 
var pill_x : int := 600
var pill_y : int := 350
var pill_x1 : int := 250
var pill_y1 : int := 350
var pill_x2 : int := 500
var pill_y2 : int := 100


%Where the game starts
loop

    %border
    drawfillbox (0, 0, 20, 420, green)
    drawfillbox (20, 420, 620, 380, green)
    drawfillbox (640, 400, 620, 20, green)
    drawfillbox (640, 0, 20, 20, green)
    %Draws pacman
    drawfillarc (x, y, 18, 18, mouth + dir, -mouth + dir, yellow)
    delay (5)
    %Draws pacmans mouth
    drawfillarc (x, y, 18, 18, mouth + dir, -mouth + dir, black)
    % If user presses a key
   
        % Reads the key pressed
          Input.KeyDown (chars)

        if  chars (KEY_RIGHT_ARROW)then
           a:=true % Pacman will go right, also what makes him not go through
           b:=false
           c:=false
           d:=false
           dir:=0
            end if
       
        if chars (KEY_UP_ARROW) then
        a:=false
        b:=true
         c:=false
           d:=false
            dir:=90
        end if
        if chars (KEY_LEFT_ARROW) then
    a:=false
        b:=false
        c:=true
       d:=false
        dir:=180
        end if
        if chars (KEY_DOWN_ARROW) then
        a:=false
        b:=false
        c:=false   
        d:=true
         dir:=270
        end if
        if a=true then
        x:=x+1
        end if
         if b=true then
        y:=y+1
        end if
         if c=true then
        x:=x-1
        end if
         if d=true then
        y:=y-1
        end if
       
       
        if x=maxx-38 then
        x:=x-1
        end if
         if y=maxy-38 then
        y:=y-1
        end if
         if x=38 then
        x:=x+1
        end if
         if y=38 then
        y:=y+1
        end if
        % move Pacman's centre depending on
        x := x + dx
        % the value of dx and dy
        y := y + dy
   
    % change size of the mouth
    mouth := mouth mod 45 + 1
    % Middle walls
    Draw.FillBox (300, 1, 312, 150, (47))
    Draw.FillBox (300, 255, 312, 490, (47))
 
     % Draws the pill
     
    Draw.FillOval (pill_x, pill_y, 4, 4, blue)
    if Math.Distance (x, y, pill_x, pill_y) < 20 then
        pill_x := 0
        pill_y := 0
   
   if pill_x=0 or pill_y=0 then
    Draw.FillOval (pill_x1, pill_y1, 4, 4, blue)
    if Math.Distance (x, y, pill_x1 ,pill_y1) < 20 then
        pill_x1 := 0
        pill_y1 := 0
        delay (500)
 if pill_x1=0 or pill_y1=0 then     
         Draw.FillOval (pill_x2, pill_y2, 20, 20, blue)
    if Math.Distance (x, y, pill_x2 ,pill_y2) < 20 then
        pill_x2 := 0
        pill_y2 := 0
   
   end if

end if
    end if
     end if


    mouth := mouth mod 45 + 1       % change size of the mouth
    drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, yellow)
    delay (100)
    drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, black)
    x := x + dx                     % move Pacman's centre depending on
    y := y + dy                     
end if
end loop


>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<4.1.1 (Latest)>



Mod Edit:
Please wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
code:

[syntax="turing"] ... code ... [/syntax]

[code] ... code ... [/code ]
Sponsor
Sponsor
Sponsor
sponsor
vertdragon23




PostPosted: Thu Oct 24, 2013 4:33 pm   Post subject: RE:Random Pill drawer and eating pacman

I figured out the random pill drawer and how to restrict pacman from going through the wall in the middle, but could someone help me troubleshoot the pacman, when he enters the hole in the two walls and goes up towards the corner, he glitches into the wall. Help would be appreciated.
vertdragon23




PostPosted: Thu Oct 24, 2013 4:36 pm   Post subject: RE:Random Pill drawer and eating pacman

%slightly glitchy background
import GUI
colourback (black)
cls
process
playmusic
Music.PlayFile ("intro.mp3")
end playmusic
fork playmusic
var font : int
font := Font.New ("serif:25")
var font2 : int
font2 := Font.New ("serif:13")
Draw.Text ("Welcome To Pacman", 180, 250, font, red)
Draw.Text ("To win the game, collect 10 pills without dying of boredom", 130, 200, font2, red)

delay (1000)
cls

/*
locate (1,1)
var timeRunning : int
timeRunning := Time.Elapsed
put "This program has run ", timeRunning, " milliseconds" */
% y of Pacman's centre
var y : int := 200
% x of Pacman's centre
var x : int :=200
% direction Pacman moves
var dx, dy : int :=0
% size of mouth
var mouth : int := 0

var dir : int := 0
var a,b,c,d : boolean :=false
var chars : array char of boolean

var pill_x : int := 600
var pill_y : int := 350
var pill_x1 : int := 250
var pill_y1 : int := 350
var pill_x2 : int := 500
var pill_y2 : int := 100
var ballx, bally, ballrad : int % ball on leftside x, y and radius for both
var ballx1, bally1 : int % ball on right side radius
var rightleft : int
rightleft := 1
randint (ballx, 60, 260) % random points for leftside ball
randint (bally,60, 340)

randint (ballx1,380 ,580) % random points for rightside ball
randint (bally1, 60, 340)
%Where the game starts
loop
loop

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Random pills
if rightleft = 0 then
drawfilloval (ballx, bally, 5,5, red)

elsif rightleft = 1 then
drawfilloval (ballx1, bally1, 5,5, red)
end if

% to get packman to eat left ball
if (x - ballx) < 8 and (x - ballx) > -8 and (y - bally) < 8 and (y - bally) > -8 then
randint (ballx, 60, 260) randint (bally,60, 340) rightleft := 1
end if

% to get pacman to eat right ball
if (x - ballx1) < 8 and (x - ballx1) > -8 and (y - bally1) < 8 and (y - bally1) > -8 then
randint (ballx1,380 ,580) randint (bally1, 60, 340) rightleft := 0
end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Random pills
%border
drawfillbox (0, 0, 20, 420, green)
drawfillbox (20, 420, 620, 380, green)
drawfillbox (640, 400, 620, 20, green)
drawfillbox (640, 0, 20, 20, green)
%Draws pacman
drawfillarc (x, y, 18, 18, mouth + dir, -mouth + dir, yellow)
delay (5)
%Draws pacmans mouth
drawfillarc (x, y, 18, 18, mouth + dir, -mouth + dir, black)
if whatdotcolor ( x, y+25 ) =(47) then
y:=y-1
elsif whatdotcolor ( x, y-25 ) =(47) then
y:=y+1
elsif whatdotcolor ( x+25, y) =(47) then
x:=x-1
elsif whatdotcolor ( x-25, y ) =(47) then
x:=x+1
end if
% If user presses a key

% Reads the key pressed
Input.KeyDown (chars)

if chars (KEY_RIGHT_ARROW)then
a:=true % Pacman will go right, also what makes him not go through
b:=false
c:=false
d:=false
dir:=0
end if

if chars (KEY_UP_ARROW) then
a:=false
b:=true
c:=false
d:=false
dir:=90
end if
if chars (KEY_LEFT_ARROW) then
a:=false
b:=false
c:=true
d:=false
dir:=180
end if
if chars (KEY_DOWN_ARROW) then
a:=false
b:=false
c:=false
d:=true
dir:=270
end if
if a=true then
x:=x+1
end if
if b=true then
y:=y+1
end if
if c=true then
x:=x-1
end if
if d=true then
y:=y-1
end if
% IAMAPENIS%

if x=maxx-38 then
x:=x-1
end if
if y=maxy-38 then
y:=y-1
end if
if x=38 then
x:=x+1
end if
if y=38 then
y:=y+1
end if
% move Pacman's centre depending on
x := x + dx
% the value of dx and dy
y := y + dy

% change size of the mouth
mouth := mouth mod 45 + 1
% Middle walls
Draw.FillBox (300, 23, 312, 150, (47))
Draw.FillBox (300, 250, 312, 420, (47))

% Draws the pills i pop

Draw.FillOval (pill_x, pill_y, 0, 0, blue)
if Math.Distance (x, y, pill_x, pill_y) < 20 then
pill_x := 0
pill_y := 0

if pill_x=0 or pill_y=0 then
Draw.FillOval (pill_x1, pill_y1,0, 0, blue)
if Math.Distance (x, y, pill_x1 ,pill_y1) < 20 then
pill_x1 := 0
pill_y1 := 0
delay (500)
if pill_x1=0 or pill_y1=0 then
Draw.FillOval (pill_x2, pill_y2, 0, 0, blue)
if Math.Distance (x, y, pill_x2 ,pill_y2) < 20 then
pill_x2 := 0
pill_y2 := 0

end if

end if
end if
end if




mouth := mouth mod 45 + 1 % change size of the mouth
drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, yellow)
delay (50)
drawfillarc (x, y, 20, 20, mouth + dir, -mouth + dir, black)
x := x + dx % move Pacman's centre depending on
y := y + dy
end if
end loop
end loop
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  [ 3 Posts ]
Jump to:   


Style:  
Search: