Commit 7ff47871 authored by ktsiam's avatar ktsiam
Browse files

fixed 1 bug

parent b05c7b5f
File deleted
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.a.out</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
...@@ -32,9 +32,8 @@ struct State { ...@@ -32,9 +32,8 @@ struct State {
} }
State() { reset(); } State() { reset(); }
#define MAX(x,y) x < y ? y : x; // y if x < y
void update(int input) { // -1 => LEFT, 1 => RIGHT, 0 => WAIT void update(int input) { // -1 => LEFT, 1 => RIGHT, 0 => WAIT
// player move // player move
if (input == -1) if (input == -1)
paddle = std::max(paddle-PADDLE_SPEED, 0); paddle = std::max(paddle-PADDLE_SPEED, 0);
...@@ -46,7 +45,7 @@ struct State { ...@@ -46,7 +45,7 @@ struct State {
ball_p[1] += ball_v[1]; ball_p[1] += ball_v[1];
// horizontal collision // horizontal collision
if (ball_p[0] < 0 or ball_p[0] > WIDTH) if (ball_p[0] <= 0 or ball_p[0] >= WIDTH)
ball_v[0] = -ball_v[0]; ball_v[0] = -ball_v[0];
// top collision // top collision
...@@ -60,6 +59,7 @@ struct State { ...@@ -60,6 +59,7 @@ struct State {
ball_v[1] = -ball_v[1]; ball_v[1] = -ball_v[1];
else { else {
reset(); // game over reset(); // game over
assert(false && "END");
return; return;
} }
} }
...@@ -73,15 +73,14 @@ struct State { ...@@ -73,15 +73,14 @@ struct State {
x_interval[0] = (i % BRICK_COLS) * BRICK_SIZE; x_interval[0] = (i % BRICK_COLS) * BRICK_SIZE;
x_interval[1] = x_interval[0] + BRICK_SIZE; x_interval[1] = x_interval[0] + BRICK_SIZE;
y_interval[0] = (i / BRICK_COLS) * BRICK_SIZE + BRICK_MIN_HEIGHT; y_interval[0] = (i / BRICK_COLS) * BRICK_SIZE; // + BRICK_MIN_HEIGHT;
y_interval[1] = y_interval[0] + BRICK_SIZE; y_interval[1] = y_interval[0] + BRICK_SIZE;
if (ball_p[0] < x_interval[0] or if (ball_p[0] < x_interval[0] or
ball_p[0] > x_interval[1] or ball_p[0] > x_interval[1] or
ball_p[1] < y_interval[0] or ball_p[1] < y_interval[0] or
ball_p[1] > y_interval[1]) ball_p[1] > y_interval[1])
continue; // no collision continue; // no collision
else { else {
bricks[i] = false; bricks[i] = false;
...@@ -110,7 +109,7 @@ struct State { ...@@ -110,7 +109,7 @@ struct State {
for (int r = 0; r < HEIGHT/UNIT; ++r) { for (int r = 0; r < HEIGHT/UNIT; ++r) {
std::cout << '|'; std::cout << '|';
for (int c = 0; c < WIDTH/UNIT; ++c) { for (int c = 0; c < WIDTH/UNIT; ++c) {
if (r < 8 and bricks[(BRICK_ROWS-r-1)*BRICK_COLS+c]) { if (r < 8 and bricks[(BRICK_ROWS-r-1)*BRICK_COLS+c]) {
std::cout << "x "; std::cout << "x ";
} else if (ball_p[0] >= c*UNIT and } else if (ball_p[0] >= c*UNIT and
......
#!/bin/bash
clang++ -std=c++14 brick-breaker.cpp
./a.out
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment