Skip to content

Commit

Permalink
Add character select
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinShadewing committed Jun 27, 2022
1 parent d47377a commit 02571b4
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 10 deletions.
1 change: 1 addition & 0 deletions game.brx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ donut("src/pred.nut")
donut("src/globals.nut")
donut("src/gmmain.nut")
donut("src/gmplay.nut")
donut("src/gmcharsel.nut")
donut("src/cursor.nut")
donut("src/menus.nut")
donut("src/debug.nut")
Expand Down
5 changes: 5 additions & 0 deletions mods/pony.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//Use this as a basis for adding your own custom prey
sprPrey["Pony"] <- {
fly = newSprite("res/pone0.png", 32, 30, 0, 0, 16, 14),
lose = 0
}
24 changes: 24 additions & 0 deletions res/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"main-menu" : {
"single" : "Single Player",
"multi" : "Multi Player",
"options" : "Options",
"quit" : "Quit"
},

"options-menu" : {
"difficulty" : "Difficulty",
"player0" : "Prey A",
"player1" : "Prey B",
"pred" : "Predator",
"fullscreen" : "Full Screen",
"cursor" : "Mouse Cursor"
},

"boolean" : {
"on" : "On",
"off" : "Off",
"yes" : "Yes",
"no" : "No"
}
}
3 changes: 0 additions & 3 deletions src/assets.nut
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ print("Loaded sndGulp.")
}
}

//Misc prey
::sprPone0 <- newSprite("res/pone0.png", 32, 30, 0, 0, 16, 14)

//Background
::bg0 <- newSprite("res/background0.png", 160, 240, 0, 0, 0, 0)
::bg1 <- newSprite("res/background1.png", 95, 48, 0, 0, 0, 0)
Expand Down
5 changes: 3 additions & 2 deletions src/globals.nut
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
right = k_d
},
prey0 = "Kelvin",
prey1 = "Passy",
prey1 = "Pony",
pred = "Comito",
showcursor = false
showcursor = false,
fullscreen = false
}

::strDifficulty <- ["Easy", "Normal", "Difficult"]
100 changes: 100 additions & 0 deletions src/gmcharsel.nut
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
::gvCharSelMode <- 0
::gvCharSelArray <- []

::startCharSel <- function(mode) {
gvCharSelMode = mode

gvCharSelArray.clear()

//Generate character list
switch(gvCharSelMode) {
case 0:
case 1:
foreach(key, i in sprPrey) {
gvCharSelArray.push(key)
}
break
case 2:
foreach(key, i in sprPred) {
gvCharSelArray.push(key)
}
break
}

//Set cursor to character
switch(gvCharSelMode) {
case 0:
for(local i = 0; i < gvCharSelArray.len(); i++) {
if(gvCharSelArray[i] == config.prey0) {
cursor = i
break
}
}
break
case 1:
for(local i = 0; i < gvCharSelArray.len(); i++) {
if(gvCharSelArray[i] == config.prey1) {
cursor = i
break
}
}
break
case 2:
for(local i = 0; i < gvCharSelArray.len(); i++) {
if(gvCharSelArray[i] == config.pred) {
cursor = i
break
}
}
break
}

gvCharSelArray.sort()
gm = gmCharSel
}

::gmCharSel <- function() {
drawBackground()

switch(gvCharSelMode) {
case 0:
case 1:
if(sprPrey.rawin(gvCharSelArray[cursor])) {
drawSprite(sprPrey[gvCharSelArray[cursor]].fly, getFrames() / 6, screenW() / 2, screenH() / 2)
drawText(font, (screenW() / 2) - (gvCharSelArray[cursor].len() * 4), 32, gvCharSelArray[cursor])
}
break
case 2:
if(sprPred.rawin(gvCharSelArray[cursor])) {
drawSprite(sprPred[gvCharSelArray[cursor]].head, getFrames() / 6, screenW() / 2, screenH() / 2)
drawSprite(sprPred[gvCharSelArray[cursor]].body, getFrames() / 6, screenW() / 2, screenH() / 2)
drawSprite(sprPred[gvCharSelArray[cursor]].wing, getFrames() / 6, screenW() / 2, screenH() / 2)
drawText(font, (screenW() / 2) - (gvCharSelArray[cursor].len() * 4), 32, gvCharSelArray[cursor])
}
break
}

if(keyPress(k_left)) cursor--
if(keyPress(k_right)) cursor++

if(cursor < 0) cursor = gvCharSelArray.len() - 1
if(cursor > gvCharSelArray.len() - 1) cursor = 0

if(keyPress(k_enter) || keyPress(k_space)) {
switch(gvCharSelMode) {
case 0:
config.prey0 = gvCharSelArray[cursor]
break
case 1:
config.prey1 = gvCharSelArray[cursor]
break
case 2:
config.pred = gvCharSelArray[cursor]
break
}

gm = gmMain
}

if(keyPress(k_escape)) gm = gmMain
}
1 change: 0 additions & 1 deletion src/gmmain.nut
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
::gmMain <- function() {
drawSprite(bgTitle, 0, 0, 0)
textMenu()
if(keyPress(k_escape)) gvQuit = true
}
3 changes: 3 additions & 0 deletions src/main.nut
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

if(fileExists("config.json")) config = mergeTable(config, jsonRead(fileRead("config.json")))

local modlist = lsdir("mods")
for(local i = 0; i < modlist.len(); i++) if(modlist[i] != "." && modlist[i] != "..") donut("mods/" + modlist[i])

//Start the music
//playMusic(music, -1)

Expand Down
6 changes: 3 additions & 3 deletions src/menus.nut
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ const menuY = 40
},
{
name = function(){ return "Prey 1: " + config.prey0 },
func = function(){}
func = function(){ startCharSel(0) }
},
{
name = function(){ return "Prey 2: " + config.prey1 },
func = function(){}
func = function(){ startCharSel(1) }
},
{
name = function(){ return "Predator: " + config.pred },
func = function(){}
func = function(){ startCharSel(2) }
},
{
name = function(){ return "Back" },
Expand Down
6 changes: 5 additions & 1 deletion src/pred.nut
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ const predMiss = 3
{
if(target.y > y + 0.2 && yspeed < 1.5) yspeed += 0.06
if(target.y < y - 0.2 && yspeed > -1.5) yspeed -= 0.06
if(target.x < x && xspeed > -2) xspeed -= 0.05
if(target.x < x) {
if(xspeed > -2) xspeed -= 0.15
if(target.y < y) yspeed -= 0.15
if(target.y > y) yspeed += 0.15
}
xspeed += 0.005

if(xspeed > 0.05 && x < target.x && distance2(x, y, target.x, target.y) > 64) xspeed -= 0.05
Expand Down

0 comments on commit 02571b4

Please sign in to comment.