Poll: lua is
You do not have permission to vote in this poll.
3 50.00%
3 50.00%
Total 6 vote(s) 100%
* You voted for this item. [Show Results]

Using Lua to create games in PR3R
Recently (actually a bit over a month ago), there has been a significant breakthrough in PR3 lua. The user gasterskyRAW has figured out an easy to implement optimization of block.getblock.teleportto. This optimization is highly effective, increasing the speed by about four to five times. 

This breakthrough has allowed the creation of a gaming console (also by gasterskyRAW), and perhaps the most advanced use of Lua in Platform Racing 3 yet.

The console provides only a few simple commands and variables to use.
draw_pixel(x, y, color) -- draw a pixel of defined color at (x,y)

draw_square(x1, y1, x2, y2, color) -- draws a rectangle of defined color between (x1,y1) and (x2,y2)

control_horizontal -- horizontal speed of player, used for controls

control_up -- is 1 when player is pressing up

r_frames -- frames since the console was turned on.

The console also originally only gave access to 16 colors.
0  - #000000 (black)
1  - #7f0000 (dark red)
2  - #007f00 (dark green)
3  - #00007f (dark blue)
4  - #7f7f00 (dark yellow)
5  - #007f7f (dark cyan)
6  - #7f007f (dark pink)
7  - #7f7f7f (dark gray)
8  - #bfbfbf (gray)
9  - #ff0000 (red)
10 - #00ff00 (green)
11 - #0000ff (blue)
12 - #ffff00 (yellow)
13 - #00ffff (cyan)
14 - #ff00ff (pink)
15 - #ffffff (white)
This was quite limited, but it was enough, and with internal structure to only use teleportto for changed pixels, it was very easy for even those not very good with Lua to make simple games. Shortly after, draw_line(x1,y1,x2,y2,color) would become a thing, and I personally made several libraries for more advanced drawing. (mainly text and circles)

Making a game isn't particularly difficult as long as you know what you're doing and refer to the lua documents enough. This led to me making several, including

[Image: UvXkwtr.png]

Super Ball

[Image: GhXaHW1.png]

Asteroid game

[Image: FP0t829.png]

[Image: pxyHRvK.png]

Revamped bucket
[Image: Ak6nmo9.png]

Tetris was also made, but not by me, and it's breaks for no reason.

Several colors were later added to fill gaps in the color specturm. Hopefully, this gets remade in ROP, which should run significantly faster than PR3 does, possibly allowing us to do far more than just these simple games. For now though, a couple more will be made in PR3 in the last few months before the game dies for good. Currently, I'm working on Super Ball 2, and eventually I'll also fix Tetris, and maybe make a quick operating system. There's a bit of hope that a few features (sound pitch and faster getblock) could help us make a few more games.

Main benefits of ROP would probably be

Larger display
60 FPS gameplay
Probably more colors because why not

eventually I'll simulate infinite rollers with one of these. Actually, I might do it now.
i failed the mario twitter challenge
The Following 4 Users Say Thank You to ThePizzaEater1000 For This Useful Post:
  • Camer the Dragon, Dangevin, Northadox, Yomakoy
it's very cool
I find the 3d ship demo very good also cos it's literally 3d wireframe made in pr3
(23rd September 2020, 4:22 PM)Camer the Dragon Wrote: it's very cool
I find the 3d ship demo very good also cos it's literally 3d wireframe made in pr3
I'm considering writing up a framework for display of wireframe 3D objects. Seems annoying to do tho.
i failed the mario twitter challenge
I didn't realize PR3R could be an Atari 2600 emulator.
The Following 2 Users Say Thank You to Yomakoy For This Useful Post:
  • gemj, Northadox
Incredibly amazing and fabulous, but ultimately pointless.
Which is exactly the sort of thing I love
[Image: aGf8Xvh.png]
The Following 2 Users Say Thank You to Northadox For This Useful Post:
  • Camer the Dragon, gemj
(25th September 2020, 11:15 PM)Delphinoid Wrote: If you can draw points, you can draw lines, and rendering 3D wireframes is one of the most basic possible applications of that. If you're not happy with orthographic projection, just multiply all your vertices through by a perspective matrix. Things get slightly trickier if you want to rasterize (textured) triangles, but it's still pretty trivial.

There is built in support for drawing lines, so that shouldn't be hard. Thing is, I want to add easy to use support for camera rotation and spin, which is the annoying bit.
i failed the mario twitter challenge
Started working on some basic 3d. Right now, it's looking to support camera position and rotation on one axis; the main reason for only one axis of rotation is because that way I can use complex numbers to easily handle rotation and it wont be as difficult as matrices. Whenever ROP (successor to PR3R) comes around is probably when I'm gonna make full 3d, since more processing power will be available and it'll be usable for far longer. Code is below

-- initialize camera vars & constants

b3d_pi = math.pi() -- defines pi if it becomes necessary
-- b3dcam_ is a prefix before properties of the camera
b3dcam_pos = {0,0,0} -- defined as a coordinate in 3d space (x,y,z)
b3dcam_rot = 0 -- defined in radians
camera only rotates on one axis (left or right)
this makes things easier on me and i dont have to implement proper 3d rotation
and complex numbers are cool and i can just use those :)
b3dcam_focallength = 100 -- defines a constant addition to perspective var to make things look right.

function b3d_camsetpos(x,y,z) -- puts camera to given xyz
  b3dcam_pos = {x,y,z}

function b3d_cammove(x,y,z) -- moves camera by given xyz
  b3dcam_pos = {b3dcam_pos[1] + x, b3dcam_pos[2] + y, b3dcam_pos[3] + z}

function b3d_camsetrot(r) -- puts camera to given rotation
  b3dcam_rot = r

function b3d_camrot(r) -- rotates camera by given rotation
  b3dcam_rot = b3dcam_rot + r

function b3d_drawobj(object,x,y,z)
  local b3d_xrel = x - b3dcam_pos[1]
  local b3d_yrel = y - b3dcam_pos[2]
  local b3d_zrel = z - b3dcam_pos[3]
  local b3d_camrot = complex.new(math.cos(b3dcam_rot),math.sin(b3dcam_rot))
  for i in ipairs(object) do -- for all triangles/squares in given object table
    local b3d_objtype = object[i][1][1]
    if b3d_objtype == 0 then
      local b3d_ptrans = {{object[i][2][1]+b3d_xrel,object[i][2][3]+b3d_zrel},{object[i][3][1]+b3d_xrel,object[i][3][3]+b3d_zrel},{object[i][4][1]+b3d_xrel,object[i][4][3]+b3d_zrel}} -- (x,z) format bc y is irrelevant
      for g=1,3,1 do
        local b3d_cmtrns = complex.new(b3d_ptrans[g][1],b3d_ptrans[g][2])
        b3d_cmtrns = complex.mul(b3d_cmtrns,b3d_camrot)
        b3d_ptrans[g] = {b3d_cmtrns.r,b3d_cmtrns.i}
    elseif b3d_objtype == 1 then
      for g=1,4,1 do
      player.chat("Error: Invalid shape on entry ".. i .."!",0xff0000)

this hasn't been tested in any capacity i have no clue if it works lol
i failed the mario twitter challenge
(10th October 2020, 9:24 PM)Delphinoid Wrote: The way you're using complex numbers right now seems totally unnecessary. The idea is fine, but you don't actually need to use a complex number library, you can stick to regular floats with just sine and cosine if you're concerned with efficiency. I can also help if you'd like more information on how to adapt matrices for rotation, I think they're pretty straightforward, and more importantly there's a lot of really nifty stuff to learn.

If you're interested, a division algebra also exists in R^4 in the form of quaternions, which can be applied to obtain rotations in R^3 similarly to how regular complex numbers give rise to rotations in R^2. Here's a nice article on them aimed at highschool students. I have an implementation here (quat.h, quat.c) if you want to see what they look like in practice. They do have a speed advantage over matrices, just like using complex numbers in 2D, and they're also very good at spherical linear interpolation.

After saying that, you're probably wondering why matrices are even used. Well, while they're slower than quaternions or complex numbers for individual transformations, the nice thing is that a single matrix can, effectively, store an ordered list of any number of transformations. If you store translation, orientation and scale separately, every time you write to the state, nothing is really preserved from the previous one. In many cases this is fine, but it has issues with things like 3D animation, since there ends up being no way to distinguish between certain orders of transformations that should give different results.
I was actually already planning to use quaternions to allow programmers to rotate a given object on a given axis, which is enough for what we're probably able to do with this with the limited computation power. It's also pretty convenient to use quaternions, since I already have code for them in the same function block that has the code for complex numbers.
i failed the mario twitter challenge
we did the is!!!

i failed the mario twitter challenge
[Image: xIA9Ju7.png]

Getting ready for 9-bit color display
i failed the mario twitter challenge
The Following 1 User Says Thank You to ThePizzaEater1000 For This Useful Post:
  • Camer the Dragon
512 colors works.

I have set up an emulator that maps old colors to new colors, and it works great! A little bit laggier but that is to be expected with such a large palette

[Image: VtDbn8L.png]
i failed the mario twitter challenge
The Following 2 Users Say Thank You to ThePizzaEater1000 For This Useful Post:
  • Camer the Dragon, John m.
and we have transparency
[Image: HjPldnu.png]
i failed the mario twitter challenge
The Following 1 User Says Thank You to ThePizzaEater1000 For This Useful Post:
  • Camer the Dragon
Can't wait for the general artificial intelligence made with PR3R lua

Forum Jump:

Users browsing this thread: 1 Guest(s)