Lightning effect using canvas?

Game Editor comments and discussion.

Lightning effect using canvas?

Postby DeltaLeeds » Sat May 02, 2015 4:18 pm

Hello everyone! Glad to see some interesting posts lately including Bat78's newspaper posts which perks me up to what's going on concerning gE's development and new rising game makers like Koala... So onto the topic!

I really want to know if it is possible to make a random lightning effect for gE using canvas... This sounds ridiculous (Especially with my knowledge of programming and stuff.) but is it possible? And if yes, how do I do it? (Tbh, I don't really know how to use canvas except for making health bars and other meters. xD)
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Lightning effect using canvas?

Postby koala » Sat May 02, 2015 6:21 pm

jonathang wrote:Hello everyone! Glad to see some interesting posts lately including Bat78's newspaper posts which perks me up to what's going on concerning gE's development and new rising game makers like Koala... So onto the topic!

I really want to know if it is possible to make a random lightning effect for gE using canvas... This sounds ridiculous (Especially with my knowledge of programming and stuff.) but is it possible? And if yes, how do I do it? (Tbh, I don't really know how to use canvas except for making health bars and other meters. xD)
Hi, jonathang! :D

Just draw a canvas and write this code to it:
Code: Select all
int i, j, k, t; // iterators
int left, right; // number of left and right branches
int leftSection, rightSection; // one section for every branch
int leftI, rightI; // starting position of a branch
int length; // length of a branch


erase(0, 0, 0, 0);

left = 4;
right = 3;
length = 100;
 
leftSection = height / (left + 1);
rightSection = height / (right + 1);


leftI = (int) rand(leftSection);
rightI = (int) rand(rightSection);


// drawing lightning
j = (int) rand(width - width / 5) + width / 10; // x coordinate
for (i = 0; i < height; i++) { // y coordinate
    // main lightning
    setpen(255, 255, 255, 0, 3);
    j = j + rand(3) - 1;
    putpixel(j, i);
 
    // one left branch
    if (i == leftI && left > 0) {
        setpen(255, 255, 255, 0, 2);
        for (k = j, t = leftI; t < leftI + length; t++) {
            k = k + (int) rand(4) - 2;
            putpixel(k, t);
        }
 
        leftI += leftSection;
        left--;
    }
 
    // one right branch
    if (i == rightI && right > 0) {
        setpen(255, 255, 255, 0, 2);
        for (k = j, t = rightI; t < rightI + length; t++) {
            k = k + (int) rand(4) - 1;
            putpixel(k, t);
        }
 
        rightI += rightSection;
        right--;
    }
}
Windows executable
ged and data files
Attachments
lightning source.zip
ged and data files
(81.53 KiB) Downloaded 118 times
lightning exe.zip
Windows executable
(773.23 KiB) Downloaded 121 times
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Lightning effect using canvas?

Postby DeltaLeeds » Wed May 06, 2015 12:51 pm

Sorry for the really late reply! :oops:
Woah! That's amazing! Thanks for the help and even a demo too (+1ed), but can we make it so that the lightning strikes a specific actor inside the canvas?
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Lightning effect using canvas?

Postby koala » Wed May 06, 2015 2:46 pm

jonathang wrote:Sorry for the really late reply! :oops:
Woah! That's amazing! Thanks for the help and even a demo too (+1ed), but can we make it so that the lightning strikes a specific actor inside the canvas?
I am glad you like it! :D Here's what you've asked.
Windows executable
ged and data files
Now you are drawing main lightning from bottom, from player's xscreen coordinate. Side lightnings are still drawn from top to bottom.
Canvas has timer now, which erases lightning and sets normal animation to player.
Attachments
lightning 2 source.zip
ged and data files
(83.56 KiB) Downloaded 128 times
lightning 2 exe.zip
Windows executable
(774.69 KiB) Downloaded 135 times
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score

Re: Lightning effect using canvas?

Postby DeltaLeeds » Thu May 07, 2015 9:06 am

koala wrote:
jonathang wrote:Sorry for the really late reply! :oops:
Woah! That's amazing! Thanks for the help and even a demo too (+1ed), but can we make it so that the lightning strikes a specific actor inside the canvas?
I am glad you like it! :D Here's what you've asked.
Windows executable
ged and data files
Now you are drawing main lightning from bottom, from player's xscreen coordinate. Side lightnings are still drawn from top to bottom.
Canvas has timer now, which erases lightning and sets normal animation to player.

Ah! So you have to draw the lightning from the player's XSCREEN coordinate.. Lol, I thought it was just the x coordinate, and I've been wondering what I was doing wrong all along!
A really clear explanation and demo! Thanks a million Koala! :D
Currently: Semi-Active.
Working on: Maybe putting my test games in gamejolt, polishing them a bit, but I still don't know when.
User avatar
DeltaLeeds
 
Posts: 693
Joined: Fri May 06, 2011 12:45 pm
Location: In front of my computer.
Score: 38 Give a positive score

Re: Lightning effect using canvas?

Postby koala » Thu May 07, 2015 11:21 am

jonathang wrote:
koala wrote:
jonathang wrote:Sorry for the really late reply! :oops:
Woah! That's amazing! Thanks for the help and even a demo too (+1ed), but can we make it so that the lightning strikes a specific actor inside the canvas?
I am glad you like it! :D Here's what you've asked.
Windows executable
ged and data files
Now you are drawing main lightning from bottom, from player's xscreen coordinate. Side lightnings are still drawn from top to bottom.
Canvas has timer now, which erases lightning and sets normal animation to player.

Ah! So you have to draw the lightning from the player's XSCREEN coordinate.. Lol, I thought it was just the x coordinate, and I've been wondering what I was doing wrong all along!
A really clear explanation and demo! Thanks a million Koala! :D
No problem, Jonathang! :D
Phascolarctos cinereus
YouTube: Marko Radivojevic
Google+: Marko Radivojevic
User avatar
koala
 
Posts: 301
Joined: Thu Mar 26, 2015 7:03 pm
Location: Serbia
Score: 30 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron