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

Username:   Password: 
 RegisterRegister   
 My 2ed Program ---PinBall---
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Holec




PostPosted: Wed Jan 17, 2007 4:51 pm   Post subject: My 2ed Program ---PinBall---

This is my first pinball game , ( i know some of my collisions are messed up) but just wondering if there are any improvments that i could make (other then a starting screen, i have it on but i cleared it up so it dosent get in the way) , so suggestions would be help-full. And if possable i would like to get help on my collisions there a "little" bugged {PS: please dont be so critical only my first year of programming, and im trying to enjoy it Surprised , learning most of it on my own but it would help to get some good advice. }

--enjoy--




const TOP := maxy + 300

var hitBottom, hitLeft, hitRight, hitTop, hitPaddle, hitPaddleL, hitPaddleR : boolean
var DT : int

var xdir : int
var ydir : int

var kolor : int

var x : int
var y : int
var r : int

var score:int

var WinID : int

var paddleX, paddleY, paddleSize, paddleSpeed : int
var font1, font2 : int

var iWindow : int := Window.Open ("graphics: max; max, nocursor, nobuttonbar")
colourback (black)
cls
drawfilloval (540, 620, 60, 60, red)

drawfilloval (300, 280, 60, 60, 24)
drawfilloval (230, 280, 50, 50, black)
drawfilloval (370, 280, 50, 50, black)
drawfilloval (300, 210, 50, 50, black)
drawfilloval (300, 350, 50, 50, black)

Draw.FillArc (310, 620, 155, 100, 25, 150, brightred)

Draw.FillBox (0, 0, 40, maxy, 46)
Draw.FillBox (0, maxy, maxx - 400, maxy - 40, 46)
Draw.FillBox (maxx - 400, maxy, maxx - 440, 0, 46)
drawfillbox (0, maxy, 100, maxy - 100, 46)
drawfilloval (60, maxy - 70, 50, 50, black)
drawfilloval (501, 583, 70, 70, black)


var x9 : array 1 .. 3 of int := init (410, 330, 340)
var y9 : array 1 .. 3 of int := init (480, 500, 450)
Draw.FillPolygon (x9, y9, 3, red)


drawfillbox (40, 400, 135, 500, 53)
drawfillbox (60, 430, 135, 475, black)
drawfillbox (60, 400, 110, 475, black)
drawfillbox (111, 375, 150, 400, 53)
drawfillbox (135, 250, 150, 375, 53)
drawfilloval (55, 345, 10, 10, blue)
drawfilloval (105, 330, 10, 10, blue)
drawfilloval (65, 280, 10, 10, blue)

drawfilloval (350, 570, 10, 10, blue)
drawfilloval (430, 575, 10, 10, blue)
drawfilloval (385, 530, 10, 10, blue)


Draw.ThickLine (500,440,570,500,2,red)
Draw.ThickLine (500,380,570,440,2,red)
drawfilloval (550,450,10,10,brightblue)


procedure makePaddle (var paddlePicID, NoPaddlePicID : int)
Draw.FillBox (paddleX, paddleY, paddleX + paddleSize, paddleY + 5, black)
NoPaddlePicID := Pic.New (paddleX, paddleY, paddleX + paddleSize, paddleY + 5)
Draw.FillBox (paddleX, paddleY, paddleX + paddleSize, paddleY + 5, yellow)
paddlePicID := Pic.New (paddleX, paddleY, paddleX + paddleSize, paddleY + 5)
end makePaddle

procedure movePaddle (paddlePicID, NoPaddlePicID, x1, x2 : int)
Pic.Draw (NoPaddlePicID, x1, paddleY, picCopy)
Pic.Draw (paddlePicID, x2, paddleY, picCopy)
end movePaddle

process paddle
var paddlePicID, NoPaddlePicID : int
var mouseX, mouseY, button, newX : int
makePaddle (paddlePicID, NoPaddlePicID)
Pic.Draw (paddlePicID, paddleX, paddleY, picCopy)

loop
Mouse.Where (mouseX, mouseY, button)
if (mouseX < maxx - 5 - paddleSize div 2) then
newX := max (mouseX - paddleSize div 2, 5)
else
newX := maxx - 5 - paddleSize
end if
if abs (newX - paddleX) > 2 then
movePaddle (paddlePicID, NoPaddlePicID, paddleX, newX)
paddleX := newX
end if
end loop
end paddle


DT := 5

paddleX := 5
paddleY := 7
paddleSize := 50
paddleSpeed := 20

xdir := 1
ydir := Rand.Int (1, 100)
kolor := brightred %colourset (rnd)
r := 5
score:=0

x := maxx div 2 - 200
const a := -0.006
var yAxis := maxx div 2
var bump := Rand.Int (70, 900)
y := round (a * (yAxis - x) ** 2 + bump)

fork paddle


% MAIN PROGRAM

loop
color (white)
locate (3,80)
put "Score: ", score
delay (DT)
ydir := -round (a * (yAxis - x) ** 2 + bump) + round (a * (yAxis - x - xdir) ** 2 + bump)

hitPaddle := false
for j : x - r + xdir .. x + r + xdir
if whatdotcolour (j, 12) = yellow and y - r + ydir <= 12 then
hitPaddle := true
end if
exit when hitPaddle
end for

if (hitPaddle = true) then % hits paddle
Draw.FillOval (x, y, r, r, black)

bump := round (-450 * abs (((paddleX + paddleSize div 2) - x) / (paddleSize div 2)) + 450)

if xdir > 0 then
yAxis := round (-sqrt (abs ((y - bump) / a)) + x)
else
yAxis := round (sqrt (abs ((y - bump) / a)) + x)
end if

xdir := xdir * -1

else
% check for boundaries
hitBottom := (y <= 5 + r - ydir)
hitTop := (y + ydir >= TOP - r - ydir - 5)
hitLeft := (x <= 5 + r - xdir)
hitRight := (x >= maxx - 5 - r - xdir)
if (hitBottom = true) then
exit
elsif (hitTop = true) then
yAxis := 2 * x - yAxis
elsif hitLeft = true then
yAxis := -yAxis
xdir := -xdir
elsif hitRight = true then
yAxis := maxx + (maxx - yAxis)
xdir := -xdir
end if
Draw.FillOval (x, y, r, r, black)
end if
x := x + xdir
y := round (a * (yAxis - x) ** 2 + bump)
Draw.FillOval (x, y, r, r, kolor)

if whatdotcolour (x - 11, y) not= 7 then
xdir *= -1
score:=score+10
end if
if whatdotcolour (x + 11, y) not= 7 then
xdir *= -1
score:=score+10
end if
if whatdotcolour (x, y - 11) not= 7 and y - 11 > 0 then
ydir *= -1
score:=score+10
end if
if whatdotcolour (x, y + 11) not= 7 then
ydir *= -1
score:=score+10
end if


end loop

if score>=100 then
cls
locate (20,20)
put "Level 2"
delay (2000)
cls
DT:=4
end if

if score>=200 then
cls
locate (20,20)
put "Level 3"
delay (2000)
cls
DT:=3
end if

%end

========================================
Also i know my lvls are screwed, also if your ball does not appear or the ball is stuck into two objects; reset the game (another bug)
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Wed Jan 17, 2007 5:43 pm   Post subject: RE:My 2ed Program ---PinBall---

please use code tags, and the game is flickery. try useing View.Update and setscreen offscreenonly
Holec




PostPosted: Wed Jan 17, 2007 5:52 pm   Post subject: RE:My 2ed Program ---PinBall---

kk, i will keep the tags in mind, but i thought i made my varables pretty clear but might just might be in my opinion. And i dont know too much about flickering, only problem im having so far is the ball ocasionally flickers but again, just might be my computer.
CodeMonkey2000




PostPosted: Wed Jan 17, 2007 6:02 pm   Post subject: Re: My 2ed Program ---PinBall---

code:
const TOP := maxy + 300

var hitBottom, hitLeft, hitRight, hitTop, hitPaddle, hitPaddleL, hitPaddleR : boolean
var DT : int

var xdir : int
var ydir : int

var kolor : int

var x : int
var y : int
var r : int

var score:int

var WinID : int

var paddleX, paddleY, paddleSize, paddleSpeed : int
var font1, font2 : int

var iWindow : int := Window.Open ("graphics: max; max, nocursor, nobuttonbar")
colourback (black)
cls
drawfilloval (540, 620, 60, 60, red)

drawfilloval (300, 280, 60, 60, 24)
drawfilloval (230, 280, 50, 50, black)
drawfilloval (370, 280, 50, 50, black)
drawfilloval (300, 210, 50, 50, black)
drawfilloval (300, 350, 50, 50, black)

Draw.FillArc (310, 620, 155, 100, 25, 150, brightred)

Draw.FillBox (0, 0, 40, maxy, 46)
Draw.FillBox (0, maxy, maxx - 400, maxy - 40, 46)
Draw.FillBox (maxx - 400, maxy, maxx - 440, 0, 46)
drawfillbox (0, maxy, 100, maxy - 100, 46)
drawfilloval (60, maxy - 70, 50, 50, black)
drawfilloval (501, 583, 70, 70, black)


var x9 : array 1 .. 3 of int := init (410, 330, 340)
var y9 : array 1 .. 3 of int := init (480, 500, 450)
Draw.FillPolygon (x9, y9, 3, red)


drawfillbox (40, 400, 135, 500, 53)
drawfillbox (60, 430, 135, 475, black)
drawfillbox (60, 400, 110, 475, black)
drawfillbox (111, 375, 150, 400, 53)
drawfillbox (135, 250, 150, 375, 53)
drawfilloval (55, 345, 10, 10, blue)
drawfilloval (105, 330, 10, 10, blue)
drawfilloval (65, 280, 10, 10, blue)

drawfilloval (350, 570, 10, 10, blue)
drawfilloval (430, 575, 10, 10, blue)
drawfilloval (385, 530, 10, 10, blue)


Draw.ThickLine (500,440,570,500,2,red)
Draw.ThickLine (500,380,570,440,2,red)
drawfilloval (550,450,10,10,brightblue)


procedure makePaddle (var paddlePicID, NoPaddlePicID : int)
Draw.FillBox (paddleX, paddleY, paddleX + paddleSize, paddleY + 5, black)
NoPaddlePicID := Pic.New (paddleX, paddleY, paddleX + paddleSize, paddleY + 5)
Draw.FillBox (paddleX, paddleY, paddleX + paddleSize, paddleY + 5, yellow)
paddlePicID := Pic.New (paddleX, paddleY, paddleX + paddleSize, paddleY + 5)
end makePaddle

procedure movePaddle (paddlePicID, NoPaddlePicID, x1, x2 : int)
Pic.Draw (NoPaddlePicID, x1, paddleY, picCopy)
Pic.Draw (paddlePicID, x2, paddleY, picCopy)
end movePaddle

process paddle
var paddlePicID, NoPaddlePicID : int
var mouseX, mouseY, button, newX : int
makePaddle (paddlePicID, NoPaddlePicID)
Pic.Draw (paddlePicID, paddleX, paddleY, picCopy)

loop
Mouse.Where (mouseX, mouseY, button)
if (mouseX < maxx - 5 - paddleSize div 2) then
newX := max (mouseX - paddleSize div 2, 5)
else
newX := maxx - 5 - paddleSize
end if
if abs (newX - paddleX) > 2 then
movePaddle (paddlePicID, NoPaddlePicID, paddleX, newX)
paddleX := newX
end if
end loop
end paddle


DT := 5

paddleX := 5
paddleY := 7
paddleSize := 50
paddleSpeed := 20

xdir := 1
ydir := Rand.Int (1, 100)
kolor := brightred %colourset (rnd)
r := 5
score:=0

x := maxx div 2 - 200
const a := -0.006
var yAxis := maxx div 2
var bump := Rand.Int (70, 900)
y := round (a * (yAxis - x) ** 2 + bump)

fork paddle


% MAIN PROGRAM

loop
color (white)
locate (3,80)
put "Score: ", score
delay (DT)
ydir := -round (a * (yAxis - x) ** 2 + bump) + round (a * (yAxis - x - xdir) ** 2 + bump)

hitPaddle := false
for j : x - r + xdir .. x + r + xdir
if whatdotcolour (j, 12) = yellow and y - r + ydir <= 12 then
hitPaddle := true
end if
exit when hitPaddle
end for

if (hitPaddle = true) then % hits paddle
Draw.FillOval (x, y, r, r, black)

bump := round (-450 * abs (((paddleX + paddleSize div 2) - x) / (paddleSize div 2)) + 450)

if xdir > 0 then
yAxis := round (-sqrt (abs ((y - bump) / a)) + x)
else
yAxis := round (sqrt (abs ((y - bump) / a)) + x)
end if

xdir := xdir * -1

else
% check for boundaries
hitBottom := (y <= 5 + r - ydir)
hitTop := (y + ydir >= TOP - r - ydir - 5)
hitLeft := (x <= 5 + r - xdir)
hitRight := (x >= maxx - 5 - r - xdir)
if (hitBottom = true) then
exit
elsif (hitTop = true) then
yAxis := 2 * x - yAxis
elsif hitLeft = true then
yAxis := -yAxis
xdir := -xdir
elsif hitRight = true then
yAxis := maxx + (maxx - yAxis)
xdir := -xdir
end if
Draw.FillOval (x, y, r, r, black)
end if
x := x + xdir
y := round (a * (yAxis - x) ** 2 + bump)
Draw.FillOval (x, y, r, r, kolor)

if whatdotcolour (x - 11, y) not= 7 then
xdir *= -1
score:=score+10
end if
if whatdotcolour (x + 11, y) not= 7 then
xdir *= -1
score:=score+10
end if
if whatdotcolour (x, y - 11) not= 7 and y - 11 > 0 then
ydir *= -1
score:=score+10
end if
if whatdotcolour (x, y + 11) not= 7 then
ydir *= -1
score:=score+10
end if


end loop

if score>=100 then
cls
locate (20,20)
put "Level 2"
delay (2000)
cls
DT:=4
end if

if score>=200 then
cls
locate (20,20)
put "Level 3"
delay (2000)
cls
DT:=3
end if

%end

here your code with offscreenonly and View.Update Very Happy
Holec




PostPosted: Wed Jan 17, 2007 6:06 pm   Post subject: RE:My 2ed Program ---PinBall---

Thx ,lol i was wrong using offscreenonly and View.Update you can see the diffrence, thx
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: