A simple challenge

alix
Posts: 17
Joined: Tue Dec 20, 2005 10:22 am

A simple challenge

Post by alix »

Here is a simple challenge that anyone can enter, from JB beginners to busy JB gurus !

Create a traffic light.
What type of traffic light ? the red, orange, green type, or similar system with arrows, that one can see on busy roads all over the world.

You may use any graphical command you like, or bitmap, or no graphics at all, just windows and button.

The main subject of your program must be a traffic light, or traffic lights. But how you present your traffic light is up to you . For example, your traffic light may have a context ( background, game, etc) or no context at all. And then, You could also let the user control the traffic light, or have random changing of colour. Finally,Your traffic light may cause some events to happen, or it could just exist for itself !

Deadline is : 1st April 2006 ! (no, this challenge is not a joke !) :D

You can post your entries here.

@+
Last edited by alix on Wed Mar 22, 2006 10:43 am, edited 1 time in total.
Beginner ? Want to create your own games?
Coolprog is for you !
http://www.coolprog.com
Welopez
Posts: 56
Joined: Fri Jan 07, 2005 11:16 pm
Location: Currently living in Riverside, CA

Stoplight DEMO Only!

Post by Welopez »

This is not a submission for Alix's challenge, merely a DEMO of a program I wrote last year. The purpose of the program is to demonstrate using MouseX and MouseY positions to simulate BMP buttons, without the need to include BMP files. By chance, I created a stoplight for this demo.

Code: Select all

'Using SELECT CASE Branch To with SUB for Delay and Re-Draw a Window
'Written by Welopez with Help from Pablo, 051305

NOMAINWIN

WindowWidth=200
WindowHeight=200
UpperLeftX=INT((DisplayWidth-WindowWidth)/2)
UpperLeftY=INT((DisplayHeight-WindowHeight)/2)

OPEN "My Stoplight" FOR GRAPHICS_nsb AS #cw  'Show the Choice Window
PRINT #cw, "trapclose [quit]"
PRINT #cw, "down"

[setUp]  'Default window
PRINT #cw, "fill buttonface" 'Fill graphic box with user's default system background color
PRINT #cw, "backcolor 0 132 0"  'Sets fill color dull green
PRINT #cw, "color BLACK"  'Sets pen color
PRINT #cw, "size 2"
PRINT #cw, "place 20 20"  'Position the pen
PRINT #cw, "circlefilled 10"  'Draw a filled circle
PRINT #cw, "place 10 140"  'Places the pen

PRINT #cw, "backcolor 232 232 157"  'Sets fill color dull yellow
PRINT #cw, "color BLACK"  'Sets pen color
PRINT #cw, "place 20 60"  'Position the pen
PRINT #cw, "circlefilled 10"  'Draw a filled circle

PRINT #cw, "backcolor 223 0 0"  'Sets fill color dull red
PRINT #cw, "color BLACK"  'Sets pen color
PRINT #cw, "place 20 100"  'Position the pen
PRINT #cw, "circlefilled 10"  'Draw a filled circle

PRINT #cw, "place 10 140"  'Places the pen
PRINT #cw, "color BLACK"  'Change the color of the pen
PRINT #cw, "backcolor buttonface"  'Background color of the text
PRINT #cw, "\Click A Color!"  'Message to user
PRINT #cw, "flush" 'Commits current set of commands to memory for to make graphics stick
PRINT #cw, "discard" 'Rids all commands prior to last flush to free memory
PRINT #cw, "when leftButtonDown [setNewColors]"  'Branch if aim is good

WAIT
[setNewColors]  'Get mouse position to make choice
IF (MouseX >12 AND MouseX < 28) AND (MouseY >12 and MouseY <28) THEN sel=1
IF (MouseX >12 AND MouseX < 28) AND (MouseY >52 and MouseY <68) THEN sel=2
IF (MouseX >12 AND MouseX < 28) AND (MouseY >92 and MouseY <108) THEN sel=3

SELECT CASE sel  'Set new colors and message
    CASE 1  'Green button is pressed
        col$="GREEN"
        msg$="GREEN!"
        loc$="20 20"
    CASE 2  'Yellow button is pressed
        col$="YELLOW"
        msg$="YELLOW!"
        loc$="20 60"
    CASE 3
        col$="RED"  'Red button is pressed
        msg$="RED!"
        loc$="20 100"
    CASE ELSE
        GOTO [setUp]
    END SELECT

[tempSetup]  'Draw Temp Window
PRINT #cw, "place 10 140"  'Places the pen
PRINT #cw, "down"
PRINT #cw, "backcolor "; col$  'Set a new color based on button pressed
PRINT #cw, "place "; loc$  'Position the pen
PRINT #cw, "circlefilled 10"  'Draw a filled circle
PRINT #cw, "place 10 140"  'Places the pen
PRINT #cw, "backcolor buttonface"  'Background color of the text
PRINT #cw, "\You pressed "; msg$  'Message to user
CALL shortPause  'Do shortPause then come back here
sel=0 : MouseX=0 : MouseY=0  'Re-set values to zero before new [setUp]
GOTO [setUp]  'Go back to the Default Window

WAIT
[quit]
    CLOSE #cw
    END

SUB shortPause
    print #cw, "disable"  'Prevents mouse input during shortPause
    TIMER 2500, [cont]  'Set pause here, more is longer.
    WAIT
    [cont]
    TIMER 0
    print #cw, "enable"  'Enable the window again
END SUB
You do not have the required permissions to view the files attached to this post.
Welopez
Posts: 56
Joined: Fri Jan 07, 2005 11:16 pm
Location: Currently living in Riverside, CA

STOPLIGHT Challenge

Post by Welopez »

Here I am sitting at home on a Friday night. One grandson is playing World of Warcraft on his computer, one grandson is spending the night at a friends, my daughter and son-in-law are watching Band of Brothers on DVD, so what shall I do? Aha! The Stoplight Challenge! :idea: Why not?

I liked the submission by BasicWebmaster, but I wanted my Stoplight to run automatically, and do several different things. This may not be the best code in the world, but it does the job and is pretty well remmed to show you what is happening.

I wrote this putting as much as possible in five sub-routines. Initially, the red and green lights are timed for four seconds each, but you can adjust that. The yellow light blinks at you! :lol:

It's just after sunset, so the night sky is a soothing shade of purple. I've been to many locations throughout the world, and stoplights come in all sizes, shapes, and colors. This one is pretty generic... because it was easy!

I wrote a single SUB for pause, but used it several places and for different intervals. A SELECT CASE block decides where we are in the cycle and calls the next SUB. When I got all done with it, I felt like adding a motor cycle cop to ride in and issue citations to motorists who don't obey the light... but that would have defeated the purpose of writing the program using no BMP images. The program is zipped into a folder of it's own, My Stoplight. Hey! It was fun, helped pass the time, and now it's time for beddy-bye-bye! :wink:
You do not have the required permissions to view the files attached to this post.
Attempt
Posts: 5
Joined: Wed Feb 08, 2006 2:27 am

My Stop Light

Post by Attempt »

Well here is mine, it is probably the worst out of all the entries.... but here it is. I got a bunch of help, so that probably also takes me out of qualifying, if that does, take this out and forget me. I only tried it, because this is the first contest that seemed somthing like I could do, but Its suprisingly not. It goes through a cycle. I made the timer last shorter on the yellow light, and made them longer on the red and green. The major downside is that it dont look like a traffic light, it just shows the lights lighting up. But its not like this:
()
()
()
but it is more like this
() () () but in all in one ()

I included the image files with it.... You will need to put the folder in my documents so it does not mess up. I hard coded them so the folder must be in the my documents folder.... Meaning, all you have to do is add that folder to the my documents, then take the .bas file out and open it with JB. :D :shock: :shock: :shock: :shock: :shock: :shock:
You do not have the required permissions to view the files attached to this post.
ajd344
Posts: 20
Joined: Wed Jul 20, 2005 5:42 am

Post by ajd344 »

Here's my entry! It took me forever!

http://www.atown.org/trafficlite.zip

Please see main thread: http://justbasic.conforums.com/index.cg ... 1142977084
alix
Posts: 17
Joined: Tue Dec 20, 2005 10:22 am

Post by alix »

Here is drawlight.bas.

I used Tom Nally's formula to draw circles, but without the XOR rule.
I also used Welopez flushing Sub and added a few features to it !
I used an array to pass colors to a function. It works well. arrays are always global, very handy.

To start the program click on the sheep and don't forget to put your sound on.
You do not have the required permissions to view the files attached to this post.
Beginner ? Want to create your own games?
Coolprog is for you !
http://www.coolprog.com