April 26, 2024, 09:46:56 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Balloons

Started by GWS, June 15, 2011, 11:57:18 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

June 15, 2011, 11:57:18 AM Last Edit: July 03, 2011, 04:12:10 AM by GWS
Hi folks,

I've been working on Input methods for my user guide, and wanted an example using the arrow keys on the keyboard ..  ::)

This little program grew too large - I shall have to think up something simpler.

Anyway, I thought I'd post it for everyone's amusement  :)

There's an .exe in the zip for those who don't have CB loaded.

all the best, :)

Graham

Tomorrow may be too late ..

GWS

Hi folks,

Well, no comments at all ..  :P .. deathly hush.

So I'll point a few things out  :)

Each pin has 3 parts - the coloured head, the body, and a (not visible) active tip.

Why? .. well I didn't want the balloon popping off if it hit a pin sideways.

The body of a pin is actually a 2pixel wide line drawn from some point and 50 pixels long. 

Attaching the coloured heads was easy, but figuring out where to put the active point when the 'pin sprite' was rotated through a random angle was a tricky bit of geometry  ::)
Collision with the balloon sprite is then checked against all the active point sprites.

That's why I didn't use a complete, drawn sprite for the pins.  When you rotate a sprite, it's about it's top left corner.  Take a peek at the attached piccy.   

Imagine rotating the sprite through some random angle - and then trying to figure out where to attach the active tip sprite.  So I chickened out and drew my own lines - at least I knew where the ends would be  :)

The little game also uses a midi file for background music.  I like these 'cos they are such small files, and using the "WINMM" API routine, they are easy to play.  They do seem to take a second or two to load though - I've no idea why.

It all worked out reasonably well I thought - but folks might have a view how it might be improved.

all the best, :)

Graham
Tomorrow may be too late ..

DominiqueB

Hello,

it works great when running from the editor, but crash when compiled and launched from .exe !

I use vista . . .

Thank's

Dominique

GWS

Hi Dominique,

Glad you got it to work in the IDE at least.

I've tried it in Win7, and it works OK there.

best wishes, :)

Graham
Tomorrow may be too late ..

GWS

Oops .. I'd forgotten to complete the timing loop ..  ::)

It's supposed to run at 40 frames per sec (or whatever you set it to) irrespective of the machine speed.

As I left it, it was running flat out with every DXUpdate event processed.

I've reloaded the .zip file with the timing now correct - I hope ..  ;D

all the best, :)

Graham
Tomorrow may be too late ..

RG

Hi Graham,

Haven't been on here for a long while. Looks as if you've been busy recently. Tried to run the .exe but get "can't find d3drm.dll" error.

Rich

GWS

Hi Rich,

You've obviously 'upgraded' if that's the right word, to Vista or Win 7 ..  ::)

Microsoft in their wisdom (or their drive to kill off legacy software), saw fit to leave the file out of their recent offerings.

I've attached a copy - just place it in your Windows System32 folder and all will be well ..  ;D

best wishes, :)

Graham
Tomorrow may be too late ..

GWS

Hi folks,

I wonder if I could ask if you would run an experiment for me ..  ;D

This program uses a GDI standard Exit button with a Direct X screen. :o

It works fine for me - and I've tried it in XP and Win7 - but I'm told it's not supposed to work (or at least, it's not recommended by Microsoft) - it might be just an unexpected 'feature' of Creative Basic.

Could you try it on your machine, and let me know if you find the button 'disappears' at times ..  ::)

It is possible to program your own button DX sprite, but it's extra work and not so neat ..

There is an exe file in the zip if you don't have Creative loaded ..

In my view, if it works - go for it - but if trouble ensues, then obviously the 'correct' method has to be used.

So the experiment is to see if it works OK on other machines and OS's.

Thanks, :)

Graham
Tomorrow may be too late ..

LarryMc

I'm assuming you are talking about your attachment to your original post since there is no attachment to your last post.

If that is correct then the exe runs fine on my win7 x64.  Exit button is rock solid.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Thanks Larry ..  ;D

I've not had any problems myself in CB (although it doesn't work in other languages I've tried), so currently I would take it that Creative is able to handle the method.

I must check if IWB will do the trick as well.

Graham.
Tomorrow may be too late ..

GWS

I think I might have figured what the difference is .. Creative uses Dirext X 'retained mode', which Microsoft superceded with their 'immediate mode' in later versions of DX for Vista and Win7 ..  ::)

Later software probably uses DX9.0c which must function differently.  Typical Microsoft, crippling what they like to call 'legacy software'.

To my old eyes, the difference between DX7 and DX9 is not clear.  Check out this comparison on Youtube:

http://www.youtube.com/watch?v=0KkL9JCP7NI

In fact I still have several wonderful games written for DOS (which can't be run nowadays of course  ::)), which I still reckon were better than DX games.

Here's what happened back in 1994 apparently ..

Quote
In late 1994, Microsoft was ready to release Windows 95, its next operating system. An important factor in the value consumers would place on it was the programs that would be able to run on it. Three Microsoft employees â€" Craig Eisler, Alex St. John, and Eric Engstrom â€" were concerned because programmers tended to see Microsoft's previous operating system, MS-DOS, as a better platform for game programming, meaning few games would be developed for Windows 95 and the operating system would not be as much of a success.

Good 'ol Microsoft - they're on par with Murdoch's Sky and media companies as far as trustworthiness goes.

So far then, it looks like Creative's graphics facilities are what you might call 'oldies but goodies'.

best wishes, :)

Graham

Tomorrow may be too late ..

LarryMc

the only diff I can see on the youtube video is that the commissar's face has more details in the dx9 version.
the dx9 has brighter highlighting of targets (the bears, jacket, etc)
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

GWS

Yep, you may be right - but there's not a lot in it.

I've checked out GDI buttons in IWB and they work fine there as well - for example (sorry it's in the CB section, but the discussion is relevant I think).

IWB Code ...

' Mandlebrot - GWS March 2012
' using DirextX 2D
' Click on the fractal to enlarge the pattern at that point.
' Click Normal to return to the standard Mandlebrot display.

autodefine "OFF"

window w
int i,y,px,wstyle,run
int Width,Height
int mx,my,clickcount
float Z_re2,Z_im2,Z_re,Z_im,c_re,c_im
float x1,x2,y1,y2
float Rfac,Ifac,scale,Re,Im
pointer sprite1

Width=1024
Height=768
run = 1

wstyle = @minbox|@noautodraw
openwindow w,0,0,Width,Height,wstyle,0,"Mandlebrot",&handler
' create a DirectX screen (no allowance is made for the user not having DirectX - just go for it) ...
attachscreen(w,Width,Height,0)

frontpen backBuffer,RGB(255,255,255)
setfont backbuffer,"Arial",10,500
drawmode backBuffer,@TRANSPARENT

control backbuffer,@BUTTON,"Normal",Width*0.1,Height*0.85,70,25,0, 1
control backbuffer,@BUTTON,"Exit",Width*0.8,Height*0.85,70,25,0, 2

' working sprite to draw on - and to refresh from if the window needs re-painting ..
sprite1 = CREATESPRITE(Width,Height,1,1)

centerwindow w

scale = 1.0
clickcount = 0

' define the corners for two complex numbers (x1+iy1) and (x2+iy2) ..
x1 = -2
y1 = -1.2
x2 = 1
y2 = 1.2

' calculate factors to match screen pixels to corresponding complex values ..
Rfac = (x2 - x1)/(Width - 1)
Ifac = (y2 - y1)/(Height - 1)

fillscreen RGB(0,0,30)
flip

gosub NewPattern

drawsprite sprite1
move backBuffer,50,20
print backBuffer,"Click anywhere on the Fractal for an enlargement."

flip

waituntil run = 0
freesprite sprite1
closescreen
closewindow w
end

sub handler
select @MESSAGE
case @IDCLOSEWINDOW
    run = 0
case @idcontrol
select @controlid
case 1
' set to display normal mandlebrot ..
clickcount = 0
Scale = 1.0
x1 = -2
x2 = 1
y1 = -1.2
y2 = 1.2
setfocus w

gosub Redraw

return
case 2
run = 0
endselect
case @IDLBUTTONDN
' where was the mouse button clicked ..
mx = @MOUSEX
my = @MOUSEY
clickcount = clickcount + 1

' magnify by 10 at each click ..
Scale = clickcount * 10

' calculate the Real and Imaginary values corresponding to the point clicked ..
Re = x1 + @mousex * Rfac
Im = y2 - @mousey * Ifac

' plot from the selected Re +/- 1.5 , and from Im -/+ 1.2
x1 = Re - 1.5 / Scale
x2 = Re + 1.5 / Scale
y1 = Im - 1.2 / Scale
y2 = Im + 1.2 / Scale

' recalculate the Re and Im factors for the current scale ..
gosub Redraw

case @IDPAINT
drawspritexy sprite1,0,0
flip
endselect
endsub


sub NewPattern
float xm
int NIter
' routine to generate a Mandlebrot pattern ..
' increase the number of iterations as the scale increases
NIter = 50 * sqrt(Scale)

SpriteToBuffer(sprite1)
Fillscreen RGB(0,0,50), SpriteBuffer
LOCKBUFFER SpriteBuffer

for y = 0 to Height - 1
c_im = y2 - y * Ifac

for px = 0 to Width - 1
c_re = x1 + px * Rfac
Z_re = c_re
Z_im = c_im

for i = 1 to NIter
xm = i :' colour multiplier

Z_re2 = Z_re * Z_re
Z_im2 = Z_im * Z_im

if (Z_re2 + Z_im2 > 4)
WritePixelFast px,y,rgb(30+xm,90+xm,190+xm),SpriteBuffer
goto break
endif

Z_im = 2 * Z_re * Z_im + c_im
Z_re = Z_re2 - Z_im2 + c_re

next i

label break

next px
next y

UNLOCKBUFFER SpriteBuffer
endsub


sub Redraw
' redraw the pattern after a change ..
Rfac = (x2 - x1)/(Width - 1)
Ifac = (y2 - y1)/(Height - 1)

gosub NewPattern

drawsprite sprite1

move backBuffer,50,20
print backBuffer,"Click on the Fractal to enlarge a section."

flip
endsub


So it seems both CB and IWB are happy with simple GDI buttons in a DX window - makes life easier ..  ;D

best wishes, :)

Graham
Tomorrow may be too late ..