You are not logged in.

#1 2018-04-12 03:14:19

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Attack of the Asteroids - A 2d shooting and defense game

Hi everyone!

I think I'm ready to release my latest project for the Arch Linux community: Attack of the Asteroids (aota)! Here we go!
The github page: https://github.com/JohnBobSmith/attackoftheasteroids
Here's the help page which should give you a nice glimpse of what this project is: http://i67.tinypic.com/2j4agbt.png
Basically, you want to defend your base. You have your primary cannon, a very fast but very weak gun. You also have a laser. The laser drains your health so use carefully! The gameplay is quite nice and I'm proud of my creation. The enemies are wave based. Each win spawns one more row of enemies until you die. Hehe. smile

I've also made a PKGBUILD for this project:

# Maintainer: David "JohnBobSmith" Bogner <myrunescapeemail609 AT gmail DOT com>
pkgname=attackoftheasteroids
pkgver=r25.a9d2532
pkgrel=1
pkgdesc="A.O.T.A - A simple 2D shooting and defense game."
arch=(x86_64)
depends=('sfml')
makedepends=('git')
url="https://github.com/JohnBobSmith/attackoftheasteroids"
license=('MIT')
source=("git+https://github.com/JohnBobSmith/attackoftheasteroids.git")
md5sums=('SKIP')

pkgver() {
  cd "$pkgname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
	cd "$pkgname/src/"
	make
}

package() {
	cd "$pkgname"
	install -D -m644 License.md "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	install -D -m755 "src/aota" "${pkgdir}/usr/bin/aota"
	install -D -m755 "textures/bg.png" "${pkgdir}/usr/share/${pkgname}/textures/bg.png"
	install -D -m755 "textures/bullet.png" "${pkgdir}/usr/share/${pkgname}/textures/bullet.png"
	install -D -m755 "textures/easyAsteroid.png" "${pkgdir}/usr/share/${pkgname}/textures/easyAsteroid.png"
	install -D -m755 "textures/laser.png" "${pkgdir}/usr/share/${pkgname}/textures/laser.png"
	install -D -m755 "textures/moonbase.png" "${pkgdir}/usr/share/${pkgname}/textures/moonbase.png"
	install -D -m755 "textures/shield.png" "${pkgdir}/usr/share/${pkgname}/textures/shield.png"
	install -D -m755 "textures/ui/help.png" "${pkgdir}/usr/share/${pkgname}/textures/ui/help.png"
	install -D -m755 "textures/ui/start.png" "${pkgdir}/usr/share/${pkgname}/textures/ui/start.png"
	install -D -m755 "textures/ui/quit.png" "${pkgdir}/usr/share/${pkgname}/textures/ui/quit.png"
	install -D -m755 "textures/ui/helppage.png" "${pkgdir}/usr/share/${pkgname}/textures/ui/helppage.png"
	install -D -m755 "fonts/ehsmb.ttf" "${pkgdir}/usr/share/${pkgname}/fonts/ehsmb.ttf"
	install -D -m755 "audio/sfx/bulletFire.wav" "${pkgdir}/usr/share/${pkgname}/audio/sfx/bulletFire.wav"
	install -D -m755 "audio/sfx/enemyDeath.wav" "${pkgdir}/usr/share/${pkgname}/audio/sfx/enemyDeath.wav"
	install -D -m755 "audio/sfx/laserFire.wav" "${pkgdir}/usr/share/${pkgname}/audio/sfx/laserFire.wav"
	install -D -m755 "audio/sfx/shieldImpact.wav" "${pkgdir}/usr/share/${pkgname}/audio/sfx/shieldImpact.wav"
	install -D -m755 "audio/music/mainMenuTheme.wav" "${pkgdir}/usr/share/${pkgname}/audio/music/mainMenuTheme.wav"
}

This works well. Note that I had tried using the following from the wiki:

make DESTDIR="$pkgdir/" install

But this resulted in a error (no target for install or something similar). Also, I don't want to install my dev folder. So thats why I did every manually. Feel free to suggest alternatives/improvements to the code and/or the PKGBUILD. Namcap agrees with the PKGBUILD so that should be good!

Planned features:
-A way to properly escape to the main menu/a way to pause the game
-A way to restart without having to exit the application
-Powerups! Regenerate shields, health, "infinite" laser (doesnt damage you), stronger gun, stuff like that.
-Possibly more enemy types. Faster enemies, enemies that are harder to kill, stuff like that. Not a priority at this time.
-A way to configure things so that you can play locally or install to the system. I briefly mentioned this in the readme. Not a huge priority, but would be nice.

Now I have some general questions which I hope you guys can help me answer.
1) What is ./configure? A shell script? Binary? I don't have that step but, seeing the previous point, I think that this might be helpful.
2) Is installing all my game data to /usr/share/${pkgname} correct? I'm not quite sure, but according to the wiki, this is used for application data so I hope that's okay?
3) Is there a way to install without doing each file manually?
4) Are the permissions on each file (755) correct? I'm not sure I need execute or not. Any pointers (no pun intended) would be nice.
5) Is hard coding my paths to system directories a good idea? For example I have:

blockFont.loadFromFile("/usr/share/attackoftheasteroids/fonts/ehsmb.ttf");

Repeat for each file that needs loading. Is this okay or is there a better way to do it?

That's it! I hope you will enjoy AOTA! I'm really proud of this project. It's the most polished, playable project that I have currently. Feel free to criticize any and all aspects of this project. I look forward to hearing your feedback! big_smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#2 2018-04-12 15:13:04

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Attack of the Asteroids - A 2d shooting and defense game

So first off, this is a git master PKGBUILD, which means the pkgname should end in -git. tongue

Regarding simplification of package, the trick is that your Makefile needs to *implement* an "install" target, which simply moves all those commands into the Makefile (simplifying the process for people who don't use the PKGBUILD, possibly because they are on some other distro).

In Makefile terms, you want to install things to:

PREFIX ?= /usr/local

install:
	install -Dm644 ... $(DESTDIR)$(PREFIX)/share/...

configure scripts are irrelevant for your purposes, they basically just modify things like PREFIX via some horrendously complicated autotools logic. (Though, some people do use homemade, simple 5-line configure scripts which use sed on config.mk to set things like PREFIX, the only difference is that you don't need to set it for `make PREFIX=/usr`.)

You should use C defines to change "/usr/share/attackoftheasteroids/fonts/ehsmb.ttf" to PREFIX"/share/attackoftheasteroids/fonts/ehsmb.ttf" at compile time.

...

Usually Makefiles are at the top-level directory, so they can do things with the resources folders.

Last edited by eschwartz (2018-04-12 15:14:38)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#3 2018-04-12 15:40:28

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

Also, note that most of those install commands can be simplified, e.g.:

install -Dm644 -t "${pkgdir}/usr/share/${pkgname}/textures" textures/*

I changed the mode to 644, there is no reason for images and audio to be executable.

If this is instead in the Makefile (as it should be) you'd just adjust the target path to use DESTDIR, PREFIX and PROG

Last edited by Trilby (2018-04-12 15:41:08)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2018-04-13 16:03:09

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: Attack of the Asteroids - A 2d shooting and defense game

Thanks for the suggestions! Unfortunately I've been frying my brain like an egg in a frying pan trying to implement all of the suggestions. Here is what I have so far:
PKGBUILD

# Maintainer: David "JohnBobSmith" Bogner <myrunescapeemail609 AT gmail DOT com>
pkgname=attackoftheasteroids-git
__pkgname=attackoftheasteroids
pkgver=r30.94e29a2
pkgrel=1
pkgdesc="A.O.T.A - A simple 2D shooting and defense game."
arch=(x86_64)
depends=('sfml')
makedepends=('git')
url="https://github.com/JohnBobSmith/attackoftheasteroids"
license=('MIT')
source=("git+https://github.com/JohnBobSmith/attackoftheasteroids.git")
md5sums=('SKIP')

pkgver() {
  cd "$_pkgname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
	cd "$_pkgname"
	make
}

package() {
	cd "$_pkgname"
	make DESTDIR="$pkgdir/" install
}

Makefile

CXX = g++
CXXFLAGS = -g -Wall
PROG  = attackoftheasteroids
ODIR  = obj
SRC = $(wildcard *.cpp $(wildcard src/*.cpp))
#SRC = $(wildcard *.cpp)
OBJS = $(addprefix $(ODIR)/,$(SRC:.cpp=.o))
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

$(ODIR)/%.o: %.cpp
	mkdir -p $(ODIR)/src/
	$(CXX) -c -o $@ $^ $(CXXFLAGS)

$(PROG): $(OBJS)
	$(CXX) -o $(PROG) $^ $(LD)

clean:
	rm -f $(ODIR)/*.o $(PROG)
	
.PHONY: clean

install:
	install -Dm644 License.md "${pkgdir}/usr/share/licenses/${_pkgname}/LICENSE"
	install -Dm755 "src/aota" "${pkgdir}/usr/bin/aota"
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures" textures/*
	#install -Dm644 "textures/bg.png" "${pkgdir}/usr/share/${_pkgname}/textures/bg.png"
	#install -Dm644 "textures/bullet.png" "${pkgdir}/usr/share/${_pkgname}/textures/bullet.png"
	#install -Dm644 "textures/easyAsteroid.png" "${pkgdir}/usr/share/${_pkgname}/textures/easyAsteroid.png"
	#install -Dm644 "textures/laser.png" "${pkgdir}/usr/share/${_pkgname}/textures/laser.png"
	#install -Dm644 "textures/moonbase.png" "${pkgdir}/usr/share/${_pkgname}/textures/moonbase.png"
	#install -Dm644 "textures/shield.png" "${pkgdir}/usr/share/${_pkgname}/textures/shield.png"
	#install -Dm644 "textures/ui/help.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/help.png"
	#install -Dm644 "textures/ui/start.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/start.png"
	#install -Dm644 "textures/ui/quit.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/quit.png"
	#install -Dm644 "textures/ui/helppage.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/helppage.png"
	#install -Dm644 "fonts/ehsmb.ttf" "${pkgdir}/usr/share/${_pkgname}/fonts/ehsmb.ttf"
	#install -Dm644 "audio/sfx/bulletFire.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/bulletFire.wav"
	#install -Dm644 "audio/sfx/enemyDeath.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/enemyDeath.wav"
	#install -Dm644 "audio/sfx/laserFire.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/laserFire.wav"
	#install -Dm644 "audio/sfx/shieldImpact.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/shieldImpact.wav"
	#install -Dm644 "audio/music/mainMenuTheme.wav" "${pkgdir}/usr/share/${_pkgname}/audio/music/mainMenuTheme.wav"

And project structure:

Fri Apr 13 jbs@dmb-gaming-laptop -> pwd
/home/jbs/cpp/aota
Fri Apr 13 jbs@dmb-gaming-laptop -> ls
audio  fonts       Makefile  PKGBUILD   src
dev    License.md  obj       README.md  textures
Fri Apr 13 jbs@dmb-gaming-laptop -> ls src/
Audio.cpp   CollisionBox.cpp  include    main.cpp   obj         Shield.cpp
Bullet.cpp  Enemy.cpp         Laser.cpp  Mouse.cpp  Player.cpp  UI.cpp
Fri Apr 13 jbs@dmb-gaming-laptop -> 

For some reason I'm getting duplicate attackoftheasteroids folder in src. I've removed them. Now  for the error message:

==> Making package: attackoftheasteroids-git r30.94e29a2-1 (Fri Apr 13 10:01:57 MDT 2018)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Cloning attackoftheasteroids git repo...
Cloning into bare repository '/home/jbs/cpp/aota/attackoftheasteroids'...
remote: Counting objects: 220, done.
remote: Compressing objects: 100% (164/164), done.
remote: Total 220 (delta 108), reused 148 (delta 46), pack-reused 0
Receiving objects: 100% (220/220), 7.69 MiB | 7.20 MiB/s, done.
Resolving deltas: 100% (108/108), done.
==> Validating source files with md5sums...
    attackoftheasteroids ... Skipped
==> Extracting sources...
  -> Creating working copy of attackoftheasteroids git repo...
Cloning into 'attackoftheasteroids'...
done.
==> Starting pkgver()...
==> Starting build()...
make: *** No targets specified and no makefile found.  Stop.
==> ERROR: A failure occurred in build().
    Aborting...
Fri Apr 13 jbs@dmb-gaming-laptop -> 

How is the Makefile not found???

Thanks for the help! Again this shouldnt be this hard but my brain tends to fry itself to the point of literally turning off and shutting down because of strong emotional pain associated with BPD. Sucks to be me I guess. sad


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#5 2018-04-13 16:21:21

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,784
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

You are using both _pkgname and __pkgname, I imagine the latter is a typo, but either way 'cd $_pkgname' expands to simply 'cd', as that variable is never assigned a value.

Small note: you should remove the 'A.O.T.A.' from the description -- there's no need to have the name of the application in the description.

Edit: also, mixing tabs and spaces is bad practice, you should use one or the other.

Last edited by WorMzy (2018-04-13 16:23:21)


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Online

#6 2018-04-13 16:48:13

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: Attack of the Asteroids - A 2d shooting and defense game

Thanks wormzy! Here is the most recent PKGBUILD

# Maintainer: David "JohnBobSmith" Bogner <myrunescapeemail609 AT gmail DOT com>
pkgname=attackoftheasteroids-git
_pkgname=attackoftheasteroids
pkgver=r30.94e29a2
pkgrel=1
pkgdesc="A simple 2D shooting and defense game."
arch=(x86_64)
depends=('sfml')
makedepends=('git')
url="https://github.com/JohnBobSmith/attackoftheasteroids"
license=('MIT')
source=("git+https://github.com/JohnBobSmith/attackoftheasteroids.git")
md5sums=('SKIP')

pkgver() {
  cd "$_pkgname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
	cd "$_pkgname"
	make
}

package() {
	cd "$_pkgname"
	make DESTDIR="$pkgdir/" install
}

That fixes the build error, but now my makefile (below) is broken

CXX = g++
CXXFLAGS = -g -Wall
PROG  = attackoftheasteroids
ODIR  = obj
SRC = $(wildcard *.cpp $(wildcard src/*.cpp))
#SRC = $(wildcard *.cpp)
OBJS = $(addprefix $(ODIR)/,$(SRC:.cpp=.o))
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

$(ODIR)/%.o: %.cpp
	mkdir -p $(ODIR)/src/
	$(CXX) -c -o $@ $^ $(CXXFLAGS)

$(PROG): $(OBJS)
	$(CXX) -o $(PROG) $^ $(LD)

clean:
	rm -f $(ODIR)/*.o $(PROG)
	
.PHONY: clean

install:
	install -Dm644 License.md "$(DESTDIR)/usr/share/licenses/$(PROG)/LICENSE"
	install -Dm755 "src/aota" "$(DESTDIR)/usr/bin/aota"
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures" textures/*
	#install -Dm644 "textures/bg.png" "${pkgdir}/usr/share/${_pkgname}/textures/bg.png"
	#install -Dm644 "textures/bullet.png" "${pkgdir}/usr/share/${_pkgname}/textures/bullet.png"
	#install -Dm644 "textures/easyAsteroid.png" "${pkgdir}/usr/share/${_pkgname}/textures/easyAsteroid.png"
	#install -Dm644 "textures/laser.png" "${pkgdir}/usr/share/${_pkgname}/textures/laser.png"
	#install -Dm644 "textures/moonbase.png" "${pkgdir}/usr/share/${_pkgname}/textures/moonbase.png"
	#install -Dm644 "textures/shield.png" "${pkgdir}/usr/share/${_pkgname}/textures/shield.png"
	#install -Dm644 "textures/ui/help.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/help.png"
	#install -Dm644 "textures/ui/start.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/start.png"
	#install -Dm644 "textures/ui/quit.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/quit.png"
	#install -Dm644 "textures/ui/helppage.png" "${pkgdir}/usr/share/${_pkgname}/textures/ui/helppage.png"
	#install -Dm644 "fonts/ehsmb.ttf" "${pkgdir}/usr/share/${_pkgname}/fonts/ehsmb.ttf"
	#install -Dm644 "audio/sfx/bulletFire.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/bulletFire.wav"
	#install -Dm644 "audio/sfx/enemyDeath.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/enemyDeath.wav"
	#install -Dm644 "audio/sfx/laserFire.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/laserFire.wav"
	#install -Dm644 "audio/sfx/shieldImpact.wav" "${pkgdir}/usr/share/${_pkgname}/audio/sfx/shieldImpact.wav"
	#install -Dm644 "audio/music/mainMenuTheme.wav" "${pkgdir}/usr/share/${_pkgname}/audio/music/mainMenuTheme.wav"

Note that I'm only trying to get one type of file (texture, audio, font) to install at a time. Thats why the bottom half is commented. The error:

Fri Apr 13 jbs@dmb-gaming-laptop -> makepkg -si
==> Making package: attackoftheasteroids-git r30.94e29a2-1 (Fri Apr 13 10:47:03 MDT 2018)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
  -> Updating attackoftheasteroids git repo...
Fetching origin
==> Validating source files with md5sums...
    attackoftheasteroids ... Skipped
==> Extracting sources...
  -> Creating working copy of attackoftheasteroids git repo...
Reset branch 'makepkg'
==> Starting pkgver()...
==> Removing existing $pkgdir/ directory...
==> Starting build()...
make: Nothing to be done for 'all'.
==> Entering fakeroot environment...
==> Starting package()...
install -Dm644 License.md "/usr/share/licenses//LICENSE"
install: cannot create regular file '/usr/share/licenses//LICENSE': Permission denied
make: *** [Makefile:25: install] Error 1
==> ERROR: A failure occurred in package().
    Aborting...
Fri Apr 13 jbs@dmb-gaming-laptop -> 

Where is the extra "/" coming from???

Will try this again later today or maybe even tomorrow once I un-fry my brain. Cheers!


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#7 2018-04-13 17:07:43

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

That Makefile has not been committed to the repo, so when you run makepkg it gets one where you used pkgdir instead of DESTDIR in the Makefile: obviously, the former is not defined, so it is attempting to install to the root of the filesystem and properly fails.

This is what is on line 25 of the Makefile when I use your PKGBUILD:

install -Dm644 License.md "${pkgdir}/usr/share/licenses/${_pkgname}/LICENSE"

Note an extra '/' is not a problem at all, you can have as many as you like.  It's there, though, because you have an undefined $_pkgname in the path rather than $(PROG).

Last edited by Trilby (2018-04-13 17:10:36)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2018-04-13 18:27:24

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Attack of the Asteroids - A 2d shooting and defense game

Keep in mind that even though you have a PKGBUILD in your repo, the PKGBUILD is cloning a new copy of the repo and building from that, not from your local testing modifications.

(This is why I dislike the somewhat common practice of including a PKGBUILD in a project repo, it only serves to confuse IMHO.)

If you just don't want to push broken stuff, this is why for testing purposes your PKGBUILD should use for example the source git+file:///home/jbs/cpp/aota/

And build your packages in e.g. /home/jbs/aurpkgs/aota/ which is clearly separated.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#9 2018-04-13 18:47:36

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

Alternatively, just use `makepkg -e` so you can experiment with the checked out sources.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#10 2018-04-13 19:34:30

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: Attack of the Asteroids - A 2d shooting and defense game

Thanks guys! I'm really glad there is some interest in my work. Here is a fully working pkgbuild and makefile that I tested. This builds and installs the package correctly:

PKGBUILD

# Maintainer: David "JohnBobSmith" Bogner <myrunescapeemail609 AT gmail DOT com>
pkgname=attackoftheasteroids-git
_pkgname=attackoftheasteroids
pkgver=r30.94e29a2
pkgrel=1
pkgdesc="A simple 2D shooting and defense game."
arch=(x86_64)
depends=('sfml')
makedepends=('git')
url="https://github.com/JohnBobSmith/attackoftheasteroids"
license=('MIT')
source=("git+https://github.com/JohnBobSmith/attackoftheasteroids.git")
md5sums=('SKIP')

pkgver() {
  cd "$_pkgname"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

build() {
	cd "$_pkgname"
	make
}

package() {
	cd "$_pkgname"
	make DESTDIR="$pkgdir/" install
}

Makefile:

CXX = g++
CXXFLAGS = -g -Wall
PROG  = attackoftheasteroids
ODIR  = obj
SRC = $(wildcard *.cpp $(wildcard src/*.cpp))
#SRC = $(wildcard *.cpp)
OBJS = $(addprefix $(ODIR)/,$(SRC:.cpp=.o))
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

$(ODIR)/%.o: %.cpp
	mkdir -p $(ODIR)/src/
	$(CXX) -c -o $@ $^ $(CXXFLAGS)

$(PROG): $(OBJS)
	$(CXX) -o $(PROG) $^ $(LD)

clean:
	rm -f $(ODIR)/*.o $(PROG)
	
.PHONY: clean

install:
	install -Dm644 License.md "$(DESTDIR)/usr/share/licenses/$(PROG)/LICENSE"
	install -Dm755 attackoftheasteroids "$(DESTDIR)/usr/bin/attackoftheasteroids"
	#install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures" textures/*
	install -Dm644 "textures/bg.png" "$(DESTDIR)/usr/share/$(PROG)/textures/bg.png"
	install -Dm644 "textures/bullet.png" "$(DESTDIR)/usr/share/$(PROG)/textures/bullet.png"
	install -Dm644 "textures/easyAsteroid.png" "$(DESTDIR)/usr/share/$(PROG)/textures/easyAsteroid.png"
	install -Dm644 "textures/laser.png" "$(DESTDIR)/usr/share/$(PROG)/textures/laser.png"
	install -Dm644 "textures/moonbase.png" "$(DESTDIR)/usr/share/$(PROG)/textures/moonbase.png"
	install -Dm644 "textures/shield.png" "$(DESTDIR)/usr/share/$(PROG)/textures/shield.png"
	install -Dm644 "textures/ui/help.png" "$(DESTDIR)/usr/share/$(PROG)/textures/ui/help.png"
	install -Dm644 "textures/ui/start.png" "$(DESTDIR)/usr/share/$(PROG)/textures/ui/start.png"
	install -Dm644 "textures/ui/quit.png" "$(DESTDIR)/usr/share/$(PROG)/textures/ui/quit.png"
	install -Dm644 "textures/ui/helppage.png" "$(DESTDIR)/usr/share/$(PROG)/textures/ui/helppage.png"
	install -Dm644 "fonts/ehsmb.ttf" "$(DESTDIR)/usr/share/$(PROG)/fonts/ehsmb.ttf"
	install -Dm644 "audio/sfx/bulletFire.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/sfx/bulletFire.wav"
	install -Dm644 "audio/sfx/enemyDeath.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/sfx/enemyDeath.wav"
	install -Dm644 "audio/sfx/laserFire.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/sfx/laserFire.wav"
	install -Dm644 "audio/sfx/shieldImpact.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/sfx/shieldImpact.wav"
	install -Dm644 "audio/music/mainMenuTheme.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/music/mainMenuTheme.wav"

These should be committed to the repository. If not let me know and I'll double check real quick.

Trilby, I tried using your simplification in post #3, but I was unable to get it to work. I don't understand the purpose of -t. According to man install, -D copies the files from SOURCE to DEST. It seems like -t is redundant? Also, and maybe I'm in the wrong here, but your arguments are in the wrong order. I want to copy textures (source) to /usr/share (dest) Again I could be wrong but those are my observations. If you want exact error messages, let me know. Basically it had to do with omitting directory textures/ui, permission denied, file exists in filesystem, stuff that like that. It should be an easy fix but I wasnt able to figure it out just yet.


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#11 2018-04-13 19:46:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

Read the man page past the first line.  The '-t' flag is documented, and there are different orders for the parameters when it is used.

I don't know off-hand it it would work with subdirectories, but at worst, you'd need two lines for all the textures:

install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures" textures/*.png
install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures/ui" textures/ui/*.png

Last edited by Trilby (2018-04-13 19:47:48)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#12 2018-04-13 20:47:59

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: Attack of the Asteroids - A 2d shooting and defense game

Thank you for your patience with me Trilby. I figured it out. smile

The following Makefile successfully implements your suggestions.

CXX = g++
CXXFLAGS = -g -Wall
PROG  = attackoftheasteroids
ODIR  = obj
SRC = $(wildcard *.cpp $(wildcard src/*.cpp))
#SRC = $(wildcard *.cpp)
OBJS = $(addprefix $(ODIR)/,$(SRC:.cpp=.o))
LD = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

$(ODIR)/%.o: %.cpp
	mkdir -p $(ODIR)/src/
	$(CXX) -c -o $@ $^ $(CXXFLAGS)

$(PROG): $(OBJS)
	$(CXX) -o $(PROG) $^ $(LD)

clean:
	rm -f $(ODIR)/*.o $(PROG)
	
.PHONY: clean

install:
	install -Dm644 License.md "$(DESTDIR)/usr/share/licenses/$(PROG)/LICENSE"
	install -Dm755 attackoftheasteroids "$(DESTDIR)/usr/bin/attackoftheasteroids"
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures" textures/*.png
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures/ui" textures/ui/*.png
	install -Dm644 "fonts/ehsmb.ttf" "$(DESTDIR)/usr/share/$(PROG)/fonts/ehsmb.ttf"
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/audio/sfx/" audio/sfx/*.wav
	install -Dm644 "audio/music/mainMenuTheme.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/music/mainMenuTheme.wav"

And this builds and installs the package correctly.

Thank you everyone for your help! I really appreciate it! One more thing: How is the actual gameplay? Is the laser balanced? From a game play/game design perspective, is everything good? Looking forward to hearing your feedback. big_smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#13 2018-04-13 22:55:01

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Attack of the Asteroids - A 2d shooting and defense game

I really have no idea how well it plays, as I don't really play computer games much. smile I was just here to discuss the topics I consider fascinating, which are build systems and PKGBUILDs.

This looks pretty decent, but a couple suggestions for better system integration? You should use "CXX ?= g++" to allow easily overriding the CXX compiler in case someone wishes to use e.g. clang. Same with your CXXFLAGS, which just turn on debugging and warnings... by setting them via ?= people who have these already set as environment variables can override them, for example PKGBUILDs get CXXFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt"

You should also use the value of LDFLAGS when linking, since build systems may set for example LDFLAGS="-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now", and if the value exists you want to use those preferences.

Distributions usually use those variables to set distro-wide policies for e.g. hardening binaries, configuring the optimization level, configuring whether or not debuginfo packages should be created, and so forth.

Also you may wish to rename the LD variable to LDLIBS which is more conventional.

...

Finally as I mentioned earlier, a common convention is to install to e.g. "$(DESTDIR)$(PREFIX)/bin/attackoftheasteroids" which is set by default to PREFIX ?= /usr/local
Distros will use `make PREFIX=/usr` and `make PREFIX=/usr DESTDIR="$pkgdir"` to build/install, while ordinarily running the makefile will default to installing in /usr/local

In order to do this you'll need to pass PREFIX as a compiler macro, e.g. `g++ -DPREFIX=$(PREFIX) ...` to define "PREFIX" in your source code as being equal to whatever the Makefile had as the PREFIX variable. This lets you use the compiled-in path to resource files in your binary, while still configuring this at build time.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#14 2018-04-13 23:05:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

Eschwartz wrote:

I really have no idea how well it plays, as I don't really play computer games much. smile I was just here to discuss the topics I consider fascinating, which are build systems and PKGBUILDs.

Wait, `make` isn't a computer game?

What about `configure`?  Surely that's some sort of dungeon-crawling labrynth puzzle game.  I thought I was about to reach a new high level in `configure` the other day but I died right before making it to the final build boss.  The complexities and continual uncertainty of autotools could best even the most leet gamers.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#15 2018-04-13 23:06:41

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: Attack of the Asteroids - A 2d shooting and defense game

Trilby wrote:

What about `configure`?  Surely that's some sort of dungeon-crawling labrynth puzzle game.  I thought I was about to reach a new high level in `configure` the other day but I died right before making it to the final build boss.  The complexities and continual uncertainty of autotools could best even the most leet gamers.

You make a convincing argument. big_smile

Last edited by eschwartz (2018-04-13 23:07:05)


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#16 2018-04-14 18:10:33

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: Attack of the Asteroids - A 2d shooting and defense game

Aright I have some bad news. I'm getting two kinds of errors that I'm not sure how to fix. First, the makefile:

CXX ?= g++
CXXFLAGS ?= -g -Wall
PREFIX ?= /usr/share
PROG  = attackoftheasteroids
ODIR  = obj
SRC = $(wildcard *.cpp $(wildcard src/*.cpp))
OBJS = $(addprefix $(ODIR)/,$(SRC:.cpp=.o))
LDLIBS = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

$(ODIR)/%.o: %.cpp
	mkdir -p $(ODIR)/src/
	$(CXX) -DPREFIX=$(PREFIX) -c -o $@ $^ $(CXXFLAGS)

$(PROG): $(OBJS)
	$(CXX) -DPREFIX=$(PREFIX) -o $(PROG) $^ $(LDLIBS)

clean:
	rm -f $(ODIR)/*.o $(PROG)
	
.PHONY: clean

install:
	install -Dm644 License.md "$(DESTDIR)/usr/share/licenses/$(PROG)/LICENSE"
	install -Dm755 attackoftheasteroids "$(DESTDIR)/usr/bin/attackoftheasteroids"
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures" textures/*.png
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/textures/ui" textures/ui/*.png
	install -Dm644 "fonts/ehsmb.ttf" "$(DESTDIR)/usr/share/$(PROG)/fonts/ehsmb.ttf"
	install -Dm644 -t "$(DESTDIR)/usr/share/$(PROG)/audio/sfx/" audio/sfx/*.wav
	install -Dm644 "audio/music/mainMenuTheme.wav" "$(DESTDIR)/usr/share/$(PROG)/audio/music/mainMenuTheme.wav"

Note that this has not been committed to the repo just yet. Now for the errors. I have this line of code:

    blockFont.loadFromFile(PREFIX "/attackoftheasteroids/fonts/ehsmb.ttf");

Which produces this error:

Sat Apr 14 jbs@dmb-gaming-laptop -> make
mkdir -p obj/src/
g++ -DPREFIX=/usr/share -c -o obj/src/main.o src/main.cpp -g -Wall
src/main.cpp: In function ‘int main()’:
<command-line>:0:8: error: expected primary-expression before ‘/’ token
src/main.cpp:29:28: note: in expansion of macro ‘PREFIX’
     blockFont.loadFromFile(PREFIX "/attackoftheasteroids/fonts/ehsmb.ttf");
                            ^~~~~~
<command-line>:0:9: error: ‘usr’ was not declared in this scope
src/main.cpp:29:28: note: in expansion of macro ‘PREFIX’
     blockFont.loadFromFile(PREFIX "/attackoftheasteroids/fonts/ehsmb.ttf");
                            ^~~~~~
<command-line>:0:13: error: ‘share’ was not declared in this scope
src/main.cpp:29:28: note: in expansion of macro ‘PREFIX’
     blockFont.loadFromFile(PREFIX "/attackoftheasteroids/fonts/ehsmb.ttf");
                            ^~~~~~
<command-line>:0:13: note: suggested alternative: ‘unshare’
src/main.cpp:29:28: note: in expansion of macro ‘PREFIX’
     blockFont.loadFromFile(PREFIX "/attackoftheasteroids/fonts/ehsmb.ttf");
                            ^~~~~~
make: *** [Makefile:14: obj/src/main.o] Error 1
Sat Apr 14 jbs@dmb-gaming-laptop -> 

If I quote the previous line of code like so:

    blockFont.loadFromFile("PREFIX/attackoftheasteroids/fonts/ehsmb.ttf");

I get the following error:

mkdir -p obj/src/
g++ -DPREFIX=/usr/share -c -o obj/src/main.o src/main.cpp -g -Wall
g++ -DPREFIX=/usr/share -o attackoftheasteroids obj/src/Enemy.o obj/src/UI.o obj/src/Laser.o obj/src/Bullet.o obj/src/Player.o obj/src/CollisionBox.o obj/src/Audio.o obj/src/Mouse.o obj/src/Shield.o obj/src/main.o -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
Sat Apr 14 jbs@dmb-gaming-laptop -> ./attackoftheasteroids 
Failed to load font "PREFIX/attackoftheasteroids/fonts/ehsmb.ttf" (failed to create the font face)
Sat Apr 14 jbs@dmb-gaming-laptop -> 

The font is not found. I havent been able to find anything on google regarding g++ -D and related errors. The macro seems to be expanding but the result is undefined? Thanks for the help!

Last edited by JohnBobSmith (2018-04-14 18:17:10)


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

#17 2018-04-14 18:42:24

progandy
Member
Registered: 2012-05-17
Posts: 5,184

Re: Attack of the Asteroids - A 2d shooting and defense game

You'll need quotes around your definition

$(CXX) -DPREFIX=\""$(PREFIX)"\" 

https://stackoverflow.com/questions/241 … mmand-line

Last edited by progandy (2018-04-14 18:44:40)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Online

#18 2018-04-14 20:17:23

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Attack of the Asteroids - A 2d shooting and defense game

Alternatively, you can "stringify" the macro within your code.  Though while it helps make your compiler command line look nicer, it's some confusing black magic in the code:

/* define a couple of macros, in this order */
#define STR(s) _STR(s)
#define _STR(s) #s

/* then use STR(PREFIX) wherever needed */
blockFont.loadFromFile(STR(PREFIX) "/attackoftheasteroids/fonts/ehsmb.ttf");

But note, your PREFIX should *not* be /usr/share.  As Eschwartz recommended, /usr/local is a good default, otherwise /usr/ could also be appropriate, but /usr/share is not.  There should be a /bin, /lib, and /share folder under PREFIX (or at least it should be reasonable to create them).  So the prefix should just be /usr/ or /usr/local/ and in your code your should get the font from the concatenation of PREFIX and /share/fonts/ehsmb.ttf.

Last edited by Trilby (2018-04-14 20:18:00)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#19 2018-04-15 00:09:29

JohnBobSmith
Member
From: Canada
Registered: 2014-11-29
Posts: 804

Re: Attack of the Asteroids - A 2d shooting and defense game

Okay I think I've implemented all of the suggestions. big_smile Let me know if I missed anything. The Makefile:

CXX ?= g++
CXXFLAGS ?= -g -Wall
PREFIX ?= /usr/
PROG  = attackoftheasteroids
ODIR  = obj
SRC = $(wildcard *.cpp $(wildcard src/*.cpp))
OBJS = $(addprefix $(ODIR)/,$(SRC:.cpp=.o))
LDLIBS = -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio

all: $(PROG)

$(ODIR)/%.o: %.cpp
	mkdir -p $(ODIR)/src/
	$(CXX) -DPREFIX=\"$(PREFIX)\" -c -o $@ $^ $(CXXFLAGS)

$(PROG): $(OBJS)
	$(CXX) -o $(PROG) $^ $(LDLIBS)

clean:
	rm -f $(ODIR)/src/*.o $(PROG)
	
.PHONY: clean

install:
	install -Dm644 License.md "$(DESTDIR)$(PREFIX)/share/licenses/$(PROG)/LICENSE"
	install -Dm755 attackoftheasteroids "$(DESTDIR)$(PREFIX)/bin/attackoftheasteroids"
	install -Dm644 -t "$(DESTDIR)$(PREFIX)/share/$(PROG)/textures" textures/*.png
	install -Dm644 -t "$(DESTDIR)$(PREFIX)/share/$(PROG)/textures/ui" textures/ui/*.png
	install -Dm644 -t "$(DESTDIR)$(PREFIX)/share/$(PROG)/audio/sfx/" audio/sfx/*.wav
	install -Dm644 "fonts/ehsmb.ttf" "$(DESTDIR)$(PREFIX)/share/$(PROG)/fonts/ehsmb.ttf"
	install -Dm644 "audio/music/mainMenuTheme.wav" "$(DESTDIR)$(PREFIX)/share/$(PROG)/audio/music/mainMenuTheme.wav"

This has been a truly incredible learning opportunity and I am grateful for that! big_smile Now that I hopefully have this Makefile/PKGBUILD stuff out of the way, I can begin work on my planned features. smile


I am diagnosed with bipolar disorder. As it turns out, what I thought was my greatest weakness is now my greatest strength.

Everyday, I make a conscious choice to overcome my challenges and my problems. It's not easy, but its better than the alternative...

Offline

Board footer

Powered by FluxBB