Skip to content
This repository has been archived by the owner on Jan 13, 2020. It is now read-only.

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebuleon committed Feb 24, 2014
0 parents commit 56a94fa
Show file tree
Hide file tree
Showing 27 changed files with 11,551 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.o
ativayeban
ativayeban-od
ativayeban-od.opk
.opk_data/
3 changes: 3 additions & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The code for Ativayeban is licensed under the GNU General Public License, version 2 or later at your option.

Code (c) Nebuleon Fumika <[email protected]>
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
TARGET ?= ativayeban

ifeq ($(TARGET), ativayeban-od)
CC := mipsel-linux-gcc
STRIP := mipsel-linux-strip
OBJS = platform/opendingux.o
else
CC := gcc
STRIP := strip
OBJS = platform/general.o
endif

SYSROOT := $(shell $(CC) --print-sysroot)
SDL_CFLAGS := $(shell $(SYSROOT)/usr/bin/sdl-config --cflags)
SDL_LIBS := $(shell $(SYSROOT)/usr/bin/sdl-config --libs)

OBJS += main.o init.o title.o game.o score.o bg.o draw.o text.o unifont.o

HEADERS += main.h init.h platform.h title.h game.h score.h bg.h draw.h text.h unifont.h

INCLUDE := -I.
DEFS :=

CFLAGS = $(SDL_CFLAGS) -Wall -Wno-unused-variable \
-O2 -fomit-frame-pointer $(DEFS) $(INCLUDE)
LDFLAGS := $(SDL_LIBS) -lm -lSDL_image

include Makefile.rules

.PHONY: all opk

all: $(TARGET)

$(TARGET): $(OBJS)

opk: $(TARGET).opk

$(TARGET).opk: $(TARGET)
$(SUM) " OPK $@"
$(CMD)rm -rf .opk_data
$(CMD)cp -r data .opk_data
$(CMD)cp $< .opk_data/$(TARGET)
$(CMD)$(STRIP) .opk_data/$(TARGET)
$(CMD)mksquashfs .opk_data $@ -all-root -noappend -no-exports -no-xattrs -no-progress >/dev/null

# The two below declarations ensure that editing a .c file recompiles only that
# file, but editing a .h file recompiles everything.
# Courtesy of Maarten ter Huurne.

# Each object file depends on its corresponding source file.
$(C_OBJS): %.o: %.c

# Object files all depend on all the headers.
$(OBJS): $(HEADERS)
25 changes: 25 additions & 0 deletions Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ifdef V
CMD:=
SUM:=@\#
else
CMD:=@
SUM:=@echo
endif

.PHONY: $(TARGET)
$(TARGET): $(OBJS)
$(SUM) " LD $@"
$(CMD)$(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@

%.o: %.c
$(SUM) " CC $@"
$(CMD)$(CC) $(CFLAGS) -c $< -o $@

%.o: %.S
$(SUM) " AS $@"
$(CMD)$(CC) $(ASFLAGS) -c $< -o $@

.PHONY: clean
clean:
$(SUM) " CLEAN ."
$(CMD)rm -rf $(OBJS) $(TARGET) $(DATA_TO_CLEAN)
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ativayeban

You are a ball and you must fall into the holes to avoid being crushed by the top of the screen!

This game requires SDL 1.2 and a C compiler. It is optimised for low-resolution screens.

Everything's under the GPL version 2.

To compile this for PC, use `make clean; make` on a PC with SDL. You'll then get a windowed SDL game.

To compile this for OpenDingux, use `make TARGET=ativayeban-od clean; make TARGET=ativayeban-od opk` on a PC with the `PATH` set to include your OpenDingux mipsel toolchain.
34 changes: 34 additions & 0 deletions bg.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Ativayeban, background rendering code file
* Copyright (C) 2014 Nebuleon Fumika <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include <math.h>

#include "SDL.h"

#include "main.h"

void AdvanceBackground(uint32_t Milliseconds)
{
}

void DrawBackground(void)
{
SDL_Rect ScreenRect = { .x = 0, .y = 0, .w = Screen->w, .h = Screen->h };
SDL_FillRect(Screen, &ScreenRect, SDL_MapRGB(Screen->format, 0, 0, 0));
}
28 changes: 28 additions & 0 deletions bg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Ativayeban, background rendering header
* Copyright (C) 2014 Nebuleon Fumika <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef _BG_H_
#define _BG_H_

#include <stdint.h>

extern void AdvanceBackground(uint32_t Milliseconds);
extern void DrawBackground(void);

#endif /* !defined(_BG_H_) */
9 changes: 9 additions & 0 deletions data/default.gcw0.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Desktop Entry]

Name=Ativayeban
Comment=Fall through a labyrinth. Avoid getting crushed!
Exec=ativayeban-od
Terminal=false
Type=Application
StartupNotify=true
Categories=games;
70 changes: 70 additions & 0 deletions draw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <math.h>
#include <stdio.h>

#include "SDL.h"

/*
* SDL_Surface 32-bit circle-fill algorithm without using trig
*
* While I humbly call this "Celdecea's Method", odds are that the
* procedure has already been documented somewhere long ago. All of
* the circle-fill examples I came across utilized trig functions or
* scanning neighbor pixels. This algorithm identifies the width of
* a semi-circle at each pixel height and draws a scan-line covering
* that width.
*
* The code is not optimized but very fast, owing to the fact that it
* alters pixels in the provided surface directly rather than through
* function calls.
*
* http://content.gpwiki.org/index.php/SDL:Tutorials:Drawing_and_Filling_Circles
*/
void DRAW_FillCircle(SDL_Surface *surface, int cx, int cy, int radius, Uint32 pixel)
{
if (SDL_MUSTLOCK(surface))
SDL_LockSurface(surface);
// Note that there is more to altering the bitrate of this
// method than just changing this value. See how pixels are
// altered at the following web page for tips:
// http://www.libsdl.org/intro.en/usingvideo.html
static const int BPP = 4;

float r = (float) radius;
float dy;

for (dy = 1.0f; dy <= r; dy += 1.0f)
{
// This loop is unrolled a bit, only iterating through half of the
// height of the circle. The result is used to draw a scan line and
// its mirror image below it.

// The following formula has been simplified from our original. We
// are using half of the width of the circle because we are provided
// with a center and we need left/right coordinates.

float dx = floorf(sqrtf((2.0f * r * dy) - (dy * dy)));
int x = cx - dx;
if (x < 0)
x = 0;

// Grab a pointer to the left-most pixel for each half of the circle
Uint8 *target_pixel_a = (Uint8 *)surface->pixels + ((int)(cy + r - dy)) * surface->pitch + x * BPP;
Uint8 *target_pixel_b = (Uint8 *)surface->pixels + ((int)(cy - r + dy)) * surface->pitch + x * BPP;

for (; x <= cx + dx && x < surface->w; x++)
{
// Range check in Y (clip to the surface's bounds)
// for both pixels to be drawn.
if ((int) (cy + r - dy) >= 0
&& (int) (cy + r - dy) < surface->h)
*(Uint32 *)target_pixel_a = pixel;
if ((int) (cy - r + dy) >= 0
&& (int) (cy - r + dy) < surface->h)
*(Uint32 *)target_pixel_b = pixel;
target_pixel_a += BPP;
target_pixel_b += BPP;
}
}
if (SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
}
8 changes: 8 additions & 0 deletions draw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _DRAW_H_
#define _DRAW_H_

#include "SDL.h"

extern void DRAW_FillCircle(SDL_Surface *surface, int cx, int cy, int radius, Uint32 pixel);

#endif /* !defined(_DRAW_H_) */
Loading

0 comments on commit 56a94fa

Please sign in to comment.