0 Members and 1 Guest are viewing this topic.
-- IMAGES --backSRC = ...duckAliveSRC = ...duckDeadSRC = ...dogSRC = ...img_dog = image.new(dogSRC)img_duckAlive = image.new(duckAliveSRC)img_duckDead = image.new(duckDeadSRC)img_background = image.new(backSRC)-- CONSTANTS --duck = { h = image.height(img_duckAlive), -- 30 px w = image.width(img_duckAlive) -- 37 px}inc = 5 -- image movement incrementbg_gap = 50 -- background gap in coord Xfunction init() dx = 100 dy = 50 alive = 1 x = 0 y = 0endinit()function on.paint(gc) cursor.set("translation") cursor.show() -- Paint background gc:setColorRGB(0, 0, 0) gc:fillRect(0, 0, ww, wh) gc:drawImage(img_background, bg_gap, 0) if alive==1 then gc:drawImage(img_duckAlive, dx, dy) gc:drawImage(img_duckAlive, dx, dy) else if dy+duck.w <170 then gc:drawImage(img_duckDead, dx, dy) else gc:drawImage(img_dog, 150, 110) end end AI()endfunction on.resize(width, height) ww = width wh = heightendfunction on.mouseDown(x, y) if between(dx, x, dx+duck.w) and between(dy, y, dy+duck.h) then shot() else miss() endendfunction between(a, x, b) -- Checks if "x" is between range [a,b] if a <= x and x <= b then return true else return false endendfunction AI() --place your Artificial Intelligence code here if alive==1 then if direction==1 then dx = dx-inc dy = dy-inc else dx = dx+inc dy = dy+inc end if dx==bg_gap then direction=1 end if dy >= wh then direction=0 end elseif dy+duck.w < 170 then dy = dy+inc endendfunction shot() alive=0endfunction miss() -- Determine what happens if you missed a shotendfunction on.escapeKey() init() platform.window:invalidate()end
Tell me when its playable, because all I see is a duck flying down with incredibly low framerate, and thats on the PC, donget me started with the on calc bit
Quote from: Augs on September 04, 2012, 06:12:42 pmTell me when its playable, because all I see is a duck flying down with incredibly low framerate, and thats on the PC, donget me started with the on calc bitWell at least give him a chance to start in Nspire programming and be more respectful for new coders. You should maybe suggest him optimizing tricks like "Someone" did, especially considering so far you didn't contribute anything for the Nspire, unlike annoyingcalc, who is trying to.
platform.apilevel = "1.0"----------------------------- Constants -----------------------------inc = 5 -- image movement incrementbg_gap = 50 -- background gap in coord-- X----------------------------- Events -----------------------------function on.paint(gc) -- Paint background gc:setColorRGB(0, 0, 0) gc:fillRect(0, 0, ww, wh) gc:drawImage(img_background, bg_gap, 0) if alive then gc:drawImage(img_duckAlive, dx, dy) else if dy + duck.h < 194 then gc:drawImage(img_duckDead, dx, dy) else gc:drawImage(img_dog, dx, dy-duck.h) end end gc:setColorRGB(255, 255, 255) gc:drawString(msg, 0, 0, "top")endfunction on.resize(width, height) cursor.set("translation") cursor.show() ww, wh = width, height platform.window:invalidate()endfunction on.mouseDown(x, y) if between(dx, x, dx + duck.w) and between(dy, y, dy + duck.h) then shot() else miss() end platform.window:invalidate()endfunction on.escapeKey() init() platform.window:invalidate()endfunction on.timer() AI() platform.window:invalidate()end----------------------------- Functions -----------------------------function init() dx = 100 dy = 50 dirX = 1 dirY = 1 alive = true x = 0 y = 0 msg = ""endfunction between(a, x, b) -- Checks if "x" is between range [a,b] return (a <= x) and (x <= b)endfunction AI() if alive then dx = dx + dirX*inc dy = dy + dirY*inc elseif dy + duck.h < 194 then dy = dy + inc end if dx <= bg_gap then dirX = 1 end if dx >= ww-duck.w then dirX = -1 end if dy <= 0 then dirY = 1 end if dy >= 170-duck.h then dirY = -1 endendfunction shot() alive = false msg = "Shot !"endfunction miss() -- Determine what happens if you missed a shot msg = "Missed !"end----------------------------- Init: ------------------------------- images --img_dog = image.new(dogSRC)img_duckAlive = image.new(duckAliveSRC)img_duckDead = image.new(duckDeadSRC)img_background = image.new(backSRC)duck = { h = image.height(img_duckAlive), -- 30 px w = image.width(img_duckAlive) -- 37 px}init()timer.start(0.05)
I was just saying that he should not make a new "release" for every line of code he types.
Also, the reason(s) why it's not working the same on-calc is becuase the computer forces the refresh of the screen, but you have to call it yourself by calling [lua]platform.window:invalidate[/lua]