Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make a simple Dragon Boat Mini Game with Matlab

Shulou Source: shulou.com Published: 2022-06-01 10:28:17 10月04日 Update

Today, the editor will share with you how to use Matlab to make a simple Dragon Boat Mini Game with detailed content and clear logic. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Effect picture:

Steps

1 create Axes and import pictures

Window creation:

Mainfig=figure ('units','pixels','position', [50 100 760400],... 'Numbertitle','off','menubar','none','resize','off',... 'name','dragonBoat'); axes (' parent',Mainfig,'position', [0 011],... 'XLim', [0760],... 'YLim', [0400],... 'NextPlot','add',... 'layer','bottom',... 'Visible','on',... 'YDir','reverse',... 'XTick', [],... 'YTick', [])

Picture Import:

[bkg_C,~,~] = imread ('river.png'); [boat_C,~,boat_Alp] = imread (' boat.png'); [stone_C,~,stone_Alp] = imread ('stone.png')

The picture material can be taken from here.

2 create a timer function to move the background

DrawBkgHdl=image ([0760], [0400], bkg_C); fps = 20game = timer ('ExecutionMode',' FixedRate', 'Period',1/fps,' TimerFcn', @ dragongame); start (game) function dragongame (~, ~) tactitmaker 6; modt=mod (tPJ 720); newBkg_C=tempBkg_C (: 1mm modtrize 684mm modtfield:) Set (DrawBkgHdl,'CData',newBkg_C) end

3 draw stones and move them

In fact, five stones change their positions back and forth, and when the position of a stone decreases to a negative number, the value is increased and redrawn.

StonePos= [600stonePos 870 [1140politics 1410]; stonePos= [stonePos,randi ([90330], [4meme 1])]; for i=1:size (stonePos,1) drawStoneHdl (I) = image ([stonePos (iMagne 1)-39 stonePos (iMagne 1) + 39], [stonePos (iMagazine 2)-20 stonePos (iMagne2) + 20], stone_C,'AlphaData',stone_Alp) End function dragongame (~, ~)% here is the background part of the code% written earlier. %. StonePos (:, 1) = stonePos (:, 1)-20 stonePos 3; stonePos (stonePos (:, 1)

Tags: Knowledge articles code functions pictures stones Mini Game dragon boats production location content background movement different large picture material piles most that is effects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Xiaomi Shulou Tech Info vpn Docker