News:

Welcome to RetroCoders Community

Main Menu

Dice

Started by johnno56, May 11, 2023, 09:47 AM

Previous topic - Next topic

johnno56

I was toying with the idea of adding graphics to the Snakes and Ladders game and was distracted by the need to include a simple dice.

The program is rough. It draws each number; stores the image (get()-()); then a simple loop generating random numbers then 'put' the images on the screen...

There is obviously a far better way of doing this... lol  But, it's what I came up with... I will not be offended if you do not use any part of this... It was just a 'see if I can' project...

Screen _NewImage(320, 200, 24)
Cls

black = _RGB(32, 32, 32)
white = _RGB(255, 255, 255)
red = _RGB(165, 0, 0)

Dim ONE%(9000)
Dim TWO%(9000)
Dim THREE%(9000)
Dim FOUR%(9000)
Dim FIVE%(9000)
Dim SIX%(9000)

RANDOMIZE TIMER

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       ONE
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
GET(0,0)-(60,60),ONE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       TWO
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),TWO%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       THREE
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),THREE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       FOUR
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),FOUR%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       FIVE
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),FIVE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       SIX
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (30, 15), 7, black: Paint (30, 15), black
Circle (30, 15), 5, white: Paint (30, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (30, 45), 7, black: Paint (30, 45), black
Circle (30, 45), 5, white: Paint (30, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),SIX%
_DELAY 1

CLS
_DELAY 2

DEL = 0.2
COUNT = 0

DO WHILE COUNT < 31
	CLS
	NUM = INT(RND*6)+1
	SELECT CASE NUM
		CASE 1
			PUT(130,70),ONE%
		CASE 2
			PUT(130,70),TWO%
		CASE 3
			PUT(130,70),THREE%
		CASE 4
			PUT(130,70),FOUR%
		CASE 5
			PUT(130,70),FIVE%
		CASE 6
			PUT(130,70),SIX%
	END SELECT
	COUNT = COUNT + 1
	_DELAY DEL
LOOP

_DELAY 2
End
May your journey be free of incident.  Live long and prosper.

johnno56

#1
My guess would be, that QB64, may have a problem with using a 24 bit colour depth... Just a guess...

Change to ... 320, 200, 32...  It should run on QB64 but I cannot guarantee the colours.... Moo Ha Ha Ha...
May your journey be free of incident.  Live long and prosper.

CharlieJV

Screen _NewImage(320, 200, 24)

Just a reminder that the third parameter of _NewImage in BAM is always screen mode, and never one of the other possibilities like in QB64/QB64pe.

"24" in the code above isn't for number of bits per pixel, it is for screen mode "24".  Screen mode 24 being 24-bit, that's just a happy coincidence.  (modes 23-27 are all 24 bit.)

For info about screen mode "24" and the other screen modes: BAM Screen Modes

CharlieJV

Quote from: johnno56 on May 11, 2023, 09:47 AMI was toying with the idea of adding graphics to the Snakes and Ladders game and was distracted by the need to include a simple dice.

The program is rough. It draws each number; stores the image (get()-()); then a simple loop generating random numbers then 'put' the images on the screen...

There is obviously a far better way of doing this... lol  But, it's what I came up with... I will not be offended if you do not use any part of this... It was just a 'see if I can' project...

Screen _NewImage(320, 200, 24)
Cls

black = _RGB(32, 32, 32)
white = _RGB(255, 255, 255)
red = _RGB(165, 0, 0)

Dim ONE%(9000)
Dim TWO%(9000)
Dim THREE%(9000)
Dim FOUR%(9000)
Dim FIVE%(9000)
Dim SIX%(9000)

RANDOMIZE TIMER

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       ONE
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
GET(0,0)-(60,60),ONE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       TWO
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),TWO%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       THREE
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),THREE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       FOUR
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),FOUR%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       FIVE
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),FIVE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       SIX
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (30, 15), 7, black: Paint (30, 15), black
Circle (30, 15), 5, white: Paint (30, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (30, 45), 7, black: Paint (30, 45), black
Circle (30, 45), 5, white: Paint (30, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),SIX%
_DELAY 1

CLS
_DELAY 2

DEL = 0.2
COUNT = 0

DO WHILE COUNT < 31
	CLS
	NUM = INT(RND*6)+1
	SELECT CASE NUM
		CASE 1
			PUT(130,70),ONE%
		CASE 2
			PUT(130,70),TWO%
		CASE 3
			PUT(130,70),THREE%
		CASE 4
			PUT(130,70),FOUR%
		CASE 5
			PUT(130,70),FIVE%
		CASE 6
			PUT(130,70),SIX%
	END SELECT
	COUNT = COUNT + 1
	_DELAY DEL
LOOP

_DELAY 2
End

That is straight-up my kind of toying around.

Rock'n roll!

johnno56

I figured, if we cannot "load" sprites/tiles, then manually draw them and store them before the game/program starts... It is a lot more work but could be fun... (of course, the 'simpler' the sprite, the better...)
May your journey be free of incident.  Live long and prosper.

CharlieJV

Quote from: johnno56 on May 11, 2023, 09:47 AMI was toying with the idea of adding graphics to the Snakes and Ladders game and was distracted by the need to include a simple dice.

The program is rough. It draws each number; stores the image (get()-()); then a simple loop generating random numbers then 'put' the images on the screen...

There is obviously a far better way of doing this... lol  But, it's what I came up with... I will not be offended if you do not use any part of this... It was just a 'see if I can' project...

Screen _NewImage(320, 200, 24)
Cls

black = _RGB(32, 32, 32)
white = _RGB(255, 255, 255)
red = _RGB(165, 0, 0)

Dim ONE%(9000)
Dim TWO%(9000)
Dim THREE%(9000)
Dim FOUR%(9000)
Dim FIVE%(9000)
Dim SIX%(9000)

RANDOMIZE TIMER

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       ONE
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
GET(0,0)-(60,60),ONE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       TWO
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),TWO%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       THREE
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),THREE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       FOUR
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),FOUR%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       FIVE
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (30, 30), 7, black: Paint (30, 30), black
Circle (30, 30), 5, white: Paint (30, 30), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),FIVE%
_DELAY 1

CLS
Line (0, 0)-Step(59, 59), black, BF
Line (2, 2)-Step(55, 55), red, BF
'       SIX
Circle (15, 15), 7, black: Paint (15, 15), black
Circle (15, 15), 5, white: Paint (15, 15), white
Circle (30, 15), 7, black: Paint (30, 15), black
Circle (30, 15), 5, white: Paint (30, 15), white
Circle (45, 15), 7, black: Paint (45, 15), black
Circle (45, 15), 5, white: Paint (45, 15), white
Circle (15, 45), 7, black: Paint (15, 45), black
Circle (15, 45), 5, white: Paint (15, 45), white
Circle (30, 45), 7, black: Paint (30, 45), black
Circle (30, 45), 5, white: Paint (30, 45), white
Circle (45, 45), 7, black: Paint (45, 45), black
Circle (45, 45), 5, white: Paint (45, 45), white
GET(0,0)-(59,59),SIX%
_DELAY 1

CLS
_DELAY 2

DEL = 0.2
COUNT = 0

DO WHILE COUNT < 31
	CLS
	NUM = INT(RND*6)+1
	SELECT CASE NUM
		CASE 1
			PUT(130,70),ONE%
		CASE 2
			PUT(130,70),TWO%
		CASE 3
			PUT(130,70),THREE%
		CASE 4
			PUT(130,70),FOUR%
		CASE 5
			PUT(130,70),FIVE%
		CASE 6
			PUT(130,70),SIX%
	END SELECT
	COUNT = COUNT + 1
	_DELAY DEL
LOOP

_DELAY 2
End

And you got me curious about low-tech character-based graphics (_LETCHR$ and PUTSTRING):