15,891,942 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by petter2012 (Top 54 by date)
petter2012
19-Oct-17 12:26pm
View
Hi, Thanks Johannes!
Actually, calling my gameloop from the CompositionTarget.Rendering event does the trick. I have now successfully tried with 30 dynamic objects as well as 300 dynamic objects. The objects are not moving smoothly if I have 300 moving objects, but the time is accurate: I have run the game for four minutes (exactly, and the time is correct to the second (at least - I'm confirming with my cellphone's timer :) ).
I will write an article about y game engine within a few weeks hopefully. If anyone needs my code now, then just PM me or so.
petter2012
14-Oct-17 13:23pm
View
Hi,
Thanks, yes of course! I did notice the error message but had forgotten about ToList(). Instead I tried (List)bodylist... but it didn't work.
Thanks again.
petter2012
30-Jul-17 19:01pm
View
Hi again Bill,
Thanks for sharing your story about your teaching experiences.
I am now in the process of writing the documentation for the game engine, and just covered the connection to the OO paradigm. I have a modest suggestion: why not take part in this project and make this the go-to game engine for educational settings? :) I used to teach my students the Physics Helper wrapper (by Andy Beaulieu) and the underlying Farseer physics engine, but this engine is so much easier to work with, yet more flexible. In fact, I covered the entire engine code in a two-hour lecture. What it doesn't have is elaborate collision detection, but then again, that isn't really the point of this particular game engine.
It's really coming along well, and if you want to I can send you a pre-release zip file of my most recent game produced with it.
/Petter
petter2012
29-Jul-17 4:17am
View
Hi Bill,
Thanks for your (as always) well-put and informative reply. I found your reply in the link to be very interesting, though I think I might stick to the static class, as it does work after all, and isn't really abusing the OO concept (or so I think). I learned to program before OOP became a standard, and having worked with mainly WinForms and traditional ASP.NET, I have never had to really dig in to the more elaborate parts of the OO architecture.
Glad to see your comment on the game engine project. I thought that there would be little interest in (yet) another free 2D game engine. However, this game engine is NOT about speed/performance really. Instead, it's written for an educational setting (with no focus on OO obviously :) ). It's extremely flexible, as everything can control everything. For example, in my game called "Mario in Moria", Super Mario fires blue fireballs on goblins. The longer the fireballs get away from Mario, the paler they get (transparency changes). The damage to the goblin is in turn related to the opacity of the fireball. Also, since all objects have "hitpoints" (to use an old D&D term), everything can be damaged if so wanted. Thus, if Mario gets stuck in the Moria dungeon, he can always fire lots of fireballs to the stone wall to eventually destroy it.
A few months ago, my students (with very little programming knowledge) created all kinds of games including gravity, such as a soccer game, a few games where falling objects should be rescued, a space shooter, a "Pingu" game, and a great ninja fighter game. In the Ninja game, there were a lot of things going on (they too could fire shots), but performance was never a problem.
I plan to write an article about this game engine here on CodeProject, sometime after summer. The game engine was first written for UWP, but as we hadn't Win 10 installed at the university, I changed it to WPF. By design, there is really very little framework or language-specific code, so I guess that, for example, a Java developer could translate this very easily to Java, or perhaps just use things like the (rather basic) Physics file for inspiration.
In addition to education, I also think that this game engine could come in handy for game designers who may work with other people who do the real coding. In such a scenario, this game engine could be suitable for prototyping, especially for games that aren't traditional in type (since its best feature is its flexibility). Since the code is so short and comparatively easy, there would be no abandonware risk - it's not difficult to add one's own physics code or the like. BTW, I hope that others will be wanting to add their own methods to this game engine, so that it can thrive and become more powerful than what I can hope to accomplish myself.
petter2012
12-Jul-17 4:53am
View
I found an answer in the Design forum (there is no such software). This question can be closed or even removed.
petter2012
18-Feb-17 10:39am
View
if someone else gets the same problem: reinstalling fixed everything and I think only a few parts of the libraries were actually downloaded, so it turned out to be a quick process.
petter2012
16-Feb-17 18:55pm
View
thanks for replying. yes I have reported the problem to the developers but haven't got a reply so far. I 'll try reinstalling then. Thanks again.
petter2012
30-Dec-16 6:53am
View
ok, thanks!
petter2012
30-Dec-16 6:24am
View
hi again,
sorry if I was unclear. Most game engine implementations use keyboard events, but I find that conceptually competing with the game loop. Thus , I am curious if it's possible to do if statements checking for different pressed keys and if this is a good approach.
Thanks for your answers so far.
petter2012
30-Dec-16 5:10am
View
hi
Well, I've tried this of course and the problem I tried to explain is that there are so many variations, hence my question.
petter2012
7-Dec-16 7:09am
View
Thanks for the link - very helpful!
petter2012
27-Sep-16 9:44am
View
Thanks a lot. Didn't recall that a comma was necessary. Actually I used this form to get in touch with the patenting department at Google. Guess they don't want new ideas from outside the company. :)
petter2012
20-Jun-16 9:54am
View
Thanks Bill!
That was actually several good suggestions. For this particular project I'll stick to a partial class, as that makes getting to XAML stuff mush easier. (In this case tht framweork is written by another person so digging into that would mean some work for me.)
Still, I think it would be nice to have coloring/highlighing available in VS. I wonder why this has never been implemented.
Thanks again,
Petter
petter2012
18-Jun-16 13:33pm
View
Yes, thanks, this is what happens:
First, the Page has (probably) focus and when I click my keyboard keys (Up Arrow for making the player go up for example) it works fine.
Then, I click somewhere in the game window with the mouse.
Now, the keys don't work anymore. I hope that's clearer.
That's why I tried the this.KeyDown code. I tried Page.KeyPreview = True, but KeyPreview doesn't seem to be available in UWP (?).
petter2012
18-Jun-16 11:46am
View
Thanks a lot for your reply. The fault is not in the two methods (the list hasn't been updated there yet) but I'll look to you other suggestions. Thanks again.
petter2012
18-Jun-16 5:57am
View
Thanks so much for taking the time to write such a detailed answer. In my case it's only a onepage game, so working in this manner will be much more work than just using another event handler or so. I'll need to sit down and Think of how I should proceed...
Thanks again.
petter2012
18-Jun-16 4:02am
View
Hi again,
To anyone looking for an answer to this question: I suddenly remembered that partial classes are great for this. I'm now using a partial class as a "wrapper" or an interface between the normal code-behind code and the more elaborate classes. This means that another coder can't (easily) accidentally trash the "wrapping" code.
petter2012
14-Jun-16 8:54am
View
Okey, thank you. It would be handy though! It could be used not only for hindering changes but also for pointing to relevant code.
petter2012
11-Jan-16 8:38am
View
AH okey - said and done! Thanks again.
petter2012
11-Jan-16 8:24am
View
Yes, I agree. I asked the question at MSDN - hope to get some help there.
I do feel bad as you helped me so much. Should I click for a five star answer and check the question as resolved even if we couldn't solve it?
Many thanks for all your help.
Petter
petter2012
11-Jan-16 8:01am
View
Hi again,
Yes, you are quite correct: during dragging there are two images present.
I tried your suggestion and played around with DataPackageOperation, but nothing happened with the code below:
private void imgDrag_DragStarting(UIElement sender, DragStartingEventArgs args)
{
args.Data.RequestedOperation = DataPackageOperation.Move;
I guess that this wasn't really what was needed after all.
Yes, i agree with you that the UWP documentation seems very incomplete. I've tried more things which I think should be rather startightforward but it looks like uncharted territory. :)
petter2012
11-Jan-16 6:49am
View
Hi again,
Thank you so much for your code!
Regrettably the DragDropEffects and a few others are not available in UWP, so I needed to look further.
Here's some code that I got to work, apart from that the original image becomes duplicated when I drag it. However, it gets removed and placed correctly when I release the mouse button.
<grid x:name="gridMain" removed="#FFFD3535" height="640" verticalalignment="Top">
<Canvas x:Name="cnvDrop" AllowDrop="True" DragOver="cnvDrop_DragOver" Drop="cnvDrop_Drop"
Background="LightBlue" Margin="10,138,140,134">
<Image x:Name="imgDrag" HorizontalAlignment="Left" Height="68" VerticalAlignment="Top" Width="64" CanDrag="True" Source="img/board.png" DragStarting="imgDrag_DragStarting" Canvas.Left="12" Canvas.Top="16" Stretch="Fill"/>
</Canvas>
private void imgDrag_DragStarting(UIElement sender, DragStartingEventArgs args)
{
//cnvDrop.Children.Remove(imgDrag);
}
private void cnvDrop_DragOver(object sender, DragEventArgs e)
{
e.AcceptedOperation = DataPackageOperation.Move;
}
private void cnvDrop_Drop(object sender, DragEventArgs e)
{
var point = e.GetPosition(cnvDrop);
Canvas.SetLeft(imgDrag, (point.X));
Canvas.SetTop(imgDrag, (point.Y));
//cnvDrop.Children.Add(imgDrag);
}
...so I'm not sure I do this the easiest way, but then again this seems unnecessarily hard (after all, I think a drag and drop operation should per default result in, well, an object being dragged and dropped...). And the only thing that remains is to somehow get rid of the original image in the DragStarting event.
(The commented code takes care of this problem, but it also deletes the image being moved.)
petter2012
10-Jan-16 5:27am
View
Hi,
Thanks, I guess that too (that it didn't have anything to do with UWP really but how drag and drop works in general).
The problem actually arises right when I start dragging the object (such as the textblock). The object gets copied instead of moved and the stops sign appears at once - which may not be so strange given that the object can't be dropped on the main grid.
So I guess I should write something in the DragStarting event but I don't know what to write and can't find anyting suitable online (to my surprise).
petter2012
7-Jan-16 20:24pm
View
Hi,
Thanks for some very useful information! This will make the task easier.
Best wishes for the new year.
Petter
petter2012
4-Jan-16 20:34pm
View
Ok, thanks a lot. I'll try that!
Petter
petter2012
4-Jan-16 16:19pm
View
Hi again,
According to posts in this thread: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/04d69ee6-d4f5-4f8f-a115-d89f7bcbc032/how-to-alter-column-to-identity11
it is possible to do it via the UI of SSMS, but not in code. Unfortunately i don't have the latest version installed so I will have to wait until I can download it. I just hope this is still the case - the posts are from 2007...
petter2012
4-Jan-16 16:13pm
View
Hi Duncan,
Thanks for the reply. However I get an error when I try to set the IDENTITY keyword on an existing column in the new db instance. Just to confirm: Is this really doable? When I surf the net for solutions I only find that one cannot set IDENTITY on an exisiting column (ie with exisiting rows/IDs).
I have removed the FK's so that's not a problem.
petter2012
30-Dec-15 4:16am
View
Wow - thank you so much for this thorough explanation! Yes, the game logic is already in place so this is exactly what I need. I actually use InkScape plus SVG export already for other vector-based stuff, but I hadn't realized it was this easy to do the game vector-based, so thanks a lot for this suggestion.
I am also used to Canvas from developing games in Silverlight using Andy Bealieu's Physics Helper (plus Farseer Physics) but have not used ViewBox, so thaht will be a new experience.
When it comes to drag'n'drop vs two-clicks, perhaps I can try to implement them both and then let the programmer decide what works best for the game in question (remember that I am creating a framework, not a game in itself).
Thanks again!
Petter
petter2012
29-Dec-15 3:48am
View
Thanks, I agree and it was a bit o a pian working so graphically with WinForms anyway. So I agree with you but I still need hints on what to use. I rephrase the heading of my question to make it more attractive. :)
petter2012
30-Oct-15 10:58am
View
Thank you, I'm sure you are correct. However, I didn't seem to have privilegies to perform a backup, and not to do a Copy database either... I ended up using the Export wizard. Now that tables and their data are moved; I only need to script the sp's as well.
Thanks again!
petter2012
5-Oct-15 2:57am
View
Ah great - thanks for your comment. I'll look more into web apps then!
petter2012
28-Apr-15 18:02pm
View
That was a very interesting point! I agree totally that with large projects, test driven applications must be wise. (Actually it's the first strong argument I've seen for ASP.NET MVC and WPF over ASP.NET and WinForms.)
I also agree that MVC and MPF are harder to dig into, and this in turn leads me to the fear of more complex, and thus more error-prone and expensive, development. Writing code is often quite fast, as long as one knows what to write, and WinForms + ASP.NET makes writing reliable code really easy.
petter2012
28-Apr-15 12:25pm
View
Thanks for your reply! I keep the question running until tomorrow and see if anyone else has ideas to share. :) Here's a URL realted to this subject that I found interesting:
http://pragmateek.com/is-wpf-dead-the-present-and-future-of-wpf/
Petter
petter2012
23-Feb-15 12:44pm
View
Thanks, but does this mean that a SelectCommand is not safe either? If I had been in charge of the .NET framework, I would have made sure it was. :)
Note: I understand more code could be added to a SELECT command and that way create a sql injection, I only wonder if it's not taken care of by using a specified SelectCommand.
Thanks again!
petter2012
24-Nov-14 5:51am
View
Thanks! Yes, I understand it could be written one way or the other without problems. I thought that perhaps static classes would have better performance, but in WinForms - who cares. :)
petter2012
24-Nov-14 2:31am
View
Thanks! I downloaded the source code and it looks good. I also read some of the text at Amazon. Though the book doesn't really incorporate OOAD with OOP, it still looks interesting and well written.
I have read the Head First OOAD book. I don't mind the humour in it, but the problem with the book is that it takes so long for it to get to the point. It's actually in the final chapter that the book starts getting interesting, and then it just stops. :( And of course, it's java.
petter2012
24-Nov-14 2:25am
View
Exciting! Thanks a lot!
petter2012
23-Nov-14 19:50pm
View
Hi again,
It really seems as if there is no good boook for this, strange as it seems. Deitel & Deitel's book is good however, and has some info on UML and the OOAD process as well.
petter2012
23-Nov-14 19:45pm
View
Hi,
Thanks so much for your kind offer.
I use VS 2010 Premium and also have 2012 Premium installed. Right now I work with .NET 4 Client Profile.
From your reply I guess that there is no really good way of contacting Game.cs from the form. The only possible way I can think about would be to somehow override all listening to user input, so instead of trapping mouse movements in forms, they get trapped in Game.cs instead.
petter2012
23-Nov-14 13:01pm
View
Thank you so much for the clarification! This means, I take it, that a lightweight OO approach would still be to ue only a form for input and output, and to have a collection of pieces be instantiated by the form in question - as you said a form is MVC in one place.
The other rather straightforward way of accomplishing this would be to let a Game.cs file control everything and flush out its data (array) to a formdisplaying the board. But if so, how on earth do I send the mousemove events back to Game.cs?
ie:
void pb_MouseMove(object sender, MouseEventArgs e)
{
//I have some code already that figure out which position in teh array is moved to what position, but how do I send this back to Game.cs?
}
petter2012
22-Nov-14 20:13pm
View
Hi,
Thanks for your replies! Here are the answers to your questions:
Yes, for this particular game at least, think chess/checkers etc.
Game.cs cretes an array of Pieces from a PieceCollection.cs class. This array is sent to Board.cs. In Board.cs, I dynamically create pictureboxes representing the pieces (and empty sqaures too), so that each position in the array is, via a normal nested for loop, put at a new Point(100*i, 100*j). In other words, a pawn at PieceArray[1,4] is drawn as a 100*100px picturebox at x=100 and y=400.
I also add drag'n'drop behaviour to the picturebox on the fly.
So the question is: How do I get the mouseup behaviors (meaning that a piece has been moved) to be reported back to Game.cs? I can calculate so that the move is rounded correctly, so the only thing I need to send back is integers for the new position in the PieceArray. Of course, some (most) moves are illegal, and when the move has somehow been reported back to Game.cs, Rules.cs is called to check if the move is okay or not. If not, the original array is sent back to Board.cs to update the layout.
In fact, all of this works nicely as long as I don't use a Game.cs class but instead do everything directly in Board.cs (or having the other classes static). What I'm trying toachieve is a good OO implementation, but can't understand how to get the user input on the board back to Game.cs.
Also, I'd really like an answer to the second comment you made. You state it's fully possible but I don't know what to write (or omit).
Thanks again!
petter2012
21-Nov-14 10:37am
View
Thank you so much for your quick and very precise reply. Actually I already have Soldier as an abstract class, so I did something right at least. :) I find that I was also right in my assuption of the need of a Game class to differ between the game and the UI.
I still wonder though what is conceptually wrong with static classes. For example, I took a look at static classes at MSDN. They showed a temperature converter, with a static class with methods for the Fahrenheit/Celsius conversions. Just as in their case, almost all classes in my example appear only once and the Rules (I guess that's SoldierManager in your vocabulary) is not that different from the temperature conversion methods. I don't question you, I'd just like to learn the idea behind this.
petter2012
31-Aug-14 5:17am
View
Hi,
I visited the links and they really look like spam sites so I can't recomment them to anyone (I didn't dare to stay on the site for long).
petter2012
30-Aug-14 10:28am
View
Thanks! Looks interesting and I'll probably buy it, but it says in the description of the book that it doesn't cover the basics of UML. It's like they hint in their text: "For the developer already familiar with UML and looking to get the best out of Visio, the Visual Studio .NET and Visio for Enterprise Architects combination is weakly documented, and the quality information needed to realize the time-saving features of Visio just does not seem to be available, until now."
In other words, my question seem legit so to speak - there's not much literature that combines UML and VS (strangely enough).
petter2012
29-Aug-14 19:51pm
View
Thanks! I'll look at the videos. However, I need to suggest a coursebook for a programming course, so I really do need a coursebook. :)
petter2012
29-Aug-14 8:45am
View
Thanks for the link!
Great stuff and I'll bookmark the link, but there's no OOAD/UML.
Thanks again
petter2012
29-Oct-13 20:25pm
View
I had no idea! I will create the winforms app immediately and try it out (I thought I had to do a console app or something). Thanks a lot!
petter2012
19-Jun-13 23:49pm
View
Thank you very much for your clarifications!
petter2012
19-Jun-13 23:48pm
View
Thanks for the pointers!
petter2012
2-Apr-13 3:41am
View
Hej Jörgen!
Thanks a lot for the insightful respone and for the pointers.
Petter :)
petter2012
1-Apr-13 8:41am
View
I totally agree (SQL is such a hack when one tries to do more than the basic and very neat CRUD operations).
However, I can't figure out how to accomplish this. I mean, sending my code to the C# methods would work just fine, but how could I evaluate the Sql data this way? What I need to do is (I think) to
1. call my stored procedure, including calls to different functions/metods
2. In my where statements, call the functions/methods for each parameter in order to get a weighing number/rating,
3. create a new sql tabl based on the ratings derived from the functions/methods.
This would mean that Sql functions would be the only way to solve this problem, but if it would be possible using C#, then so much better.
petter2012
31-Mar-13 18:45pm
View
Ah - okey I see. Then I understood you correctly after all. Thanks! :)
petter2012
31-Mar-13 15:55pm
View
Hi,
Thanks a lot for your reply!
If I understand you correctly, you mean that .Net doesn't dispose of the image just because I told it to. (The Dispose method is .Net's own, not a method of mine.)
So do you mean that I should do a while loop, kind of:
<pre lang="c#">while !(disposed)
{
Thread.Sleep(500);
}</pre>
This sounds a bit spooky to me, but perhaps I read you wrong.
Thanks again,
Petter
petter2012
23-Mar-13 14:41pm
View
Hi, Thanks for your reply. Yes, I think as well that this could be done rather quickly (for educational purposes only). What I'd like to be able to do is to, say, display news and perhaps select something from table A where the ID = the ID in another table.
I'm still thinking on how to implement the engine. I guess I could write a class in C# which simply parses the XML-ish text, and hook up methods to the ten (or so) most commonly used SQL statements. Rather interesting, really! :)
Show More