Skip to content

Commit

Permalink
Initial gamerzilla implementation. Still need to make it conditional.
Browse files Browse the repository at this point in the history
  • Loading branch information
dulsi committed Jul 26, 2020
1 parent 19d9e08 commit 6d26c3d
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 2 deletions.
Binary file added assets/gamerzilla/completed0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gamerzilla/completed1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gamerzilla/monster0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/gamerzilla/monster1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions assets/gamerzilla/smalltrek.game
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"shortname": "smalltrek",
"name": "Smalltrek",
"image": "gamerzilla/smalltrek.png",
"version": "1",
"trophy": [
{
"trophy_name": "Peace!",
"trophy_desc": "Restore peace to the universe.",
"max_progress": "32",
"trueimage": "gamerzilla/completed1.png",
"falseimage": "gamerzilla/completed0.png"
},
{
"trophy_name": "You Monster",
"trophy_desc": "Eradicated all Cuwudles from a planet.",
"max_progress": "0",
"trueimage": "gamerzilla/monster1.png",
"falseimage": "gamerzilla/monster0.png"
}
]
}
Binary file added assets/gamerzilla/smalltrek.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/gamerzilla.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{.deadCodeElim: on.}

template decl(libname, filename: untyped) =
when not declared `libname`:
const `libname`* {.inject.} = filename

when defined windows:

decl(GAMERZILLA_LIB, "libgamerzilla.dll")

elif defined macosx:

decl(GAMERZILLA_LIB, "libgamerzilla.dylib")

else:

decl(GAMERZILLA_LIB, "libgamerzilla.so")

proc start*(server: cint, savedir: cstring): cint {.
cdecl, importc: "GamerzillaStart", dynlib: GAMERZILLA_LIB, discardable.}

proc setGameFromFile*(filename: cstring, datadir: cstring): cint {.
cdecl, importc: "GamerzillaSetGameFromFile", dynlib: GAMERZILLA_LIB.}

proc getTrophyStat*(gameID: cint, name: cstring, progress: ptr cint): cint {.
cdecl, importc: "GamerzillaGetTrophyStat", dynlib: GAMERZILLA_LIB, discardable.}

proc setTrophy*(gameID: cint, name: cstring): cint {.
cdecl, importc: "GamerzillaSetTrophy", dynlib: GAMERZILLA_LIB, discardable.}

proc setTrophyStat*(gameID: cint, name: cstring, progress: cint): cint {.
cdecl, importc: "GamerzillaSetTrophyStat", dynlib: GAMERZILLA_LIB, discardable.}

proc quit*() {.
cdecl, importc: "GamerzillaQuit", dynlib: GAMERZILLA_LIB.}
33 changes: 31 additions & 2 deletions src/main.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import sequtils
import pool
import math
import glitch
import gamerzilla
import sdl2/sdl

{.this:self.}

Expand Down Expand Up @@ -170,6 +172,9 @@ type Message = object
step: int
ttl: float32

type GameStats {.pure.} = enum
Eradicated

# GLOBALS

var frame: int
Expand All @@ -178,6 +183,7 @@ var nextLevelId: int
var previousLevelId: int = -1
var unlockedLevel: float32
var levelsCompleted: array[32, int]
var gameStatsCollected: array[GameStats, int]
var currentLevel: Level
var lastCursor = vec2i(0,0)
var cursor = vec2i(0,0)
Expand All @@ -192,9 +198,23 @@ var particles: Pool[Particle]
var confirmAbort: bool
var warpUnlocked: bool
var messages: seq[Message]
var gameID: int

var moveBuffer: seq[Vec2i]


proc updateTrophies() =
var num : cint = 0
gamerzilla.getTrophyStat(gameID, "Peace!", num.addr)
var tmp : cint = 0
for i in 0..<levelsCompleted.len:
if levelsCompleted[i] > 0:
tmp += 1
if tmp > num:
gamerzilla.setTrophyStat(gameID, "Peace!", tmp)
if gameStatsCollected[GameStats.Eradicated] > 0:
gamerzilla.setTrophy(gameID, "You Monster")

proc getViewPos(self: Movable): Vec2i =
let currentPos = vec2f(float32(pos.x * 16), float32(pos.y * 16))
let lastPos = vec2f(float32(lastPos.x * 16), float32(lastPos.y * 16))
Expand Down Expand Up @@ -645,6 +665,10 @@ method update(self: Ship, dt: float32) =
if (currentLevel.success or currentLevel.failed or currentLevel.aborted) and currentLevel.timeout <= 0:
if altitude == 0:
sfx(3,sfxTakeoff.int)
gameStatsCollected[GameStats.Eradicated] += 1
updateConfigValue("Stats", $GameStats.Eradicated, $gameStatsCollected[GameStats.Eradicated])
saveConfig();
updateTrophies()
# taking off
shake += 0.5
altitude = lerp(altitude, 128, 0.01)
Expand Down Expand Up @@ -822,8 +846,6 @@ proc update(self: var Level, dt: float32) =
p.pos += p.vel
p.vel *= 0.98



proc gameInit() =
#setWindowTitle("smalltrek")
#setTargetSize(128,128)
Expand Down Expand Up @@ -1031,6 +1053,11 @@ proc menuInit() =
levelsCompleted[i] = try: parseInt(getConfigValue("Levels", $i)) except: 0
if levelsCompleted[i] > 0:
unlockedLevel += 1.25
updateTrophies()

for i in low(GameStats)..high(GameStats):
gameStatsCollected[i] = try: parseInt(getConfigValue("Stats", $i)) except: 0
updateTrophies()

nextLevelId = 33
for i in 0..<levelsCompleted.len:
Expand Down Expand Up @@ -1527,5 +1554,7 @@ proc introDraw() =
nico.run(menuInit, menuUpdate, menuDraw)

nico.init("impbox","smalltrek")
gamerzilla.start(0, $sdl.getPrefPath("impbox","smalltrek"))
gameID = int gamerzilla.setGameFromFile("assets/gamerzilla/smalltrek.game", "./assets/")
nico.createWindow("smalltrek", 128,128,4,false)
nico.run(introInit, introUpdate, introDraw)

0 comments on commit 6d26c3d

Please sign in to comment.