Programming Simple 2D game with Dolphin.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

Programming Simple 2D game with Dolphin.

Syver Enstad-3
Is there an easy way to setup an application with a surface/Canvas
that you can blit to, set pixel, get pixel, easy toggling of
fullscreen would be nice, but not essential. I would hope to be able
to dodge directx for the time being, I just want a plain canvas to
draw on and my own mainloop.

Python has got a wonderfully simple library for
writing simple games (Pygame) which works something like this, setup the main
window (one call), loop until some quit condition while polling input
events and blitting (bitmaps loaded from disk in one call too) and
drawing to the screen. Very nice, but I really miss programming more
Smalltalk so I am considering finding out how much more hassle it
would be to implement the same with Dolpin instead.

Thanks for any tips or pointers.

--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Andy Bower
Syver,

> Is there an easy way to setup an application with a surface/Canvas
> that you can blit to, set pixel, get pixel, easy toggling of
> fullscreen would be nice, but not essential. I would hope to be able
> to dodge directx for the time being, I just want a plain canvas to
> draw on and my own mainloop.
>
> Python has got a wonderfully simple library for
> writing simple games (Pygame) which works something like this, setup the
main
> window (one call), loop until some quit condition while polling input
> events and blitting (bitmaps loaded from disk in one call too) and
> drawing to the screen. Very nice, but I really miss programming more
> Smalltalk so I am considering finding out how much more hassle it
> would be to implement the same with Dolpin instead.

Take a look at the DoubleBufferedView class and, in particular it's
BouncingBallsView subclass. These will show you how to easily perform smooth
animation in Dolphin. You can easily get a Canvas to draw your game on
although I wouldn't really recommend doing too much with set/get pixel since
these will probably end up being too slow if you need to do a lot of pixel
pushing. See Canvas>>pixelAt: and Canvas>>pixelAt:put:.

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Syver Enstad-3
"Andy Bower" <[hidden email]> writes:
>
> Take a look at the DoubleBufferedView class and, in particular it's
> BouncingBallsView subclass. These will show you how to easily perform
> smooth
> animation in Dolphin.

Sounds fine, but where can I find it? Aha, it's probably part of the
much coveted Dolphin XP, which I due to my present financial situation
are unable to lay my hands on ;-( Too bad.

>You can easily get a Canvas to draw your game on
>
> although I wouldn't really recommend doing too much with set/get pixel
> since these will probably end up being too slow if you need to do a lot of
> pixel pushing. See Canvas>>pixelAt: and Canvas>>pixelAt:put:.

Yes I know that (I've been using Python for these things and it is not
exactly super fast).


--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Christopher J. Demers
Syver Enstad <[hidden email]> wrote in message
news:[hidden email]...

> "Andy Bower" <[hidden email]> writes:
> >
> > Take a look at the DoubleBufferedView class and, in particular it's
> > BouncingBallsView subclass. These will show you how to easily perform
> > smooth
> > animation in Dolphin.
>
> Sounds fine, but where can I find it? Aha, it's probably part of the
> much coveted Dolphin XP, which I due to my present financial situation
> are unable to lay my hands on ;-( Too bad.
...

Andy posted an example package for Dolphin 4.0 that included a
DoubleBufferedView some time ago.  I don't know if it has changed much in
D5, but it should be a good starting point for you.  You can find it in
Google here
http://groups.google.com/groups?q=Dolphin+DoubleBufferedView&hl=en&selm=9o9t
k8%24c1h94%241%40ID-51044.news.dfncis.de&rnum=1 and probably in Ian's
newsgroup archive as well.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Syver Enstad-3
In reply to this post by Andy Bower
"Andy Bower" <[hidden email]> writes:
 
> Take a look at the DoubleBufferedView class and, in particular it's
> BouncingBallsView subclass. These will show you how to easily perform
> smooth animation in Dolphin. You can easily get a Canvas to draw your game on
> although I wouldn't really recommend doing too much with set/get pixel
> since these will probably end up being too slow if you need to do a lot of
> pixel pushing. See Canvas>>pixelAt: and Canvas>>pixelAt:put:.

Cool, a couple of more questions (I know that I could try to find out
about these issues on my own, but I would be glad if anyone could
help).

Loading images, bmp, maybe gif, jpeg too.

Sounds, easy loading and playing of .wav files.

Fullscreen ?

Game Controllers  ?

--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Christopher J. Demers
Syver Enstad <[hidden email]> wrote in message
news:[hidden email]...
>
> Cool, a couple of more questions (I know that I could try to find out
> about these issues on my own, but I would be glad if anyone could
> help).

I can answer some of these.

> Loading images, bmp, maybe gif, jpeg too.

Look at the Image class side methods, particularly fromFile:.  The
OLEPicture class will handle JPG's and GIF's.
ex: OLEPicture fromFile: 'mygraphic.jpg'.

> Sounds, easy loading and playing of .wav files.

See the Sound class.  Here is an example from the Welcome file:
(Sound fromFile: 'xxxxx.wav') woofAndWait; woofAndWait.

> Fullscreen ?

The closest easy thing I am aware of would be to just maximize the Window.
Maybe others can comment.  Here is one way:

shell:= Shell create.
shell view showMaximized.

> Game Controllers  ?

I have no idea.  You might have to look at the DirectInput part of DriectX.
If Python exposes as much source as Smalltalk you might look to see how they
do this, perhaps there is a simpler API.

If you get some kind of graphical game working I would be interested to know
how you fare.

Chris


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Ian Bartholomew-10
A couple of additions to Chris' reply

> > Sounds, easy loading and playing of .wav files.
>
> See the Sound class.  Here is an example from the Welcome file:
> (Sound fromFile: 'xxxxx.wav') woofAndWait; woofAndWait.

If you want a little more control over the file that is being played you can
investigate the Windows MCI (Media Control Interface) which can allow you to
play (and record apparently - but I never got that working correctly) using
simple string commands. It's accessed via Dolphins WinMMLibrary.

If you want a _lot_ more control you can use the Windows api directly. I've
got some classes that do this (because of the recording problem mentioned
above) but it is a lot more complicated.

Both these options are accessed via Dolphins WinMMLibrary but you will have
to spend a bit of time on MSDN for details.

> > Game Controllers  ?
>
> I have no idea.  You might have to look at the DirectInput part of
DriectX.
> If Python exposes as much source as Smalltalk you might look to see how
they
> do this, perhaps there is a simpler API.

I'm not sure of the current state of this, it's a few years since I looked
at it [1], but there is a Windows api for accessing the Joystick. I have no
idea if "Game Controllers" work in a different way as the old "Joysticks",
they certainly sound more impressive, but it might be enough to get you
started?.  Once again it is accessed via the WinMMLibrary with functions
that start with 'joy'. "joyGetPos", for example, answers the current
position of the joystick and state of the buttons.

[1] but only to use it as a quick and simple, albeit not very accurate, A-D
interface for external sensors.

--
Ian
Due to spamming the reply-to address may only be valid for the next few
days.  Use it to mail me _now_ if you want a longer term contact address.


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Andy Bower
In reply to this post by Syver Enstad-3
Syver,

> Cool, a couple of more questions (I know that I could try to find out
> about these issues on my own, but I would be glad if anyone could
> help).
>
> Loading images, bmp, maybe gif, jpeg too.

Bitmap fromFile: 'MyPicture.bmp' "Bitmaps"
OLEPicture fromFile: 'MyPicture.jpg" "Bitmaps and JPEGs and GIFs)

> Sounds, easy loading and playing of .wav files.

Look in the sound class.

sound := Sound fromFile: 'MySound.wav'.
sound woof.
sound woofAndWait.

> Fullscreen ?

I don't think you'll be able to do this without using DirectDraw from
DirectX.

> Game Controllers  ?

Ditto. You'll need a DirectPlay interface.

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Andy Bower
Syver,

> > Game Controllers  ?
>
> Ditto. You'll need a DirectPlay interface.

Of course, after reading Chris's post, I realize that this should be
DirectInput.

Best Regards,

Andy Bower
Dolphin Support
http://www.object-arts.com
---
Are you trying too hard?
http://www.object-arts.com/Relax.htm
---


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Syver Enstad-3
In reply to this post by Christopher J. Demers
"Christopher J. Demers" <[hidden email]> writes:

>
> > Fullscreen ?
>
> The closest easy thing I am aware of would be to just maximize the
> Window.
>
> Maybe others can comment.  Here is one way:
>
> shell:= Shell create.
> shell view showMaximized.


That's close enough for the moment, thanks.

> > Game Controllers  ?
>
> I have no idea.  You might have to look at the DirectInput part of
> DriectX.

Mmm, I was hoping to avoid DirectX as long as I could, to avoid being
drawn into too many technical considerations prematurely. I know that
win32api exposes game controller functionality through the multimedia
api separately from Direct Input, is this functionality supported by
Dolphin? What the heck, I suppose Direct Input might not be so bad,
I'll just have to look into it then.

> If Python exposes as much source as Smalltalk you might look to see
> how they do this, perhaps there is a simpler API.

Yes the source is exposed, but it's C extensions and they run against
a simplyfied cross platform multimedia library called SDL, that works
with DirectX behind the scenes on win32, so I don't think that will help.

>
> If you get some kind of graphical game working I would be interested
> to know how you fare.

I'll do that, I warn you that it will be nothing exciting, at the
moment I am thinking of Breakout/Pong (you know Ball, Bat and a Wall
of Bricks).



--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Syver Enstad-3
In reply to this post by Ian Bartholomew-10
"Ian Bartholomew" <[hidden email]> writes:
 
> > > Game Controllers  ?

> I'm not sure of the current state of this, it's a few years since I
> looked at it [1], but there is a Windows api for accessing the
> Joystick. I have no idea if "Game Controllers" work in a different
> way as the old "Joysticks", they certainly sound more impressive,
> but it might be enough to get you started?.  Once again it is
> accessed via the WinMMLibrary with functions
>
> that start with 'joy'. "joyGetPos", for example, answers the current
> position of the joystick and state of the buttons.

That was exactly what I was looking for, I've fooled around with these
when I was writing straight win32 applications in C++ (before I
discovered Python and Smalltalk, I thought C++ was the coolest there
was).

--

Vennlig hilsen

Syver Enstad


Reply | Threaded
Open this post in threaded view
|

Re: Programming Simple 2D game with Dolphin.

Syver Enstad-3
In reply to this post by Andy Bower
"Andy Bower" <[hidden email]> writes:

> Syver,
>
> > > Game Controllers  ?
> >
> > Ditto. You'll need a DirectPlay interface.
>
> Of course, after reading Chris's post, I realize that this should be
> DirectInput.

That's okay, I also tend to think that DirectPlay involves game
controllers when it really is for network multiplayer gaming.

I found out (via a post here) that the win32 multimedia could be used,
I have used these functions before so I'll try that first.

--

Vennlig hilsen

Syver Enstad