RetroEmu: Codes Snippets and Libraries - RetroEmu

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Codes Snippets and Libraries Share your LPE codes with others

Poll: Codes Snippets and Libraries (1 member(s) have cast votes)

Are These Library and Code Snippets Helpful?

  1. Yes (1 votes [100.00%] - View)

    Percentage of vote: 100.00%

  2. No (0 votes [0.00%])

    Percentage of vote: 0.00%

  3. I'm not a programmer (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#1 User is offline   cmbeke Icon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 272
  • Joined: 18-October 09
  • LocationIowa

Posted 18 October 2009 - 06:51 PM

Release any LPE related libraries and code snippets here.





splashLib


This is a small customizable library that easily allows the transitioning of three images on to and then off the screen.
System.splashScreen(imageA, imageB, imageC, [speed], [delay])

As you can see the layout of the function is very easy to use, you can omit the boxed in variables from your code to use the default speed and delay values or you can put in your own. To use put right after your System.endDraw() so your splash images will be on top

Attached File(s)



do not trust anything i say i am certifiably mentaly unstable - me...wait a minute
Posted Image
Posted Image
do you dare click?

1

#2 User is offline   dan369 Icon

  • Moderator
  • Icon
  • Group: Moderators
  • Posts: 106
  • Joined: 18-October 09
  • LocationWales

Posted 18 October 2009 - 09:46 PM

@ cmbeke - You should place everything in one big post ;). So its easier for someone to view.
0

#3 User is offline   cmbeke Icon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 272
  • Joined: 18-October 09
  • LocationIowa

Posted 18 October 2009 - 10:32 PM

fine <_<

do not trust anything i say i am certifiably mentaly unstable - me...wait a minute
Posted Image
Posted Image
do you dare click?

1

#4 User is offline   Arcile Icon

  • Snes9x Euphoria GFX Guru
  • Icon
  • Group: Moderators
  • Posts: 100
  • Joined: 21-October 09
  • LocationBurning Sounder

Posted 22 October 2009 - 09:19 PM

lol, hey what ever works right, lol!

View Postcmbeke, on 18 October 2009 - 03:32 PM, said:

fine <_<

~----------------------------My Sigs---------------------------

Posted Image
0

#5 User is offline   cmbeke Icon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 272
  • Joined: 18-October 09
  • LocationIowa

Posted 27 October 2009 - 11:22 PM

intrafontLib

Posted Image


This is a small customizable library that easily allows use of IntraFont.

--IntraFont Colors
     IntraColor = {black = 0, red = 1, blue = 2, white = 3, lightGrey = 4, grey = 5, darkGrey = 6, purple = 7, yellow  = 8, orange = 9, transparent = 10}
-- Shadow text
     IntraFont:shadow(font, x, y, textSize, color, text, [shadowColor], [offX], [offY], [shadowSize])
-- Flashing Text
     IntraFont:flash(font, x, y, textSize, color, text, flashColor, [speed])

--Example Shadow Usage
     IntraFont:shadow(ComicSansMS, 95, 43, .6, IntraColor.blue, "Shadows")
--Example Flash Usage
     IntraFont:flash(ComicSansMS, 43, 103, .9, IntraColor.red, "I Flashed You", IntraColor.darkGrey, 100)


As you can see the layout of the function is very easy to use, you can omit the boxed in variables from your code to use the default values or you can put in your own. For flash the speed can be any number from 1 - 150

Attached File(s)



do not trust anything i say i am certifiably mentaly unstable - me...wait a minute
Posted Image
Posted Image
do you dare click?

0

#6 User is offline   emcp Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 23
  • Joined: 30-December 09

Posted 03 January 2010 - 06:35 PM

Thought i should post this, ive only spent a day on it but im already quite happy with the results
None of graphics have been done yet, im proceeding onto them now, and hence i want to post this before putting my own stamp on it, and without textures etc

It requires LuaPlayer Euphoria
also it can be heavily optimise, but its already producing fairly large maps, although other things still need added such as ai etc

things such as recalculating values can be cleaned out
also im only currently culling inside large blocks with integer heights,

im added a quick map randomiser, so you can tweak the size yourself
ive also included a map i created myself, which can be used to see the steps etc


Oh btw theres some bad clipping, (famous on the psp)
ive tried tessellating the blocks, but theres was improvement


A fews things im still wondering about is
lighting
(doubt if GLSL [shaders], are supported)

the for loops for generating the cubes, currently if its not integers, i have to do a second check to ensure any remainder is done,
is there a better method

also i heard you should only set the perspective when you need to, ie outside loops (this is from a c/c++ tutorial), but all lua examples i see it inside the loop?
heres the link http://www.ghoti.nl/PSPtutorial1.php

he also says he has a way to fix clipping of large triangles, but doesnt reveal it. But the GOW devs said the method they found best was just to tessellate it

finally just a note, this is just educational for me, i doubt if it will be turned into a game, although im aiming towards it
i already have a script which exports 3d max models as an array with textures etc. so the blocky look simplistic look was a design decision, and i have a collision engine for such models. I just decided blocks as i wanted to create limits

red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
gray = Color.new(128, 128, 128)
cyan = Color.new(100, 255, 255)

block = Color.new(55, 65, 75)--Color.new(31, 31, 31)
topblock = Color.new(30, 35, 40)
planecol = Color.new(60, 105, 155)--Color.new(61, 61, 61)

navygreen=Color.new(95, 185, 35)
navyred=Color.new(130, 0, 45)

RAD=Gu.PI/180

Player={t={x=15,y=5,z=15},r={x=0,y=0,z=0}}
s=0.25
c=0.1
World ={
	Map={
		{1,1,1,1,1,1,1,1,1,1,1,1}, -- Z increas Down, X increases Right
		{1,c,c,c,c,c,c,c,c,c,c,1},
		{1,c,s,s*2,0,0,0,10,c,0,c,1},
		{1,c,0,s*3,1,0,0,10,c,0,c,1},
		{1,c,0,c,2,0,0,1,c,0,c,1},
		{1,c,0,c,1,0,0,1,c,0,c,1},
		{1,c,0,c,1,0,0,1,c,0,c,1},
		{1,c,0,c,1,1,1,1,c,0,c,1},
		{1,c,0,c,c,c,c,c,c,0,c,1},
		{1,c,0,0,0,0,0,0,0,0,c,1},
		{1,c,c,c,c,c,c,c,c,c,c,1},
		{1,1,1,1,1,1,1,1,1,1,1,1}
	}
}

--- Comment out between here and
World.Map={}
for y=1,10 do
	World.Map[y]={}
	for x=1,10 do
		ht=math.random(0,15)-10
		if ht<0 then ht=0 end
		World.Map[y][x]=ht
	end
end
--- here, for some stairway action

World.h=table.getn(World.Map)
World.w=table.getn(World.Map[1])
World.ts=5

function DrawCube(col, w,h,d, col2,tu,tr,td,tl)
if not col2 then local col2=col end
obj = {
		-- Top Face
		{topblock, w, h*World.ts, d},
		{topblock, 0, h*World.ts, d},
		{topblock, 0, h*World.ts, 0},

		{topblock, 0, h*World.ts, 0},
		{topblock, w, h*World.ts, 0},
		{topblock, w, h*World.ts, d}
}
	tu=math.floor(tu);td=math.floor(td);tl=math.floor(tl);tr=math.floor(tr)
	for y=tu,h do
		y=y*World.ts
		-- Front Face
		table.insert(obj, {col2, 0, y-World.ts, 0})
		table.insert(obj, {col2, w, y-World.ts, 0})
		table.insert(obj, {col, w, y, 0})

		table.insert(obj, {col, w, y, 0})
		table.insert(obj, {col, 0, y, 0})
		table.insert(obj, {col2, 0, y-World.ts, 0})
	end
	
	for y=tl,h do
	y=y*World.ts
		-- Left Face
		table.insert(obj, {col2, 0, y-World.ts, 0})
		table.insert(obj, {col, 0, y, 0})
		table.insert(obj, {col, 0, y, d})

		table.insert(obj, {col, 0, y, d})
		table.insert(obj, {col2, 0, y-World.ts, d})
		table.insert(obj, {col2, 0, y-World.ts, 0})
	end
		
	for y=td,h do
	y=y*World.ts
				-- Back Face
		table.insert(obj, {col, w, y, d})
		table.insert(obj, {col2, w, y-World.ts, d})
		table.insert(obj, {col2, 0, y-World.ts, d})

		table.insert(obj, {col2, 0, y-World.ts, d})
		table.insert(obj, {col, 0, y, d})
		table.insert(obj, {col, w, y, d})
	end
	
	for y=tr,h do
	y=y*World.ts
		-- Right Face
		table.insert(obj, {col, w, y, d})
		table.insert(obj, {col, w, y, 0})
		table.insert(obj, {col2, w, y-World.ts, 0})
	
		table.insert(obj, {col2, w, y-World.ts, 0})
		table.insert(obj, {col2, w, y-World.ts, d})
		table.insert(obj, {col, w, y, d})
	end
	
	-- fixes remaider of tile if not interger
	if h ~= math.floor(h) then
		y=math.floor(h)*World.ts
		rem=h*World.ts-y
		
		-- Front Face
		table.insert(obj, {col2, 0, y, 0})
		table.insert(obj, {col2, w, y, 0})
		table.insert(obj, {col, w, y+rem, 0})

		table.insert(obj, {col, w, y+rem, 0})
		table.insert(obj, {col, 0, y+rem, 0})
		table.insert(obj, {col2, 0, y, 0})

		-- Left Face
		table.insert(obj, {col2, 0, y, 0})
		table.insert(obj, {col, 0, y+rem, 0})
		table.insert(obj, {col, 0, y+rem, d})

		table.insert(obj, {col, 0, y+rem, d})
		table.insert(obj, {col2, 0, y, d})
		table.insert(obj, {col2, 0, y, 0})
		
				-- Back Face
		table.insert(obj, {col, w, y+rem, d})
		table.insert(obj, {col2, w, y, d})
		table.insert(obj, {col2, 0, y, d})

		table.insert(obj, {col2, 0, y, d})
		table.insert(obj, {col, 0, y+rem, d})
		table.insert(obj, {col, w, y+rem, d})
	
		-- Right Face
		table.insert(obj, {col, w, y+rem, d})
		table.insert(obj, {col, w, y+rem, 0})
		table.insert(obj, {col2, w, 0, 0})
	
		table.insert(obj, {col2, w, y, 0})
		table.insert(obj, {col2, w, y, d})
		table.insert(obj, {col, w, y+rem, d})
	end

		-- Bottom Face
		--{col, 0, 0, 0},
		--{col, 0, 0, d},
		--{col, w, 0, d},

		--{col, w, 0, d},
		--{col, w, 0, 0},
		--{col, 0, 0, 0},
------------------------------------------------------------ Now starts at top back right instead of bottom front left
	return obj
end

function RetT(pt)
return math.floor(pt/World.ts)
end

function Collide(x,z)
	if 	World.Map[RetT(z-1)][RetT(x+1)]*World.ts > Player.t.y+2 or
		World.Map[RetT(z+1)][RetT(x+1)]*World.ts > Player.t.y+2 or
		World.Map[RetT(z-1)][RetT(x-1)]*World.ts > Player.t.y+2 or
		World.Map[RetT(z+1)][RetT(x-1)]*World.ts > Player.t.y+2 then return true end
end

function MovePlayer()
	local rad=Player.r.y*RAD
		local Zmov=math.cos(rad)
		local Xmov=-math.sin(rad)
	
	Player.flr=math.max(World.Map[RetT(Player.t.z-1)][RetT(Player.t.x-1)],World.Map[RetT(Player.t.z-1)][RetT(Player.t.x+1)],World.Map[RetT(Player.t.z+1)][RetT(Player.t.x+1)],World.Map[RetT(Player.t.z+1)][RetT(Player.t.x-1)])

	if pad:up() then
		if not Collide(Player.t.x, Player.t.z-Zmov) then Player.t.z = Player.t.z-Zmov end
		if not Collide(Player.t.x-Xmov, Player.t.z) then Player.t.x = Player.t.x-Xmov end
	elseif pad:down() then
		if not Collide(Player.t.x, Player.t.z+Zmov) then Player.t.z = Player.t.z+Zmov end
		if not Collide(Player.t.x+Xmov, Player.t.z) then Player.t.x = Player.t.x+Xmov end
	end
	
	if pad:left() then
		if not Collide(Player.t.x, Player.t.z+Xmov) then Player.t.z = Player.t.z+Xmov end
		if not Collide(Player.t.x-Zmov, Player.t.z) then Player.t.x = Player.t.x-Zmov end
	elseif pad:right() then 
		if not Collide(Player.t.x, Player.t.z-Xmov) then Player.t.z = Player.t.z-Xmov end
		if not Collide(Player.t.x+Zmov, Player.t.z) then Player.t.x = Player.t.x+Zmov end
	end

	--if pad:r() then Player.t.y=Player.t.y+1
	--elseif pad:l() then Player.t.y=Player.t.y-1 end
	if pad:l() and Player.t.y == Player.flr*World.ts then Player.t.y=Player.t.y+World.ts+1 end
	
	if Player.t.y > Player.flr*World.ts then Player.t.y=Player.t.y-1 else Player.t.y = Player.flr*World.ts end
	
	if pad:square() then Player.r.y=Player.r.y-5 end
	if pad:circle() then Player.r.y=Player.r.y+5 end
	if Player.r.y >= 360 then Player.r.y = 0 elseif Player.r.y < 0 then Player.r.y = 360+Player.r.y end
	
	if pad:triangle() then Player.r.x=Player.r.x-5 end
	if pad:cross() then Player.r.x=Player.r.x+5 end
	if Player.r.x >= 50 then Player.r.x = 50 elseif Player.r.x < -50 then Player.r.x = -50 end
end

Scene={}

plane={}
for x=1,World.w do
	for y=1,World.h do
		table.insert(plane, {planecol, (x+1)*World.ts,0,(y+1)*World.ts})
		table.insert(plane, {planecol, x*World.ts,0,(y+1)*World.ts})
		table.insert(plane, {planecol, x*World.ts,0,y*World.ts})
			
		table.insert(plane, {planecol, x*World.ts,0,y*World.ts})
		table.insert(plane, {planecol, (x+1)*World.ts,0,y*World.ts})
		table.insert(plane, {planecol, (x+1)*World.ts,0,(y+1)*World.ts})
	end
end

for x=1,World.w do
	for z=1,World.h do
		if World.Map[z][x] > 0 then
			if World.Map[z-1] then tu =World.Map[z-1][x] else tu =0 end
			if World.Map[z+1] then td =World.Map[z+1][x] else td =0 end
			if World.Map[z][x+1] then tr =World.Map[z][x+1] else tr =0 end
			if World.Map[z][x-1] then tl =World.Map[z][x-1] else tl =0 end
			
			--print(tu,td,tr,tl)

			table.insert(Scene, {x*World.ts,z*World.ts,DrawCube(block, World.ts,World.Map[z][x],World.ts, black, tu,tr,td,tl)})
		end
	end
end


--check scene size
verts=0
for s=1,table.getn(Scene) do
	verts=verts+table.getn(Scene[s][3])
end
print(verts)


while true do
	pad = Controls.read()
	
	MovePlayer()
	
	Gu.start3d()

	-- clear screen
	Gu.clearDepth(0);
	Gu.clear(Gu.COLOR_BUFFER_BIT+Gu.DEPTH_BUFFER_BIT)

	-- setup projection and view matrices

	Gum.matrixMode(Gu.PROJECTION)
	Gum.loadIdentity()
	Gum.perspective(75, 16/9, 1, 100)
	
	--transform world
	Gum.matrixMode(Gu.VIEW)
	Gum.loadIdentity()

	Gum.rotateXYZ(Player.r.x*RAD, Player.r.y*RAD, Player.r.z*RAD);
	Gum.translate(-Player.t.x,-Player.t.y-5,-Player.t.z)

	-- setup matrix for cube
	Gum.matrixMode(Gu.MODEL)
	Gum.loadIdentity()
	
	Gu.disable(Gu.TEXTURE_2D)
	
	Gum.drawArray(Gu.TRIANGLES, Gu.COLOR_8888+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, plane)
	
	for s=1,table.getn(Scene) do
		Gum.translate(Scene[s][1],0,Scene[s][2])
		Gum.drawArray(Gu.TRIANGLES, Gu.COLOR_8888+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, Scene[s][3])
		Gum.translate(-Scene[s][1],0,-Scene[s][2])
	end	

	Gu.end3d()
	
	Player.t.old={x=Player.t.x,y=Player.t.y,z=Player.t.z}

	if Controls.read():start() then
		break
	end
	screen:clear()
	screen.waitVblankStart()
	screen.flip()
end


0

#7 User is offline   cmbeke Icon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 272
  • Joined: 18-October 09
  • LocationIowa

Posted 03 January 2010 - 07:11 PM

like i said on evilmana nice job :D

do not trust anything i say i am certifiably mentaly unstable - me...wait a minute
Posted Image
Posted Image
do you dare click?

0

#8 User is offline   emcp Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 23
  • Joined: 30-December 09

Posted 03 January 2010 - 11:12 PM

View Postcmbeke, on 03 January 2010 - 07:11 PM, said:

like i said on evilmana nice job :D

thanks heres an update

Infact heres a video of it with textures
the textures are dynamic, ie i can change the colours in-game
the colors are random

im hoping on adding one more effect, using the DOT function, to create a dust like effect similar to that in cod4 in the sniper mission, when you walk through the house, only they will be solid black particles, just to add depth

Framerate and quality suffers due to video capturing, also you can notice one instance of bad clipping
and incase your wondering why the black line looks a bit bold around the pat, its because i used the wrong uv co-ords [now fixed]. Also the steps are dark in colour so you can easily spot them from afar, it only darkens out the remainder of the integer (ie if theres room for a full block under it, the block is shown in color and the remainder darken out)

I may remove the colors and just have the grayscale, looks good just gray although id have to add color to something other than enemies

one good thing i can do is make the floor flash, looks quite good lol, or alternate the colors, to make it more dynamic looking



Black and White Pics
Posted Image
Posted Image
Posted Image
0

#9 User is offline   cmbeke Icon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 272
  • Joined: 18-October 09
  • LocationIowa

Posted 04 January 2010 - 12:58 AM

looks very nice, thats some of the best 3d homebrew i've seen. if you make a game out of this it would look great :) i embeded the video for you if thats ok (all you have to do is add [media*][/media*] without the * around the url)

do not trust anything i say i am certifiably mentaly unstable - me...wait a minute
Posted Image
Posted Image
do you dare click?

0

#10 User is offline   vladgalay Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 08-January 10
  • LocationРоссия

Posted 09 January 2010 - 05:42 PM

Here are one of my libraries:
BoldPrint function
Spoiler

DrawRect function
Spoiler

0

#11 User is offline   cmbeke Icon

  • Administrator
  • Icon
  • Group: Administrators
  • Posts: 272
  • Joined: 18-October 09
  • LocationIowa

Posted 08 June 2010 - 01:16 AM

Heres a small sprite sheet animation library that uses timers:

-- Animates An Image	
function Image.animate(table, xFrame, yFrame, delay, offset, limit)
	-- creates animation table that all info is in for easy removal (table.remove(table.animate)) and easy changes outside of function
	if table.animate == nil then
		table.animate = {}
		-- Creates a way to pause animation
			table.animate.pause = false
		table.animate.timer = Timer.new()
		table.animate.num= {}
			table.animate.num.x = 0
			table.animate.num.y = 0
		table.animate.width = table.image:width()/xFrame
		table.animate.height = table.image:height()/yFrame
		table.animate.ratio = {}
			table.animate.ratio.x = table.image:width()/xFrame
			table.animate.ratio.y = table.image:height()/yFrame
		-- Offset is advanced, makes it so you only do specifyed rows
		if offset ~= nil then
			table.animate.offset = offset-1
			table.animate.limit = limit-1
		else
			table.animate.offset = 0
			table.animate.limit = yFrame
		end
		-- Sets Alpha
		if table.animate.alpha == nil then
			table.animate.alpha = 255
		end
	end
	-- if animation is not paused
	if not table.animate.pause then
		-- Starts Timer for first time, and after every reset
		table.animate.timer:start()
		-- Reset timer, move along a row
		if table.animate.timer:time() >= delay then
			table.animate.num.x = table.animate.num.x + 1
			table.animate.timer:reset()
		end
		-- Go back to first frame, go to next row
		if table.animate.num.x >= xFrame then
			table.animate.num.x = 0
			table.animate.num.y = table.animate.num.y + 1
		end
		-- Go from last row to first row
		if table.animate.num.y >= table.animate.limit then
			table.animate.num.y = table.animate.offset
		end
		-- Sets frame positions
		table.animate.sourcex = table.animate.num.x*table.animate.ratio.x
		table.animate.sourcey = table.animate.num.y*table.animate.ratio.y
		-- blits animation
		screen:blit(table.x, table.y, table.image, table.animate.alpha, table.animate.sourcex, table.animate.sourcey, table.animate.width, table.animate.height)
	end
end

-- Pauses Animation
function Image.pause(table)
	table.animate.pause = true
end

-- Blits a static frame 
function Image.frame(table, xFrame, yFrame)
	if xFrame ~= nil and yFrame ~= nil then
		screen:blit(table.x, table.y, table.image, table.animate.alpha, (xFrame-1)*table.animate.ratio.x, (yFrame-1)*table.animate.ratio.y, table.animate.width, table.animate.height)
	else
		screen:blit(table.x, table.y, table.image, table.animate.alpha, table.animate.sourcex, table.animate.sourcey, table.animate.width, table.animate.height)
	end
end
-- Resumes Animation
function Image.resume(table)
	table.animate.pause = false
end

xFrame is number of frames in a row & yFrame is the number of rows

example useage:
test = {x = 30, y = 40, image = Image.load("a.png")}
dofile("animation.lua")
while true do
	System.draw()
		screen:clear(Color.new(255,255,255))
		Image.animate(test, 7, 2, 145)
	System.endDraw()
	screen.flip()
end


do not trust anything i say i am certifiably mentaly unstable - me...wait a minute
Posted Image
Posted Image
do you dare click?

0

#12 User is offline   stepheninabox Icon

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 08-July 10

Posted 17 August 2010 - 11:25 PM

How do i call an Orthographic view instead of perspective...tried running Gum.Ortho() and Gum.ortho and got nil?
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users