Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart and Android Side Improvents #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.buildlog/
.history
.svn/
.vscode/

# IntelliJ related
*.iml
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

The beloved vintage Pacman game with Flutter Animations and Sound Effects compatible in both Andriod and IOS.

## License
MIT


## Project Structure:
The rough breakdown of the current state of the game will consist of
Expand All @@ -16,8 +19,8 @@ algorithm for Ghosts to target Pacman in the game.


## Dependencies
1. audioplayers: ^0.17.0
2. flutter_phoenix: ^0.1.0
flutter_phoenix: ^0.1.0
audioplayers: ^0.20.1


## App Preview
Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdkVersion 31

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -40,7 +40,7 @@ android {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.packman"
minSdkVersion 16
targetSdkVersion 29
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
10 changes: 1 addition & 9 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:exported="true"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
Expand All @@ -18,15 +19,6 @@
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
4 changes: 2 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.4.21'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
11 changes: 0 additions & 11 deletions lib/ghost.dart

This file was deleted.

11 changes: 0 additions & 11 deletions lib/ghost2.dart

This file was deleted.

11 changes: 0 additions & 11 deletions lib/ghost3.dart

This file was deleted.

2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'HomePage.dart';
import 'pages/homepage.dart';

void main() {
runApp(MyApp());
Expand Down
92 changes: 46 additions & 46 deletions lib/HomePage.dart → lib/pages/homepage.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:packman/ghost.dart';
import 'package:packman/ghost3.dart';
import 'package:packman/ghost2.dart';
import 'package:packman/path.dart';
import 'package:packman/pixel.dart';
import 'package:packman/player.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:audioplayers/audio_cache.dart';

import '../widgets/imports.dart';

class HomePage extends StatefulWidget {
@override
Expand All @@ -30,13 +23,13 @@ class _HomePageState extends State<HomePage> {
var controller;
int score = 0;
bool paused = false;
AudioPlayer advancedPlayer = new AudioPlayer();
AudioPlayer advancedPlayer2 = new AudioPlayer();
AudioCache audioInGame = new AudioCache(prefix: 'assets/');
AudioCache audioMunch = new AudioCache(prefix: 'assets/');
AudioCache audioDeath = new AudioCache(prefix: 'assets/');
AudioCache audioPaused = new AudioCache(prefix: 'assets/');
List<int> barriers = [
AudioPlayer advancedPlayer = AudioPlayer();
AudioPlayer advancedPlayer2 = AudioPlayer();
AudioCache audioInGame = AudioCache(prefix: 'assets/');
AudioCache audioMunch = AudioCache(prefix: 'assets/');
AudioCache audioDeath = AudioCache(prefix: 'assets/');
AudioCache audioPaused = AudioCache(prefix: 'assets/');
List<int> barriers = const [
0,
1,
2,
Expand Down Expand Up @@ -141,10 +134,10 @@ class _HomePageState extends State<HomePage> {

void startGame() {
if (preGame) {
advancedPlayer = new AudioPlayer();
audioInGame = new AudioCache(fixedPlayer: advancedPlayer);
audioPaused = new AudioCache(fixedPlayer: advancedPlayer2);
audioInGame.loop('pacman_beginning.wav');
advancedPlayer = AudioPlayer();
audioInGame = AudioCache(fixedPlayer: advancedPlayer);
audioPaused = AudioCache(fixedPlayer: advancedPlayer2);
audioInGame.loop('audio/pacman_beginning.wav');
preGame = false;
getFood();

Expand All @@ -155,7 +148,7 @@ class _HomePageState extends State<HomePage> {
}
if (player == ghost || player == ghost2 || player == ghost3) {
advancedPlayer.stop();
audioDeath.play('pacman_death.wav');
audioDeath.play('audio/pacman_death.wav');
setState(() {
player = -1;
});
Expand All @@ -167,9 +160,9 @@ class _HomePageState extends State<HomePage> {
title: Center(child: Text("Game Over!")),
content: Text("Your Score : " + (score).toString()),
actions: [
RaisedButton(
ElevatedButton(
onPressed: () {
audioInGame.loop('pacman_beginning.wav');
audioInGame.loop('audio/pacman_beginning.wav');
setState(() {
player = numberInRow * 14 + 1;
ghost = numberInRow * 2 - 2;
Expand All @@ -185,12 +178,20 @@ class _HomePageState extends State<HomePage> {
Navigator.pop(context);
});
},
textColor: Colors.white,
padding: const EdgeInsets.all(0.0),
style: ButtonStyle(
textStyle: MaterialStateProperty.all(
const TextStyle(
color: Colors.white,
),
),
padding: MaterialStateProperty.all(
const EdgeInsets.all(0.0),
),
),
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
colors: [
Color(0xFF0D47A1),
Color(0xFF1976D2),
Color(0xFF42A5F5),
Expand Down Expand Up @@ -218,7 +219,7 @@ class _HomePageState extends State<HomePage> {
mouthClosed = !mouthClosed;
});
if (food.contains(player)) {
audioMunch.play('pacman_chomp.wav');
audioMunch.play('audio/pacman_chomp.wav');
setState(() {
food.remove(player);
});
Expand Down Expand Up @@ -677,62 +678,61 @@ class _HomePageState extends State<HomePage> {
physics: NeverScrollableScrollPhysics(),
itemCount: numberOfSquares,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: numberInRow),
crossAxisCount: numberInRow,
),
itemBuilder: (BuildContext context, int index) {
if (mouthClosed && player == index) {
return Padding(
padding: EdgeInsets.all(4),
child: Container(
decoration: BoxDecoration(
color: Colors.yellow, shape: BoxShape.circle),
color: Colors.yellow,
shape: BoxShape.circle,
),
),
);
} else if (player == index) {
switch (direction) {
case "left":
return Transform.rotate(
angle: pi,
child: MyPlayer(),
child: Player(),
);
break;
case "right":
return MyPlayer();
break;
return Player();
case "up":
return Transform.rotate(
angle: 3 * pi / 2,
child: MyPlayer(),
child: Player(),
);
break;
case "down":
return Transform.rotate(
angle: pi / 2,
child: MyPlayer(),
child: Player(),
);
break;
default:
return MyPlayer();
return Player();
}
} else if (ghost == index) {
return MyGhost();
return Ghost(1);
} else if (ghost2 == index) {
return MyGhost2();
return Ghost(2);
} else if (ghost3 == index) {
return MyGhost3();
return Ghost(3);
} else if (barriers.contains(index)) {
return MyPixel(
return Pixel(
innerColor: Colors.blue[900],
outerColor: Colors.blue[800],
// child: Text(index.toString()),
);
} else if (preGame || food.contains(index)) {
return MyPath(
return Path(
innerColor: Colors.yellow,
outerColor: Colors.black,
// child: Text(index.toString()),
);
} else {
return MyPath(
return Path(
innerColor: Colors.black,
outerColor: Colors.black,
);
Expand Down Expand Up @@ -770,7 +770,7 @@ class _HomePageState extends State<HomePage> {
{
paused = true,
advancedPlayer.pause(),
audioPaused.loop('pacman_intermission.wav'),
audioPaused.loop('audio/pacman_intermission.wav'),
}
else
{
Expand All @@ -796,7 +796,7 @@ class _HomePageState extends State<HomePage> {
{
paused = true,
advancedPlayer.pause(),
audioPaused.loop('pacman_intermission.wav'),
audioPaused.loop('audio/pacman_intermission.wav'),
},
},
),
Expand Down
17 changes: 17 additions & 0 deletions lib/widgets/ghost.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';

class Ghost extends StatelessWidget {
final int index;
const Ghost(
this.index, {
Key? key,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(2),
child: Image.asset('assets/images/ghost${this.index}.png'),
);
}
}
4 changes: 4 additions & 0 deletions lib/widgets/imports.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export 'path.dart';
export 'ghost.dart';
export 'player.dart';
export 'pixel.dart';
4 changes: 2 additions & 2 deletions lib/path.dart → lib/widgets/path.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';

class MyPath extends StatelessWidget {
class Path extends StatelessWidget {
final innerColor;
final outerColor;
final child;

MyPath({this.innerColor, this.outerColor, this.child});
const Path({this.innerColor, this.outerColor, this.child});
@override
Widget build(BuildContext context) {
return Padding(
Expand Down
5 changes: 3 additions & 2 deletions lib/pixel.dart → lib/widgets/pixel.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'package:flutter/material.dart';

class MyPixel extends StatelessWidget {
class Pixel extends StatelessWidget {
final innerColor;
final outerColor;
final child;

MyPixel({this.innerColor, this.outerColor, this.child});
const Pixel({this.innerColor, this.outerColor, this.child});

@override
Widget build(BuildContext context) {
return Padding(
Expand Down
Loading