What do you think of this idea?
Good
 0%  [ 0 ]
Great
 0%  [ 0 ]
I want this
 25%  [ 1 ]
Gimme gimme gimme!!!!!!
 75%  [ 3 ]
Total Votes : 4

The_Coded wrote:
Thanks ashbad, I've read over the references for LuaZM for 2 days now, but looking at the code I have so far, I can't see where as of yet I need the ZMG commands


You'll need them for all graphical operations, key detection, and if the game uses tick counts or timers, that too then. What you have so far won't need to touch the ZMG library, but later mechanics such as rendering and key input reactions will depend upon it.
If I miss any commands that need it I'm sure the more advanced community will catch it :p welp, the next section of code is the drawing of the whole thing, I'll do my best to convert
Any drawing commands will need to be replaced with their ZMG library equivalents. Any input commands will have to be replaced with one of the ZMG key-input commands. Any time-related commands will be switched to either zmg.ticks() or zmg.time(). If you need OS commands or IO (file-management) commands, you're out of luck until LuaZM v0.2.
Idk about OS commands, but I bet there will be some at some point. I'm going to try and finish some porting as best I can
The_Coded wrote:
Idk about OS commands, but I bet there will be some at some point. I'm going to try and finish some porting as best I can
If in doubt, try to port it a bit at a time. For example, if you can get the skeletal framework of drawing a bit of the track and some key input working without the rest of the program to be able to test that code on its own, you'll be able to debug before moving onto the more complex track- and car-drawing.
Kerm I'm going to assume you mean me drawing a car sprite and moving it left and right via key-presses? If so I'll just try and draw the car and move it, no bg, no track...sound good?
The_Coded wrote:
Kerm I'm going to assume you mean me drawing a car sprite and moving it left and right via key-presses? If so I'll just try and draw the car and move it, no bg, no track...sound good?
Yes, that's a good start! Remember that after you finish all the drawing commands, you need to use zmg.fastCopy() to copy the screen buffer to the physical LCD.
Huh? I'll post the code later
The_Coded wrote:
Huh? I'll post the code later


Kerm means that all the drawing functions are being written to memory (kind of like RAM on a computer), and to display the display data in memory, you have to use the zmg.fastCopy() function. Wink
flyingfisch wrote:
The_Coded wrote:
Huh? I'll post the code later


Kerm means that all the drawing functions are being written to memory (kind of like RAM on a computer), and to display the display data in memory, you have to use the zmg.fastCopy() function. Wink
For what it's worth, most TI-83+/84+ ASM programs are the same way. You draw the monochrome contents that you want to have on the screen into the graph buffer (gbuf), then once you have finished rendering the entire contents, the iFastCopy routine moves that data onto the LCD in one fell swoop. While you're setting up the new contents in the background, the LCD continues to display its old contents.
KermMartian wrote:
flyingfisch wrote:
The_Coded wrote:
Huh? I'll post the code later


Kerm means that all the drawing functions are being written to memory (kind of like RAM on a computer), and to display the display data in memory, you have to use the zmg.fastCopy() function. Wink
For what it's worth, most TI-83+/84+ ASM programs are the same way. You draw the monochrome contents that you want to have on the screen into the graph buffer (gbuf), then once you have finished rendering the entire contents, the iFastCopy routine moves that data onto the LCD in one fell swoop. While you're setting up the new contents in the background, the LCD continues to display its old contents.


Actually, I think most non-BASIC calc langs have some sort of refresh or fastcopy function.
Ok, here's what Code I have totally unmodified for tonight, it shall be uploaded like this tonight, and tomorrow my modifications on it; so for now enjoy.


Code:

---PRiZM ENDURO---
---Main.Lua---
-- global screen size constants
HEIGHT=216
WIDTH=384
bottomY = math.floor(HEIGHT *.21)
trackWidth = math.floor(WIDTH * .9) -- width of the track at the bottom
horizonY = math.floor(trackWidth * .55 + bottomY)
trackHeight = horizonY - bottomY
trackLength = 100  -- in meters

-- main objects
myCar = nil
cars = {}
day = nil
track = nil

-- various global variables
speed = 0                 -- for showing to the user
location = 0              -- my location
maxPosition = -1000       -- the location relative to me where the front-most car is
lastCollisionT = -1000    -- last time i collided, for the penalty
gameTime = 0              -- for reporting to the user

startTime = 0             -- the time at which the game started

days = 1                  -- which day we're on

carsToPassInit = 150          -- on day 1 we need this many

carsToPass = carsToPassInit   -- how many cars to advance to the next day

gameOver = false

gameStarted = false           -- whether the user has started the game

gamePaused = false

maxSpeed = 150

regularSpeed = 85
function setup()
    track = Track()
    day = Day()
    myCar = Car(0,0,0)
    myCar.speed = 120
end

print("Instructions:")
    print("Press Shift to accelerate")
    print("Press Alpha to break")
    print("Press nothing to maintain speed")
    print("Use Prizm D-pad to Steer")
    print("F1 to Start")

function draw()

rectMode(CORNER)
      ellipseMode(RADIUS)
      speed = myCar.speed





------------- UPDATE GAME STATE ----------------
    if not gameOver then
        if not gameStarted or gamePaused then
            stoppedUserInputs()
        else
            accelerating = runningUserInputs()     -- start, left, right, brake, etc

-- move track around
            turnTrack(gameTime,track)
               
            -- move the day forward in time
            day:updateMode(gameTime)
       
            if gameStarted then
                gameTime = ElapsedTime - startTime
                location = location + DeltaTime*myCar.speed/100
                spawnNewCars()
                myCar:updateTireState()
                day:updateFogEnd(myCar.speed)
            end

-- if we're turning then apply the centrifugal force
            centrifugal = track:centrifugal()
            centrifugal = centrifugal * myCar.speed / 150
            myCar.x = myCar.x + centrifugal/100
            day:moveX(centrifugal*7)
       
            collided = checkForCollisions()
            moveCars()
        end
    end
    --------------- DRAW ---------------
    -- field, tracks, sky, controls, etc
    drawBackground()
   
    --draw all cars
    myCar:draw(track,day)
    for i,c in ipairs(cars) do
        if c.y > 0 and c.y <= .9*trackLength and c.real then
            c:draw(track,day)
        end
    end
   
    day:drawFog()    -- has to be drawn last
   
    drawPauseButton()
    drawUserFeedback(accelerating,collided)  -- userfedback at the bottom of the screen
end

function moveCars()
    maxPosition = -1000
    for i,c in ipairs(cars) do
        change = -DeltaTime*(myCar.speed-c.speed)/1.3
        beforeY = c.y
        c.y = c.y + change

        -- count carsPassed
        if c.real then
            if c.y<0 and beforeY>0 and not day.won then carsToPass = carsToPass - 1 end
            if c.y>0 and beforeY<0 and not day.won then carsToPass = carsToPass + 1 end
        end

        if carsToPass == 0 and not day.won then
            day.won = true
            print("Achievement unlocked: Day", days)
        end

        -- remove cars
        -- avoid collisions from the back by removing cars
        if c.y>0 and beforeY<0 and collidesWithMyCar(c) then
            table.remove(cars,i)
        -- remove cars that are too far
        elseif c.y < -5 * trackLength or c.y > 2 * trackLength then
            table.remove(cars,i)
        else c:updateTireState() end

        maxPosition = math.max(maxPosition,c.y)
    end
end


from this point forward I'm only posting the new code I'm working on so as not to bother anyone or seem excessive.
Have you been testing this code as you go along? One of the best lessons of coding is to test code in as small units as possible so that you'll be able to with decent fidelity narrow down what causes any new problems you encounter.
Em, well testing it might be a good thing, I'll do it in the morning
Well no iPad now, and I'm not sure how to test the code without uploading to PrIzm, but I'll start that right after I finish my report on hypoxia.
The_Coded wrote:
Well no iPad now, and I'm not sure how to test the code without uploading to PrIzm, but I'll start that right after I finish my report on hypoxia.
There's no way to test without uploading to a "Prizm" (the I is not capitalized) yet.
Forgive me if progress is super slow until maybe November...4 Psych tests, 2 math, 5-6 reports are all due in the next 2 weeks...as well as my ecology thesis on the effects of gulf hypoxia on shrimp..so, this is going to be rather super slow for a while...I'm working on the car as time permits, so maybe in a few weeks I'll have a demo for you all to play with Very Happy
Sounds good; good luck with all of your schoolwork. Make sure it comes first! And don't hesitate to try a smaller project or two, maybe something from scratch, to help yourself understand Lua in the meantime.
I can make a circle move in BASIC, therefore It should apply to lua as well, I suck from scratch...although idk...I'm trying to do things as best I can. here's the car.lua'


Code:

--[[    ------------------------------------------------------------
                           Car.lua
--]]    ------------------------------------------------------------

dayCarColors = {
    color(255, 0, 0, 255),
    color(0, 35, 255, 255),
    color(11, 255, 0, 255),
    color(255, 245, 0, 255)
}

nightCarColors = {
    color(255, 0, 0, 255),
    color(255, 0, 188, 255),
    color(255, 0, 188, 255),
    color(255, 0, 0, 255)
}

Car = class()

function Car:init(x,y,color)
    self.x = x    -- between -1 and 1
    self.y = y    -- from 0 to trackLength in meters
    self.color = color
    self.speed = regularSpeed
    self.real = true  -- unreal cars help with spawning
    self.tireState = true  -- for tire animation
    self.tireStateHelper = 0
end

function Car:updateTireState()
    self.tireStateHelper = self.tireStateHelper + self.speed / 60
    if self.tireStateHelper > 5 then
        self.tireStateHelper = 0
        self.tireState = not self.tireState
    end
end

function Car:draw(track,day)
    -- coords of the track at this y
    leftX = track:leftAt(self.y)
    rightX = track:rightAt(self.y)

    -- my coord at this y
    x = ((1+self.x)*rightX + (1-self.x)*leftX)/2

    s = metersToPixels(self.y) -- implemented in the track class
    self:drawHelper(x,s,1-s/trackHeight,self.color,self.tireState,day)
end

-- x relative to middle of the screen in pixels, y relative to the bottom of the track
-- scale relative to a car at the bottom of the screen
-- tireState is true or false, for animation
function Car:drawHelper(x,y,s,colorIdx,tireState,day)
    pushMatrix()
    pushStyle()
    resetMatrix()
    translate(WIDTH/2+x,bottomY+y)
    scale(trackWidth*s/90,trackHeight*s/108)

    if colorIdx == 0 then -- hack for my car
        thisColor = color(190,190,190,255)
    elseif modes[day.mode].rearlights then
        thisColor = nightCarColors[colorIdx]
    else
        thisColor = dayCarColors[colorIdx]
    end

    fill(thisColor)
    stroke(thisColor)
    strokeWidth(2)

    if not modes[day.mode].rearlights or colorIdx == 0 then
        -- regular car
        rect(-4,1,8,7) -- body horizontal
        rect(-2,0,4,12) -- body vertical
        rect(-6,8,12,3) -- top wing
        rect(-6,8,3,4) -- left wing
        rect(3,8,3,4) -- right wing
        for i = 0,7 do
            if tireState == (i%2==0) then startX = -8 else startX = -6 end
            rect(startX,i,3,2)
            rect(startX+11,i,3,2)
        end
    else
        -- rear lights
        rect(2,0,5,4)
        rect(-6,0,5,4)
    end
    popMatrix()
    popStyle()
end

function spawnNewCars()
    if maxPosition < 65 then -- space the cars apart
        rand1 = random()
        if rand1 < 0.7 then
            -- spawn one car
            x = (math.floor(3*random())-1)/2
            newCar = Car(x,.9*trackLength,randColor())
            table.insert(cars,newCar)
        else
            newCar = Car(0,.9*trackLength,randColor())
            newCar.real = false
            table.insert(cars,newCar)
        end
    end
end

-- used above
function randColor()
    ncolors = table.maxn(dayCarColors)
    idx = math.ceil(random()*ncolors)
    return(idx)
end
So the project is on temporary Hold until my fall break in november, I'm focusing on school and Learning how to draw on the prizm.

feel free to add take away etc. to the code if I'm unable to do anything Very Happy...and at least look at the guys' code on codea that's on the first page on the pastebin thing
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 2 of 3
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement