Author Topic: Pig  (Read 15120 times)

0 Members and 1 Guest are viewing this topic.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #45 on: October 23, 2018, 06:19:35 pm »
Nice sheet!  That's going to make a serious animation... I'll start on it right away.  Does it come in red? lol Kidding...

Thank you.

J
Logic is the beginning of wisdom.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #46 on: October 24, 2018, 04:56:19 am »
Ok. I found a free animated dice gif and extracted each frame. Made a simple roller. It's not efficient but it works. It's just to see if something like this can be used for Pig. No user input. Rolls and gives a number.

J
* diceroll-red.zip (Filesize: 87.99 KB, Downloads: 263)
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #47 on: October 24, 2018, 09:31:29 am »
Johnno, a most excellent start!

I am currently knee deep in a Word Search Editor so if you don't mind continuing or maybe I can talk you through.

First you can optimize the file loads by creating the file names programatically (@Spell Checker = SC what? not a word? sheez)
sub loadManyImages(baseName, numOfFiles)
for i = 1 to numOfFiles
   filename$(i) = baseName + ltrim$(str$(i))+ ".png"
   dice&(i) = _LoadImage( filename$(i)) '<<<<<<<<<<<<<< DIM SHARED dice&(1 to numOfFiles) at code start
next
end sub
something like that, load 100's of images same 4 lines or so of code.

The one, two, three.. dice I would rename something like show1, show2, show3... show 6 and use same technique for loading.

Then setup a di Type for handling up to ... 18-100 di ( @SC, I like di sorry) in array of that Type.
track x, y, dx, dy, frame, directionRotation?< to decide next frame...
maybe a targetFrame too to stop dice spinning when on the ground with that frame up.

then dig up some old code with bouncing balls and plug-in dice images use same collision code use radius something between 1/2 di width/height and 1/2 the diagonal.

Oh it might be helpful to track the di frame with the face number(s) showing and associate that with the file name for loading.
3 faces at most would show list those in file from mainly to hardly showing 365 (if that is possible? hmm the only impossible is a face opposite)...  eh might be getting carried away... ;-)) but that is getting into a numbers sort thing, where is codeguy?

Actually I was wondering if Terry wanted to give his library a workout? perhaps a demo for setting up and using this di rolling thing.
« Last Edit: October 24, 2018, 09:39:44 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #48 on: October 24, 2018, 03:05:09 pm »
Dang start talking about it and next thing you know you have some mods:
* diceroll-red B+ mods 10-24.zip (Filesize: 787.85 KB, Downloads: 246)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Pig
« Reply #49 on: October 24, 2018, 03:30:59 pm »
Optimising the 'load' worked like a treat... Excellent. I tried to do that earlier but had no idea that I had to use 'ltrim$()'... To quote the late, great, Maxwell Smart... "Missed it by THAT much..."

I spent at least an hour on extracting the dice images from the 'sheet' that Steve provided. I duplicated the red dice roller... The red dice roller used 15 images... Steve's black dice uses 114... So, no prizes for guessing, how THAT was coded. Your optimisation will GREATLY reduce the size of THAT listing...

As to the rest of it... You obviously have a greater belief in my abilities than I do...  I have had little to no experience with 'Type'. In fact, I have avoided it in the past, because of that... I know. Quite sad... I had thought of 'dynamic' dice (bounce and roll across the screen) but had no idea how to do that. The best I could hope for was rotating dice, in one spot, but could not figure out how to rotate so I resorted to multiple images.

The program, for want of a better word, that I provided was intended as a 'proof of concept' and took me ages just to figure it out... I am not a programmer. I enjoy tinkering with code and graphics. I have to use tutorials because it takes too long to have conversations. One of the downsides of living 'down under'. What I produce is based on what I know. I do not know anywhere near as much as you guys. Targetframe; Bouncing; Collision; Tracking and now the possibility of external libraries... This is too much to handle. This stuff may 'come easy' for you guys, but for me, not so much... This is all my fault for suggesting graphics... I should have been satisfied with 'Screen 0'...
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #50 on: October 24, 2018, 10:57:21 pm »
Hi Johnno,

You sound overwhelmed, relax I don't think Terry is going to get involved with external libraries but aren't you the one who keeps asking for tutorials? Terry would be great.

Target frame is only the show # image we want to display at the end of the dice roll, the face number for the roll.

Collision and bounce we've not done yet but it's the same as any particle code, you've been there before. You even posted great collision code for rectangles that I saved for future reference.

TYPE is no mystery, instead of ballX() ballY() ballColor() 3 arrays for each character of ball, such that ballX(10), ballY(10) ballColor(10) describe ball 10.

With Type you can do a setup like this:

Type ballType
  x as integer
  y as integer
  kolor as _unsigned long '< best type for colors
end type

Dim ball(nBalls) as BallType 

This sets up an array that includes all the type definitions for one object, instead of 3 separate but related arrays, you have this one that groups them together.

Now ball 10 looks like this:
ball(10).x
ball(10).y
ball(10).kolor

Type just adds a .thing and embeds a () for the index number of the array. It is just the same as ballX(10) ballY(10) ballKolor(10), instead of needing 3 arrays you just use one to cover all the ball characteristics

In QB64, everything has a type (well in any PL everything has a type but some PL's leave it under the hood (SmallBASIC, SdlBasic..) more than others Naalaa and QB64 gives like 16 options for type of one variable.)

Here is my cheat sheet for Types, don't leave home without it:

Append: This is better and more complete of course but not quite at your fingertips (I typed my Type sheet out on Printer).
http://qb64.org/wiki/Variable_Types

I left out Memory stuff and forgot to mention fixed string types on my cheat sheet.

So in summary, all the variables have a Type and a TYPE definition groups several variables of different types (or the same) into an object or record. These can be dimensioned singly or in arrays like other variable types.

Lecture over, quiz on Friday. ;)

PS For a crash course on learning type, put OPTION _EXPLICIT at the top of your code then you will learn your number one bug is getting a variable DIM 'd but it will save you from those pesky less easy to find bugs caused by misspelling. It will also be quizzing you automatically about what type you want or at least have you thinking what type you really need.

* QB64 types.txt (Filesize: 0.44 KB, Downloads: 222)
« Last Edit: October 25, 2018, 12:52:08 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Pig
« Reply #51 on: October 25, 2018, 05:06:57 pm »
Boink update, Graphic Boink has dice rolling and bouncing and no more sliding around after settling on the floor and all this is incorporated into the game:

Plenty left to do, like leaving a score board up all the time.
* Graphic Boink.zip (Filesize: 952.63 KB, Downloads: 255)
Graphic Boink.PNG
* Graphic Boink.PNG (Filesize: 44.91 KB, Dimensions: 1191x743, Views: 420)
« Last Edit: October 27, 2018, 03:38:10 am by bplus »