User Tools

Site Tools


Sidebar

projects

ntr0 (due 20210825)
pct1 (bonus; due 20210819)
wcp1 (due 20210818)
pct2 (due 20210825)
wcp2 (due 20210825)
lob0 (due 20210901)
pct3 (bonus; due 20210901)
wcp3 (due 20210901)
led0 (due 20210908)
pct4 (due 20210908)
wcp4 (due 20210908)
led1 (due 20210915)
gfo0 (due 20210915)
pct5 (bonus; due 20210915)
wcp5 (due 20210915)
led2 (due 20210922)
pct6 (due 20210922)
wcp6 (due 20210922)
iwb0 (due 20210929)
pct7 (bonus; due 20210929)
wcp7 (due 20210929)
iwb1 (due 20211006)
pct8 (due 20211006)
wcp8 (due 20211006)
iwb2 (due 20211020)
pct9 (bonus; due 20211020)
bwp1 (bonus; due 20211020)
wcp9 (due 20211020)
clr0 (due 20211027)
gfo1 (due 20211027)
pctA (due 20211027)
wcpA (due 20211027)
clr1 (due 20211103)
pctB (bonus; due 20211103)
wcpB (due 20211103)
clr2 (due 20211110)
pctC (due 20211110)
wcpC (due 20211110)
gfo2 (due 20211117)
pctD (bonus; due 20211117)
pctE (bonus; due 20211201)
bwp2 (bonus; due 20211201)
EoCE (due 20211209)
haas:fall2021:c4eng:projects:brickify

This is an old revision of the document!


Corning Community College

ENGR1050 C for Engineers

ACTIVITY: BRICKIFY PONG

Objective

In the past few classes, we have been building and optimizing a pong game with various programming facilities, namely arrays and structs.

Here, we will continue that specific exploration, taking our struct-based code and adding in code for displaying and processing blocks in our game, turning pong into more of a breakout game.

Getting started

We will start this from a blank slate. You will want to:

  • open up TIC-80
  • clear out the sample/demo code (CTRL-a then backspace or delete)
  • go into the sprite editor:
    • select foreground sprites
      • in #257: draw an 8×4 paddle tile, going from edge to edge, and only using the top 4 rows of the tile
      • in #258: in the top left of the tile, draw a 2×2 ball tile
      • in #259: from the top left of the tile, draw a 7×4 brick tile (using only the first 4 rows)
  • proceed back to the code editor to input the code

Header and support function

The first thing you will want to place in your TIC-80 code editor is the top header (switching us to js mode) and the supporting getRandomNumber() function used for determining a random ball direction. You can copy and paste the following into TIC-80:

// program: brkoutjs.tic
// description: breakout-style struct-based pong-like game
// script: js
//
// You will need 3 foreground tiles created to use this program:
//
// #257: your paddle segment sprite (8x4, top left of 8x8 tile)
// #258: your ball sprite (2x2, top left of 8x8 tile)
// #259: your block sprite (7x4, top left of 8x8 tile)
//
//////////////////////////////////////////////////////////////////////////////
 
//////////////////////////////////////////////////////////////////////////////
//
// getRandomDirection() is a function to query the random number
// generator to produce one of -1 or 1, used to set one of the ball
// direction attributes (xdir, ydir).
//
function getRandomDirection()
{
  ////////////////////////////////////////////////////////////////////////////
  //
  // The random number generator is not returning a whole number, so
  // we need a routine to strip the decimal places from it.
  //
  var min = Math.ceil(0);
  var max = Math.floor(1);
  var value = Math.floor (Math.random () * (max - min + 1)) + min;
 
  ////////////////////////////////////////////////////////////////////////////
  //
  // Should the generated value be 0, adjust it to -1, to match our
  // desired output of -1 or 1.
  //
  if (value == 0)
  {
    value  = -1;
  }
 
  return (value);
}
haas/fall2021/c4eng/projects/brickify.1633459886.txt.gz · Last modified: 2021/10/05 18:51 by wedge