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

Username:   Password: 
 RegisterRegister   
 Help with Breakout Game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ncmitchell




PostPosted: Thu Jan 12, 2012 6:34 pm   Post subject: Help with Breakout Game

I'm making a Breakout game for my grade 11 computer science class, and my code isn't nearly finished, but I'm stuck on how to make it hit the paddle and bounce back up again. I've tried using whatdotcolour, but I haven't been able to make that work. All help is appreciated!! Thank you.

View.Set ("offscreenonly")

const PaddleColour := 102
const EscKey := chr (27)
const up := 0
const down := 1
const BallRad := 6
const BallColour := 26

setscreen ("graphics:800,800")

% DECLARE VARIABLES
var map : array 1 .. 20, 1 .. 20 of int
var NumRows, NumCols, font1, font2 : int
var mx, my, button : int
var x, y, Paddlex1, Paddlex2, Paddley1, Paddley2 : int
var Ballx, Bally, direction : int
var level, lives : int

level := 0

font1 := Font.New ("Arial:25:bold")
font2 := Font.New ("Arial:30:bold")

procedure ReadMap (filename : string, var map : array 1 .. *, 1 .. * of int, var NumRows, NumCols : int)
var stream : int

% OPEN FILE
open : stream, filename, get
if stream not= 0 then
get : stream, NumRows
get : stream, NumCols

for row : 1 .. NumRows
for col : 1 .. NumCols
get : stream, map (row, col)
end for
end for

% CLOSE THE FILE
close : stream
end if
end ReadMap

procedure DrawMap (map : array 1 .. *, 1 .. * of int, NumRows, NumCols : int)
var x, y : int
y := maxy - 40
for row : 1 .. NumRows
x := 0
for col : 1 .. NumCols
% BLUE BORDER
if map (row, col) = 54 then
drawfillbox (x, y, x + 40, y + 40, map (row, col))
% BLACK BACKGROUND
elsif map (row, col) = 7 then
drawfillbox (x, y, x + 40, y + 40, map (row, col))
end if
x := x + 40
end for
y := y - 40
end for
end DrawMap

procedure calculatexy (var x, y : real, angle, step : real)
x := step * cosd (angle) + x
y := step * sind (angle) + y
end calculatexy

ReadMap ("map.txt", map, NumRows, NumCols)

DrawMap (map, NumRows, NumCols)

% MAIN SCREEN
Font.Draw ("B", 40, maxy - 30, font2, 12)
Font.Draw ("R", 65, maxy - 30, font2, 52)
Font.Draw ("E", 90, maxy - 30, font2, 47)
Font.Draw ("A", 115, maxy - 30, font2, 42)
Font.Draw ("K", 140, maxy - 30, font2, 14)
Font.Draw ("O", 165, maxy - 30, font2, 35)
Font.Draw ("U", 190, maxy - 30, font2, 46)
Font.Draw ("T", 215, maxy - 30, font2, 80)

Font.Draw ("LEVEL:", 420, maxy - 25, font1, white)
Font.Draw ("LIVES:", 620, maxy - 25, font1, white)

% LEVEL 1 ---------------------------------------------------------------------
setscreen ("nocursor")

% PADDLE COORDINATES
Paddlex1 := 370
Paddley1 := 10
Paddlex2 := 430
Paddley2 := 20

% BALL COORDINATES
Ballx := 400
Bally := 26

% X AND Y COORDINATES
x := 87
y := maxy - 100

% LEVEL AND LIVES SETTING
level := 1
lives := 3

direction := 0

% SET LEVELS
if level = 1 then
Font.Draw ("1", 540, maxy - 25, font1, 12)
elsif level = 2 then
Font.Draw ("2", 540, maxy - 25, font1, 52)
elsif level = 3 then
Font.Draw ("1", 540, maxy - 25, font1, 47)
elsif level = 4 then
Font.Draw ("1", 540, maxy - 25, font1, 42)
elsif level = 5 then
Font.Draw ("1", 540, maxy - 25, font1, 14)
elsif level = 6 then
Font.Draw ("1", 540, maxy - 25, font1, 35)
elsif level = 7 then
Font.Draw ("1", 540, maxy - 25, font1, 46)
elsif level = 8 then
Font.Draw ("1", 540, maxy - 25, font1, 80)
end if

% LIVES SETTING
if lives = 3 then
Font.Draw ("3", 730, maxy - 25, font1, 12)
elsif lives = 2 then
Font.Draw ("2", 730, maxy - 25, font1, 12)
elsif lives = 1 then
Font.Draw ("1", 730, maxy - 25, font1, 12)
end if

% BOXES
for row : 1 .. 13
drawfillbox (x, y, x + 40, y + 15, 12)
x := x + 45
for col : 1 .. 14
drawfillbox (x, y, x + 40, y + 15, 12)
end for
y := y - 20
end for

% DRAW PADDLE AND BALL
drawfillbox (Paddlex1, Paddley1, Paddlex2, Paddley2, PaddleColour)

drawfilloval (Ballx, Bally, BallRad, BallRad, BallColour)

loop
View.Update
% GET MOUSE SIGNAL
mousewhere (mx, my, button)

% ERASE THE PADDLE AND BALL
drawfillbox (Paddlex1, Paddley1, Paddlex2, Paddley2, black)

drawfilloval (Ballx, Bally, BallRad, BallRad, black)

Paddlex1 := mx - 30
Paddlex2 := mx + 30

if direction = 0 then
Ballx := mx
end if

% PADDLE BOUNDARIES
if Paddlex1 <= 80 then
Paddlex1 := 80
end if

if Paddlex2 <= 140 then
Paddlex2 := 140
end if

if Paddlex2 >= maxx - 80 then
Paddlex2 := maxx - 80
end if

if Paddlex1 >= maxx - 140 then
Paddlex1 := maxx - 140
end if

% BALL BOUNDARIES
if Ballx <= 110 and direction = 0 then
Ballx := 110
end if

if Ballx >= maxx - 110 and direction = 0 then
Ballx := maxx - 110
end if

% DIRECTION SETTINGS
if direction = 1 then
Ballx := Ballx + 5
Bally := Bally + 5
elsif direction = 2 then
Ballx := Ballx + 5
Bally := Bally - 5
elsif direction = 3 then
Ballx := Ballx - 5
Bally := Bally - 5
elsif direction = 4 then
Ballx := Ballx - 5
Bally := Bally + 5
end if

% BLUE BOUNDARY SETTINGS
if Ballx + BallRad >= maxx - 84 then
if direction = 1 then
direction := 4
elsif direction = 2 then
direction := 3
end if
elsif Ballx - BallRad <= 83 then
if direction = 4 then
direction := 1
elsif direction = 3 then
direction := 2
end if
elsif Bally + BallRad >= maxy - 83 then
if direction = 1 then
direction := 2
elsif direction = 4 then
direction := 3
end if
end if

% BEGINNING SETTINGS
if button = down and Ballx = mx then
direction := 1
end if

if whatdotcolour (Ballx, Bally) = 102 then
if direction = 2 and Bally <= 20 then
direction := 1
elsif direction = 3 and Bally <= 20 then
direction := 4
end if
end if

% RE-DRAW THE PADDLE AND BALL
drawfillbox (Paddlex1, Paddley1, Paddlex2, Paddley2, PaddleColour)

drawfilloval (Ballx, Bally, BallRad, BallRad, BallColour)

% TIME DELAY
delay (20)
end loop
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Thu Jan 12, 2012 7:38 pm   Post subject: RE:Help with Breakout Game

i made breakout for my grade 11 final aswell, but i programmed my game vs a.i what are you looking for in general, the code itself or a synopsis of how to write the code?
ncmitchell




PostPosted: Thu Jan 12, 2012 8:10 pm   Post subject: RE:Help with Breakout Game

Either or, the code would probably be easier so that I have a better idea of what I should do, but if you have any help to give that'd be great
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: