• Home
  • Index
  • Search
  • Download
  • Server Rules
  • House Roleplay Laws
  • Player Utilities
  • Player Help
  • Forum Utilities
  • Returning Player?
  • Toggle Sidebar
Interactive Nav-Map
Interactive DarkMap
Tutorials
New Wiki
ID reference
Restart reference
Players Online
Player Activity
Faction Activity
Player Base Status
Discord Help Channel
DarkStat
Server public configs
POB Administration
Missing Powerplant
Stuck in Connecticut
Account Banned
Lost Ship/Account
POB Restoration
Disconnected
Member List
Forum Stats
Show Team
View New Posts
View Today's Posts
Calendar
Help
Archive Mode




Hi there Guest,  
Existing user?   Sign in    Create account
Login
Username:
Password: Lost Password?
 
  Discovery Gaming Community The Community Real Life Discussion
« Previous 1 … 80 81 82 83 84 … 246 Next »
A lil C# help

Server Time (24h)

Players Online

Active Events - Scoreboard

Latest activity

Pages (3): 1 2 3 Next »
A lil C# help
Offline Huhuh
05-02-2013, 12:05 PM,
#1
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

I'm making a space invaders game for uni in C#

Can someone please instruct me on how to use a timer to update the frames so the sprites move about (smoothly)?

[Image: 6fZYcda.gif]

Reply  
Offline Bitjump
05-02-2013, 12:19 PM, (This post was last modified: 05-02-2013, 12:21 PM by Bitjump.)
#2
Member
Posts: 25
Threads: 1
Joined: Apr 2013

If you can elaborate, I can probably help. You mean like a timer to control your average update/render cycle?
Reply  
Offline massdriver
05-02-2013, 12:44 PM, (This post was last modified: 05-02-2013, 12:44 PM by massdriver.)
#3
Member
Posts: 698
Threads: 34
Joined: Dec 2009

should look like (not actual working code but a basic msg runloop section):

MSG msg;
PeekMessage( &msg, NULL, 0, 0, PM_REMOVE );

// Some timer object
_timer.Start();

while( msg.message != WM_QUIT )
{
// Process all win messages
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
continue;
};

// Update time based actions
float time = _timer.GetElapsedTime();

if( time > 0.0f )
Update( time );

// Render frame
Render();
}

[Image: UHiNafb.png]
  Reply  
Offline Bitjump
05-02-2013, 12:48 PM,
#4
Member
Posts: 25
Threads: 1
Joined: Apr 2013

Massdriver is spot on.

Basically, store the current time (in ms). Handle input, then update positions, then render. When you loop, calculate the ms passed since last update and pass it to the update and render methods. It's usually referred to as "delta". Rinse and repeat, updating according to calculations done with delta.
Reply  
Offline utrack
05-02-2013, 12:48 PM, (This post was last modified: 05-02-2013, 12:51 PM by utrack.)
#5
Member
Posts: 368
Threads: 16
Joined: Jan 2013

@massdriver: C# is more high-level than C++. Smile

use Timer.Tick event - it called each time timer ticks (duh)
or you need something more specific?

You'll need to make interval ~40 msec or so for 25 fps. Possible invoking it from another thread so main window won't get locked for too long
Also it's good idea to use 2D SlimDX or Ogre so you'll get real DirectX and your invaders won't get locked at all - and you'll get real game. Smile

[11:20:20] aerelm: its not fl dev work if you dont have to power through the whole thing on your own
[11:20:32] aerelm: help is for pussy devs like in dota
topic Discovery Server Watcher | FL Open Server | Account Manager G2 topic
something something zoners
  Reply  
Offline Huhuh
05-02-2013, 01:18 PM,
#6
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

(05-02-2013, 12:48 PM)utrack Wrote: use Timer.Tick event - it called each time timer ticks (duh)
or you need something more specific?

That sounds spot on. Where can I access that?

Basically, I need my space invaders to move to the right at a constant rate for a period of time, then move down, and then left at a constant rate.

I will also need each shot fired to move upwards or downwards (depending on the firer) at a constant rate until it either leaves the game area or intercepts a valid hitbox (which technically don't exist, as I'll simply check if the shot is within a certain area from the point of origin of each entity).

[Image: 6fZYcda.gif]

Reply  
Offline massdriver
05-02-2013, 01:23 PM,
#7
Member
Posts: 698
Threads: 34
Joined: Dec 2009

(05-02-2013, 12:48 PM)utrack Wrote: @massdriver: C# is more high-level than C++. Smile
[Image: kYRAwAg.jpg]

indeed its above any planes

[Image: UHiNafb.png]
  Reply  
Offline massdriver
05-02-2013, 01:24 PM,
#8
Member
Posts: 698
Threads: 34
Joined: Dec 2009

(05-02-2013, 01:18 PM)Crackpunch Wrote:
(05-02-2013, 12:48 PM)utrack Wrote: use Timer.Tick event - it called each time timer ticks (duh)
or you need something more specific?

That sounds spot on. Where can I access that?

Basically, I need my space invaders to move to the right at a constant rate for a period of time, then move down, and then left at a constant rate.

I will also need each shot fired to move upwards or downwards (depending on the firer) at a constant rate until it either leaves the game area or intercepts a valid hitbox (which technically don't exist, as I'll simply check if the shot is within a certain area from the point of origin of each entity).

also try appgamekit, must go for you ideally

[Image: UHiNafb.png]
  Reply  
Offline Huhuh
05-02-2013, 01:55 PM,
#9
Member
Posts: 2,458
Threads: 148
Joined: Apr 2010

It needs to be coded in C# (which is indeed higher level than C++).

[Image: 6fZYcda.gif]

Reply  
Offline utrack
05-02-2013, 01:56 PM,
#10
Member
Posts: 368
Threads: 16
Joined: Jan 2013

@massdriver: rofl
i can't into english lately

@crackpunch: well, here's example
Code:
public partial class FormWithTimer : Form
    {
        Timer timer = new Timer();

        public FormWithTimer()
        {
            InitializeComponent();

            timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
            timer.Interval = (1000) / (25);             // 25 FPS
            timer.Enabled = true;                       // Enable the timer
            timer.Start();                              // Start the timer
        }

        void timer_Tick(object sender, EventArgs e)
        {
            RenewImage();
        }
    }
goes kinda like that.

For the moving part - maybe you'll need UpwardShot and DownwardShot classes ('cause there could be more than one shot at once) with refresh methods and coords properties, and Refresh() will be called by RenewImage procedure which will just add some points when called.

Then for enemies: again classes for each type of enemy and some simple variable as step count, which will be ++'d each frame - and simple "select case" with this variable which will decide which coordinate to change on refresh. After some point it should be zeroed, cause you want them to move in loop.

Then you should get all the instances with their coordinates and place bitmaps using these coords. DOne - frame ready

P.S.: this could work only for uni project, for production better use 2D DX or OpenGL
P.P.S.: this algorithm was written under the influence of beer, and i don't know what performance it'll get. The code will look nicely tho

[11:20:20] aerelm: its not fl dev work if you dont have to power through the whole thing on your own
[11:20:32] aerelm: help is for pussy devs like in dota
topic Discovery Server Watcher | FL Open Server | Account Manager G2 topic
something something zoners
  Reply  
Pages (3): 1 2 3 Next »


  • View a Printable Version
  • Subscribe to this thread


Users browsing this thread:
1 Guest(s)



Powered By MyBB, © 2002-2026 MyBB Group. Theme © 2014 iAndrew & DiscoveryGC
  • Contact Us
  •  Lite mode
Linear Mode
Threaded Mode