π
<-

nSnake LUA Adventure

Pour TI-Nspire OS 3.0 ou ultérieur.

nSnake LUA Adventure

Unread postby technolapin » 22 Dec 2013, 18:58

Bon, comme vous avez étés si nombreux à télécharger mon snake (plus que deux, c'est énorme), j'en ai fait une nouvelle version et doublé la taille du code :D !

Voici le code, un peut désordonné, mais qui marche:

Code: Select all
function on.resize ()



levels = {
{"too easy", 0.5, 0.5, "color = {unpack(snake[dephased])}", "toric", 1},
{"easy", 0.1, 1, "color = {unpack(snake[dephased])}", "toric", 1},
{"medium", 0.07, 4, "color = {unpack(snake[dephased])}", 2},
{"hard", 0.04, 6, "color = {unpack(snake[dephased])}", 4},
{"very hard", 0.06, 8, "color = {250, 250, 250}", 5},
{"suicide", 0.04, 32, "color = {255, 255, 255}", 16},
{"psychotic", 0.04, 6, "color = {math.random (0, 255), math.random (0, 255), math.random (0, 255)}", 3},
}

background = {}
background[0] = {255, 255, 255}
background[1] = {0, 0, 0}
snake = {}
snake[0] = {0, 0, 0}
snake[1] = {255, 255, 255}
width = platform.window: width  ()
height = platform.window: height  ()
w = math.ceil (width/4)
h = math.ceil (height/4)

requiredscore = 100
unlocked = var.recall ("unlocked") or 1
txt = ""
txtcool = 0
smap = 1

maps = {
{},
{{20, 12, "fill", 40, 32}},
{{18, 16, "portal", w-18, h-16}, {18, h-16, "portal", w-18, 16}},
{{16, 32, "dir", "up"}, {16, 16, "dir", "right"}, {64, 16, "dir", "down"}, {64, 32, "dir", "left"}},
{{35, 27, "dephaser"}, {43, 27, "dephaser"}, {39, 1, "fill", 1, h}},
{{1, 1, "fill", w, 15}, {1, 39, "fill", w, 15}},
{{1, 26, "fill", w, 1}, {40, 1, "fill", 1, h}, {38, 13, "portal", 42, 13}, {19, 28, "portal", 19, 24}, {60, 24, "portal", 60, 28}, {42, 39, "portal", 38, 39}},
}

maps["txt"] = {}
maps["txt"][1] = "This is just an empty map."
maps["txt"][2] = "The wall is not your friend."
maps["txt"][3] = "Welcome to Aperture science, [player name]."
maps["txt"][4] = "The arrows will change your direction."
maps["txt"][5] = "When you go on a dephaser, you're not in our world, so you can't read that."
maps["txt"][6] = "More walls"
maps["txt"][7] = "You can't solve this map! MWOUHAHAHAHA!!!"
map = {}

tile = {}
tile["up"] = "^"
tile["down"] = "∨"
tile["left"] = "<"
tile["right"] = ">"
sel = 0
level = levels[4]
hscores = var.recall ("hightscores") or {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

game    = class ()
endgame = class ()
menu    = class ()
sdif    = class ()
selmap  = class ()
mode = game ()

function add () cool = cool + 2 + (math.floor (#mat/32*level[5])) end
function place ()
apple = {math. random (1, w), math.random (1, h)}
while (map[apple[1]] or {})[apple[2]] do
  apple = {math. random (1, w), math.random (1, h)}
end
end
function move ()
for a = #mat+1, 1, -1 do
  mat[a] = {}
  mat[a]["x"] = mat[a-1]["x"]
  mat[a]["y"] = mat[a-1]["y"]
  if mat[a]["x"] == mat[0]["x"] and  mat[a]["y"] == mat[0]["y"] and a > 1 then mode = endgame () end
  end
mat[0]["x"] = mat[0]["x"] + x
mat[0]["y"] = mat[0]["y"] + y
if cool == 0 then mat[#mat] = nil else cool = cool - 1 end
if mat[0]["x"] == apple[1] and mat[0]["y"] == apple[2] and dephased == 0 then add () place () score = score+level[3] if score >= requiredscore and smap == unlocked then unlocked = unlocked+1 txt = "Map "..unlocked.." unlocked." txtcool = 32 var.store ("unlocked", unlocked) end end
col ()
end
function col ()
sx = mat[0]["x"]
sy = mat[0]["y"]
if map[sx] then
  if map[sx][sy] then
   if map[sx][sy][1] == 0 and dephased == 0 then mode = endgame () end
   if map[sx][sy][1] == "portal" and dephased == 0 then
    mat[0]["x"] = map[sx][sy][2]
    mat[0]["y"] = map[sx][sy][3]
   end
   if map[sx][sy][1] == "dir" then
    if map[sx][sy][2] == "up" and dir == "x" then x = 0 y = -1 dir = "y" end
    if map[sx][sy][2] == "down" and dir == "x" then x = 0 y = 1 dir = "y" end
    if map[sx][sy][2] == "left" and dir == "y" then x = -1 y = 0 dir = "x" end
    if map[sx][sy][2] == "right" and dir == "y" then x = 1 y = 0 dir = "x" end
   end
   if map[sx][sy][1] == "dephaser" then
    if dephased == 0 then
     dephased = 1
    else
     dephased = 0
    end
   end
  end
end
if level[5] == "toric" then
  if mat[0]["x"] < 1 then mat[0]["x"] = w end
  if mat[0]["x"] > w then mat[0]["x"] = 1 end
  if mat[0]["y"] < 1 then mat[0]["y"] = h end
  if mat[0]["y"] > h then mat[0]["y"] = 1 end
else
  if mat[0]["x"] < 1
  or mat[0]["x"] > w
  or mat[0]["y"] < 1
  or mat[0]["y"] > h then mode = endgame ()
end
end
end
function storescore (score)
for a = 1, 10 do
  if score >hscores[a] then
   for b = 10, a+1, -1 do
    hscores[b] = hscores[b-1]
   end
   hscores[a] = score score = -1
  end
end
var.store ("hightscores", hscores)
end

function game: init ()
map = {}
txt = maps["txt"][smap] or ""
for a = 1, #maps[smap] do
  p1 = maps[smap][a][1]
  p2 = maps[smap][a][2]
  p3 = maps[smap][a][4]
  p4 = maps[smap][a][5]
  typ = maps[smap][a][3]
  if map[p1] then else map[p1] = {} end
  if typ then else map[p1][p2] = 0 end
  if typ == "fill" then
   for b = p1, p1+p3-1 do
    if map[b] then else map[b] = {} end
    for c = p2, p2+p4-1 do
     map[b][c] = {0}
    end
   end
  end
  if typ == "portal" then
   if map[p3] then else map[p3] = {} end
    map[p1][p2] = {"portal", p3, p4}
    map[p3][p4] = {"portal", p1, p2}
  end
  if typ == "dir" then
   map[p1][p2] = {"dir", p3}
  end
  if typ == "dephaser" then
   map[p1][p2] = {"dephaser"}
  end
end
dir = "x"
score = 0
apple = {}
mat = {}
cool = 0
dephased = 0
x = 1
y = 0
pause = 0
for a = 0, 8 do
  mat[a] = {}
  mat[a]["x"] = 8-a
  mat[a]["y"] = 16
end
place ()
timer.start (level[2])
end
game: init ()
function game: paint (gc)
gc: setColorRGB (unpack (background[dephased]))
gc: fillRect (0, 0, width, height)
loadstring (level[4])()
gc: setColorRGB (unpack (color))
for a = 0, #mat do
  gc: fillArc (mat[a]["x"]*4-4, mat[a]["y"]*4-4, 4, 4, 0, 360)
end
gc: setColorRGB (0, 180, 0)
gc: fillRect (apple[1]*4-5, apple[2]*4-5, 3, 3)
gc: setColorRGB (255, 0, 0)
gc: fillArc (apple[1]*4-4, apple[2]*4-4, 4, 4, 0, 360)
for a = 1, #maps[smap] do
  if maps[smap][a][3] == "fill" then gc: setColorRGB (100, 100, 100) gc: fillRect(maps[smap][a][1]*4-4, maps[smap][a][2]*4-4, maps[smap][a][4]*4, maps[smap][a][5]*4) end
  if maps[smap][a][3] == "portal" then gc: setColorRGB (100, 200, 255) gc: fillRect(maps[smap][a][1]*4-4, maps[smap][a][2]*4-4, 4, 4) gc: setColorRGB (255, 230, 0) gc: fillRect(maps[smap][a][4]*4-4, maps[smap][a][5]*4-4, 4, 4) end
  if maps[smap][a][3] == "dir" then gc: setFont ("serif", "b", 10) gc: setColorRGB (0, 0, 0) gc: drawString (tile[maps[smap][a][4]], maps[smap][a][1]*4-5, maps[smap][a][2]*4+6) end
  if maps[smap][a][3] == "dephaser" then gc: setColorRGB (177, 215, 127)  gc: fillRect(maps[smap][a][1]*4-4, maps[smap][a][2]*4-4, 4, 4) end
end
gc: setColorRGB (0, 0, 0)
gc: drawString (score, 4, 20)
gc: setFont ("serif", "b", 8)
gc: drawString (txt, 2, height)
end
function game: timer () if pause == 0 then move () platform.window: invalidate () if x == 0 then dir = "y" else dir = "x" end end end
function game: left  () if dir == "y" then x = -1 y = 0 end end
function game: right () if dir == "y" then x = 1  y = 0 end end
function game: up    () if dir == "x" then y = -1 x = 0 end end
function game: down  () if dir == "x" then y = 1  x = 0 end end
function game: enter () mode = menu menu: init () end
function game: charin (char)
if char == "4" then mode: left  () end
if char == "6" then mode: right () end
if char == "8" then mode: up    () end
if char == "2" then mode: down  () end
end

function endgame: init () self.cool = 30 timer.start (0.06) sel = 0 storescore (score) end
function endgame: timer ()
if self.cool > 0 then self.cool = self.cool - 1 end
platform.window: invalidate ()
end
function endgame: paint (gc)
gc: setFont ("serif", "b", 32)
gc: drawString ("GAME OVER", 16, 60+self.cool)
if self.cool == 0 then
  gc: setFont ("serif", "b", 16)
  gc: drawString ("⇒", 2, 102+sel*32)
  gc: drawString ("play again", 24, 100)
  gc: setFont ("serif", "b", 12)
  gc: drawString ("Hight scores:", 226, 16)
  for a = 1, 10 do
   gc: drawString ("-"..hscores[a], 230, 18*a+18)
  end
end
end

function endgame: enter () if self.cool == 0 then mode = game game: init () end end
function endgame: left  () end
function endgame: right () end
function endgame: down  () end
function endgame: up    () end
function endgame: charin() end

function menu: init () sel = 1 end
function menu: timer () platform.window: invalidate () end
function menu: paint (gc)
gc: setFont ("serif", "b", 32)
gc: drawString ("GAME PAUSED", (width-236)/2, 48)
gc: setFont ("serif", "b", 16)
gc: drawString ("Resume game", (width-126)/2, 72)
gc: drawString ("Change difficulty", (width-159)/2, 96)
gc: drawString ("Change map", (width-117)/2, 120)
gc: drawString ("⇒", 32, 24*sel+48)
end
function menu: left () end
function menu: right () end
function menu: up () if sel>1 then sel=sel-1 end end
function menu: down () if sel<3 then sel=sel+1 end end
function menu: enter () if sel == 1 then mode = game elseif sel == 2 then mode = sdif elseif sel == 3 then mode = selmap end if sel > 1 then mode: init () end end
function menu: charin (char) end


function sdif: init () sel = 0 timer.start (0.1) end
function sdif: timer () platform.window: invalidate () end
function sdif: paint (gc)
gc: drawString ("Resume", 220, 196)
for a = 1, 7 do
  gc: drawString (levels[a][1], 32, 48+20*a)
end
if sel == 0 then gc: drawString ("⇒", 200, 196) else gc: drawString ("⇒", 16, 48+20*sel) end
gc: setFont ("serif", "b", 16)
gc: drawString ("Change difficulty:", 8, 32)
end
function sdif: left  () end
function sdif: right () end
function sdif: up    () if sel > 0 then sel = sel-1 else sel = 7 end end
function sdif: down  () if sel < 7 then sel = sel+1 else sel = 0 end end
function sdif: enter () if sel > 0 then level = levels[sel] game: init () end mode = game end
function sdif: charin () end

function selmap: init   () sel = 1 wmin = 1 end
function selmap: timer () platform.window: invalidate () end
function selmap: paint  (gc)
gc: setFont ("serif", "b", 32)
gc: drawString ("Change Map", (width-236)/2, 32)
gc: setFont ("serif", "b", 16)
for a = wmin, wmin+6 do
  if maps[a] then
   gc: drawString ("map "..a, 60, 24*(a-wmin+1)+32)
   if a > unlocked then
    gc: setColorRGB (255, 0, 0)
    gc: drawString ("χ", 20, 24*(a-wmin+1)+32)
   end
   if a < unlocked then
    gc: setColorRGB (0, 255, 0)
    gc: drawString ("✓", 20, 24*(a-wmin+1)+32)
   end
   if a == unlocked then
    gc: setColorRGB (100, 200, 255)
    gc: drawString ("★", 16, 24*(a-wmin+1)+32)
   end
   gc: setColorRGB (0, 0, 0)
  end
  gc: drawString ("Back", 224, 200)
  if sel > 0 then gc: drawString ("⇒", 32, 24*(sel-wmin+1)+32) else gc: drawString ("⇒", 200, 200) end
end
end
function selmap: left   () sel = wmin end
function selmap: right  () sel = 0 end
function selmap: up     () if sel > 0 then sel = sel-1 else sel = #maps end if sel > wmin+6 then wmin = sel-6 end if sel < wmin and sel > 0 then wmin = sel end end
function selmap: down   () if sel < #maps then sel = sel+1 else sel = 0 end if sel > wmin+6 then wmin = sel-6 end if sel < wmin and sel > 0 then wmin = sel end end
function selmap: enter  ()
if sel > 0 and sel <= unlocked then
  smap = sel
  mode = game
  mode: init ()
end
if sel == 0 then
  mode = menu
  mode: init ()
end
end
function selmap: charin () end



function on.timer () mode: timer ()     end
function on.paint (gc) mode: paint (gc) end
function on.arrowLeft () mode: left ()  end
function on.arrowRight() mode: right () end
function on.arrowUp   () mode: up ()    end
function on.arrowDown () mode: down ()  end
function on.enterKey  () mode: enter () end
function on.charIn (char) mode: charin (char) end


end



J'espère que je vais pas trop me faire explosé à propos de la propreté du code :? , et je m'en vais de ce pas l'upload (enfin, il manque des maps, je ferais ça au fur et à mesure ;) )
Votez Kasane Teto 2017
User avatar
technolapin
Niveau 13: CU (Calculateur Universel)
Niveau 13: CU (Calculateur Universel)
Level up: 97.8%
 
Posts: 514
Images: 25
Joined: 31 Dec 2012, 10:48
Location: Chez moi
Gender: Male
Calculator(s):
MyCalcs profile
Class: Chui en vacance ducon

Re: nSnake LUA Adventure

Unread postby matref » 22 Dec 2013, 19:04

Kessecékça ? :P

On veut un TNS nous :D
User avatar
matref
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 25%
 
Posts: 506
Joined: 11 Dec 2011, 03:08
Location: France, Châteaurenard
Gender: Male
Calculator(s):
MyCalcs profile
Class: Prépa MPSI

Re: nSnake LUA Adventure

Unread postby technolapin » 22 Dec 2013, 19:07

Rhaaa! mais je suis en train de l'upload! :D
Votez Kasane Teto 2017
User avatar
technolapin
Niveau 13: CU (Calculateur Universel)
Niveau 13: CU (Calculateur Universel)
Level up: 97.8%
 
Posts: 514
Images: 25
Joined: 31 Dec 2012, 10:48
Location: Chez moi
Gender: Male
Calculator(s):
MyCalcs profile
Class: Chui en vacance ducon

Re: nSnake LUA Adventure

Unread postby matref » 22 Dec 2013, 19:07

Ben oui mais je suis tellement un fan sans cervelle que j'ai pas pu attendre :D
User avatar
matref
Niveau 15: CC (Chevalier des Calculatrices)
Niveau 15: CC (Chevalier des Calculatrices)
Level up: 25%
 
Posts: 506
Joined: 11 Dec 2011, 03:08
Location: France, Châteaurenard
Gender: Male
Calculator(s):
MyCalcs profile
Class: Prépa MPSI

Re: nSnake LUA Adventure

Unread postby mdr1 » 22 Dec 2013, 19:38

Le jeu est super ! Tu as une belle marge de progression en plus. :bj:
Image ImageImage
User avatar
mdr1Premium
Niveau 14: CI (Calculateur de l'Infini)
Niveau 14: CI (Calculateur de l'Infini)
Level up: 44%
 
Posts: 1083
Images: 12
Joined: 28 Mar 2011, 00:00
Gender: Not specified
Calculator(s):
MyCalcs profile
Class: Je voyage toujours en première.


Return to Nspire-Lua

Who is online

Users browsing this forum: ClaudeBot [spider] and 6 guests

-
Search
-
Social TI-Planet
-
Featured topics
Comparaisons des meilleurs prix pour acheter sa calculatrice !
"1 calculatrice pour tous", le programme solidaire de Texas Instruments. Reçois gratuitement et sans aucune obligation d'achat, 5 calculatrices couleur programmables en Python à donner aux élèves les plus nécessiteux de ton lycée. Tu peux recevoir au choix 5 TI-82 Advanced Edition Python ou bien 5 TI-83 Premium CE Edition Python.
Enseignant(e), reçois gratuitement 1 exemplaire de test de la TI-82 Advanced Edition Python. À demander d'ici le 31 décembre 2024.
Aidez la communauté à documenter les révisions matérielles en listant vos calculatrices graphiques !
1234
-
Donations / Premium
For more contests, prizes, reviews, helping us pay the server and domains...
Donate
Discover the the advantages of a donor account !
JoinRejoignez the donors and/or premium!les donateurs et/ou premium !


Partner and ad
Notre partenaire Jarrety Calculatrices à acheter chez Calcuso
-
Stats.
1231 utilisateurs:
>1212 invités
>14 membres
>5 robots
Record simultané (sur 6 mois):
6892 utilisateurs (le 07/06/2017)
-
Other interesting websites
Texas Instruments Education
Global | France
 (English / Français)
Banque de programmes TI
ticalc.org
 (English)
La communauté TI-82
tout82.free.fr
 (Français)