Computer Science Canada Assistance Request Vertdragon |
Author: | vertdragon23 [ Tue Oct 22, 2013 1:22 pm ] |
Post subject: | Assistance Request Vertdragon |
What is it you are trying to achieve? Making a pacman game but need some help with a few errors. What is the problem you are having? <Setscreen offscreenonly is acting weird and program doesnt work without it?> Describe what you have tried to solve this problem Asked many people. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) <Answer Here> import GUI View.Set ("offscreenonly") var chars : array char of boolean var x, y : int var stateofpac : boolean var font : int process playmusic Music.PlayFile ("intro.mp3") end playmusic fork playmusic x := 120 y := 120 stateofpac := true procedure game1 loop Input.KeyDown (chars) if chars (KEY_RIGHT_ARROW) then if stateofpac = true then drawfilloval (x, y, 20, 20, yellow) x := x + 5 stateofpac := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 310, 40, black) x := x + 5 stateofpac := true end if elsif chars (KEY_LEFT_ARROW) then if stateofpac = true then drawfilloval (x, y, 20, 20, yellow) x := x - 5 stateofpac := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 130, 210, black) x := x - 5 stateofpac := true end if elsif chars (KEY_DOWN_ARROW) then if stateofpac = true then drawfilloval (x, y, 20, 20, yellow) y := y - 5 stateofpac := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 230, 310, black) y := y - 5 stateofpac := true end if elsif chars (KEY_UP_ARROW) then if stateofpac = true then drawfilloval (x, y, 20, 20, yellow) y := y + 5 stateofpac := false else drawfilloval (x, y, 20, 20, yellow) drawfillarc (x, y, 20, 20, 70, 120, black) y := y + 5 stateofpac := true end if else drawfilloval (x, y, 20, 20, yellow) end if View.UpdateArea (x - 45, y - 45, x + 45, y + 45) drawfilloval (x, y, 45, 45, black) delay (50) end loop end game1 procedure leave quit end leave colorback (black) cls font := Font.New ("serif:25") Draw.Text ("Welcome to Pacman", 180, 250, font, red) delay (1000) var game : int := GUI.CreateButton (200, 20, 10, "Start game", game1) delay (2000) cls loop exit when GUI.ProcessEvent end loop var leave1 : int := GUI.CreateButton (100, 20, 0, "Quit", leave) [/syntax] Please specify what version of Turing you are using 4.1.1 (latest) |
Author: | Dreadnought [ Tue Oct 22, 2013 6:20 pm ] |
Post subject: | Re: Assistance Request Vertdragon |
When using offscreenonly, you need to call View.Update when you want to update the screen. How exactly is it "acting weird"? |
Author: | vertdragon23 [ Wed Oct 23, 2013 5:46 pm ] |
Post subject: | RE:Assistance Request Vertdragon |
I am going to re code the base and structure of this program as this one is very buggy, the new one is not gonna have a menu because that makes turing glitchy. |
Author: | vertdragon23 [ Wed Oct 23, 2013 9:11 pm ] |
Post subject: | RE:Assistance Request Vertdragon |
This is the new code it works, If anyone knows how to make the pacman continue in the direction last clicked, that would be very helpful. %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:20") Draw.Text ("Welcome To Pacman", 180, 250, font, 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 %Read More % size of mouth var mouth : int := 0 var dir : int := 0 var key : string (1) %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 (10) %Draws pacmans mouth drawfillarc (x, y, 18, 18, mouth + dir, -mouth + dir, black) % If user presses a key if hasch then % Reads the key pressed getch (key) if ord (key) = 205 then if x < maxx-41 then % Pacman will go right, also what makes him not go through dir := 0 dx := 8 dy := 0 else dx := 0 end if end if if ord (key) = 200 then if y < 355 then % Pacman will go up, also what makes him not go through dir := 90 dx := 0 dy := 8 else dy := 0 end if end if if ord (key) = 203 then if x > 41 then % Pacman will go left, also what makes him not go through dir := 180 dx := -8 dy := 0 else dx := 0 end if end if if ord (key) = 208 then if y > 41 then % Pacman will go down, also what makes him not go through dir := 270 dx := 0 dy := -8 else dy := 0 end if end if % move Pacman's centre depending on x := x + dx % the value of dx and dy y := y + dy end if % change size of the mouth mouth := mouth mod 45 + 1 % Draws the walls in the middle Draw.FillBox (300, 1, 312, 150, green) Draw.FillBox (300, 255, 312, 490, green) end loop |
Author: | Raknarg [ Wed Oct 23, 2013 9:28 pm ] |
Post subject: | RE:Assistance Request Vertdragon |
I don't know if you've tried using this already, but all you need to do is store the direction and just have him constantly going that direction. Rather than have the keys decide his movement, they simply decide the direction |
Author: | vertdragon23 [ Wed Oct 23, 2013 9:35 pm ] |
Post subject: | RE:Assistance Request Vertdragon |
Thanks raknarg that makes a little sense but can you please elaborate? Like are you saying that instead of using the ascii codes to move the pacman, I should use (e.g key.down) or getch? |
Author: | Raknarg [ Wed Oct 23, 2013 10:34 pm ] | ||
Post subject: | RE:Assistance Request Vertdragon | ||
There's different things you can do. One of my favorites:
hasch is only true when you've entered a key. SO once you enter a key, we look at that key. If it is w a s or d, we set the dx and dy values accordingly. Then, the circles position is changed by dx and dy, and as you can see remembers what direction to go and keep going regardless of input. |
Author: | vertdragon23 [ Wed Oct 23, 2013 10:43 pm ] |
Post subject: | RE:Assistance Request Vertdragon |
This assignment is due tomorrow and I've worked all day. If someone could help with pacmans continuous movement in last arrow key clicked, and help me fix the pills, I need it to be like a pill appears on right side, then left, then right, randomly. Help would be greatly appreciated. %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 % size of mouth var mouth : int := 0 var dir : int := 0 var key : string (1) 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 (10) %Draws pacmans mouth drawfillarc (x, y, 18, 18, mouth + dir, -mouth + dir, black) % If user presses a key if hasch then % Reads the key pressed getch (key) if ord (key) = 205 then if x < maxx-41 then % Pacman will go right, also what makes him not go through dir := 0 dx := 8 dy := 0 else dx := 0 end if end if if ord (key) = 200 then if y < 355 then % Pacman will go up, also what makes him not go through dir := 90 dx := 0 dy := 8 else dy := 0 end if end if if ord (key) = 203 then if x > 41 then % Pacman will go left, also what makes him not go through dir := 180 dx := -8 dy := 0 else dx := 0 end if end if if ord (key) = 208 then if y > 41 then % Pacman will go down, also what makes him not go through dir := 270 dx := 0 dy := -8 else dy := 0 end if end if % move Pacman's centre depending on x := x + dx % the value of dx and dy y := y + dy end if % change size of the mouth mouth := mouth mod 45 + 1 % Middle walls Draw.FillBox (300, 1, 312, 150, green) Draw.FillBox (300, 255, 312, 490, green) % 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 (5) 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 |