Drawing help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Drawing help

Post by TurtleP »

Hello all,

I am trying to draw an image in this class, box.lua. However, it will not appear. I looked at the hamster ball tutorial, and still it refuses to draw!

Code: Select all

box = class:new()

function box:init(x, y)
	--PHYSICS STUFF
	self.cox = x
	self.coy = y
	self.x = x-12/16
	self.y = y-14/16
	self.speedy = 0
	self.speedx = 0
	self.width = 12/16
	self.height = 14/16
	self.static = false
	self.active = true
	self.category = 9
	self.parent = nil
	self.portaloverride = true

	self.mask = {	true,
					false, false, false, false, false,
					false, true, false, true, true,
					false, false, true, false, false,
					true, true, false, false, true,
					false, true, true, false, false,
					true, false, true, true, true}
					
	self.emancipatecheck = true

	self.userect = adduserect(self.x, self.y, 12/16, 12/16, self)
	
	--IMAGE STUFF
	self.drawable = true
	self.graphic = Turret
	self.quad = Turretquad
	self.offsetX = 6
	self.offsetY = 6
	self.quadcenterX = 6
	self.quadcenterY = 6
	
	self.rotation = 0 --for portals
	
	self.falling = false
	self.destroying = false
	self.outtable = {}
	self.portaledframe = false
end

function box:draw()
	love.graphics.draw(lazerimg, self.x, self.y)
end


function box:update(dt)

	local friction = boxfrictionair
	if self.falling == false then
		friction = boxfriction
	end
	
	if not self.pushed then
		if self.speedx > 0 then
			self.speedx = self.speedx - friction*dt
			if self.speedx < 0 then
				self.speedx = 0
			end
		else
			self.speedx = self.speedx + friction*dt
			if self.speedx > 0 then
				self.speedx = 0
			end
		end
	else
		self.pushed = false
	end
	
	--rotate back to 0 (portals)
	self.rotation = math.mod(self.rotation, math.pi*2)
	if self.rotation > 0 then
		self.rotation = self.rotation - portalrotationalignmentspeed*dt
		if self.rotation < 0 then
			self.rotation = 0
		end
	elseif self.rotation < 0 then
		self.rotation = self.rotation + portalrotationalignmentspeed*dt
		if self.rotation > 0 then
			self.rotation = 0
		end
	end
	
	if self.parent then
		local oldx = self.x
		local oldy = self.y
		
		self.x = self.parent.x+math.sin(-self.parent.pointingangle)*0.3
		self.y = self.parent.y-math.cos(-self.parent.pointingangle)*0.3
		
		if self.portaledframe == false then
			for h, u in pairs(emancipationgrills) do
				if u.dir == "hor" then
					if inrange(self.x+6/16, u.startx-1, u.endx, true) and inrange(u.y-14/16, oldy, self.y, true) then
						self:emancipate(h)
					end
				else
					if inrange(self.y+6/16, u.starty-1, u.endy, true) and inrange(u.x-14/16, oldx, self.x, true) then
						self:emancipate(h)
					end
				end
			end
		end
	end
	
	self.userect.x = self.x
	self.userect.y = self.y

	--check if offscreen
	if self.y > 17 then
		self:destroy()
	end
	
	self.portaledframe = false
	
	if self.destroying then
		return true
	else
		return false
	end
end

function box:leftcollide(a, b)
	if a == "button" then
		self.y = b.y - self.height
		self.x = b.x + b.width - 0.01
		if self.speedy > 0 then
			self.speedy = 0
		end
		return false
	elseif a == "player" then
		self.pushed = true
		return false
	end
end

function box:rightcollide(a, b)
	if a == "button" then
		self.y = b.y - self.height
		self.x = b.x - self.width+0.01
		if self.speedy > 0 then
			self.speedy = 0
		end
		return false
	elseif a == "player" then
		self.pushed = true
		return false
	end
end

function box:floorcollide(a, b)
	if self.falling then
		self.falling = false
	end
	
	if a == "goomba" or a == "bulletbill" then
		b:stomp()
		addpoints(200, self.x, self.y)
		playsound(stompsound)
		self.falling = true
		return false
	end
	
end

function box:passivecollide(a, b)
	if a == "player" then
		if self.x+self.width > b.x+b.width then
			self.x = b.x+b.width
		else
			self.x = b.x-self.width
		end
	end
end

function box:startfall()
	self.falling = true
	speech = math.random(0, 1)
	if speech == 0 then
		playsound(wee)
	end 
end

function box:emancipate()
	if self.parent then
		self.parent:cubeemancipate()
	end
	self:destroy()
	playsound(emancipater)
	playsound(emancipated)
end


function box:destroy()
	self.userect.delete = true
	self.destroying = true

	for i = 1, #self.outtable do
		if self.outtable[i].input then
			self.outtable[i]:input("toggle")
		end
	end
end

function box:addoutput(a)
	table.insert(self.outtable, a)
end


function box:used(id)
	self.parent = objects["player"][id]
	self.active = false
	objects["player"][id]:pickupbox(self)
	if self.falling == false then
	speech = math.random(0, 4)
	if speech == 0 then
	playsound(who)
	end
	if speech == 1 then
	playsound(please)
	end
end
	
end

function box:dropped()
	self.parent = nil
	self.active = true
end

function box:portaled()
	self.portaledframe = true
end
User avatar
veethree
Inner party member
Posts: 874
Joined: Sat Dec 10, 2011 7:18 pm

Re: Drawing help

Post by veethree »

Do you call the box:draw function in the love.draw in main.lua?
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Drawing help

Post by TurtleP »

veethree wrote:Do you call the box:draw function in the love.draw in main.lua?
I believe so. It's a mod I'm making for Mari0 btw.

EDIT:

It's not doing anything because it "expects userdata"
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Drawing help

Post by Robin »

TurtleP wrote:It's not doing anything because it "expects userdata"
Did you use box.draw() or box:draw()?
Help us help you: attach a .love.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Drawing help

Post by TurtleP »

Robin wrote:
TurtleP wrote:It's not doing anything because it "expects userdata"
Did you use box.draw() or box:draw()?
Well, I moved it into floorcollide. But it still expects userdata
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Drawing help

Post by Robin »

:huh:
Help us help you: attach a .love.
User avatar
jradich
Party member
Posts: 100
Joined: Mon Dec 12, 2011 8:44 pm

Re: Drawing help

Post by jradich »

TurtleP wrote:
Robin wrote:
TurtleP wrote:It's not doing anything because it "expects userdata"
Did you use box.draw() or box:draw()?
Well, I moved it into floorcollide. But it still expects userdata
Hey turtle. I'm this guy http://forum.stabyourself.net/memberlis ... file&u=159. Explain the problem more. I think you should try box:draw() or floorcollide:draw() or whatever instead of what you are doing at the moment... that's the only help i can provide.
Losing a friend's trust is the fastest way to lose a friend, forever. FOREVER!
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Drawing help

Post by TurtleP »

Well either way, do I put those in box.lua? Because it's not drawing anything now.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Drawing help

Post by Robin »

TurtleP wrote:Well either way, do I put those in box.lua? Because it's not drawing anything now.
You gotta be more specific than that.

Which file you put things in doesn't matter that much. It matters which files you require, what function you put things in and when you call those functions.

Also, if you read the rules you can see you can save us all a lot of time by uploading a .love of your game.
Help us help you: attach a .love.
User avatar
TurtleP
Party member
Posts: 147
Joined: Thu Mar 22, 2012 9:20 pm
Contact:

Re: Drawing help

Post by TurtleP »

Robin wrote:
TurtleP wrote:Well either way, do I put those in box.lua? Because it's not drawing anything now.
You gotta be more specific than that.

Which file you put things in doesn't matter that much. It matters which files you require, what function you put things in and when you call those functions.

Also, if you read the rules you can see you can save us all a lot of time by uploading a .love of your game.
Alright. Enjoy some turrets that don't fire laser (more than everyone else at Stabyourself.net forums)
Attachments
mari0-source.zip
Turrets. Maybe they are not harmful..
(3.96 MiB) Downloaded 92 times
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 43 guests