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

Username:   Password: 
 RegisterRegister   
 Turing (Gravity Guy Game) HELP
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Katanakama9




PostPosted: Wed May 13, 2015 6:34 pm   Post subject: Turing (Gravity Guy Game) HELP

What is it you are trying to achieve?
I need to create game loosely based on Gravity Guy game. Where the player (small square) can change gravity to all 4 directions (using arrow keys) and collect coins and avoid squares. It also should have boundaries and if it goes out of the you lose.


What is the problem you are having?
I need to fill pre-made parts of the program by using provided procedure names.


Describe what you have tried to solve this problem
I can't figure out the processes. especially order of multidimensional arrays and procedures. (Too Confused)

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is the pre made code to fill in:


%***********************************************************************
% THE ANTI-GRAVITY GAME
%
% Capture all the coins to win while avoiding crashing into obstacles or
% the edge of the screen.
%
% You can move left and right using the arrow keys; pressing any other
% key will invert gravity (that is, make up become down and down become
% up, so you you will begin falling in the opposite direction).
%***********************************************************************

% Set the screen to be 600 x 600 pixels, and to only repaint the monitor
% when View.Update is called (keep track of all graphical changes off the
% monitor until View.Update is called)--this prevents flickering
setscreen ("graphics:600;600,offscreenonly")

% The size of the obstacles the ship can run into, in pixels
const OBSTACLE_WIDTH : int := maxx div 10
const OBSTACLE_HEIGHT : int := maxy div 10

% The size of the player and coins the player collects, in pixels
const PLAYER_SIZE : int := 10
const COIN_SIZE : int := 20

% The number of obstacles the player must avoid, and the number of
% coins the player must capture before winning the game
const NUM_OBSTACLES : int := 3
const NUM_COINS : int := 3

% This is just a two-dimensional game (up/down and left/right)
const NUM_DIMENSIONS : int := 2

% The position of all the obstacles onscreen; there is one index
% in the first dimension of the array for each obstacle onscreen;
% the array's second dimension gives the x (second-dimension index 1)
% and y (second-dimension index 2) coordinate of that obstacle's
% bottom left corner, in pixels
var map : array 1 .. NUM_OBSTACLES, 1 .. NUM_DIMENSIONS of int

% The position of all the coins onscreen; there is one index in the
% first dimension of the array for each coin onscreen; the array's
% second dimension gives the x (second-dimension index 1) and
% y (second-dimension index 2) coordinate of that coin's centre,
% in pixels
var coins : array 1 .. NUM_COINS, 1 .. NUM_DIMENSIONS of int

% Player 1's color; there is only one player at the moment
const PLAYER_1 : int := 1

% The ship's thrust left or right (in fractions of pixels) when the
% left or right arrow is pressed
const THRUST : real := 0.2

% The error-margin (in fractions of pixels) in the ship's thrust, so
% that pressing the left or right arrow doesn't produce exactly the
% same amount of thrust every single time
const THR_ERR : real := 0.04

% The x and y coordinates of the centre of player 1's ship (in pixels)
var x : real := maxx div 2
var y : real := maxy div 2

% The x and y velocity of player 1's ship (in pixels)
var dx : real := 0
var dy : real := 0
var gravity : real := -0.005

% Player 1's score--increase it by 1 with every coin hit
var score : int := 0

% The number of coins remaining for the player to hit before winning
% the game
var coins_remaining : int := NUM_COINS

% The number of milliseconds that have passed from the time the RUN
% button was pressed--use this to smooth out the player movement
var runTime : int := 0

% This procedure prints the player's score neatly at the top of the screen
procedure printScore (score : int)
% Complete this procedure
end printScore

% -------------------------------------------------------------------------
% initMap
% This procedure initializes the locations of all the obstacles; in the
% example game, the locations were randomly assigned, but you can locate
% them however you want.
% Parameters
% map: the array containing the coordinates of all the obstacles
% -------------------------------------------------------------------------
procedure initMap (var map : array 1 .. *, 1 .. * of int)
% Complete this procedure
end initMap

% -------------------------------------------------------------------------
% initCoins
% This procedure initializes the locations of all the coins; in the
% example game, the locations were randomly assigned, but you can locate
% them however you want.
% Parameters
% coins: the array containing the coordinates of all the coins
% -------------------------------------------------------------------------
procedure initCoins (var coins : array 1 .. *, 1 .. * of int)
% Complete this procedure
end initCoins

% -------------------------------------------------------------------------
% drawMap
% This procedure draws all the obstacles onscreen based on their positions
% in the array of obstacles.
% Parameters
% map: the array containing the coordinates of all the obstacles
% -------------------------------------------------------------------------
procedure drawMap (m : array 1 .. *, 1 .. * of int)
% Complete this procedure
end drawMap

% -------------------------------------------------------------------------
% drawCoins
% This procedure draws all the coins onscreen based on their positions
% in the array of coins.
% Parameters
% coins: the array containing the coordinates of all the coins
% -------------------------------------------------------------------------
procedure drawCoins (coins : array 1 .. *, 1 .. * of int)
% Complete this procedure
end drawCoins

% -------------------------------------------------------------------------
% drawPlayer
% This procedure draws a player onscreen at the x and y coordinates given.
% Parameters
% x: the x coordinate of the player
% y: the y coordinate of the player
% number: the player number (e.g., Player 1)
% -------------------------------------------------------------------------
procedure drawPlayer (x, y, number : int)
% Complete this procedure
end drawPlayer

% -------------------------------------------------------------------------
% isWall
% This function determines if the player has hit either an obstacle or the
% edge of the screen.
% Parameters
% map: the array containing the coordinates of all the obstacles
% x: the x coordinate of the player, in pixels
% y: the y coordinate of the player, in pixels
% Result
% true if the player's x and y mean it has hit an obstacle or the edge;
% false if not
% -------------------------------------------------------------------------
function isWall (map : array 1 .. *, 1 .. * of int, x, y : int) : boolean
var hitSomething : boolean := false
% Complete this function
result hitSomething
end isWall

% -------------------------------------------------------------------------
% isCoin
% This function determines if the player has hit a coin.
% Parameters
% coins: the array containing the coordinates of all the coins
% x: the x coordinate of the player, in pixels
% y: the y coordinate of the player, in pixels
% Result
% zero if the player has not hit a coin; the coin number hit otherwise
% -------------------------------------------------------------------------
function isCoin (var coins : array 1 .. *, 1 .. * of int, x, y : int) : int
var hitCoinNumber : int := 0
% Complete this function
result hitCoinNumber
end isCoin

% -------------------------------------------------------------------------
% updateMovement
% This procedure changes either the player's velocity or the direction of
% gravity depending on whether the left or right arrow or some other key
% has been pressed.
% Parameters
% ch: the last key pressed
% dx: the x-directional velocity (left/right) of the player
% gravity: the acceleration due to gravity (up/down)
% -------------------------------------------------------------------------
procedure updateMovement (ch : string (1), var dx, gravity : real)
% Complete this procedure
end updateMovement

% -------------------------------------------------------------------------
% updateCoins
% Once it has been determined that a coin has been hit, this procedure changes
% the number of coins remaining and removes the coin just hit from the array
% of coins.
% Parameters
% coinHit: the number of the coin that was hit
% coins: the array containing the coordinates of all the coins
% coinsRemaining: the number of coins remaining before the player wins
% -------------------------------------------------------------------------
procedure updateCoins (coinHit : int, var coins : array 1 .. *, 1 .. * of int, var coins_remaining : int)
% Complete this procedure
end updateCoins

% -------------------------------------------------------------------------
% endGame
% This procedure wraps up the game by pausing the screen for a few seconds
% before clearing it, determining if the player won or lost, and printing
% a message neatly saying that the player either won or lost.
% Parameters
% coinsRemaining: the number of coins that remained for the player to hit
% when the game finished
% -------------------------------------------------------------------------
procedure endGame (coins_remaining : int)
% Complete this procedure
end endGame


% ****************************************************
% YOU DO NOT NEED TO CHANGE ANYTHING FROM HERE ON DOWN
% UNLESS YOU ARE ADDING YOUR OWN FEATURES (AND EVEN
% THEN YOU MAY NOT NEED TO)
% ****************************************************

initMap (map)
initCoins (coins)

loop
cls

printScore (score)
drawMap (map)
drawPlayer (round (x), round (y), PLAYER_1)

exit when isWall (map, round (x), round (y)) or coins_remaining = 0

drawCoins (coins)

if hasch then
var ch : string (1)
getch (ch)
updateMovement (ch, dx, gravity)
end if

var coinHit : int := isCoin (coins, round (x), round (y))
if coinHit not= 0 then
score := score + 1
updateCoins(coinHit, coins, coins_remaining)
end if

if Time.Elapsed - runTime > 5 then
x := x + dx
y := y + dy
dy := dy + gravity
runTime := Time.Elapsed
end if

View.Update
end loop

endGame (coins_remaining)


Turing:





Please specify what version of Turing you are using
I use Turing 4.11
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed May 13, 2015 7:54 pm   Post subject: RE:Turing (Gravity Guy Game) HELP

Quote:
I can't figure out the processes.


Can you figure out any of them? What have you tried so far?
Katanakama9




PostPosted: Wed May 13, 2015 8:01 pm   Post subject: RE:Turing (Gravity Guy Game) HELP

Well, our teacher gave us this code with procedure names, vars and some values. In general I don't understand how can I make player (square) to move with thrust and connect this code with given procedures.
Insectoid




PostPosted: Thu May 14, 2015 5:06 am   Post subject: RE:Turing (Gravity Guy Game) HELP

Then start with the other procedures, like drawMap, initMap, etc. The best way to learn this stuff is to screw around with the code and see what happens.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: