0 Members and 2 Guests are viewing this topic.
Yes I'm guessing that trigonometry is essential if I want to learn to program games. I learned basic trig in Geometry, how can I apply that to programming? It's something I've been wondering for a very long time, as i want to program my first game in lua, on the nspire.EDIT:Not actually ON the nspire, just for it.
function on.paint(gc) local screen = platform.window local h=screen:height() local w=screen:width() gc:setFont("sansserif", "b", 24) gc:setColorRGB(255,193,37) local sw = gc:getStringWidth("Pong") local sh = gc:getStringHeight("Pong") gc:drawString("Pong",w/2-sw/2,h/16+sh/16) gc:setFont("sansserif", "r", 12) gc:setColorRGB(255,255,255) local s2w = gc:getStringWidth("Simple Pong clone by njaddison") local s2h = gc:getStringHeight("Simple Pong clone by njaddison") gc:drawString("Simple Pong clone by njaddison",w/2-s2w/2,h/2+s2h/2)endfunction on.enterKey() screen:invalidate()end
while true do
I'm not so sure about mirroring images within the Lua code itself, but if you have the original image (.gif, .png etc) you could mirror it and convert it to image code.
function mirror_img(imgstr, width , height) local out = imgstr:sub(1, 20) local p = 21 for y=1, height do local row = "" for x=1, width do row = imgstr:sub(p, p +1) .. row p = p + 2 end out = out .. row end return outendimg_hi_src = "\32\0\0\0\32\0\0\0\0\0\0\0\64\0\0\0\16\0\1\000alalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalal\194\253alalalalalalalalalalalalalalalalalalalalalalalalalalalalalalal\194\253alalalalalalalalal\194\253alalalalal\194\253alalalalal\194\253\194\253alalalalalalal\194\253\194\253alalalalalalalalal\194\253alalalalal\194\253alalalalal\194\253\194\253alalalalalalal\194\253\194\253alalalalalalalalal\194\253alalalalal\194\253alalalal\194\253\194\253alalalalalalalal\194\253\194\253alalalalalalalal\194\253\194\253alalalalal\194\253alalalalalalalalalalalalalal\194\253\194\253alalalalalalalal\194\253\194\253alalalalal\194\253alalalalalalalalalalalalalal\194\253\194\253alalalalalalalal\194\253\194\253alalalalal\194\253alalalalalalalalalalalalalal\194\253\194\253alalalalalalalal\194\253\194\253alalalalal\194\253alalalalalalalalalalalalalal\194\253\194\253alalalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalalalal\194\253\194\253\194\253\194\253\194\253\194\253\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalal\194\253\194\253\194\253\194\253\194\253\194\253alal\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalal\194\253\194\253\194\253alal\194\253\194\253\194\253\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalalal\194\253\194\253alalalalal\194\253alalalalalalalalalalalalalal\194\253alalalalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalal\194\253alalalalalalalalal\194\253a\144alalalalal\194\253alalalalalal\194\253alalalalalalalalalalalalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalalalal\194\253alalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalalal\194\253\194\253alalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalal\194\253\194\253\194\253alalalalalalal\194\253\194\253alalalalal\194\253alalalalalal\194\253alalalalalalal\194\253\194\253alalalalalalalalal\194\253alalalalalalalalalalalalalalalalalalalal\194\253alalalalalalalalalal\194\253alalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalalal"img_hi = image.new(img_hi_src)img_hi_reverted=image.new(mirror_img(img_hi_src, 32, 32))function on.paint(gc) gc:drawImage(img_hi, 10, 10) gc:drawImage(img_hi_reverted, 10, 100)end
Please could someone help me ?
----------------------------------------------------------- LUA FALLDOWN, BY ANTOX98 -----------------------------------------------------------platform.apilevel = "2.0"require "physics"--------------------------- BALL CLASS ---------------------------Ball = class()Seg = class()function Ball:init(x, y, w, mass) self.width = w self.body = physics.Body(mass, physics.misc.momentForCircle(mass, 0, 10, ZERO)) self.body:setPos(physics.Vect(x, y)) self.body:setMass(mass) self.shape = physics.CircleShape(self.body, w, ZERO) self.shape:setRestitution(0.6) self.shape:setFriction(0.6)endfunction Seg:init(x1, y1, x2, y2) local a, b = physics.Vect(x1, y1), physics.Vect(x2, y2) local mass = physics.misc.INFINITY() self.coor = {x1,y1,x2,y2} self.body = physics.Body(mass, physics.misc.momentForSegment(mass, a, b)) --self.body:setPos(physics.Vect(x1, y1)) self.body:setMass(mass) self.shape = physics.SegmentShape(self.body, a, b, 10) self.shape:setRestitution(0.6) self.shape:setFriction(0.6)endfunction Ball:paint(gc) local p = self.body:pos() local x, y = p:x(), p:y() local r = self.width / 2 gc:setColorRGB(255,0,0) gc:fillArc(x+r, y+r , self.width, self.width, 0, 360)endfunction Seg:paint(gc) local a = self.shape:a() local b = self.shape:b() gc:setColorRGB(0,0,0) gc:drawLine(a:x(), a:y(), b:x(), b:y())endfunction initGame() w = 318 h = 212 ZERO = physics.Vect(0,0) LARGE = physics.misc.INFINITY() space = physics.Space() space:setGravity(physics.Vect(0,9.) sol = Seg(0,200,w,200) --space:addBody(sol.body) space:addShape(sol.shape) ball = Ball(w/2-10, 30, 20, 1000) space:addBody(ball.body) space:addShape(ball.shape) sol.body:setPos(physics.Vect(0,-30)) timer.start(0.01)endinitGame()function on.timer() space:step(0.1) platform.window:invalidate()endfunction on.paint(gc) ball:paint(gc) sol:paint(gc)end