Jump to content


Photo

Drawing Doubts


  • Please log in to reply
6 replies to this topic

#1 saim

saim

    GMC Member

  • New Member
  • 1085 posts

Posted 07 March 2010 - 01:59 AM

EDIT: Changed the subject, please go straight to post#5

Is there a way to draw an incomplete circle? Better, an incomplete donut?
I want to make a timer around my object, so I'm thinking in drawing 2 complete donuts around it and as times goes down, I deplete one of them.
I seached the tutorial for fancy healthbars, but nothing like this came up.
I can make several lines pointing to the center, but the result feels... I don't know how to explain... Furry? If you want to take a look on what I mean, make an object, add this code:
var i;
i=0
draw_set_color(c_red)
repeat(360)
{
x1=x+lengthdir_x(10,i)
y1=y+lengthdir_y(10,i)
x2=x+lengthdir_x(20,i)
y2=y+lengthdir_y(20,i)
draw_line(x1,y1,x2,y2)
i+=1
}
draw_set_color(c_green)
i=0
repeat(10*alarm[0])
{
x1=x+lengthdir_x(10,i)
y1=y+lengthdir_y(10,i)
x2=x+lengthdir_x(20,i)
y2=y+lengthdir_y(20,i)
draw_line(x1,y1,x2,y2)
i+=1
}
and make sure alarm[0] is setted to 36.
If there is no other way, I can live with this furry timer, but if you can help, I'd appreciate.

Edited by saim, 19 March 2010 - 12:37 PM.

  • 0

#2 jordan leffl

jordan leffl

    GMC Member

  • GMC Member
  • 188 posts

Posted 07 March 2010 - 02:55 AM

Hey, I made a drawring script a while ago, it seems good for what you need:

draw_set_color(argument3)
draw_primitive_begin(pr_trianglestrip)
for(j=0; j<argument0; j+=1){
	draw_vertex(argument4+lengthdir_x(argument1,j*10),argument5+lengthdir_y(argument1,j*10))
	draw_vertex(argument4+lengthdir_x(argument1,(j+1)*10),argument5+lengthdir_y(argument1,(j+1)*10))
	draw_vertex(argument4+lengthdir_x(argument1+argument2,(j+1)*10),argument5+lengthdir_y(argument1+argument2,(j+1)*10))
	draw_vertex(argument4+lengthdir_x(argument1+argument2,j*10),argument5+lengthdir_y(argument1+argument2,j*10))
	draw_vertex(argument4+lengthdir_x(argument1,j*10),argument5+lengthdir_y(argument1,j*10))
}
draw_primitive_end();
draw_set_color(0)

Usage: drawring(35,100,10,c_red,x,y);

The first argument is how much ring (36 = 360 degrees, 18 = 180 degrees, etc).
Second argument is how far away from the point to draw.
Third argument is how thick.
Fourth argument is the color.
Fifth and sixth arguments are the point to draw it from.
  • 0

#3 saim

saim

    GMC Member

  • New Member
  • 1085 posts

Posted 07 March 2010 - 05:01 PM

Sorry, I should have mentioned I use lite.
Anyway, it is a nice piece of code you have, there!
Then, for the gone time, I could substitute the first argument by 35*(remaining_time/total_time), right?
EDIT: wait, there's a draw_triangle function! I'll try to adapt it and see it it works! Thank you!

Edited by saim, 08 March 2010 - 11:31 AM.

  • 0

#4 saim

saim

    GMC Member

  • New Member
  • 1085 posts

Posted 09 March 2010 - 12:57 AM

Ok, the hard part is done, the donut is drawn. But, for some reason, I still can't see the alarm go down. Could anyone take a look at the code, please?
<draw event>
var i, distance, thick, angle, color, centerx, centery, tot_time, rem_time;
distance=20 //inner radius
thick=10 // distance between inner and outer radius
color=c_red //color, duh
centerx=x //x-center of the circle
centery=y //y-center of the circle
tot_time=36 //total time
rem_time=alarm[0] //remaining time
angle=360 //angle to be fulfilled

//draw the ring for the total time
for (i=0;i<round(angle/10);i+=1)
{
v1x=centerx+lengthdir_x(distance,i*10)
v1y=centery+lengthdir_y(distance,i*10)
v2x=centerx+lengthdir_x(distance+thick,(i+1)*10)
v2y=centery+lengthdir_y(distance+thick,(i+1)*10)
v3x=centerx+lengthdir_x(distance,(i+1)*10)
v3y=centery+lengthdir_y(distance,(i+1)*10)
draw_triangle(v1x,v1y,v2x,v2y,v3x,v3y,0)
v3x=centerx+lengthdir_x(distance+thick,(i*10))
v3y=centery+lengthdir_y(distance+thick,(i*10))
draw_triangle(v1x,v1y,v2x,v2y,v3x,v3y,0)
}

//draw the arc for the remaining time
color=c_green
angle=360*(rem_time/tot_time)
for (i=0;i<round(angle/10);i+=1)
{
v1x=centerx+lengthdir_x(distance,i*10)
v1y=centery+lengthdir_y(distance,i*10)
v2x=centerx+lengthdir_x(distance+thick,(i+1)*10)
v2y=centery+lengthdir_y(distance+thick,(i+1)*10)
v3x=centerx+lengthdir_x(distance,(i+1)*10)
v3y=centery+lengthdir_y(distance,(i+1)*10)
draw_triangle(v1x,v1y,v2x,v2y,v3x,v3y,0)
v3x=centerx+lengthdir_x(distance+thick,(i*10))
v3y=centery+lengthdir_y(distance+thick,(i*10))
draw_triangle(v1x,v1y,v2x,v2y,v3x,v3y,0)
}
and for creation and alarm[0], all I have is
alarm[0]=36
The oddest thing is that I used the same line of thinking for other counters and it worked all right, but this code only shows me a full green donut.
  • 0

#5 saim

saim

    GMC Member

  • New Member
  • 1085 posts

Posted 19 March 2010 - 02:04 AM

Kind of a bump, it was the color setting, it works now, but I have more doubts:
I'm trying to make a flametrhower effect. I don't want to create an object just for that if I can avoid it (if there is no other way, I'll do it). Here's the effect I want:
- When I press space, many flame sprites are successively drawn moving away from the object, one after another, until a maximum lenght is reached.
- When I press "left/right", the sprites keep being drawn, but moving in another angle. Plus, the ones that are already drawn keep the angle they got, giving to the flames a "snake" aspect.
- When I press "up/down", it increases the lenght the flames go until disapear.
- If that's not hard enough, I want the flames to incease in size as move away from the object.
- Ah, using GM8, lite.

Using an object for the flames would be simple, but I'm complicated. Well, I already have something, but as anyone who tests it will notice, it is far from the effect I want. Let me post the object info:
Information about object: obj_flamethrower

Create Event:
execute code:

fire=12
fire_lenght=32
var i;
for (i=0;i<=fire;i+=1)
{
dir[i]=direction
xx[i]=x
yy[i]=y
}

Step Event:

var i;
for (i=fire;i>0;i-=1)
{
xx[i]=xx[i-1]+lengthdir_x(fire_lenght,dir[i-1])
yy[i]=yy[i-1]+lengthdir_y(fire_lenght,dir[i-1])
dir[i]=dir[i-1]
}
xx[0]=x
yy[0]=y
dir[0]=direction
 
if keyboard_check(vk_space)
 fire_lenght=32
 else
  fire_lenght=0
  
if keyboard_check(vk_left)
direction+=10

if keyboard_check(vk_right)
direction-=10

if keyboard_check(vk_up)
fire+=1

if keyboard_check(vk_down)
fire-=1

Draw Event:

var i;
for (i=0;i<=fire;i+=1)
{
draw_sprite(spr_fire,0,xx[i],yy[i])
}
So far, the sprites are all the same size. When I stop pressing space, the flames "go back" to the object (I'd like them to keep their move until the maximum lenght and disappear). And, when I try to increase the chain size (pressing up beyond the point it started) I get the following error:

___________________________________________
ERROR in
action number 1
of Draw Event
for object obj_flamethrower:

Error in code at line 4:
draw_sprite(spr_fire,0,xx[i],yy[i])
^
at position 25: Unknown variable xx or array index out of bounds

I know, I didn't set the array to go that far, but how do I do this on the fly? Do I need to make a huge array and hope the player doesn't go beyond its size?

Edited by saim, 19 March 2010 - 02:24 AM.

  • 0

#6 Canite

Canite

    Canigget

  • GMC Member
  • 1358 posts
  • Version:GM8

Posted 19 March 2010 - 02:51 AM

Shadow gave me a code for a neat half donut healthbar a few days ago. I made a sample of it here.

Edited by Canite, 19 March 2010 - 02:51 AM.

  • 0

#7 saim

saim

    GMC Member

  • New Member
  • 1085 posts

Posted 19 March 2010 - 12:42 PM

Thank you, Canite, I'll take a look, but that is already solved, based on jordan leffl's code. I have a new, improved challenge for everyone, take a look 2 posts above (the "bumping" post).
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users