Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
saiaaaaaaa committed Dec 10, 2023
0 parents commit 335bbb3
Show file tree
Hide file tree
Showing 60 changed files with 1,737 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

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

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

19 changes: 19 additions & 0 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/misc.xml

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

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id 'com.android.application'
}

android {
namespace 'com.salazarisaiahnoel.pacmanandroid'
compileSdk 34

defaultConfig {
applicationId "com.salazarisaiahnoel.pacmanandroid"
minSdk 19
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_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.salazarisaiahnoel.pacmanandroid;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.salazarisaiahnoel.pacmanandroid", appContext.getPackageName());
}
}
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.PacmanAndroid"
tools:targetApi="31">
<activity
android:name=".Play"
android:exported="false"
android:screenOrientation="portrait"/>
<activity
android:name=".MainActivity"
android:exported="true"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.salazarisaiahnoel.pacmanandroid;

import android.app.Activity;
import android.view.View;

public class Fullscreen {
public static void enableFullscreen(Activity activity){
int UI_OPTIONS = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
activity.getWindow().getDecorView().setSystemUiVisibility(UI_OPTIONS);
}
}
151 changes: 151 additions & 0 deletions app/src/main/java/com/salazarisaiahnoel/pacmanandroid/Ghost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package com.salazarisaiahnoel.pacmanandroid;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import java.util.Random;

public class Ghost {
int[][] map;
int cellSizeRow, cellSizeCol;
int posX, posY;
int speed;
int color;
boolean isMoving = false;
boolean isStart = false;
int goOutCounter = 0;
boolean should = false;

boolean canMoveUp, canMoveDown, canMoveLeft, canMoveRight;
Random ran = new Random();
int dir = 0;

public Ghost(int color, int[][] map, int cellSizeRow, int cellSizeCol, int speed, int position, int place){
this.color = color;
this.map = map;
this.cellSizeRow = cellSizeRow;
this.cellSizeCol = cellSizeCol;
this.speed = speed;
posX = cellSizeCol * (position + 9);
posY = cellSizeRow * place;
}

public void draw(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.TRANSPARENT);
canvas.drawRect(posX, posY, posX + cellSizeCol, posY + cellSizeRow, paint);

paint.setColor(color);
canvas.drawCircle(posX + cellSizeCol / 2, posY + cellSizeRow / 2, cellSizeCol / 2, paint);
canvas.drawRect(posX, posY + (cellSizeRow / 2), posX + cellSizeCol, posY + cellSizeRow, paint);
}

public void move(int dx, int dy) {
int newX = posX + dx;
int newY = posY + dy;

if (isValidMove(newX, newY) && isValidMove(newX + cellSizeCol - 1, newY + cellSizeRow - 1) && isValidMove(newX, newY + cellSizeRow - 1) && isValidMove(newX + cellSizeCol - 1, newY)){
posX = newX;
posY = newY;
isMoving = true;
} else {
isMoving = false;
}
}

boolean isValidMove(int newX, int newY){
if (newX >= 0 && newX < map[0].length * cellSizeCol && newY >= 0 && newY < map.length * cellSizeRow) {
int col = newX / cellSizeCol;
int row = newY / cellSizeRow;

if (map[row][col] != 1) {
return true;
}
}
return false;
}

void goOutside(){
switch (goOutCounter){
case 0:
if (!isStart){
move(-speed, 0);
}
if (!isMoving){
isStart = true;
goOutCounter++;
}
break;
case 1:
if (isStart){
move(0, -speed);
}
if (!isMoving){
isStart = false;
goOutCounter++;
}
break;
case 2:
if (!isStart){
if (isValidMove(posX, posY - speed) && isValidMove(posX + cellSizeCol - 1, posY + cellSizeRow - 1 - speed) && isValidMove(posX, posY + cellSizeRow - 1 - speed) && isValidMove(posX + cellSizeCol - 1, posY - speed)){
move(0, -speed);
should = true;
} else {
if (should){
isStart = true;
goOutCounter++;
}
move(speed, 0);
}
}
break;
case 3:
if (isStart){
move(-speed, 0);
}
if (!isMoving){
isStart = false;
goOutCounter++;
}
break;
}
}

void moveRandomly(){
canMoveUp = isValidMove(posX, posY - speed) && isValidMove(posX + cellSizeCol - 1, posY + cellSizeRow - 1 - speed) && isValidMove(posX, posY + cellSizeRow - 1 - speed) && isValidMove(posX + cellSizeCol - 1, posY - speed);
canMoveDown = isValidMove(posX, posY + speed) && isValidMove(posX + cellSizeCol - 1, posY + cellSizeRow - 1 + speed) && isValidMove(posX, posY + cellSizeRow - 1 + speed) && isValidMove(posX + cellSizeCol - 1, posY + speed);
canMoveLeft = isValidMove(posX - speed, posY) && isValidMove(posX + cellSizeCol - 1 - speed, posY + cellSizeRow - 1) && isValidMove(posX - speed, posY + cellSizeRow - 1) && isValidMove(posX + cellSizeCol - 1 - speed, posY);
canMoveRight = isValidMove(posX + speed, posY) && isValidMove(posX + cellSizeCol - 1 + speed, posY + cellSizeRow - 1) && isValidMove(posX + speed, posY + cellSizeRow - 1) && isValidMove(posX + cellSizeCol - 1 + speed, posY);
switch (dir){
case 0:
if (canMoveUp){
move(0, -speed);
} else {
dir = ran.nextInt(4);
}
break;
case 1:
if (canMoveDown){
move(0, speed);
} else {
dir = ran.nextInt(4);
}
break;
case 2:
if (canMoveLeft){
move(-speed, 0);
} else {
dir = ran.nextInt(4);
}
break;
case 3:
if (canMoveRight){
move(speed, 0);
} else {
dir = ran.nextInt(4);
}
break;
}
}
}
Loading

0 comments on commit 335bbb3

Please sign in to comment.