Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/AndroidProjectSystem.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 27 additions & 14 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
apply plugin: 'com.android.application'
plugins {
id 'com.android.application'
}

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
namespace 'com.infowithvijay.pong2dgame' // ✅ Required in AGP 8.0+
compileSdk = 34 // ✅ Updated to latest stable
defaultConfig {
applicationId "com.infowithvijay.pong2dgame"
minSdkVersion 25
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
minSdk = 26 // ✅ 25 is okay, but 26+ is more stable now
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_17 // ✅ Match with your JDK (e.g., Java 17)
targetCompatibility JavaVersion.VERSION_17
}

buildFeatures {
viewBinding true // Optional but useful
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

</activity>
<activity android:name=".GameActivity"
android:exported="true"
android:theme="@style/AppTheme"
android:configChanges="keyboardHidden|orientation|screenSize"
android:screenOrientation="sensorLandscape"
Expand Down
52 changes: 26 additions & 26 deletions app/src/main/java/com/infowithvijay/pong2dgame/PongTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ private void doAI(){
public void update(Canvas canvas){


if (checkCollisionPlayer(mPlayer,mBall)){
handleCollision(mPlayer,mBall);
}else if (checkCollisionPlayer(mOpponent,mBall)){
handleCollision(mOpponent,mBall);
}else if (checkCollisionWithTopOrBottomWall()){
mBall.velocity_y = -mBall.velocity_y;
}else if (checkCollisionWithLeftWall()){
mGame.setState(GameThread.STATE_LOSE);
return;
}else if (checkCollisionWithRightWall()){
mGame.setState(GameThread.STATE_WIN);
return;
}
if (checkCollisionPlayer(mPlayer,mBall)){
handleCollision(mPlayer,mBall);
}else if (checkCollisionPlayer(mOpponent,mBall)){
handleCollision(mOpponent,mBall);
}else if (checkCollisionWithTopOrBottomWall()){
mBall.velocity_y = -mBall.velocity_y;
}else if (checkCollisionWithLeftWall()){
mGame.setState(GameThread.STATE_LOSE);
return;
}else if (checkCollisionWithRightWall()){
mGame.setState(GameThread.STATE_WIN);
return;
}



Expand All @@ -246,26 +246,26 @@ public void update(Canvas canvas){
}


private boolean checkCollisionPlayer(Player player,Ball ball){
private boolean checkCollisionPlayer(Player player,Ball ball){

return player.bounds.intersects(
ball.cx - ball.getRadius(),
ball.cy - ball.getRadius(),
ball.cx + ball.getRadius(),
ball.cy + ball.getRadius()
ball.cx - ball.getRadius(),
ball.cy - ball.getRadius(),
ball.cx + ball.getRadius(),
ball.cy + ball.getRadius()
);

}
}


private boolean checkCollisionWithTopOrBottomWall(){
private boolean checkCollisionWithTopOrBottomWall(){
return ((mBall.cy <= mBall.getRadius()) || (mBall.cy + mBall.getRadius() >= mTableHeight -1));
}
}


private boolean checkCollisionWithLeftWall(){
private boolean checkCollisionWithLeftWall(){
return mBall.cx <= mBall.getRadius();
}
}


private boolean checkCollisionWithRightWall(){
Expand Down Expand Up @@ -305,7 +305,7 @@ public boolean onTouchEvent(MotionEvent event) {
mlastTouchY = event.getY();
}
}
break;
break;

case MotionEvent.ACTION_MOVE:
if (moving){
Expand All @@ -318,7 +318,7 @@ public boolean onTouchEvent(MotionEvent event) {

movePlayerRacquet(dy,mPlayer);
}
break;
break;

case MotionEvent.ACTION_UP:
moving = false;
Expand Down Expand Up @@ -414,4 +414,4 @@ private void placeBall(){



}
}
11 changes: 3 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@
buildscript {
repositories {
google()
jcenter()

mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:8.3.0' // ✅ Updated plugin
}
}

allprojects {
repositories {
google()
jcenter()

mavenCentral() // ✅ Replace jcenter with mavenCentral
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Apr 14 22:54:25 PDT 2020
#Sun Jun 15 09:37:51 EAT 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip